ding-react-admin 2.0.0 → 2.0.5
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 +1 -0
- package/dist/index.js +1773 -1170
- 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 +85 -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,85 +1,85 @@
|
|
|
1
|
-
import { useMemo } from "react";
|
|
2
|
-
import type { BaseSourceProps, DisplayProps, ReferenceProps } from "../types";
|
|
3
|
-
import { useRegisterColumn } from "../context/ListContext";
|
|
4
|
-
import { useChoices } from "../utils/useChoices";
|
|
5
|
-
import { renderDisplayValue } from "./TextColumn";
|
|
6
|
-
|
|
7
|
-
export type ReferenceColumnProps = BaseSourceProps &
|
|
8
|
-
ReferenceProps &
|
|
9
|
-
DisplayProps & {
|
|
10
|
-
sortable?: boolean;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
function ReferenceColumnCell({
|
|
14
|
-
record,
|
|
15
|
-
source,
|
|
16
|
-
display,
|
|
17
|
-
reference,
|
|
18
|
-
choices,
|
|
19
|
-
optionLabel,
|
|
20
|
-
optionValue,
|
|
21
|
-
}: ReferenceColumnProps & { record: Record<string, unknown> }) {
|
|
22
|
-
const { labelForValue } = useChoices(
|
|
23
|
-
choices,
|
|
24
|
-
reference,
|
|
25
|
-
optionLabel,
|
|
26
|
-
optionValue,
|
|
27
|
-
);
|
|
28
|
-
const raw = record[source];
|
|
29
|
-
if (typeof display === "function") return <>{display(record)}</>;
|
|
30
|
-
if (display && display !== source) {
|
|
31
|
-
const nested = renderDisplayValue(record, source, display);
|
|
32
|
-
return <>{nested != null ? String(nested) : "—"}</>;
|
|
33
|
-
}
|
|
34
|
-
return <>{labelForValue(raw)}</>;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function ReferenceColumn({
|
|
38
|
-
source,
|
|
39
|
-
label,
|
|
40
|
-
reference,
|
|
41
|
-
choices,
|
|
42
|
-
optionLabel = "name",
|
|
43
|
-
optionValue = "id",
|
|
44
|
-
display,
|
|
45
|
-
sortable = true,
|
|
46
|
-
}: ReferenceColumnProps) {
|
|
47
|
-
const def = useMemo(
|
|
48
|
-
() => ({
|
|
49
|
-
key: source,
|
|
50
|
-
source,
|
|
51
|
-
label,
|
|
52
|
-
sortable,
|
|
53
|
-
buildColumn: () => ({
|
|
54
|
-
title: label ?? source,
|
|
55
|
-
dataIndex: source,
|
|
56
|
-
key: source,
|
|
57
|
-
sorter: sortable ? true : undefined,
|
|
58
|
-
render: (_: unknown, record: Record<string, unknown>) => (
|
|
59
|
-
<ReferenceColumnCell
|
|
60
|
-
record={record}
|
|
61
|
-
source={source}
|
|
62
|
-
label={label}
|
|
63
|
-
reference={reference}
|
|
64
|
-
choices={choices}
|
|
65
|
-
optionLabel={optionLabel}
|
|
66
|
-
optionValue={optionValue}
|
|
67
|
-
display={display ?? optionLabel}
|
|
68
|
-
/>
|
|
69
|
-
),
|
|
70
|
-
}),
|
|
71
|
-
}),
|
|
72
|
-
[
|
|
73
|
-
source,
|
|
74
|
-
label,
|
|
75
|
-
sortable,
|
|
76
|
-
reference,
|
|
77
|
-
choices,
|
|
78
|
-
optionLabel,
|
|
79
|
-
optionValue,
|
|
80
|
-
display,
|
|
81
|
-
],
|
|
82
|
-
);
|
|
83
|
-
useRegisterColumn(def);
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import type { BaseSourceProps, DisplayProps, ReferenceProps } from "../types";
|
|
3
|
+
import { useRegisterColumn } from "../context/ListContext";
|
|
4
|
+
import { useChoices } from "../utils/useChoices";
|
|
5
|
+
import { renderDisplayValue } from "./TextColumn";
|
|
6
|
+
|
|
7
|
+
export type ReferenceColumnProps = BaseSourceProps &
|
|
8
|
+
ReferenceProps &
|
|
9
|
+
DisplayProps & {
|
|
10
|
+
sortable?: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
function ReferenceColumnCell({
|
|
14
|
+
record,
|
|
15
|
+
source,
|
|
16
|
+
display,
|
|
17
|
+
reference,
|
|
18
|
+
choices,
|
|
19
|
+
optionLabel,
|
|
20
|
+
optionValue,
|
|
21
|
+
}: ReferenceColumnProps & { record: Record<string, unknown> }) {
|
|
22
|
+
const { labelForValue } = useChoices(
|
|
23
|
+
choices,
|
|
24
|
+
reference,
|
|
25
|
+
optionLabel,
|
|
26
|
+
optionValue,
|
|
27
|
+
);
|
|
28
|
+
const raw = record[source];
|
|
29
|
+
if (typeof display === "function") return <>{display(record)}</>;
|
|
30
|
+
if (display && display !== source) {
|
|
31
|
+
const nested = renderDisplayValue(record, source, display);
|
|
32
|
+
return <>{nested != null ? String(nested) : "—"}</>;
|
|
33
|
+
}
|
|
34
|
+
return <>{labelForValue(raw)}</>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function ReferenceColumn({
|
|
38
|
+
source,
|
|
39
|
+
label,
|
|
40
|
+
reference,
|
|
41
|
+
choices,
|
|
42
|
+
optionLabel = "name",
|
|
43
|
+
optionValue = "id",
|
|
44
|
+
display,
|
|
45
|
+
sortable = true,
|
|
46
|
+
}: ReferenceColumnProps) {
|
|
47
|
+
const def = useMemo(
|
|
48
|
+
() => ({
|
|
49
|
+
key: source,
|
|
50
|
+
source,
|
|
51
|
+
label,
|
|
52
|
+
sortable,
|
|
53
|
+
buildColumn: () => ({
|
|
54
|
+
title: label ?? source,
|
|
55
|
+
dataIndex: source,
|
|
56
|
+
key: source,
|
|
57
|
+
sorter: sortable ? true : undefined,
|
|
58
|
+
render: (_: unknown, record: Record<string, unknown>) => (
|
|
59
|
+
<ReferenceColumnCell
|
|
60
|
+
record={record}
|
|
61
|
+
source={source}
|
|
62
|
+
label={label}
|
|
63
|
+
reference={reference}
|
|
64
|
+
choices={choices}
|
|
65
|
+
optionLabel={optionLabel}
|
|
66
|
+
optionValue={optionValue}
|
|
67
|
+
display={display ?? optionLabel}
|
|
68
|
+
/>
|
|
69
|
+
),
|
|
70
|
+
}),
|
|
71
|
+
}),
|
|
72
|
+
[
|
|
73
|
+
source,
|
|
74
|
+
label,
|
|
75
|
+
sortable,
|
|
76
|
+
reference,
|
|
77
|
+
choices,
|
|
78
|
+
optionLabel,
|
|
79
|
+
optionValue,
|
|
80
|
+
display,
|
|
81
|
+
],
|
|
82
|
+
);
|
|
83
|
+
useRegisterColumn(def);
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
import { useMemo } from "react";
|
|
2
|
-
import type { BaseSourceProps, DisplayProps, ReferenceProps } from "../types";
|
|
3
|
-
import { useRegisterColumn } from "../context/ListContext";
|
|
4
|
-
import { useChoices } from "../utils/useChoices";
|
|
5
|
-
|
|
6
|
-
export type ReferenceManyColumnProps = BaseSourceProps &
|
|
7
|
-
ReferenceProps &
|
|
8
|
-
DisplayProps & {
|
|
9
|
-
sortable?: boolean;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
function ReferenceManyColumnCell({
|
|
13
|
-
record,
|
|
14
|
-
source,
|
|
15
|
-
reference,
|
|
16
|
-
choices,
|
|
17
|
-
optionLabel,
|
|
18
|
-
optionValue,
|
|
19
|
-
}: ReferenceManyColumnProps & { record: Record<string, unknown> }) {
|
|
20
|
-
const { labelsForValues } = useChoices(
|
|
21
|
-
choices,
|
|
22
|
-
reference,
|
|
23
|
-
optionLabel,
|
|
24
|
-
optionValue,
|
|
25
|
-
);
|
|
26
|
-
const raw = record[source];
|
|
27
|
-
const values = Array.isArray(raw) ? raw : [];
|
|
28
|
-
return <>{labelsForValues(values)}</>;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function ReferenceManyColumn({
|
|
32
|
-
source,
|
|
33
|
-
label,
|
|
34
|
-
reference,
|
|
35
|
-
choices,
|
|
36
|
-
optionLabel = "name",
|
|
37
|
-
optionValue = "id",
|
|
38
|
-
sortable = false,
|
|
39
|
-
}: ReferenceManyColumnProps) {
|
|
40
|
-
const def = useMemo(
|
|
41
|
-
() => ({
|
|
42
|
-
key: source,
|
|
43
|
-
source,
|
|
44
|
-
label,
|
|
45
|
-
sortable,
|
|
46
|
-
buildColumn: () => ({
|
|
47
|
-
title: label ?? source,
|
|
48
|
-
dataIndex: source,
|
|
49
|
-
key: source,
|
|
50
|
-
sorter: sortable ? true : undefined,
|
|
51
|
-
render: (_: unknown, record: Record<string, unknown>) => (
|
|
52
|
-
<ReferenceManyColumnCell
|
|
53
|
-
record={record}
|
|
54
|
-
source={source}
|
|
55
|
-
reference={reference}
|
|
56
|
-
choices={choices}
|
|
57
|
-
optionLabel={optionLabel}
|
|
58
|
-
optionValue={optionValue}
|
|
59
|
-
/>
|
|
60
|
-
),
|
|
61
|
-
}),
|
|
62
|
-
}),
|
|
63
|
-
[source, label, sortable, reference, choices, optionLabel, optionValue],
|
|
64
|
-
);
|
|
65
|
-
useRegisterColumn(def);
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import type { BaseSourceProps, DisplayProps, ReferenceProps } from "../types";
|
|
3
|
+
import { useRegisterColumn } from "../context/ListContext";
|
|
4
|
+
import { useChoices } from "../utils/useChoices";
|
|
5
|
+
|
|
6
|
+
export type ReferenceManyColumnProps = BaseSourceProps &
|
|
7
|
+
ReferenceProps &
|
|
8
|
+
DisplayProps & {
|
|
9
|
+
sortable?: boolean;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
function ReferenceManyColumnCell({
|
|
13
|
+
record,
|
|
14
|
+
source,
|
|
15
|
+
reference,
|
|
16
|
+
choices,
|
|
17
|
+
optionLabel,
|
|
18
|
+
optionValue,
|
|
19
|
+
}: ReferenceManyColumnProps & { record: Record<string, unknown> }) {
|
|
20
|
+
const { labelsForValues } = useChoices(
|
|
21
|
+
choices,
|
|
22
|
+
reference,
|
|
23
|
+
optionLabel,
|
|
24
|
+
optionValue,
|
|
25
|
+
);
|
|
26
|
+
const raw = record[source];
|
|
27
|
+
const values = Array.isArray(raw) ? raw : [];
|
|
28
|
+
return <>{labelsForValues(values)}</>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function ReferenceManyColumn({
|
|
32
|
+
source,
|
|
33
|
+
label,
|
|
34
|
+
reference,
|
|
35
|
+
choices,
|
|
36
|
+
optionLabel = "name",
|
|
37
|
+
optionValue = "id",
|
|
38
|
+
sortable = false,
|
|
39
|
+
}: ReferenceManyColumnProps) {
|
|
40
|
+
const def = useMemo(
|
|
41
|
+
() => ({
|
|
42
|
+
key: source,
|
|
43
|
+
source,
|
|
44
|
+
label,
|
|
45
|
+
sortable,
|
|
46
|
+
buildColumn: () => ({
|
|
47
|
+
title: label ?? source,
|
|
48
|
+
dataIndex: source,
|
|
49
|
+
key: source,
|
|
50
|
+
sorter: sortable ? true : undefined,
|
|
51
|
+
render: (_: unknown, record: Record<string, unknown>) => (
|
|
52
|
+
<ReferenceManyColumnCell
|
|
53
|
+
record={record}
|
|
54
|
+
source={source}
|
|
55
|
+
reference={reference}
|
|
56
|
+
choices={choices}
|
|
57
|
+
optionLabel={optionLabel}
|
|
58
|
+
optionValue={optionValue}
|
|
59
|
+
/>
|
|
60
|
+
),
|
|
61
|
+
}),
|
|
62
|
+
}),
|
|
63
|
+
[source, label, sortable, reference, choices, optionLabel, optionValue],
|
|
64
|
+
);
|
|
65
|
+
useRegisterColumn(def);
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import { useMemo } from "react";
|
|
2
|
-
import type { BaseSourceProps } from "../types";
|
|
3
|
-
import { getFormValue } from "../utils/getFormValue";
|
|
4
|
-
import { useRegisterColumn } from "../context/ListContext";
|
|
5
|
-
|
|
6
|
-
export type TextColumnProps = BaseSourceProps & {
|
|
7
|
-
sortable?: boolean;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export function TextColumn({ source, label, sortable = true }: TextColumnProps) {
|
|
11
|
-
const def = useMemo(
|
|
12
|
-
() => ({
|
|
13
|
-
key: source,
|
|
14
|
-
source,
|
|
15
|
-
label,
|
|
16
|
-
sortable,
|
|
17
|
-
buildColumn: () => ({
|
|
18
|
-
title: label ?? source,
|
|
19
|
-
dataIndex: source,
|
|
20
|
-
key: source,
|
|
21
|
-
sorter: sortable ? true : undefined,
|
|
22
|
-
}),
|
|
23
|
-
}),
|
|
24
|
-
[source, label, sortable],
|
|
25
|
-
);
|
|
26
|
-
useRegisterColumn(def);
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function renderDisplayValue(
|
|
31
|
-
record: Record<string, unknown>,
|
|
32
|
-
source: string,
|
|
33
|
-
display?: string | ((record: Record<string, unknown>) => unknown),
|
|
34
|
-
): unknown {
|
|
35
|
-
if (typeof display === "function") return display(record);
|
|
36
|
-
if (display) return getFormValue(record, display);
|
|
37
|
-
return record[source];
|
|
38
|
-
}
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import type { BaseSourceProps } from "../types";
|
|
3
|
+
import { getFormValue } from "../utils/getFormValue";
|
|
4
|
+
import { useRegisterColumn } from "../context/ListContext";
|
|
5
|
+
|
|
6
|
+
export type TextColumnProps = BaseSourceProps & {
|
|
7
|
+
sortable?: boolean;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function TextColumn({ source, label, sortable = true }: TextColumnProps) {
|
|
11
|
+
const def = useMemo(
|
|
12
|
+
() => ({
|
|
13
|
+
key: source,
|
|
14
|
+
source,
|
|
15
|
+
label,
|
|
16
|
+
sortable,
|
|
17
|
+
buildColumn: () => ({
|
|
18
|
+
title: label ?? source,
|
|
19
|
+
dataIndex: source,
|
|
20
|
+
key: source,
|
|
21
|
+
sorter: sortable ? true : undefined,
|
|
22
|
+
}),
|
|
23
|
+
}),
|
|
24
|
+
[source, label, sortable],
|
|
25
|
+
);
|
|
26
|
+
useRegisterColumn(def);
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function renderDisplayValue(
|
|
31
|
+
record: Record<string, unknown>,
|
|
32
|
+
source: string,
|
|
33
|
+
display?: string | ((record: Record<string, unknown>) => unknown),
|
|
34
|
+
): unknown {
|
|
35
|
+
if (typeof display === "function") return display(record);
|
|
36
|
+
if (display) return getFormValue(record, display);
|
|
37
|
+
return record[source];
|
|
38
|
+
}
|
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createContext,
|
|
3
|
-
useCallback,
|
|
4
|
-
useContext,
|
|
5
|
-
useEffect,
|
|
6
|
-
useMemo,
|
|
7
|
-
useState,
|
|
8
|
-
type ReactNode,
|
|
9
|
-
} from "react";
|
|
10
|
-
import type { FilterDefinition } from "../types";
|
|
11
|
-
|
|
12
|
-
type FilterContextValue = {
|
|
13
|
-
registerFilter: (def: FilterDefinition) => () => void;
|
|
14
|
-
filters: FilterDefinition[];
|
|
15
|
-
values: Record<string, unknown>;
|
|
16
|
-
setFilterValue: (source: string, value: unknown) => void;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const FilterContext = createContext<FilterContextValue | null>(null);
|
|
20
|
-
|
|
21
|
-
export function FilterContextProvider({
|
|
22
|
-
children,
|
|
23
|
-
values,
|
|
24
|
-
setFilterValue,
|
|
25
|
-
}: {
|
|
26
|
-
children: ReactNode;
|
|
27
|
-
values: Record<string, unknown>;
|
|
28
|
-
setFilterValue: (source: string, value: unknown) => void;
|
|
29
|
-
}) {
|
|
30
|
-
const [filters, setFilters] = useState<FilterDefinition[]>([]);
|
|
31
|
-
|
|
32
|
-
const registerFilter = useCallback((def: FilterDefinition) => {
|
|
33
|
-
setFilters((prev) => {
|
|
34
|
-
const idx = prev.findIndex((f) => f.key === def.key);
|
|
35
|
-
if (idx < 0) return [...prev, def];
|
|
36
|
-
if (prev[idx] === def) return prev;
|
|
37
|
-
const next = [...prev];
|
|
38
|
-
next[idx] = def;
|
|
39
|
-
return next;
|
|
40
|
-
});
|
|
41
|
-
return () => {
|
|
42
|
-
setFilters((prev) => prev.filter((f) => f.key !== def.key));
|
|
43
|
-
};
|
|
44
|
-
}, []);
|
|
45
|
-
|
|
46
|
-
const value = useMemo(
|
|
47
|
-
(): FilterContextValue => ({
|
|
48
|
-
filters,
|
|
49
|
-
values,
|
|
50
|
-
setFilterValue,
|
|
51
|
-
registerFilter,
|
|
52
|
-
}),
|
|
53
|
-
[filters, values, setFilterValue, registerFilter],
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
return (
|
|
57
|
-
<FilterContext.Provider value={value}>{children}</FilterContext.Provider>
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export function useFilterContext() {
|
|
62
|
-
return useContext(FilterContext);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function useRegisterFilter(def: FilterDefinition) {
|
|
66
|
-
const registerFilter = useFilterContext()?.registerFilter;
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
if (!registerFilter) return;
|
|
69
|
-
return registerFilter(def);
|
|
70
|
-
}, [registerFilter, def]);
|
|
71
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
useCallback,
|
|
4
|
+
useContext,
|
|
5
|
+
useEffect,
|
|
6
|
+
useMemo,
|
|
7
|
+
useState,
|
|
8
|
+
type ReactNode,
|
|
9
|
+
} from "react";
|
|
10
|
+
import type { FilterDefinition } from "../types";
|
|
11
|
+
|
|
12
|
+
type FilterContextValue = {
|
|
13
|
+
registerFilter: (def: FilterDefinition) => () => void;
|
|
14
|
+
filters: FilterDefinition[];
|
|
15
|
+
values: Record<string, unknown>;
|
|
16
|
+
setFilterValue: (source: string, value: unknown) => void;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const FilterContext = createContext<FilterContextValue | null>(null);
|
|
20
|
+
|
|
21
|
+
export function FilterContextProvider({
|
|
22
|
+
children,
|
|
23
|
+
values,
|
|
24
|
+
setFilterValue,
|
|
25
|
+
}: {
|
|
26
|
+
children: ReactNode;
|
|
27
|
+
values: Record<string, unknown>;
|
|
28
|
+
setFilterValue: (source: string, value: unknown) => void;
|
|
29
|
+
}) {
|
|
30
|
+
const [filters, setFilters] = useState<FilterDefinition[]>([]);
|
|
31
|
+
|
|
32
|
+
const registerFilter = useCallback((def: FilterDefinition) => {
|
|
33
|
+
setFilters((prev) => {
|
|
34
|
+
const idx = prev.findIndex((f) => f.key === def.key);
|
|
35
|
+
if (idx < 0) return [...prev, def];
|
|
36
|
+
if (prev[idx] === def) return prev;
|
|
37
|
+
const next = [...prev];
|
|
38
|
+
next[idx] = def;
|
|
39
|
+
return next;
|
|
40
|
+
});
|
|
41
|
+
return () => {
|
|
42
|
+
setFilters((prev) => prev.filter((f) => f.key !== def.key));
|
|
43
|
+
};
|
|
44
|
+
}, []);
|
|
45
|
+
|
|
46
|
+
const value = useMemo(
|
|
47
|
+
(): FilterContextValue => ({
|
|
48
|
+
filters,
|
|
49
|
+
values,
|
|
50
|
+
setFilterValue,
|
|
51
|
+
registerFilter,
|
|
52
|
+
}),
|
|
53
|
+
[filters, values, setFilterValue, registerFilter],
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<FilterContext.Provider value={value}>{children}</FilterContext.Provider>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function useFilterContext() {
|
|
62
|
+
return useContext(FilterContext);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function useRegisterFilter(def: FilterDefinition) {
|
|
66
|
+
const registerFilter = useFilterContext()?.registerFilter;
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (!registerFilter) return;
|
|
69
|
+
return registerFilter(def);
|
|
70
|
+
}, [registerFilter, def]);
|
|
71
|
+
}
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import { createContext, useContext, type ReactNode } from "react";
|
|
2
|
-
|
|
3
|
-
type FormMetaContextValue = {
|
|
4
|
-
resource: string;
|
|
5
|
-
isNew: boolean;
|
|
6
|
-
disabled?: boolean;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
const FormMetaContext = createContext<FormMetaContextValue | null>(null);
|
|
10
|
-
|
|
11
|
-
export function FormMetaProvider({
|
|
12
|
-
children,
|
|
13
|
-
resource,
|
|
14
|
-
isNew,
|
|
15
|
-
disabled,
|
|
16
|
-
}: {
|
|
17
|
-
children: ReactNode;
|
|
18
|
-
resource: string;
|
|
19
|
-
isNew: boolean;
|
|
20
|
-
disabled?: boolean;
|
|
21
|
-
}) {
|
|
22
|
-
return (
|
|
23
|
-
<FormMetaContext.Provider value={{ resource, isNew, disabled }}>
|
|
24
|
-
{children}
|
|
25
|
-
</FormMetaContext.Provider>
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function useFormMeta() {
|
|
30
|
-
const ctx = useContext(FormMetaContext);
|
|
31
|
-
if (!ctx) {
|
|
32
|
-
throw new Error("Field components must be used within
|
|
33
|
-
}
|
|
34
|
-
return ctx;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function useFormMetaOptional() {
|
|
38
|
-
return useContext(FormMetaContext);
|
|
39
|
-
}
|
|
1
|
+
import { createContext, useContext, type ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
type FormMetaContextValue = {
|
|
4
|
+
resource: string;
|
|
5
|
+
isNew: boolean;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const FormMetaContext = createContext<FormMetaContextValue | null>(null);
|
|
10
|
+
|
|
11
|
+
export function FormMetaProvider({
|
|
12
|
+
children,
|
|
13
|
+
resource,
|
|
14
|
+
isNew,
|
|
15
|
+
disabled,
|
|
16
|
+
}: {
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
resource: string;
|
|
19
|
+
isNew: boolean;
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
}) {
|
|
22
|
+
return (
|
|
23
|
+
<FormMetaContext.Provider value={{ resource, isNew, disabled }}>
|
|
24
|
+
{children}
|
|
25
|
+
</FormMetaContext.Provider>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function useFormMeta() {
|
|
30
|
+
const ctx = useContext(FormMetaContext);
|
|
31
|
+
if (!ctx) {
|
|
32
|
+
throw new Error("Field components must be used within a resource form");
|
|
33
|
+
}
|
|
34
|
+
return ctx;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function useFormMetaOptional() {
|
|
38
|
+
return useContext(FormMetaContext);
|
|
39
|
+
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { createContext, useContext, type MutableRefObject, type ReactNode } from "react";
|
|
2
|
-
|
|
3
|
-
const FormSectionSourcesContext =
|
|
4
|
-
createContext<MutableRefObject<Set<string>> | null>(null);
|
|
5
|
-
|
|
6
|
-
export function FormSectionSourcesProvider({
|
|
7
|
-
sourcesRef,
|
|
8
|
-
children,
|
|
9
|
-
}: {
|
|
10
|
-
sourcesRef: MutableRefObject<Set<string>>;
|
|
11
|
-
children: ReactNode;
|
|
12
|
-
}) {
|
|
13
|
-
return (
|
|
14
|
-
<FormSectionSourcesContext.Provider value={sourcesRef}>
|
|
15
|
-
{children}
|
|
16
|
-
</FormSectionSourcesContext.Provider>
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function useFormSectionSourcesOptional() {
|
|
21
|
-
return useContext(FormSectionSourcesContext);
|
|
22
|
-
}
|
|
1
|
+
import { createContext, useContext, type MutableRefObject, type ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
const FormSectionSourcesContext =
|
|
4
|
+
createContext<MutableRefObject<Set<string>> | null>(null);
|
|
5
|
+
|
|
6
|
+
export function FormSectionSourcesProvider({
|
|
7
|
+
sourcesRef,
|
|
8
|
+
children,
|
|
9
|
+
}: {
|
|
10
|
+
sourcesRef: MutableRefObject<Set<string>>;
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
}) {
|
|
13
|
+
return (
|
|
14
|
+
<FormSectionSourcesContext.Provider value={sourcesRef}>
|
|
15
|
+
{children}
|
|
16
|
+
</FormSectionSourcesContext.Provider>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function useFormSectionSourcesOptional() {
|
|
21
|
+
return useContext(FormSectionSourcesContext);
|
|
22
|
+
}
|