ding-react-admin 2.0.0 → 2.0.4
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/LICENSE +21 -21
- package/README.md +254 -195
- package/dist/index.css +2 -0
- package/dist/index.js +1772 -1169
- package/dist/src/components/NavMenuLabel.d.ts +8 -0
- package/dist/src/components/NavMenuLabel.d.ts.map +1 -0
- package/dist/src/components/NavMenuSearch.d.ts +9 -0
- package/dist/src/components/NavMenuSearch.d.ts.map +1 -0
- package/dist/src/components/ScrollableArea.d.ts +10 -0
- package/dist/src/components/ScrollableArea.d.ts.map +1 -0
- package/dist/src/components/index.d.ts +3 -0
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/context/AuthProvider.d.ts +2 -0
- package/dist/src/context/AuthProvider.d.ts.map +1 -1
- package/dist/src/crud/FormGlobalErrorsAlert.d.ts +5 -0
- package/dist/src/crud/FormGlobalErrorsAlert.d.ts.map +1 -0
- package/dist/src/crud/ResourceForm.d.ts +1 -4
- package/dist/src/crud/ResourceForm.d.ts.map +1 -1
- package/dist/src/crud/ResourceFormModal.d.ts +7 -1
- package/dist/src/crud/ResourceFormModal.d.ts.map +1 -1
- package/dist/src/crud/ResourceRecordForm.d.ts +27 -0
- package/dist/src/crud/ResourceRecordForm.d.ts.map +1 -0
- package/dist/src/crud/fields/ReferenceField.d.ts +12 -2
- package/dist/src/crud/fields/ReferenceField.d.ts.map +1 -1
- package/dist/src/crud/fields/ReferenceInputActions.d.ts +16 -0
- package/dist/src/crud/fields/ReferenceInputActions.d.ts.map +1 -0
- package/dist/src/crud/fields/ReferenceManyField.d.ts +10 -1
- package/dist/src/crud/fields/ReferenceManyField.d.ts.map +1 -1
- package/dist/src/crud/filters/ReferenceFilter.d.ts +1 -1
- package/dist/src/crud/filters/ReferenceFilter.d.ts.map +1 -1
- package/dist/src/crud/index.d.ts +5 -0
- package/dist/src/crud/index.d.ts.map +1 -1
- package/dist/src/crud/types.d.ts +12 -0
- package/dist/src/crud/types.d.ts.map +1 -1
- package/dist/src/crud/utils/choiceSelectionUtils.d.ts +10 -0
- package/dist/src/crud/utils/choiceSelectionUtils.d.ts.map +1 -0
- package/dist/src/crud/utils/choiceSelectionUtils.test.d.ts +2 -0
- package/dist/src/crud/utils/choiceSelectionUtils.test.d.ts.map +1 -0
- package/dist/src/crud/utils/formErrors.d.ts +18 -7
- package/dist/src/crud/utils/formErrors.d.ts.map +1 -1
- package/dist/src/crud/utils/formErrors.test.d.ts +2 -0
- package/dist/src/crud/utils/formErrors.test.d.ts.map +1 -0
- package/dist/src/crud/utils/prepareFormSubmitBody.d.ts +1 -0
- package/dist/src/crud/utils/prepareFormSubmitBody.d.ts.map +1 -1
- package/dist/src/crud/utils/referenceSelectNotFoundContent.d.ts +4 -0
- package/dist/src/crud/utils/referenceSelectNotFoundContent.d.ts.map +1 -0
- package/dist/src/crud/utils/toFormData.d.ts +1 -1
- package/dist/src/crud/utils/toFormData.d.ts.map +1 -1
- package/dist/src/crud/utils/uploadReferenceUtils.d.ts +5 -0
- package/dist/src/crud/utils/uploadReferenceUtils.d.ts.map +1 -0
- package/dist/src/crud/utils/useChoices.d.ts +27 -1
- package/dist/src/crud/utils/useChoices.d.ts.map +1 -1
- package/dist/src/crud/utils/useFormRecord.d.ts +9 -7
- package/dist/src/crud/utils/useFormRecord.d.ts.map +1 -1
- package/dist/src/data/parseFormErrorHelpers.d.ts +6 -27
- package/dist/src/data/parseFormErrorHelpers.d.ts.map +1 -1
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/layouts/AdminLayout.d.ts +1 -1
- package/dist/src/layouts/AdminLayout.d.ts.map +1 -1
- package/dist/src/layouts/AuthPageLayout.d.ts.map +1 -1
- package/dist/src/layouts/navFilter.d.ts +5 -0
- package/dist/src/layouts/navFilter.d.ts.map +1 -0
- package/dist/src/layouts/navMenuItems.d.ts +6 -0
- package/dist/src/layouts/navMenuItems.d.ts.map +1 -0
- package/dist/src/types.d.ts +12 -0
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +79 -59
- package/src/app/AdminApp.tsx +34 -34
- package/src/components/AuthAlternateLink.tsx +23 -23
- package/src/components/DensitySwitch.tsx +31 -31
- package/src/components/NavMenuLabel.tsx +26 -0
- package/src/components/NavMenuSearch.tsx +76 -0
- package/src/components/ScrollableArea.tsx +46 -0
- package/src/components/ThemeSwitch.tsx +28 -28
- package/src/components/ThemeToolbar.tsx +34 -34
- package/src/components/index.ts +7 -4
- package/src/components/navMenu.css +21 -0
- package/src/components/scrollable.css +28 -0
- package/src/context/AppThemeProvider.tsx +128 -128
- package/src/context/AuthProvider.tsx +89 -77
- package/src/context/DataProvider.tsx +30 -30
- package/src/context/PermissionsProvider.tsx +57 -57
- package/src/crud/FilterBar.tsx +36 -36
- package/src/crud/FormGlobalErrorsAlert.tsx +36 -0
- package/src/crud/FormSteps.tsx +135 -135
- package/src/crud/FormTabs.tsx +126 -126
- package/src/crud/InlineFormSet.tsx +162 -162
- package/src/crud/ListActionsBar.tsx +106 -106
- package/src/crud/ResourceForm.tsx +83 -160
- package/src/crud/ResourceFormModal.tsx +75 -133
- package/src/crud/ResourceRecordForm.tsx +166 -0
- package/src/crud/columns/BooleanColumn.tsx +32 -32
- package/src/crud/columns/CustomColumn.tsx +33 -33
- package/src/crud/columns/DateColumn.tsx +28 -28
- package/src/crud/columns/ImageColumn.tsx +58 -58
- package/src/crud/columns/NumberColumn.tsx +31 -31
- package/src/crud/columns/ReferenceColumn.tsx +85 -85
- package/src/crud/columns/ReferenceManyColumn.tsx +67 -67
- package/src/crud/columns/TextColumn.tsx +38 -38
- package/src/crud/context/FilterContext.tsx +71 -71
- package/src/crud/context/FormContext.tsx +39 -39
- package/src/crud/context/FormSectionContext.tsx +22 -22
- package/src/crud/context/InlineFieldsRegistry.tsx +61 -61
- package/src/crud/context/ListContext.tsx +93 -93
- package/src/crud/fields/BooleanField.tsx +38 -38
- package/src/crud/fields/DateField.tsx +53 -53
- package/src/crud/fields/FileField.tsx +123 -123
- package/src/crud/fields/ImageField.tsx +120 -120
- package/src/crud/fields/NumberField.tsx +52 -52
- package/src/crud/fields/PasswordField.tsx +99 -99
- package/src/crud/fields/ReferenceField.tsx +237 -96
- package/src/crud/fields/ReferenceInputActions.tsx +106 -0
- package/src/crud/fields/ReferenceManyField.tsx +200 -76
- package/src/crud/fields/SelectField.tsx +48 -48
- package/src/crud/fields/TextField.tsx +46 -46
- package/src/crud/fields/uploadFieldUtils.ts +21 -21
- package/src/crud/fields/useUploadPreviewUrl.ts +20 -20
- package/src/crud/filters/BooleanFilter.tsx +38 -38
- package/src/crud/filters/DateFilter.tsx +35 -35
- package/src/crud/filters/NumberFilter.tsx +33 -33
- package/src/crud/filters/ReferenceFilter.tsx +192 -173
- package/src/crud/filters/SelectFilter.tsx +44 -44
- package/src/crud/filters/TextFilter.tsx +36 -36
- package/src/crud/index.ts +99 -94
- package/src/crud/types.ts +146 -134
- package/src/crud/utils/buildFormPayload.ts +24 -24
- package/src/crud/utils/buildInlineRowsPayload.ts +37 -37
- package/src/crud/utils/buildResourceFormSubmitBody.ts +29 -29
- package/src/crud/utils/choiceSelectionUtils.test.ts +45 -0
- package/src/crud/utils/choiceSelectionUtils.ts +116 -0
- package/src/crud/utils/formErrors.test.ts +168 -0
- package/src/crud/utils/formErrors.ts +138 -42
- package/src/crud/utils/formSectionErrors.ts +85 -85
- package/src/crud/utils/getFormValue.ts +13 -13
- package/src/crud/utils/hasUploadValues.ts +9 -9
- package/src/crud/utils/nestedFieldPath.ts +8 -8
- package/src/crud/utils/prepareFormSubmitBody.ts +22 -17
- package/src/crud/utils/referenceSelectNotFoundContent.tsx +7 -0
- package/src/crud/utils/setFormValue.ts +18 -18
- package/src/crud/utils/sortQueryParam.ts +37 -37
- package/src/crud/utils/toFormData.ts +79 -81
- package/src/crud/utils/uploadReferenceUtils.ts +44 -0
- package/src/crud/utils/useAbortableEffect.ts +17 -17
- package/src/crud/utils/useChoices.ts +330 -182
- package/src/crud/utils/useFormRecord.ts +179 -156
- package/src/crud/utils/useListQueryState.ts +191 -191
- package/src/data/abortError.test.ts +19 -19
- package/src/data/abortError.ts +10 -10
- package/src/data/createMemoryResourceHandlers.ts +78 -78
- package/src/data/createRestResourceHandlers.ts +63 -63
- package/src/data/dataUtils.test.ts +228 -220
- package/src/data/inMemoryList.ts +97 -97
- package/src/data/parseFormErrorHelpers.test.ts +201 -138
- package/src/data/parseFormErrorHelpers.ts +376 -311
- package/src/data/sortHelpers.ts +48 -48
- package/src/index.ts +211 -207
- package/src/layouts/AdminLayout.tsx +530 -382
- package/src/layouts/AuthPageLayout.tsx +87 -81
- package/src/layouts/navFilter.ts +49 -0
- package/src/layouts/navMenuItems.tsx +44 -0
- package/src/pages/LoginPage.tsx +80 -80
- package/src/pages/PlaceholderPage.tsx +9 -9
- package/src/permissions/resourcePermissions.ts +47 -47
- package/src/router/createAdminRouter.tsx +64 -64
- package/src/router/guards.tsx +63 -63
- package/src/router/routeAccess.ts +89 -89
- package/src/types.ts +10 -0
- package/src/vite-env.d.ts +1 -1
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createContext,
|
|
3
|
-
useContext,
|
|
4
|
-
useEffect,
|
|
5
|
-
type RefObject,
|
|
6
|
-
type ReactNode,
|
|
7
|
-
} from "react";
|
|
8
|
-
|
|
9
|
-
export type InlineFieldRegistration = {
|
|
10
|
-
field: string;
|
|
11
|
-
sources: string[];
|
|
12
|
-
payloadKey?: string;
|
|
13
|
-
transformRows?: (rows: Record<string, unknown>[]) => unknown;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const InlineFieldsRegistryContext =
|
|
17
|
-
createContext<RefObject<Map<string, InlineFieldRegistration>> | null>(
|
|
18
|
-
null,
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
export function InlineFieldsRegistryProvider({
|
|
22
|
-
children,
|
|
23
|
-
registryRef,
|
|
24
|
-
}: {
|
|
25
|
-
children: ReactNode;
|
|
26
|
-
registryRef: RefObject<Map<string, InlineFieldRegistration>>;
|
|
27
|
-
}) {
|
|
28
|
-
return (
|
|
29
|
-
<InlineFieldsRegistryContext.Provider value={registryRef}>
|
|
30
|
-
{children}
|
|
31
|
-
</InlineFieldsRegistryContext.Provider>
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function useInlineFieldsRegistryOptional() {
|
|
36
|
-
return useContext(InlineFieldsRegistryContext);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/** Register an inline field array (`useFieldArray` name) for save payload cleaning. */
|
|
40
|
-
export function useRegisterInlineField(
|
|
41
|
-
field: string,
|
|
42
|
-
sources: string[],
|
|
43
|
-
payloadKey?: string,
|
|
44
|
-
transformRows?: (rows: Record<string, unknown>[]) => unknown,
|
|
45
|
-
enabled = true,
|
|
46
|
-
) {
|
|
47
|
-
const registryRef = useInlineFieldsRegistryOptional();
|
|
48
|
-
|
|
49
|
-
useEffect(() => {
|
|
50
|
-
if (!enabled || !registryRef) return;
|
|
51
|
-
registryRef.current.set(field, {
|
|
52
|
-
field,
|
|
53
|
-
sources,
|
|
54
|
-
payloadKey,
|
|
55
|
-
transformRows,
|
|
56
|
-
});
|
|
57
|
-
return () => {
|
|
58
|
-
registryRef.current.delete(field);
|
|
59
|
-
};
|
|
60
|
-
}, [registryRef, field, sources, payloadKey, transformRows, enabled]);
|
|
61
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
useContext,
|
|
4
|
+
useEffect,
|
|
5
|
+
type RefObject,
|
|
6
|
+
type ReactNode,
|
|
7
|
+
} from "react";
|
|
8
|
+
|
|
9
|
+
export type InlineFieldRegistration = {
|
|
10
|
+
field: string;
|
|
11
|
+
sources: string[];
|
|
12
|
+
payloadKey?: string;
|
|
13
|
+
transformRows?: (rows: Record<string, unknown>[]) => unknown;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const InlineFieldsRegistryContext =
|
|
17
|
+
createContext<RefObject<Map<string, InlineFieldRegistration>> | null>(
|
|
18
|
+
null,
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export function InlineFieldsRegistryProvider({
|
|
22
|
+
children,
|
|
23
|
+
registryRef,
|
|
24
|
+
}: {
|
|
25
|
+
children: ReactNode;
|
|
26
|
+
registryRef: RefObject<Map<string, InlineFieldRegistration>>;
|
|
27
|
+
}) {
|
|
28
|
+
return (
|
|
29
|
+
<InlineFieldsRegistryContext.Provider value={registryRef}>
|
|
30
|
+
{children}
|
|
31
|
+
</InlineFieldsRegistryContext.Provider>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function useInlineFieldsRegistryOptional() {
|
|
36
|
+
return useContext(InlineFieldsRegistryContext);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Register an inline field array (`useFieldArray` name) for save payload cleaning. */
|
|
40
|
+
export function useRegisterInlineField(
|
|
41
|
+
field: string,
|
|
42
|
+
sources: string[],
|
|
43
|
+
payloadKey?: string,
|
|
44
|
+
transformRows?: (rows: Record<string, unknown>[]) => unknown,
|
|
45
|
+
enabled = true,
|
|
46
|
+
) {
|
|
47
|
+
const registryRef = useInlineFieldsRegistryOptional();
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (!enabled || !registryRef) return;
|
|
51
|
+
registryRef.current.set(field, {
|
|
52
|
+
field,
|
|
53
|
+
sources,
|
|
54
|
+
payloadKey,
|
|
55
|
+
transformRows,
|
|
56
|
+
});
|
|
57
|
+
return () => {
|
|
58
|
+
registryRef.current.delete(field);
|
|
59
|
+
};
|
|
60
|
+
}, [registryRef, field, sources, payloadKey, transformRows, enabled]);
|
|
61
|
+
}
|
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createContext,
|
|
3
|
-
useCallback,
|
|
4
|
-
useContext,
|
|
5
|
-
useEffect,
|
|
6
|
-
useMemo,
|
|
7
|
-
useState,
|
|
8
|
-
type ReactNode,
|
|
9
|
-
} from "react";
|
|
10
|
-
import type { ColumnDefinition } from "../types";
|
|
11
|
-
import { sortPrioritiesFromSpecs } from "../utils/sortQueryParam";
|
|
12
|
-
|
|
13
|
-
type ListContextValue = {
|
|
14
|
-
registerColumn: (def: ColumnDefinition<Record<string, unknown>>) => () => void;
|
|
15
|
-
columns: ColumnDefinition<Record<string, unknown>>[];
|
|
16
|
-
toggleSort: (field: string) => void;
|
|
17
|
-
sortFields: Set<string>;
|
|
18
|
-
sortOrders: Map<string, "ASC" | "DESC">;
|
|
19
|
-
sortPriorities: Map<string, number>;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const ListContext = createContext<ListContextValue | null>(null);
|
|
23
|
-
|
|
24
|
-
export function ListContextProvider({
|
|
25
|
-
children,
|
|
26
|
-
toggleSort,
|
|
27
|
-
sort,
|
|
28
|
-
}: {
|
|
29
|
-
children: ReactNode;
|
|
30
|
-
toggleSort: (field: string) => void;
|
|
31
|
-
sort: { field: string; order: "ASC" | "DESC" }[];
|
|
32
|
-
}) {
|
|
33
|
-
const [columns, setColumns] = useState<
|
|
34
|
-
ColumnDefinition<Record<string, unknown>>[]
|
|
35
|
-
>([]);
|
|
36
|
-
|
|
37
|
-
const sortFields = useMemo(() => new Set(sort.map((s) => s.field)), [sort]);
|
|
38
|
-
const sortOrders = useMemo(
|
|
39
|
-
() => new Map(sort.map((s) => [s.field, s.order])),
|
|
40
|
-
[sort],
|
|
41
|
-
);
|
|
42
|
-
const sortPriorities = useMemo(() => sortPrioritiesFromSpecs(sort), [sort]);
|
|
43
|
-
|
|
44
|
-
const registerColumn = useCallback(
|
|
45
|
-
(def: ColumnDefinition<Record<string, unknown>>) => {
|
|
46
|
-
setColumns((prev) => {
|
|
47
|
-
const idx = prev.findIndex((c) => c.key === def.key);
|
|
48
|
-
if (idx < 0) return [...prev, def];
|
|
49
|
-
if (prev[idx] === def) return prev;
|
|
50
|
-
const next = [...prev];
|
|
51
|
-
next[idx] = def;
|
|
52
|
-
return next;
|
|
53
|
-
});
|
|
54
|
-
return () => {
|
|
55
|
-
setColumns((prev) => prev.filter((c) => c.key !== def.key));
|
|
56
|
-
};
|
|
57
|
-
},
|
|
58
|
-
[],
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
const value = useMemo(
|
|
62
|
-
(): ListContextValue => ({
|
|
63
|
-
columns,
|
|
64
|
-
toggleSort,
|
|
65
|
-
sortFields,
|
|
66
|
-
sortOrders,
|
|
67
|
-
sortPriorities,
|
|
68
|
-
registerColumn,
|
|
69
|
-
}),
|
|
70
|
-
[columns, toggleSort, sortFields, sortOrders, sortPriorities, registerColumn],
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
return (
|
|
74
|
-
<ListContext.Provider value={value}>{children}</ListContext.Provider>
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function useListContext() {
|
|
79
|
-
const ctx = useContext(ListContext);
|
|
80
|
-
if (!ctx) {
|
|
81
|
-
throw new Error("Column components must be used within ResourceList");
|
|
82
|
-
}
|
|
83
|
-
return ctx;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function useRegisterColumn(
|
|
87
|
-
def: ColumnDefinition<Record<string, unknown>>,
|
|
88
|
-
) {
|
|
89
|
-
const { registerColumn } = useListContext();
|
|
90
|
-
useEffect(() => {
|
|
91
|
-
return registerColumn(def);
|
|
92
|
-
}, [registerColumn, def]);
|
|
93
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
useCallback,
|
|
4
|
+
useContext,
|
|
5
|
+
useEffect,
|
|
6
|
+
useMemo,
|
|
7
|
+
useState,
|
|
8
|
+
type ReactNode,
|
|
9
|
+
} from "react";
|
|
10
|
+
import type { ColumnDefinition } from "../types";
|
|
11
|
+
import { sortPrioritiesFromSpecs } from "../utils/sortQueryParam";
|
|
12
|
+
|
|
13
|
+
type ListContextValue = {
|
|
14
|
+
registerColumn: (def: ColumnDefinition<Record<string, unknown>>) => () => void;
|
|
15
|
+
columns: ColumnDefinition<Record<string, unknown>>[];
|
|
16
|
+
toggleSort: (field: string) => void;
|
|
17
|
+
sortFields: Set<string>;
|
|
18
|
+
sortOrders: Map<string, "ASC" | "DESC">;
|
|
19
|
+
sortPriorities: Map<string, number>;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const ListContext = createContext<ListContextValue | null>(null);
|
|
23
|
+
|
|
24
|
+
export function ListContextProvider({
|
|
25
|
+
children,
|
|
26
|
+
toggleSort,
|
|
27
|
+
sort,
|
|
28
|
+
}: {
|
|
29
|
+
children: ReactNode;
|
|
30
|
+
toggleSort: (field: string) => void;
|
|
31
|
+
sort: { field: string; order: "ASC" | "DESC" }[];
|
|
32
|
+
}) {
|
|
33
|
+
const [columns, setColumns] = useState<
|
|
34
|
+
ColumnDefinition<Record<string, unknown>>[]
|
|
35
|
+
>([]);
|
|
36
|
+
|
|
37
|
+
const sortFields = useMemo(() => new Set(sort.map((s) => s.field)), [sort]);
|
|
38
|
+
const sortOrders = useMemo(
|
|
39
|
+
() => new Map(sort.map((s) => [s.field, s.order])),
|
|
40
|
+
[sort],
|
|
41
|
+
);
|
|
42
|
+
const sortPriorities = useMemo(() => sortPrioritiesFromSpecs(sort), [sort]);
|
|
43
|
+
|
|
44
|
+
const registerColumn = useCallback(
|
|
45
|
+
(def: ColumnDefinition<Record<string, unknown>>) => {
|
|
46
|
+
setColumns((prev) => {
|
|
47
|
+
const idx = prev.findIndex((c) => c.key === def.key);
|
|
48
|
+
if (idx < 0) return [...prev, def];
|
|
49
|
+
if (prev[idx] === def) return prev;
|
|
50
|
+
const next = [...prev];
|
|
51
|
+
next[idx] = def;
|
|
52
|
+
return next;
|
|
53
|
+
});
|
|
54
|
+
return () => {
|
|
55
|
+
setColumns((prev) => prev.filter((c) => c.key !== def.key));
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
[],
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const value = useMemo(
|
|
62
|
+
(): ListContextValue => ({
|
|
63
|
+
columns,
|
|
64
|
+
toggleSort,
|
|
65
|
+
sortFields,
|
|
66
|
+
sortOrders,
|
|
67
|
+
sortPriorities,
|
|
68
|
+
registerColumn,
|
|
69
|
+
}),
|
|
70
|
+
[columns, toggleSort, sortFields, sortOrders, sortPriorities, registerColumn],
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<ListContext.Provider value={value}>{children}</ListContext.Provider>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function useListContext() {
|
|
79
|
+
const ctx = useContext(ListContext);
|
|
80
|
+
if (!ctx) {
|
|
81
|
+
throw new Error("Column components must be used within ResourceList");
|
|
82
|
+
}
|
|
83
|
+
return ctx;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function useRegisterColumn(
|
|
87
|
+
def: ColumnDefinition<Record<string, unknown>>,
|
|
88
|
+
) {
|
|
89
|
+
const { registerColumn } = useListContext();
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
return registerColumn(def);
|
|
92
|
+
}, [registerColumn, def]);
|
|
93
|
+
}
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import { Switch } from "antd";
|
|
2
|
-
import type { BaseSourceProps, FieldRules } from "../types";
|
|
3
|
-
import { FieldWrapper } from "./FieldWrapper";
|
|
4
|
-
|
|
5
|
-
export type BooleanFieldProps = BaseSourceProps & {
|
|
6
|
-
name?: string;
|
|
7
|
-
required?: boolean;
|
|
8
|
-
rules?: FieldRules;
|
|
9
|
-
hideLabel?: boolean;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export function BooleanField({
|
|
13
|
-
source,
|
|
14
|
-
name,
|
|
15
|
-
label,
|
|
16
|
-
required,
|
|
17
|
-
rules,
|
|
18
|
-
hideLabel,
|
|
19
|
-
}: BooleanFieldProps) {
|
|
20
|
-
return (
|
|
21
|
-
<FieldWrapper
|
|
22
|
-
source={source}
|
|
23
|
-
name={name}
|
|
24
|
-
label={label}
|
|
25
|
-
required={required}
|
|
26
|
-
rules={rules}
|
|
27
|
-
hideLabel={hideLabel}
|
|
28
|
-
>
|
|
29
|
-
{({ value, onChange, disabled }) => (
|
|
30
|
-
<Switch
|
|
31
|
-
checked={Boolean(value)}
|
|
32
|
-
onChange={onChange}
|
|
33
|
-
disabled={disabled}
|
|
34
|
-
/>
|
|
35
|
-
)}
|
|
36
|
-
</FieldWrapper>
|
|
37
|
-
);
|
|
38
|
-
}
|
|
1
|
+
import { Switch } from "antd";
|
|
2
|
+
import type { BaseSourceProps, FieldRules } from "../types";
|
|
3
|
+
import { FieldWrapper } from "./FieldWrapper";
|
|
4
|
+
|
|
5
|
+
export type BooleanFieldProps = BaseSourceProps & {
|
|
6
|
+
name?: string;
|
|
7
|
+
required?: boolean;
|
|
8
|
+
rules?: FieldRules;
|
|
9
|
+
hideLabel?: boolean;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export function BooleanField({
|
|
13
|
+
source,
|
|
14
|
+
name,
|
|
15
|
+
label,
|
|
16
|
+
required,
|
|
17
|
+
rules,
|
|
18
|
+
hideLabel,
|
|
19
|
+
}: BooleanFieldProps) {
|
|
20
|
+
return (
|
|
21
|
+
<FieldWrapper
|
|
22
|
+
source={source}
|
|
23
|
+
name={name}
|
|
24
|
+
label={label}
|
|
25
|
+
required={required}
|
|
26
|
+
rules={rules}
|
|
27
|
+
hideLabel={hideLabel}
|
|
28
|
+
>
|
|
29
|
+
{({ value, onChange, disabled }) => (
|
|
30
|
+
<Switch
|
|
31
|
+
checked={Boolean(value)}
|
|
32
|
+
onChange={onChange}
|
|
33
|
+
disabled={disabled}
|
|
34
|
+
/>
|
|
35
|
+
)}
|
|
36
|
+
</FieldWrapper>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import { DatePicker } from "antd";
|
|
2
|
-
import dayjs from "dayjs";
|
|
3
|
-
import type { BaseSourceProps, FieldRules } from "../types";
|
|
4
|
-
import { FieldWrapper } from "./FieldWrapper";
|
|
5
|
-
|
|
6
|
-
const DATE_FORMAT = "YYYY-MM-DD";
|
|
7
|
-
|
|
8
|
-
export type DateFieldProps = BaseSourceProps & {
|
|
9
|
-
name?: string;
|
|
10
|
-
required?: boolean;
|
|
11
|
-
rules?: FieldRules;
|
|
12
|
-
showTime?: boolean;
|
|
13
|
-
hideLabel?: boolean;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export function DateField({
|
|
17
|
-
source,
|
|
18
|
-
name,
|
|
19
|
-
label,
|
|
20
|
-
required,
|
|
21
|
-
rules,
|
|
22
|
-
showTime,
|
|
23
|
-
hideLabel,
|
|
24
|
-
}: DateFieldProps) {
|
|
25
|
-
return (
|
|
26
|
-
<FieldWrapper
|
|
27
|
-
source={source}
|
|
28
|
-
name={name}
|
|
29
|
-
label={label}
|
|
30
|
-
required={required}
|
|
31
|
-
rules={rules}
|
|
32
|
-
hideLabel={hideLabel}
|
|
33
|
-
>
|
|
34
|
-
{({ value, onChange, onBlur, disabled }) => (
|
|
35
|
-
<DatePicker
|
|
36
|
-
value={value ? dayjs(String(value)) : null}
|
|
37
|
-
onChange={(d) =>
|
|
38
|
-
onChange(
|
|
39
|
-
d
|
|
40
|
-
? d.format(showTime ? `${DATE_FORMAT} HH:mm:ss` : DATE_FORMAT)
|
|
41
|
-
: null,
|
|
42
|
-
)
|
|
43
|
-
}
|
|
44
|
-
onBlur={onBlur}
|
|
45
|
-
showTime={showTime}
|
|
46
|
-
disabled={disabled}
|
|
47
|
-
format={showTime ? `${DATE_FORMAT} HH:mm:ss` : DATE_FORMAT}
|
|
48
|
-
style={{ width: "100%" }}
|
|
49
|
-
/>
|
|
50
|
-
)}
|
|
51
|
-
</FieldWrapper>
|
|
52
|
-
);
|
|
53
|
-
}
|
|
1
|
+
import { DatePicker } from "antd";
|
|
2
|
+
import dayjs from "dayjs";
|
|
3
|
+
import type { BaseSourceProps, FieldRules } from "../types";
|
|
4
|
+
import { FieldWrapper } from "./FieldWrapper";
|
|
5
|
+
|
|
6
|
+
const DATE_FORMAT = "YYYY-MM-DD";
|
|
7
|
+
|
|
8
|
+
export type DateFieldProps = BaseSourceProps & {
|
|
9
|
+
name?: string;
|
|
10
|
+
required?: boolean;
|
|
11
|
+
rules?: FieldRules;
|
|
12
|
+
showTime?: boolean;
|
|
13
|
+
hideLabel?: boolean;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export function DateField({
|
|
17
|
+
source,
|
|
18
|
+
name,
|
|
19
|
+
label,
|
|
20
|
+
required,
|
|
21
|
+
rules,
|
|
22
|
+
showTime,
|
|
23
|
+
hideLabel,
|
|
24
|
+
}: DateFieldProps) {
|
|
25
|
+
return (
|
|
26
|
+
<FieldWrapper
|
|
27
|
+
source={source}
|
|
28
|
+
name={name}
|
|
29
|
+
label={label}
|
|
30
|
+
required={required}
|
|
31
|
+
rules={rules}
|
|
32
|
+
hideLabel={hideLabel}
|
|
33
|
+
>
|
|
34
|
+
{({ value, onChange, onBlur, disabled }) => (
|
|
35
|
+
<DatePicker
|
|
36
|
+
value={value ? dayjs(String(value)) : null}
|
|
37
|
+
onChange={(d) =>
|
|
38
|
+
onChange(
|
|
39
|
+
d
|
|
40
|
+
? d.format(showTime ? `${DATE_FORMAT} HH:mm:ss` : DATE_FORMAT)
|
|
41
|
+
: null,
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
onBlur={onBlur}
|
|
45
|
+
showTime={showTime}
|
|
46
|
+
disabled={disabled}
|
|
47
|
+
format={showTime ? `${DATE_FORMAT} HH:mm:ss` : DATE_FORMAT}
|
|
48
|
+
style={{ width: "100%" }}
|
|
49
|
+
/>
|
|
50
|
+
)}
|
|
51
|
+
</FieldWrapper>
|
|
52
|
+
);
|
|
53
|
+
}
|