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,35 +1,35 @@
|
|
|
1
|
-
import { DatePicker } from "antd";
|
|
2
|
-
import dayjs from "dayjs";
|
|
3
|
-
import { useMemo } from "react";
|
|
4
|
-
import type { BaseSourceProps } from "../types";
|
|
5
|
-
import { useRegisterFilter } from "../context/FilterContext";
|
|
6
|
-
|
|
7
|
-
export type DateFilterProps = BaseSourceProps;
|
|
8
|
-
|
|
9
|
-
export function DateFilter({ source, label }: DateFilterProps) {
|
|
10
|
-
const def = useMemo(
|
|
11
|
-
() => ({
|
|
12
|
-
key: source,
|
|
13
|
-
source,
|
|
14
|
-
label,
|
|
15
|
-
render: ({
|
|
16
|
-
value,
|
|
17
|
-
onChange,
|
|
18
|
-
}: {
|
|
19
|
-
value: unknown;
|
|
20
|
-
onChange: (value: unknown) => void;
|
|
21
|
-
}) => (
|
|
22
|
-
<DatePicker
|
|
23
|
-
allowClear
|
|
24
|
-
placeholder={label ?? source}
|
|
25
|
-
value={value ? dayjs(String(value)) : null}
|
|
26
|
-
onChange={(d) => onChange(d ? d.format("YYYY-MM-DD") : undefined)}
|
|
27
|
-
style={{ minWidth: 160 }}
|
|
28
|
-
/>
|
|
29
|
-
),
|
|
30
|
-
}),
|
|
31
|
-
[source, label],
|
|
32
|
-
);
|
|
33
|
-
useRegisterFilter(def);
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
1
|
+
import { DatePicker } from "antd";
|
|
2
|
+
import dayjs from "dayjs";
|
|
3
|
+
import { useMemo } from "react";
|
|
4
|
+
import type { BaseSourceProps } from "../types";
|
|
5
|
+
import { useRegisterFilter } from "../context/FilterContext";
|
|
6
|
+
|
|
7
|
+
export type DateFilterProps = BaseSourceProps;
|
|
8
|
+
|
|
9
|
+
export function DateFilter({ source, label }: DateFilterProps) {
|
|
10
|
+
const def = useMemo(
|
|
11
|
+
() => ({
|
|
12
|
+
key: source,
|
|
13
|
+
source,
|
|
14
|
+
label,
|
|
15
|
+
render: ({
|
|
16
|
+
value,
|
|
17
|
+
onChange,
|
|
18
|
+
}: {
|
|
19
|
+
value: unknown;
|
|
20
|
+
onChange: (value: unknown) => void;
|
|
21
|
+
}) => (
|
|
22
|
+
<DatePicker
|
|
23
|
+
allowClear
|
|
24
|
+
placeholder={label ?? source}
|
|
25
|
+
value={value ? dayjs(String(value)) : null}
|
|
26
|
+
onChange={(d) => onChange(d ? d.format("YYYY-MM-DD") : undefined)}
|
|
27
|
+
style={{ minWidth: 160 }}
|
|
28
|
+
/>
|
|
29
|
+
),
|
|
30
|
+
}),
|
|
31
|
+
[source, label],
|
|
32
|
+
);
|
|
33
|
+
useRegisterFilter(def);
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { InputNumber } from "antd";
|
|
2
|
-
import { useMemo } from "react";
|
|
3
|
-
import type { BaseSourceProps } from "../types";
|
|
4
|
-
import { useRegisterFilter } from "../context/FilterContext";
|
|
5
|
-
|
|
6
|
-
export type NumberFilterProps = BaseSourceProps;
|
|
7
|
-
|
|
8
|
-
export function NumberFilter({ source, label }: NumberFilterProps) {
|
|
9
|
-
const def = useMemo(
|
|
10
|
-
() => ({
|
|
11
|
-
key: source,
|
|
12
|
-
source,
|
|
13
|
-
label,
|
|
14
|
-
render: ({
|
|
15
|
-
value,
|
|
16
|
-
onChange,
|
|
17
|
-
}: {
|
|
18
|
-
value: unknown;
|
|
19
|
-
onChange: (value: unknown) => void;
|
|
20
|
-
}) => (
|
|
21
|
-
<InputNumber
|
|
22
|
-
placeholder={label ?? source}
|
|
23
|
-
value={value as number | undefined}
|
|
24
|
-
onChange={(v) => onChange(v ?? undefined)}
|
|
25
|
-
style={{ minWidth: 120 }}
|
|
26
|
-
/>
|
|
27
|
-
),
|
|
28
|
-
}),
|
|
29
|
-
[source, label],
|
|
30
|
-
);
|
|
31
|
-
useRegisterFilter(def);
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
1
|
+
import { InputNumber } from "antd";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import type { BaseSourceProps } from "../types";
|
|
4
|
+
import { useRegisterFilter } from "../context/FilterContext";
|
|
5
|
+
|
|
6
|
+
export type NumberFilterProps = BaseSourceProps;
|
|
7
|
+
|
|
8
|
+
export function NumberFilter({ source, label }: NumberFilterProps) {
|
|
9
|
+
const def = useMemo(
|
|
10
|
+
() => ({
|
|
11
|
+
key: source,
|
|
12
|
+
source,
|
|
13
|
+
label,
|
|
14
|
+
render: ({
|
|
15
|
+
value,
|
|
16
|
+
onChange,
|
|
17
|
+
}: {
|
|
18
|
+
value: unknown;
|
|
19
|
+
onChange: (value: unknown) => void;
|
|
20
|
+
}) => (
|
|
21
|
+
<InputNumber
|
|
22
|
+
placeholder={label ?? source}
|
|
23
|
+
value={value as number | undefined}
|
|
24
|
+
onChange={(v) => onChange(v ?? undefined)}
|
|
25
|
+
style={{ minWidth: 120 }}
|
|
26
|
+
/>
|
|
27
|
+
),
|
|
28
|
+
}),
|
|
29
|
+
[source, label],
|
|
30
|
+
);
|
|
31
|
+
useRegisterFilter(def);
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
@@ -1,173 +1,192 @@
|
|
|
1
|
-
import { Select } from "antd";
|
|
2
|
-
import { useMemo, useState } from "react";
|
|
3
|
-
import type { BaseSourceProps, ChoiceOption, ReferenceProps } from "../types";
|
|
4
|
-
import { useRegisterFilter } from "../context/FilterContext";
|
|
5
|
-
import { useChoices } from "../utils/useChoices";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
source,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
value
|
|
89
|
-
onChange
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
1
|
+
import { Select } from "antd";
|
|
2
|
+
import { useMemo, useState } from "react";
|
|
3
|
+
import type { BaseSourceProps, ChoiceOption, ReferenceProps } from "../types";
|
|
4
|
+
import { useRegisterFilter } from "../context/FilterContext";
|
|
5
|
+
import { useChoices } from "../utils/useChoices";
|
|
6
|
+
import { referenceSelectNotFoundContent } from "../utils/referenceSelectNotFoundContent";
|
|
7
|
+
|
|
8
|
+
export type SelectFilterProps = BaseSourceProps & {
|
|
9
|
+
choices: ChoiceOption[];
|
|
10
|
+
multiple?: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
function SelectFilterInput({
|
|
14
|
+
source,
|
|
15
|
+
label,
|
|
16
|
+
choices,
|
|
17
|
+
multiple,
|
|
18
|
+
value,
|
|
19
|
+
onChange,
|
|
20
|
+
}: SelectFilterProps & {
|
|
21
|
+
value: unknown;
|
|
22
|
+
onChange: (value: unknown) => void;
|
|
23
|
+
}) {
|
|
24
|
+
return (
|
|
25
|
+
<Select
|
|
26
|
+
allowClear
|
|
27
|
+
mode={multiple ? "multiple" : undefined}
|
|
28
|
+
placeholder={label ?? source}
|
|
29
|
+
value={value as string | number | (string | number)[] | undefined}
|
|
30
|
+
onChange={onChange}
|
|
31
|
+
options={choices}
|
|
32
|
+
style={{ minWidth: 160 }}
|
|
33
|
+
/>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function SelectFilter({
|
|
38
|
+
source,
|
|
39
|
+
label,
|
|
40
|
+
choices,
|
|
41
|
+
multiple,
|
|
42
|
+
}: SelectFilterProps) {
|
|
43
|
+
const def = useMemo(
|
|
44
|
+
() => ({
|
|
45
|
+
key: source,
|
|
46
|
+
source,
|
|
47
|
+
label,
|
|
48
|
+
render: ({
|
|
49
|
+
value,
|
|
50
|
+
onChange,
|
|
51
|
+
}: {
|
|
52
|
+
value: unknown;
|
|
53
|
+
onChange: (value: unknown) => void;
|
|
54
|
+
}) => (
|
|
55
|
+
<SelectFilterInput
|
|
56
|
+
source={source}
|
|
57
|
+
label={label}
|
|
58
|
+
choices={choices}
|
|
59
|
+
multiple={multiple}
|
|
60
|
+
value={value}
|
|
61
|
+
onChange={onChange}
|
|
62
|
+
/>
|
|
63
|
+
),
|
|
64
|
+
}),
|
|
65
|
+
[source, label, choices, multiple],
|
|
66
|
+
);
|
|
67
|
+
useRegisterFilter(def);
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type ReferenceFilterProps = BaseSourceProps &
|
|
72
|
+
ReferenceProps & {
|
|
73
|
+
multiple?: boolean;
|
|
74
|
+
search?: boolean;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
function ReferenceFilterInput({
|
|
78
|
+
source,
|
|
79
|
+
label,
|
|
80
|
+
reference,
|
|
81
|
+
choices,
|
|
82
|
+
optionLabel,
|
|
83
|
+
optionValue,
|
|
84
|
+
multiple,
|
|
85
|
+
search,
|
|
86
|
+
lazy = true,
|
|
87
|
+
fetchSelected = true,
|
|
88
|
+
value,
|
|
89
|
+
onChange,
|
|
90
|
+
}: ReferenceFilterProps & {
|
|
91
|
+
value: unknown;
|
|
92
|
+
onChange: (value: unknown) => void;
|
|
93
|
+
}) {
|
|
94
|
+
const [searchText, setSearchText] = useState<string | undefined>();
|
|
95
|
+
const [dropdownOpen, setDropdownOpen] = useState(false);
|
|
96
|
+
const active = dropdownOpen || Boolean(searchText);
|
|
97
|
+
|
|
98
|
+
const { options, loading } = useChoices(
|
|
99
|
+
choices,
|
|
100
|
+
reference,
|
|
101
|
+
optionLabel,
|
|
102
|
+
optionValue,
|
|
103
|
+
search ? searchText : undefined,
|
|
104
|
+
{ lazy, active, selectedValues: value, fetchSelected },
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<Select
|
|
109
|
+
allowClear
|
|
110
|
+
mode={multiple ? "multiple" : undefined}
|
|
111
|
+
placeholder={label ?? source}
|
|
112
|
+
value={value as string | number | (string | number)[] | undefined}
|
|
113
|
+
onChange={onChange}
|
|
114
|
+
options={options.map((o) => ({
|
|
115
|
+
label: o.label,
|
|
116
|
+
value: o.value as string | number,
|
|
117
|
+
}))}
|
|
118
|
+
loading={loading}
|
|
119
|
+
notFoundContent={referenceSelectNotFoundContent(loading)}
|
|
120
|
+
showSearch={search}
|
|
121
|
+
filterOption={search ? false : undefined}
|
|
122
|
+
onSearch={search ? setSearchText : undefined}
|
|
123
|
+
onDropdownVisibleChange={(open) => {
|
|
124
|
+
setDropdownOpen(open);
|
|
125
|
+
if (!open) setSearchText(undefined);
|
|
126
|
+
}}
|
|
127
|
+
optionFilterProp="label"
|
|
128
|
+
style={{ minWidth: 180 }}
|
|
129
|
+
/>
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function ReferenceFilter({
|
|
134
|
+
source,
|
|
135
|
+
label,
|
|
136
|
+
reference,
|
|
137
|
+
choices,
|
|
138
|
+
optionLabel = "name",
|
|
139
|
+
optionValue = "id",
|
|
140
|
+
multiple,
|
|
141
|
+
search,
|
|
142
|
+
lazy = true,
|
|
143
|
+
fetchSelected = true,
|
|
144
|
+
}: ReferenceFilterProps) {
|
|
145
|
+
const def = useMemo(
|
|
146
|
+
() => ({
|
|
147
|
+
key: source,
|
|
148
|
+
source,
|
|
149
|
+
label,
|
|
150
|
+
render: ({
|
|
151
|
+
value,
|
|
152
|
+
onChange,
|
|
153
|
+
}: {
|
|
154
|
+
value: unknown;
|
|
155
|
+
onChange: (value: unknown) => void;
|
|
156
|
+
}) => (
|
|
157
|
+
<ReferenceFilterInput
|
|
158
|
+
source={source}
|
|
159
|
+
label={label}
|
|
160
|
+
reference={reference}
|
|
161
|
+
choices={choices}
|
|
162
|
+
optionLabel={optionLabel}
|
|
163
|
+
optionValue={optionValue}
|
|
164
|
+
multiple={multiple}
|
|
165
|
+
search={search}
|
|
166
|
+
lazy={lazy}
|
|
167
|
+
fetchSelected={fetchSelected}
|
|
168
|
+
value={value}
|
|
169
|
+
onChange={onChange}
|
|
170
|
+
/>
|
|
171
|
+
),
|
|
172
|
+
}),
|
|
173
|
+
[
|
|
174
|
+
source,
|
|
175
|
+
label,
|
|
176
|
+
reference,
|
|
177
|
+
choices,
|
|
178
|
+
optionLabel,
|
|
179
|
+
optionValue,
|
|
180
|
+
multiple,
|
|
181
|
+
search,
|
|
182
|
+
lazy,
|
|
183
|
+
fetchSelected,
|
|
184
|
+
],
|
|
185
|
+
);
|
|
186
|
+
useRegisterFilter(def);
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function ReferenceManyFilter(props: ReferenceFilterProps) {
|
|
191
|
+
return <ReferenceFilter {...props} multiple />;
|
|
192
|
+
}
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import { Select } from "antd";
|
|
2
|
-
import { useMemo } from "react";
|
|
3
|
-
import type { BaseSourceProps, ChoiceOption } from "../types";
|
|
4
|
-
import { useRegisterFilter } from "../context/FilterContext";
|
|
5
|
-
|
|
6
|
-
export type SelectFilterProps = BaseSourceProps & {
|
|
7
|
-
choices: ChoiceOption[];
|
|
8
|
-
multiple?: boolean;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export function SelectFilter({
|
|
12
|
-
source,
|
|
13
|
-
label,
|
|
14
|
-
choices,
|
|
15
|
-
multiple,
|
|
16
|
-
}: SelectFilterProps) {
|
|
17
|
-
const def = useMemo(
|
|
18
|
-
() => ({
|
|
19
|
-
key: source,
|
|
20
|
-
source,
|
|
21
|
-
label,
|
|
22
|
-
render: ({
|
|
23
|
-
value,
|
|
24
|
-
onChange,
|
|
25
|
-
}: {
|
|
26
|
-
value: unknown;
|
|
27
|
-
onChange: (value: unknown) => void;
|
|
28
|
-
}) => (
|
|
29
|
-
<Select
|
|
30
|
-
allowClear
|
|
31
|
-
mode={multiple ? "multiple" : undefined}
|
|
32
|
-
placeholder={label ?? source}
|
|
33
|
-
value={value as string | number | (string | number)[] | undefined}
|
|
34
|
-
onChange={onChange}
|
|
35
|
-
options={choices}
|
|
36
|
-
style={{ minWidth: 160 }}
|
|
37
|
-
/>
|
|
38
|
-
),
|
|
39
|
-
}),
|
|
40
|
-
[source, label, choices, multiple],
|
|
41
|
-
);
|
|
42
|
-
useRegisterFilter(def);
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
1
|
+
import { Select } from "antd";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import type { BaseSourceProps, ChoiceOption } from "../types";
|
|
4
|
+
import { useRegisterFilter } from "../context/FilterContext";
|
|
5
|
+
|
|
6
|
+
export type SelectFilterProps = BaseSourceProps & {
|
|
7
|
+
choices: ChoiceOption[];
|
|
8
|
+
multiple?: boolean;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function SelectFilter({
|
|
12
|
+
source,
|
|
13
|
+
label,
|
|
14
|
+
choices,
|
|
15
|
+
multiple,
|
|
16
|
+
}: SelectFilterProps) {
|
|
17
|
+
const def = useMemo(
|
|
18
|
+
() => ({
|
|
19
|
+
key: source,
|
|
20
|
+
source,
|
|
21
|
+
label,
|
|
22
|
+
render: ({
|
|
23
|
+
value,
|
|
24
|
+
onChange,
|
|
25
|
+
}: {
|
|
26
|
+
value: unknown;
|
|
27
|
+
onChange: (value: unknown) => void;
|
|
28
|
+
}) => (
|
|
29
|
+
<Select
|
|
30
|
+
allowClear
|
|
31
|
+
mode={multiple ? "multiple" : undefined}
|
|
32
|
+
placeholder={label ?? source}
|
|
33
|
+
value={value as string | number | (string | number)[] | undefined}
|
|
34
|
+
onChange={onChange}
|
|
35
|
+
options={choices}
|
|
36
|
+
style={{ minWidth: 160 }}
|
|
37
|
+
/>
|
|
38
|
+
),
|
|
39
|
+
}),
|
|
40
|
+
[source, label, choices, multiple],
|
|
41
|
+
);
|
|
42
|
+
useRegisterFilter(def);
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import { Input } from "antd";
|
|
2
|
-
import { useMemo } from "react";
|
|
3
|
-
import type { BaseSourceProps } from "../types";
|
|
4
|
-
import { useRegisterFilter } from "../context/FilterContext";
|
|
5
|
-
|
|
6
|
-
export type TextFilterProps = BaseSourceProps & {
|
|
7
|
-
placeholder?: string;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export function TextFilter({ source, label, placeholder }: TextFilterProps) {
|
|
11
|
-
const def = useMemo(
|
|
12
|
-
() => ({
|
|
13
|
-
key: source,
|
|
14
|
-
source,
|
|
15
|
-
label,
|
|
16
|
-
render: ({
|
|
17
|
-
value,
|
|
18
|
-
onChange,
|
|
19
|
-
}: {
|
|
20
|
-
value: unknown;
|
|
21
|
-
onChange: (value: unknown) => void;
|
|
22
|
-
}) => (
|
|
23
|
-
<Input
|
|
24
|
-
allowClear
|
|
25
|
-
placeholder={placeholder ?? label ?? source}
|
|
26
|
-
value={(value as string) ?? ""}
|
|
27
|
-
onChange={(e) => onChange(e.target.value || undefined)}
|
|
28
|
-
style={{ minWidth: 160 }}
|
|
29
|
-
/>
|
|
30
|
-
),
|
|
31
|
-
}),
|
|
32
|
-
[source, label, placeholder],
|
|
33
|
-
);
|
|
34
|
-
useRegisterFilter(def);
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
1
|
+
import { Input } from "antd";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import type { BaseSourceProps } from "../types";
|
|
4
|
+
import { useRegisterFilter } from "../context/FilterContext";
|
|
5
|
+
|
|
6
|
+
export type TextFilterProps = BaseSourceProps & {
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function TextFilter({ source, label, placeholder }: TextFilterProps) {
|
|
11
|
+
const def = useMemo(
|
|
12
|
+
() => ({
|
|
13
|
+
key: source,
|
|
14
|
+
source,
|
|
15
|
+
label,
|
|
16
|
+
render: ({
|
|
17
|
+
value,
|
|
18
|
+
onChange,
|
|
19
|
+
}: {
|
|
20
|
+
value: unknown;
|
|
21
|
+
onChange: (value: unknown) => void;
|
|
22
|
+
}) => (
|
|
23
|
+
<Input
|
|
24
|
+
allowClear
|
|
25
|
+
placeholder={placeholder ?? label ?? source}
|
|
26
|
+
value={(value as string) ?? ""}
|
|
27
|
+
onChange={(e) => onChange(e.target.value || undefined)}
|
|
28
|
+
style={{ minWidth: 160 }}
|
|
29
|
+
/>
|
|
30
|
+
),
|
|
31
|
+
}),
|
|
32
|
+
[source, label, placeholder],
|
|
33
|
+
);
|
|
34
|
+
useRegisterFilter(def);
|
|
35
|
+
return null;
|
|
36
|
+
}
|