muffin-admin 8.5.6 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/buildRA.js +5 -2
- package/dist/filters/DateRangeFilter.d.ts +1 -0
- package/dist/filters/DateRangeFilter.js +17 -0
- package/dist/filters/Filter.d.ts +2 -0
- package/dist/{inputs/FilterInput.js → filters/Filter.js} +4 -3
- package/dist/filters/index.d.ts +2 -0
- package/dist/filters/index.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/inputs/DateRangeInput.d.ts +8 -0
- package/dist/inputs/DateRangeInput.js +26 -0
- package/dist/inputs/index.d.ts +0 -1
- package/dist/inputs/index.js +0 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -1
- package/src/MuffinAdmin.tsx +6 -5
- package/src/buildRA.tsx +6 -2
- package/src/filters/DateRangeFilter.tsx +17 -0
- package/src/{inputs/FilterInput.tsx → filters/Filter.tsx} +7 -2
- package/src/filters/index.ts +2 -0
- package/src/index.tsx +1 -1
- package/src/inputs/DateRangeInput.tsx +38 -0
- package/src/inputs/index.ts +0 -1
- package/dist/inputs/FilterInput.d.ts +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "muffin-admin",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.1.0",
|
|
4
4
|
"description": "NPM package for https://github.com/klen/muffin-admin",
|
|
5
5
|
"files": [
|
|
6
6
|
"src",
|
|
@@ -23,10 +23,12 @@
|
|
|
23
23
|
},
|
|
24
24
|
"homepage": "https://github.com/klen/muffin-admin#readme",
|
|
25
25
|
"dependencies": {
|
|
26
|
+
"date-fns": "^4.1.0",
|
|
26
27
|
"js-cookie": "^3.0.5",
|
|
27
28
|
"ra-language-russian": "^4.14.2",
|
|
28
29
|
"react": "^18.3.1",
|
|
29
30
|
"react-admin": "^5.4.0",
|
|
31
|
+
"react-datepicker": "^8.1.0",
|
|
30
32
|
"react-dom": "^18.3.1",
|
|
31
33
|
"validator": "^13.12.0"
|
|
32
34
|
},
|
|
@@ -38,6 +40,7 @@
|
|
|
38
40
|
"@types/react-window": "^1.8.8",
|
|
39
41
|
"@typescript-eslint/eslint-plugin": "^7.12.0",
|
|
40
42
|
"@typescript-eslint/parser": "^7.12.0",
|
|
43
|
+
"css-loader": "^7.1.2",
|
|
41
44
|
"dotenv": "^16.4.5",
|
|
42
45
|
"eslint": "^8",
|
|
43
46
|
"eslint-config-prettier": "^9.1.0",
|
|
@@ -47,6 +50,7 @@
|
|
|
47
50
|
"husky": "^9.0.11",
|
|
48
51
|
"prettier": "^3.2",
|
|
49
52
|
"prettier-plugin-organize-imports": "^3.2",
|
|
53
|
+
"style-loader": "^4.0.0",
|
|
50
54
|
"ts-loader": "^9.5.1",
|
|
51
55
|
"typescript": "^5.4.5",
|
|
52
56
|
"webpack": "^5.91.0",
|
package/src/MuffinAdmin.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import IconButton from "@mui/material/IconButton"
|
|
2
2
|
import SvgIcon from "@mui/material/SvgIcon"
|
|
3
3
|
import Tooltip from "@mui/material/Tooltip"
|
|
4
|
+
|
|
4
5
|
import Typography from "@mui/material/Typography"
|
|
5
6
|
import {
|
|
6
7
|
AdminContext,
|
|
@@ -27,11 +28,11 @@ export function MuffinAdmin(props: AdminProps) {
|
|
|
27
28
|
const muffinI18nProvider = buildProvider(
|
|
28
29
|
backendLocales
|
|
29
30
|
? Object.fromEntries(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
Object.entries(muffinTranslations).map(([locale, messages]) => [
|
|
32
|
+
locale,
|
|
33
|
+
deepMerge({}, messages, backendLocales[locale], buildAdmin(["locale", locale]) || {}),
|
|
34
|
+
])
|
|
35
|
+
)
|
|
35
36
|
: muffinTranslations
|
|
36
37
|
)
|
|
37
38
|
|
package/src/buildRA.tsx
CHANGED
|
@@ -36,7 +36,8 @@ import {
|
|
|
36
36
|
} from "react-admin"
|
|
37
37
|
|
|
38
38
|
import { AvatarField, CopyField, EditableBooleanField, FKField, JsonField } from "./fields"
|
|
39
|
-
import {
|
|
39
|
+
import { DateRangeFilter, Filter } from "./filters"
|
|
40
|
+
import { FKInput, JsonInput, TimestampInput } from "./inputs"
|
|
40
41
|
|
|
41
42
|
const UI: Record<string, JSX.ElementType> = {
|
|
42
43
|
// Fields
|
|
@@ -68,7 +69,6 @@ const UI: Record<string, JSX.ElementType> = {
|
|
|
68
69
|
BooleanInput,
|
|
69
70
|
CheckboxGroupInput,
|
|
70
71
|
DateInput,
|
|
71
|
-
FilterInput,
|
|
72
72
|
DateTimeInput,
|
|
73
73
|
FKInput,
|
|
74
74
|
FileInput,
|
|
@@ -84,6 +84,10 @@ const UI: Record<string, JSX.ElementType> = {
|
|
|
84
84
|
SelectInput,
|
|
85
85
|
TextInput,
|
|
86
86
|
TimestampInput,
|
|
87
|
+
|
|
88
|
+
// Filters
|
|
89
|
+
Filter,
|
|
90
|
+
DateRangeFilter,
|
|
87
91
|
}
|
|
88
92
|
|
|
89
93
|
export function buildRAComponent(name: string, props: any) {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useInput } from "react-admin"
|
|
2
|
+
import { DateRangeInput } from "../inputs/DateRangeInput"
|
|
3
|
+
|
|
4
|
+
export function DateRangeFilter(props) {
|
|
5
|
+
const { field } = useInput(props)
|
|
6
|
+
|
|
7
|
+
const onChange = (dates: [Date, Date]) => {
|
|
8
|
+
field.onChange({
|
|
9
|
+
$between: dates.map((d) => d?.toISOString() || null),
|
|
10
|
+
})
|
|
11
|
+
}
|
|
12
|
+
let filterValue = field.value.$between ?? [null, null]
|
|
13
|
+
if (!Array.isArray(filterValue)) filterValue = [null, null]
|
|
14
|
+
const value = filterValue.map((d: string) => (d ? new Date(d) : d))
|
|
15
|
+
|
|
16
|
+
return <DateRangeInput value={value} onChange={onChange} {...props} />
|
|
17
|
+
}
|
|
@@ -4,7 +4,7 @@ import Menu from "@mui/material/Menu"
|
|
|
4
4
|
import MenuItem from "@mui/material/MenuItem"
|
|
5
5
|
import TextField from "@mui/material/TextField"
|
|
6
6
|
import { useState } from "react"
|
|
7
|
-
import { useInput } from "react-admin"
|
|
7
|
+
import { FieldTitle, InputProps, useInput } from "react-admin"
|
|
8
8
|
|
|
9
9
|
const OPERATORS = {
|
|
10
10
|
$eq: "=",
|
|
@@ -15,7 +15,7 @@ const OPERATORS = {
|
|
|
15
15
|
$le: "≤",
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export function
|
|
18
|
+
export function Filter({ type = "text", ...props }: InputProps) {
|
|
19
19
|
const { field } = useInput({
|
|
20
20
|
format: (value: any) => (value ? value[Object.keys(value)[0]] : ""),
|
|
21
21
|
...props,
|
|
@@ -28,6 +28,8 @@ export function FilterInput({ type = "text", ...props }: any) {
|
|
|
28
28
|
|
|
29
29
|
const [menuEl, setMenuEl] = useState(null)
|
|
30
30
|
const open = Boolean(menuEl)
|
|
31
|
+
const { label, source, resource, isRequired } = props
|
|
32
|
+
|
|
31
33
|
return (
|
|
32
34
|
<>
|
|
33
35
|
<FormGroup row sx={{ flexWrap: "nowrap" }}>
|
|
@@ -45,6 +47,9 @@ export function FilterInput({ type = "text", ...props }: any) {
|
|
|
45
47
|
value={field.value}
|
|
46
48
|
variant="outlined"
|
|
47
49
|
type={type}
|
|
50
|
+
label={
|
|
51
|
+
<FieldTitle label={label} source={source} resource={resource} isRequired={isRequired} />
|
|
52
|
+
}
|
|
48
53
|
/>
|
|
49
54
|
</FormGroup>
|
|
50
55
|
<Menu open={open} onClose={() => setMenuEl(null)} anchorEl={menuEl}>
|
package/src/index.tsx
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import TextField from "@mui/material/TextField"
|
|
2
|
+
import { enGB, ru } from "date-fns/locale"
|
|
3
|
+
import { FieldTitle, InputProps, useLocale } from "react-admin"
|
|
4
|
+
import DatePicker, { registerLocale } from "react-datepicker"
|
|
5
|
+
import "react-datepicker/dist/react-datepicker.css"
|
|
6
|
+
|
|
7
|
+
registerLocale("ru", ru)
|
|
8
|
+
registerLocale("en", enGB)
|
|
9
|
+
|
|
10
|
+
type TProps = InputProps & {
|
|
11
|
+
value: [Date, Date]
|
|
12
|
+
onChange: (value: [Date, Date]) => void
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function DateRangeInput({ value, onChange, ...props }: TProps) {
|
|
16
|
+
const [startDate, endDate] = value
|
|
17
|
+
const locale = useLocale()
|
|
18
|
+
const { label, source, resource, isRequired } = props
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<DatePicker
|
|
22
|
+
withPortal
|
|
23
|
+
locale={locale}
|
|
24
|
+
selectsRange
|
|
25
|
+
endDate={endDate}
|
|
26
|
+
onChange={onChange}
|
|
27
|
+
startDate={startDate}
|
|
28
|
+
customInput={
|
|
29
|
+
<TextField
|
|
30
|
+
variant="outlined"
|
|
31
|
+
label={
|
|
32
|
+
<FieldTitle label={label} source={source} resource={resource} isRequired={isRequired} />
|
|
33
|
+
}
|
|
34
|
+
/>
|
|
35
|
+
}
|
|
36
|
+
/>
|
|
37
|
+
)
|
|
38
|
+
}
|
package/src/inputs/index.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function FilterInput({ type, ...props }: any): import("react/jsx-runtime").JSX.Element;
|