@refinedev/antd 5.37.3 → 5.37.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/CHANGELOG.md +1766 -1776
- package/dist/components/autoSaveIndicator/index.d.ts.map +1 -1
- package/dist/components/breadcrumb/index.d.ts.map +1 -1
- package/dist/components/buttons/create/index.d.ts.map +1 -1
- package/dist/components/buttons/delete/index.d.ts.map +1 -1
- package/dist/components/buttons/import/index.d.ts.map +1 -1
- package/dist/components/buttons/types.d.ts.map +1 -1
- package/dist/components/crud/edit/index.d.ts.map +1 -1
- package/dist/components/crud/list/index.d.ts.map +1 -1
- package/dist/components/crud/show/index.d.ts.map +1 -1
- package/dist/components/crud/types.d.ts.map +1 -1
- package/dist/components/fields/date/index.d.ts.map +1 -1
- package/dist/components/fields/email/index.d.ts.map +1 -1
- package/dist/components/fields/number/index.d.ts.map +1 -1
- package/dist/components/fields/text/index.d.ts.map +1 -1
- package/dist/components/fields/types.d.ts.map +1 -1
- package/dist/components/fields/url/index.d.ts.map +1 -1
- package/dist/components/layout/header/index.d.ts.map +1 -1
- package/dist/components/layout/sider/index.d.ts.map +1 -1
- package/dist/components/layout/title/index.d.ts.map +1 -1
- package/dist/components/layout/types.d.ts.map +1 -1
- package/dist/components/pageHeader/index.d.ts.map +1 -1
- package/dist/components/pages/auth/components/forgotPassword/index.d.ts.map +1 -1
- package/dist/components/pages/auth/components/login/index.d.ts.map +1 -1
- package/dist/components/pages/auth/components/register/index.d.ts.map +1 -1
- package/dist/components/pages/auth/components/updatePassword/index.d.ts.map +1 -1
- package/dist/components/pages/auth/index.d.ts.map +1 -1
- package/dist/components/pages/error/index.d.ts.map +1 -1
- package/dist/components/pages/login/index.d.ts.map +1 -1
- package/dist/components/pages/ready/index.d.ts.map +1 -1
- package/dist/components/table/components/filterDropdown/index.d.ts.map +1 -1
- package/dist/components/themedLayout/header/index.d.ts.map +1 -1
- package/dist/components/themedLayout/sider/index.d.ts.map +1 -1
- package/dist/components/themedLayout/title/index.d.ts.map +1 -1
- package/dist/components/themedLayout/types.d.ts.map +1 -1
- package/dist/components/themedLayoutV2/header/index.d.ts.map +1 -1
- package/dist/components/themedLayoutV2/index.d.ts.map +1 -1
- package/dist/components/themedLayoutV2/sider/index.d.ts.map +1 -1
- package/dist/components/themedLayoutV2/title/index.d.ts.map +1 -1
- package/dist/components/themedLayoutV2/types.d.ts.map +1 -1
- package/dist/components/undoableNotification/index.d.ts.map +1 -1
- package/dist/contexts/index.d.ts.map +1 -1
- package/dist/contexts/themedLayoutContext/IThemedLayoutContext.d.ts.map +1 -1
- package/dist/contexts/themedLayoutContext/index.d.ts.map +1 -1
- package/dist/definitions/table/index.d.ts.map +1 -1
- package/dist/definitions/themes/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/hooks/fields/useCheckboxGroup/index.d.ts.map +1 -1
- package/dist/hooks/fields/useRadioGroup/index.d.ts.map +1 -1
- package/dist/hooks/fields/useSelect/index.d.ts.map +1 -1
- package/dist/hooks/form/index.d.ts.map +1 -1
- package/dist/hooks/form/useDrawerForm/index.d.ts.map +1 -1
- package/dist/hooks/form/useDrawerForm/useDrawerForm.d.ts.map +1 -1
- package/dist/hooks/form/useForm.d.ts.map +1 -1
- package/dist/hooks/form/useModalForm/index.d.ts.map +1 -1
- package/dist/hooks/form/useModalForm/useModalForm.d.ts.map +1 -1
- package/dist/hooks/form/useStepsForm/index.d.ts.map +1 -1
- package/dist/hooks/form/useStepsForm/useStepsForm.d.ts.map +1 -1
- package/dist/hooks/import/index.d.ts.map +1 -1
- package/dist/hooks/list/useSimpleList/useSimpleList.d.ts.map +1 -1
- package/dist/hooks/modal/useModal/index.d.ts.map +1 -1
- package/dist/hooks/table/useEditableTable/useEditableTable.d.ts.map +1 -1
- package/dist/hooks/table/useTable/paginationLink.d.ts.map +1 -1
- package/dist/hooks/table/useTable/useTable.d.ts.map +1 -1
- package/dist/hooks/useFileUploadState/index.d.ts.map +1 -1
- package/dist/hooks/useSiderVisible/index.d.ts.map +1 -1
- package/dist/iife/index.js +11 -10
- package/dist/iife/index.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces/field.d.ts.map +1 -1
- package/dist/interfaces/index.d.ts.map +1 -1
- package/dist/interfaces/upload.d.ts.map +1 -1
- package/package.json +32 -32
- package/refine.config.js +497 -524
- package/src/components/autoSaveIndicator/index.tsx +69 -70
- package/src/components/breadcrumb/index.tsx +63 -65
- package/src/components/buttons/clone/index.tsx +86 -86
- package/src/components/buttons/create/index.tsx +85 -86
- package/src/components/buttons/delete/index.tsx +114 -119
- package/src/components/buttons/edit/index.tsx +86 -86
- package/src/components/buttons/export/index.tsx +17 -17
- package/src/components/buttons/import/index.tsx +19 -20
- package/src/components/buttons/list/index.tsx +105 -105
- package/src/components/buttons/refresh/index.tsx +50 -50
- package/src/components/buttons/save/index.tsx +17 -17
- package/src/components/buttons/show/index.tsx +86 -86
- package/src/components/buttons/types.ts +20 -20
- package/src/components/crud/create/index.tsx +120 -120
- package/src/components/crud/edit/index.tsx +205 -207
- package/src/components/crud/list/index.tsx +88 -90
- package/src/components/crud/show/index.tsx +175 -185
- package/src/components/crud/types.ts +41 -56
- package/src/components/fields/boolean/index.tsx +11 -11
- package/src/components/fields/date/index.tsx +13 -15
- package/src/components/fields/email/index.tsx +5 -7
- package/src/components/fields/file/index.tsx +8 -8
- package/src/components/fields/image/index.tsx +4 -4
- package/src/components/fields/markdown/index.tsx +9 -9
- package/src/components/fields/number/index.tsx +17 -19
- package/src/components/fields/tag/index.tsx +1 -1
- package/src/components/fields/text/index.tsx +1 -3
- package/src/components/fields/types.ts +18 -18
- package/src/components/fields/url/index.tsx +8 -10
- package/src/components/layout/header/index.tsx +25 -26
- package/src/components/layout/index.tsx +30 -30
- package/src/components/layout/sider/index.tsx +238 -248
- package/src/components/layout/sider/styles.ts +5 -5
- package/src/components/layout/title/index.tsx +40 -40
- package/src/components/layout/types.ts +6 -6
- package/src/components/pageHeader/index.tsx +44 -44
- package/src/components/pages/auth/components/forgotPassword/index.tsx +177 -183
- package/src/components/pages/auth/components/login/index.tsx +258 -274
- package/src/components/pages/auth/components/register/index.tsx +247 -266
- package/src/components/pages/auth/components/styles.ts +16 -16
- package/src/components/pages/auth/components/updatePassword/index.tsx +160 -177
- package/src/components/pages/auth/index.tsx +23 -23
- package/src/components/pages/error/index.tsx +57 -59
- package/src/components/pages/login/index.tsx +120 -147
- package/src/components/pages/login/styles.ts +12 -12
- package/src/components/pages/ready/index.tsx +72 -80
- package/src/components/pages/welcome/index.tsx +1 -1
- package/src/components/table/components/filterDropdown/index.tsx +89 -92
- package/src/components/themedLayout/header/index.tsx +28 -33
- package/src/components/themedLayout/index.tsx +30 -30
- package/src/components/themedLayout/sider/index.tsx +279 -282
- package/src/components/themedLayout/sider/styles.ts +5 -5
- package/src/components/themedLayout/title/index.tsx +66 -68
- package/src/components/themedLayout/types.ts +8 -8
- package/src/components/themedLayoutV2/header/index.tsx +43 -48
- package/src/components/themedLayoutV2/index.tsx +34 -36
- package/src/components/themedLayoutV2/sider/index.tsx +309 -316
- package/src/components/themedLayoutV2/sider/styles.ts +5 -5
- package/src/components/themedLayoutV2/title/index.tsx +66 -68
- package/src/components/themedLayoutV2/types.ts +9 -9
- package/src/components/undoableNotification/index.tsx +31 -31
- package/src/contexts/index.ts +2 -2
- package/src/contexts/themedLayoutContext/IThemedLayoutContext.ts +4 -4
- package/src/contexts/themedLayoutContext/index.tsx +22 -22
- package/src/definitions/table/index.ts +81 -82
- package/src/definitions/themes/index.ts +35 -35
- package/src/definitions/upload/index.ts +17 -17
- package/src/hooks/fields/useCheckboxGroup/index.ts +64 -64
- package/src/hooks/fields/useRadioGroup/index.ts +60 -63
- package/src/hooks/fields/useSelect/index.ts +30 -30
- package/src/hooks/form/index.ts +10 -10
- package/src/hooks/form/useDrawerForm/index.ts +4 -4
- package/src/hooks/form/useDrawerForm/useDrawerForm.ts +257 -261
- package/src/hooks/form/useForm.ts +256 -259
- package/src/hooks/form/useModalForm/index.ts +3 -3
- package/src/hooks/form/useModalForm/useModalForm.ts +289 -295
- package/src/hooks/form/useStepsForm/index.ts +3 -3
- package/src/hooks/form/useStepsForm/useStepsForm.ts +96 -96
- package/src/hooks/import/index.tsx +104 -106
- package/src/hooks/list/useSimpleList/useSimpleList.ts +179 -185
- package/src/hooks/modal/useModal/index.tsx +24 -24
- package/src/hooks/table/useEditableTable/useEditableTable.ts +85 -85
- package/src/hooks/table/useTable/paginationLink.tsx +17 -17
- package/src/hooks/table/useTable/useTable.ts +199 -205
- package/src/hooks/useFileUploadState/index.ts +20 -20
- package/src/hooks/useSiderVisible/index.ts +16 -16
- package/src/hooks/useThemedLayoutContext/index.ts +12 -12
- package/src/index.tsx +4 -4
- package/src/interfaces/field.ts +1 -1
- package/src/interfaces/index.ts +7 -8
- package/src/interfaces/upload.ts +7 -7
- package/src/providers/notificationProvider/index.tsx +78 -78
- package/src/types/index.d.ts +2 -2
- package/src/types/sunflower.d.ts +68 -68
- package/tsconfig.json +26 -26
@@ -2,83 +2,83 @@ import React, { useCallback } from "react";
|
|
2
2
|
import { UseFormConfig } from "sunflower-antd";
|
3
3
|
import { FormInstance, FormProps, DrawerProps, ButtonProps } from "antd";
|
4
4
|
import {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
5
|
+
useTranslate,
|
6
|
+
useWarnAboutChange,
|
7
|
+
UseFormProps as UseFormPropsCore,
|
8
|
+
HttpError,
|
9
|
+
LiveModeProps,
|
10
|
+
BaseRecord,
|
11
|
+
FormWithSyncWithLocationParams,
|
12
|
+
BaseKey,
|
13
|
+
useResource,
|
14
|
+
useParsed,
|
15
|
+
useGo,
|
16
|
+
useModal,
|
17
|
+
useInvalidate,
|
18
18
|
} from "@refinedev/core";
|
19
19
|
|
20
20
|
import { useForm, UseFormProps, UseFormReturnType } from "../useForm";
|
21
21
|
import { DeleteButtonProps } from "../../../components";
|
22
22
|
|
23
23
|
export interface UseDrawerFormConfig extends UseFormConfig {
|
24
|
-
|
24
|
+
action: "show" | "edit" | "create" | "clone";
|
25
25
|
}
|
26
26
|
|
27
27
|
export type UseDrawerFormProps<
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
TQueryFnData extends BaseRecord = BaseRecord,
|
29
|
+
TError extends HttpError = HttpError,
|
30
|
+
TVariables = {},
|
31
|
+
TData extends BaseRecord = TQueryFnData,
|
32
|
+
TResponse extends BaseRecord = TData,
|
33
|
+
TResponseError extends HttpError = TError,
|
34
34
|
> = UseFormPropsCore<
|
35
|
+
TQueryFnData,
|
36
|
+
TError,
|
37
|
+
TVariables,
|
38
|
+
TData,
|
39
|
+
TResponse,
|
40
|
+
TResponseError
|
41
|
+
> &
|
42
|
+
UseFormProps<
|
35
43
|
TQueryFnData,
|
36
44
|
TError,
|
37
45
|
TVariables,
|
38
46
|
TData,
|
39
47
|
TResponse,
|
40
48
|
TResponseError
|
41
|
-
> &
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
> &
|
50
|
-
UseDrawerFormConfig &
|
51
|
-
LiveModeProps &
|
52
|
-
FormWithSyncWithLocationParams & {
|
53
|
-
defaultVisible?: boolean;
|
54
|
-
autoSubmitClose?: boolean;
|
55
|
-
autoResetForm?: boolean;
|
56
|
-
};
|
49
|
+
> &
|
50
|
+
UseDrawerFormConfig &
|
51
|
+
LiveModeProps &
|
52
|
+
FormWithSyncWithLocationParams & {
|
53
|
+
defaultVisible?: boolean;
|
54
|
+
autoSubmitClose?: boolean;
|
55
|
+
autoResetForm?: boolean;
|
56
|
+
};
|
57
57
|
|
58
58
|
export type UseDrawerFormReturnType<
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
59
|
+
TQueryFnData extends BaseRecord = BaseRecord,
|
60
|
+
TError extends HttpError = HttpError,
|
61
|
+
TVariables = {},
|
62
|
+
TData extends BaseRecord = TQueryFnData,
|
63
|
+
TResponse extends BaseRecord = TData,
|
64
|
+
TResponseError extends HttpError = TError,
|
65
65
|
> = UseFormReturnType<
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
66
|
+
TQueryFnData,
|
67
|
+
TError,
|
68
|
+
TVariables,
|
69
|
+
TData,
|
70
|
+
TResponse,
|
71
|
+
TResponseError
|
72
72
|
> & {
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
73
|
+
formProps: FormProps<TVariables> & {
|
74
|
+
form: FormInstance<TVariables>;
|
75
|
+
};
|
76
|
+
show: (id?: BaseKey) => void;
|
77
|
+
close: () => void;
|
78
|
+
drawerProps: DrawerProps;
|
79
|
+
saveButtonProps: ButtonProps;
|
80
|
+
deleteButtonProps: DeleteButtonProps;
|
81
|
+
formLoading: boolean;
|
82
82
|
};
|
83
83
|
|
84
84
|
/**
|
@@ -94,236 +94,232 @@ export type UseDrawerFormReturnType<
|
|
94
94
|
*/
|
95
95
|
|
96
96
|
export const useDrawerForm = <
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
97
|
+
TQueryFnData extends BaseRecord = BaseRecord,
|
98
|
+
TError extends HttpError = HttpError,
|
99
|
+
TVariables = {},
|
100
|
+
TData extends BaseRecord = TQueryFnData,
|
101
|
+
TResponse extends BaseRecord = TData,
|
102
|
+
TResponseError extends HttpError = TError,
|
103
103
|
>({
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
104
|
+
syncWithLocation,
|
105
|
+
defaultVisible = false,
|
106
|
+
autoSubmitClose = true,
|
107
|
+
autoResetForm = true,
|
108
|
+
autoSave,
|
109
|
+
invalidates,
|
110
|
+
...rest
|
111
111
|
}: UseDrawerFormProps<
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
112
|
+
TQueryFnData,
|
113
|
+
TError,
|
114
|
+
TVariables,
|
115
|
+
TData,
|
116
|
+
TResponse,
|
117
|
+
TResponseError
|
118
118
|
>): UseDrawerFormReturnType<
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
119
|
+
TQueryFnData,
|
120
|
+
TError,
|
121
|
+
TVariables,
|
122
|
+
TData,
|
123
|
+
TResponse,
|
124
|
+
TResponseError
|
125
125
|
> => {
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
const { visible, show, close } = useModal({
|
130
|
-
defaultVisible,
|
131
|
-
});
|
132
|
-
|
133
|
-
const {
|
134
|
-
resource,
|
135
|
-
action: actionFromParams,
|
136
|
-
identifier,
|
137
|
-
} = useResource(rest.resource);
|
126
|
+
const invalidate = useInvalidate();
|
127
|
+
const [initiallySynced, setInitiallySynced] = React.useState(false);
|
138
128
|
|
139
|
-
|
140
|
-
|
129
|
+
const { visible, show, close } = useModal({
|
130
|
+
defaultVisible,
|
131
|
+
});
|
141
132
|
|
142
|
-
|
133
|
+
const {
|
134
|
+
resource,
|
135
|
+
action: actionFromParams,
|
136
|
+
identifier,
|
137
|
+
} = useResource(rest.resource);
|
143
138
|
|
144
|
-
|
145
|
-
|
146
|
-
syncWithLocation?.syncId === false
|
147
|
-
);
|
139
|
+
const parsed = useParsed();
|
140
|
+
const go = useGo();
|
148
141
|
|
149
|
-
|
150
|
-
typeof syncWithLocation === "object" && "key" in syncWithLocation
|
151
|
-
? syncWithLocation.key
|
152
|
-
: resource && action && syncWithLocation
|
153
|
-
? `drawer-${resource?.identifier ?? resource?.name}-${action}`
|
154
|
-
: undefined;
|
142
|
+
const action = rest.action ?? actionFromParams ?? "";
|
155
143
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
TVariables,
|
160
|
-
TData,
|
161
|
-
TResponse,
|
162
|
-
TResponseError
|
163
|
-
>({
|
164
|
-
meta: {
|
165
|
-
...(syncWithLocationKey
|
166
|
-
? { [syncWithLocationKey]: undefined }
|
167
|
-
: {}),
|
168
|
-
...rest.meta,
|
169
|
-
},
|
170
|
-
autoSave,
|
171
|
-
invalidates,
|
172
|
-
...rest,
|
173
|
-
});
|
144
|
+
const syncingId = !(
|
145
|
+
typeof syncWithLocation === "object" && syncWithLocation?.syncId === false
|
146
|
+
);
|
174
147
|
|
175
|
-
|
176
|
-
|
148
|
+
const syncWithLocationKey =
|
149
|
+
typeof syncWithLocation === "object" && "key" in syncWithLocation
|
150
|
+
? syncWithLocation.key
|
151
|
+
: resource && action && syncWithLocation
|
152
|
+
? `drawer-${resource?.identifier ?? resource?.name}-${action}`
|
153
|
+
: undefined;
|
177
154
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
155
|
+
const useFormProps = useForm<
|
156
|
+
TQueryFnData,
|
157
|
+
TError,
|
158
|
+
TVariables,
|
159
|
+
TData,
|
160
|
+
TResponse,
|
161
|
+
TResponseError
|
162
|
+
>({
|
163
|
+
meta: {
|
164
|
+
...(syncWithLocationKey ? { [syncWithLocationKey]: undefined } : {}),
|
165
|
+
...rest.meta,
|
166
|
+
},
|
167
|
+
autoSave,
|
168
|
+
invalidates,
|
169
|
+
...rest,
|
170
|
+
});
|
188
171
|
|
189
|
-
|
190
|
-
|
191
|
-
if (idFromParams) {
|
192
|
-
setId?.(idFromParams);
|
193
|
-
}
|
194
|
-
}
|
172
|
+
const { form, formProps, formLoading, id, setId, onFinish, autoSaveProps } =
|
173
|
+
useFormProps;
|
195
174
|
|
196
|
-
|
175
|
+
React.useEffect(() => {
|
176
|
+
if (initiallySynced === false && syncWithLocationKey) {
|
177
|
+
const openStatus = parsed?.params?.[syncWithLocationKey]?.open;
|
178
|
+
if (typeof openStatus === "boolean") {
|
179
|
+
openStatus ? show() : close();
|
180
|
+
} else if (typeof openStatus === "string") {
|
181
|
+
if (openStatus === "true") {
|
182
|
+
show();
|
197
183
|
}
|
198
|
-
|
184
|
+
}
|
199
185
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
query: {
|
205
|
-
[syncWithLocationKey]: {
|
206
|
-
...parsed?.params?.[syncWithLocationKey],
|
207
|
-
open: true,
|
208
|
-
...(syncingId && id && { id }),
|
209
|
-
},
|
210
|
-
},
|
211
|
-
options: { keepQuery: true },
|
212
|
-
type: "replace",
|
213
|
-
});
|
214
|
-
} else if (syncWithLocationKey && !visible) {
|
215
|
-
go({
|
216
|
-
query: {
|
217
|
-
[syncWithLocationKey]: undefined,
|
218
|
-
},
|
219
|
-
options: { keepQuery: true },
|
220
|
-
type: "replace",
|
221
|
-
});
|
222
|
-
}
|
186
|
+
if (syncingId) {
|
187
|
+
const idFromParams = parsed?.params?.[syncWithLocationKey]?.id;
|
188
|
+
if (idFromParams) {
|
189
|
+
setId?.(idFromParams);
|
223
190
|
}
|
224
|
-
|
225
|
-
id,
|
226
|
-
visible,
|
227
|
-
show,
|
228
|
-
close,
|
229
|
-
syncWithLocationKey,
|
230
|
-
syncingId,
|
231
|
-
initiallySynced,
|
232
|
-
]);
|
191
|
+
}
|
233
192
|
|
234
|
-
|
193
|
+
setInitiallySynced(true);
|
194
|
+
}
|
195
|
+
}, [syncWithLocationKey, parsed, syncingId, setId, initiallySynced]);
|
235
196
|
|
236
|
-
|
197
|
+
React.useEffect(() => {
|
198
|
+
if (initiallySynced === true) {
|
199
|
+
if (visible && syncWithLocationKey) {
|
200
|
+
go({
|
201
|
+
query: {
|
202
|
+
[syncWithLocationKey]: {
|
203
|
+
...parsed?.params?.[syncWithLocationKey],
|
204
|
+
open: true,
|
205
|
+
...(syncingId && id && { id }),
|
206
|
+
},
|
207
|
+
},
|
208
|
+
options: { keepQuery: true },
|
209
|
+
type: "replace",
|
210
|
+
});
|
211
|
+
} else if (syncWithLocationKey && !visible) {
|
212
|
+
go({
|
213
|
+
query: {
|
214
|
+
[syncWithLocationKey]: undefined,
|
215
|
+
},
|
216
|
+
options: { keepQuery: true },
|
217
|
+
type: "replace",
|
218
|
+
});
|
219
|
+
}
|
220
|
+
}
|
221
|
+
}, [
|
222
|
+
id,
|
223
|
+
visible,
|
224
|
+
show,
|
225
|
+
close,
|
226
|
+
syncWithLocationKey,
|
227
|
+
syncingId,
|
228
|
+
initiallySynced,
|
229
|
+
]);
|
237
230
|
|
238
|
-
|
239
|
-
disabled: formLoading,
|
240
|
-
onClick: () => {
|
241
|
-
form.submit();
|
242
|
-
},
|
243
|
-
loading: formLoading,
|
244
|
-
};
|
231
|
+
const translate = useTranslate();
|
245
232
|
|
246
|
-
|
247
|
-
recordItemId: id,
|
248
|
-
onSuccess: () => {
|
249
|
-
setId?.(undefined);
|
250
|
-
close();
|
251
|
-
},
|
252
|
-
};
|
233
|
+
const { warnWhen, setWarnWhen } = useWarnAboutChange();
|
253
234
|
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
});
|
262
|
-
}
|
235
|
+
const saveButtonProps = {
|
236
|
+
disabled: formLoading,
|
237
|
+
onClick: () => {
|
238
|
+
form.submit();
|
239
|
+
},
|
240
|
+
loading: formLoading,
|
241
|
+
};
|
263
242
|
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
243
|
+
const deleteButtonProps = {
|
244
|
+
recordItemId: id,
|
245
|
+
onSuccess: () => {
|
246
|
+
setId?.(undefined);
|
247
|
+
close();
|
248
|
+
},
|
249
|
+
};
|
271
250
|
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
251
|
+
const handleClose = useCallback(() => {
|
252
|
+
if (autoSaveProps.status === "success" && autoSave?.invalidateOnClose) {
|
253
|
+
invalidate({
|
254
|
+
id,
|
255
|
+
invalidates: invalidates || ["list", "many", "detail"],
|
256
|
+
dataProviderName: rest.dataProviderName,
|
257
|
+
resource: identifier,
|
258
|
+
});
|
259
|
+
}
|
278
260
|
|
279
|
-
|
280
|
-
|
281
|
-
|
261
|
+
if (warnWhen) {
|
262
|
+
const warnWhenConfirm = window.confirm(
|
263
|
+
translate(
|
264
|
+
"warnWhenUnsavedChanges",
|
265
|
+
"Are you sure you want to leave? You have unsaved changes.",
|
266
|
+
),
|
267
|
+
);
|
282
268
|
|
283
|
-
|
284
|
-
(
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
const hasId =
|
290
|
-
typeof showId !== "undefined" || typeof id !== "undefined";
|
291
|
-
if (needsIdToOpen ? hasId : true) {
|
292
|
-
show();
|
293
|
-
}
|
294
|
-
},
|
295
|
-
[id],
|
296
|
-
);
|
269
|
+
if (warnWhenConfirm) {
|
270
|
+
setWarnWhen(false);
|
271
|
+
} else {
|
272
|
+
return;
|
273
|
+
}
|
274
|
+
}
|
297
275
|
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
close: handleClose,
|
302
|
-
formProps: {
|
303
|
-
form,
|
304
|
-
...useFormProps.formProps,
|
305
|
-
onValuesChange: formProps?.onValuesChange,
|
306
|
-
onKeyUp: formProps?.onKeyUp,
|
307
|
-
onFinish: async (values) => {
|
308
|
-
await onFinish(values);
|
276
|
+
close();
|
277
|
+
setId?.(undefined);
|
278
|
+
}, [warnWhen]);
|
309
279
|
|
310
|
-
|
311
|
-
|
312
|
-
|
280
|
+
const handleShow = useCallback(
|
281
|
+
(showId?: BaseKey) => {
|
282
|
+
if (typeof showId !== "undefined") {
|
283
|
+
setId?.(showId);
|
284
|
+
}
|
285
|
+
const needsIdToOpen = action === "edit" || action === "clone";
|
286
|
+
const hasId = typeof showId !== "undefined" || typeof id !== "undefined";
|
287
|
+
if (needsIdToOpen ? hasId : true) {
|
288
|
+
show();
|
289
|
+
}
|
290
|
+
},
|
291
|
+
[id],
|
292
|
+
);
|
313
293
|
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
294
|
+
return {
|
295
|
+
...useFormProps,
|
296
|
+
show: handleShow,
|
297
|
+
close: handleClose,
|
298
|
+
formProps: {
|
299
|
+
form,
|
300
|
+
...useFormProps.formProps,
|
301
|
+
onValuesChange: formProps?.onValuesChange,
|
302
|
+
onKeyUp: formProps?.onKeyUp,
|
303
|
+
onFinish: async (values) => {
|
304
|
+
await onFinish(values);
|
305
|
+
|
306
|
+
if (autoSubmitClose) {
|
307
|
+
close();
|
308
|
+
}
|
309
|
+
|
310
|
+
if (autoResetForm) {
|
311
|
+
form.resetFields();
|
312
|
+
}
|
313
|
+
},
|
314
|
+
},
|
315
|
+
drawerProps: {
|
316
|
+
width: "500px",
|
317
|
+
onClose: handleClose,
|
318
|
+
open: visible,
|
319
|
+
forceRender: true,
|
320
|
+
},
|
321
|
+
saveButtonProps,
|
322
|
+
deleteButtonProps,
|
323
|
+
formLoading,
|
324
|
+
};
|
329
325
|
};
|