muffin-admin 8.5.6 → 9.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muffin-admin",
3
- "version": "8.5.6",
3
+ "version": "9.0.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",
@@ -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
- Object.entries(muffinTranslations).map(([locale, messages]) => [
31
- locale,
32
- deepMerge({}, messages, backendLocales[locale], buildAdmin(["locale", locale]) || {}),
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 { FilterInput, FKInput, JsonInput, TimestampInput } from "./inputs"
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 { InputProps, useInput } from "react-admin"
2
+ import { DateRangeInput } from "../inputs/DateRangeInput"
3
+
4
+ export function DateRangeFilter(props: InputProps) {
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} />
17
+ }
@@ -15,7 +15,7 @@ const OPERATORS = {
15
15
  $le: "≤",
16
16
  }
17
17
 
18
- export function FilterInput({ type = "text", ...props }: any) {
18
+ export function Filter({ type = "text", ...props }: any) {
19
19
  const { field } = useInput({
20
20
  format: (value: any) => (value ? value[Object.keys(value)[0]] : ""),
21
21
  ...props,
@@ -0,0 +1,2 @@
1
+ export * from "./DateRangeFilter"
2
+ export * from "./Filter"
package/src/index.tsx CHANGED
@@ -36,4 +36,4 @@ export async function initAdmin(prefix = "", containerId: string = "root") {
36
36
  )
37
37
  }
38
38
 
39
- export const VERSION = "8.5.6"
39
+ export const VERSION = "9.0.0"
@@ -0,0 +1,29 @@
1
+ import TextField from "@mui/material/TextField"
2
+ import { enGB, ru } from "date-fns/locale"
3
+ import { 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 = {
11
+ value: [Date, Date]
12
+ onChange: (value: [Date, Date]) => void
13
+ }
14
+
15
+ export function DateRangeInput({ value, onChange }: TProps) {
16
+ const [startDate, endDate] = value
17
+ const locale = useLocale()
18
+ return (
19
+ <DatePicker
20
+ withPortal
21
+ locale={locale}
22
+ selectsRange
23
+ endDate={endDate}
24
+ onChange={onChange}
25
+ startDate={startDate}
26
+ customInput={<TextField variant="outlined" />}
27
+ />
28
+ )
29
+ }
@@ -1,4 +1,3 @@
1
- export * from "./FilterInput"
2
1
  export * from "./FKInput"
3
2
  export * from "./JsonInput"
4
3
  export * from "./TimestampInput"
@@ -1 +0,0 @@
1
- export declare function FilterInput({ type, ...props }: any): import("react/jsx-runtime").JSX.Element;