@applica-software-guru/react-admin 1.4.200 → 1.4.202
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/dist/components/ra-buttons/CreateInDialogButton.d.ts +22 -3
- package/dist/components/ra-buttons/CreateInDialogButton.d.ts.map +1 -1
- package/dist/components/ra-buttons/EditInDialogButton.d.ts +3 -2
- package/dist/components/ra-buttons/EditInDialogButton.d.ts.map +1 -1
- package/dist/components/ra-fields/ReferenceManyField.d.ts.map +1 -1
- package/dist/components/ra-forms/Create.d.ts +1 -1
- package/dist/react-admin.cjs.js +58 -58
- package/dist/react-admin.cjs.js.map +1 -1
- package/dist/react-admin.es.js +5338 -5321
- package/dist/react-admin.es.js.map +1 -1
- package/dist/react-admin.umd.js +58 -58
- package/dist/react-admin.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/ra-buttons/CreateInDialogButton.tsx +36 -8
- package/src/components/ra-buttons/EditInDialogButton.tsx +25 -13
- package/src/components/ra-fields/ReferenceManyField.tsx +1 -2
package/package.json
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
Button,
|
|
3
3
|
CreateButtonClasses,
|
|
4
4
|
CreateContextProvider,
|
|
5
|
+
CreateControllerProps,
|
|
5
6
|
CreateControllerResult,
|
|
6
7
|
RedirectionSideEffect,
|
|
7
8
|
SaveButton,
|
|
@@ -9,16 +10,17 @@ import {
|
|
|
9
10
|
useNotify,
|
|
10
11
|
useRedirect,
|
|
11
12
|
useResourceContext,
|
|
12
|
-
useTranslate
|
|
13
|
+
useTranslate,
|
|
14
|
+
UseCreateMutateParams
|
|
13
15
|
} from 'react-admin';
|
|
14
16
|
import { Dialog, Fab, useMediaQuery, useTheme } from '@mui/material';
|
|
15
17
|
import React, { useCallback, useState } from 'react';
|
|
16
18
|
import { SxProps, Theme, styled } from '@mui/material/styles';
|
|
17
|
-
import { PlusCircleOutlined } from '@ant-design/icons';
|
|
18
19
|
import { Toolbar } from '../ra-forms';
|
|
19
20
|
import clsx from 'clsx';
|
|
20
21
|
import { useAppConfig } from '../../hooks';
|
|
21
22
|
import { useQueryClient } from 'react-query';
|
|
23
|
+
import ContentAdd from '@mui/icons-material/Add';
|
|
22
24
|
|
|
23
25
|
const updateColl = (old: any, data: any) => {
|
|
24
26
|
const id = data.id;
|
|
@@ -38,13 +40,22 @@ const setManyQueryData = (coll: any, data: any) => (coll && coll.length > 0 ? up
|
|
|
38
40
|
const setListQueryData = (res: any, data: any) =>
|
|
39
41
|
res && res.data ? { ...res, data: updateColl(res.data, data), total: res.total + 1 } : res;
|
|
40
42
|
|
|
41
|
-
export type CreateInDialogContentProps = {
|
|
43
|
+
export type CreateInDialogContentProps = CreateControllerProps & {
|
|
42
44
|
onClose: () => void;
|
|
43
45
|
record?: any;
|
|
44
46
|
redirect: RedirectionSideEffect | boolean | undefined;
|
|
45
47
|
children: React.ReactElement;
|
|
48
|
+
/**
|
|
49
|
+
* @deprecated Use mutationOptions.onSubmit instead
|
|
50
|
+
*/
|
|
46
51
|
onSubmit?: (record: any, close: () => void) => void;
|
|
52
|
+
/**
|
|
53
|
+
* @deprecated Use mutationOptions.onSuccess instead
|
|
54
|
+
*/
|
|
47
55
|
onSuccess?: (data: any) => void;
|
|
56
|
+
/**
|
|
57
|
+
* @deprecated Use mutationOptions.onError instead
|
|
58
|
+
*/
|
|
48
59
|
onError?: (error: any) => void;
|
|
49
60
|
};
|
|
50
61
|
|
|
@@ -55,14 +66,15 @@ const CreateInDialogContent = ({
|
|
|
55
66
|
redirect: _redirect = false,
|
|
56
67
|
onSubmit,
|
|
57
68
|
onSuccess,
|
|
58
|
-
onError
|
|
69
|
+
onError,
|
|
70
|
+
...props
|
|
59
71
|
}: CreateInDialogContentProps) => {
|
|
60
72
|
const queryClient = useQueryClient();
|
|
61
73
|
const resource = useResourceContext();
|
|
62
74
|
const redirect = useRedirect();
|
|
63
75
|
const notify = useNotify();
|
|
64
76
|
const handleSuccess = useCallback(
|
|
65
|
-
(data: any) => {
|
|
77
|
+
(data: any, variables: UseCreateMutateParams<any>, context: unknown) => {
|
|
66
78
|
const now = Date.now();
|
|
67
79
|
const updatedAt = now;
|
|
68
80
|
|
|
@@ -83,11 +95,17 @@ const CreateInDialogContent = ({
|
|
|
83
95
|
if (onSuccess) {
|
|
84
96
|
onSuccess(data);
|
|
85
97
|
}
|
|
98
|
+
// WARN: This is a temporary solution to handle onSuccess from mutationOptions
|
|
99
|
+
if (props?.mutationOptions?.onSuccess) {
|
|
100
|
+
props.mutationOptions.onSuccess(data, variables, context);
|
|
101
|
+
}
|
|
86
102
|
},
|
|
87
103
|
[onClose, onSuccess, queryClient, resource, notify, redirect, _redirect]
|
|
88
104
|
);
|
|
89
105
|
const { save, ...createProps } = useCreateController({
|
|
106
|
+
...props,
|
|
90
107
|
mutationOptions: {
|
|
108
|
+
...props?.mutationOptions,
|
|
91
109
|
onSuccess: handleSuccess,
|
|
92
110
|
onError: onError
|
|
93
111
|
}
|
|
@@ -144,7 +162,7 @@ const StyledFab = styled(Fab, { overridesResolver: (_props, styles) => styles.ro
|
|
|
144
162
|
}
|
|
145
163
|
}));
|
|
146
164
|
|
|
147
|
-
export type CreateInDialogButtonProps = {
|
|
165
|
+
export type CreateInDialogButtonProps = CreateControllerProps & {
|
|
148
166
|
fullWidth?: boolean;
|
|
149
167
|
maxWidth?: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | false;
|
|
150
168
|
label?: string;
|
|
@@ -159,8 +177,18 @@ export type CreateInDialogButtonProps = {
|
|
|
159
177
|
* If set to false, the button will always render as a regular button, regardless of the screen size.
|
|
160
178
|
*/
|
|
161
179
|
fab: boolean;
|
|
180
|
+
/**
|
|
181
|
+
* @deprecated Use mutationOptions.onSubmit instead
|
|
182
|
+
*/
|
|
162
183
|
onSubmit?: (record: any, close: () => void) => void;
|
|
184
|
+
/**
|
|
185
|
+
* @deprecated Use mutationOptions.onSuccess instead
|
|
186
|
+
*/
|
|
163
187
|
onSuccess?: (data: any) => void;
|
|
188
|
+
/**
|
|
189
|
+
*
|
|
190
|
+
* @deprecated Use mutationOptions.onError instead
|
|
191
|
+
*/
|
|
164
192
|
onError?: (error: any) => void;
|
|
165
193
|
};
|
|
166
194
|
|
|
@@ -204,11 +232,11 @@ export function CreateInDialogButton({
|
|
|
204
232
|
aria-label={label && translate(label)}
|
|
205
233
|
onClick={handleOpen}
|
|
206
234
|
>
|
|
207
|
-
<
|
|
235
|
+
<ContentAdd />
|
|
208
236
|
</StyledFab>
|
|
209
237
|
) : (
|
|
210
238
|
<Button {...props} sx={sx} label={label} onClick={handleOpen} style={style}>
|
|
211
|
-
<
|
|
239
|
+
<ContentAdd />
|
|
212
240
|
</Button>
|
|
213
241
|
)}
|
|
214
242
|
<Dialog
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import {
|
|
3
3
|
Button,
|
|
4
4
|
EditContextProvider,
|
|
5
|
+
EditControllerProps,
|
|
5
6
|
SaveButton,
|
|
6
7
|
useEditController,
|
|
7
8
|
useGetOne,
|
|
@@ -16,31 +17,39 @@ import { Edit } from '@mui/icons-material';
|
|
|
16
17
|
import { Toolbar } from '../ra-forms';
|
|
17
18
|
import { useAppConfig } from '../../hooks';
|
|
18
19
|
|
|
19
|
-
type EditInDialogContentProps = {
|
|
20
|
+
type EditInDialogContentProps = EditControllerProps & {
|
|
20
21
|
onClose: () => void;
|
|
21
22
|
children: React.ReactElement;
|
|
22
23
|
};
|
|
23
|
-
const EditInDialogContent = ({ onClose, children }: EditInDialogContentProps) => {
|
|
24
|
+
const EditInDialogContent = ({ onClose, children, mutationMode = 'pessimistic', ...props }: EditInDialogContentProps) => {
|
|
24
25
|
const notify = useNotify();
|
|
25
26
|
const record = useRecordContext();
|
|
26
27
|
const resource = useResourceContext();
|
|
27
28
|
const { id } = record;
|
|
28
29
|
const { isLoading, data } = useGetOne(resource, { id });
|
|
29
30
|
|
|
30
|
-
const handleSuccess = useCallback(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
const handleSuccess = useCallback(
|
|
32
|
+
(...args: any) => {
|
|
33
|
+
notify('ra.notification.updated', {
|
|
34
|
+
type: 'info',
|
|
35
|
+
messageArgs: {
|
|
36
|
+
smart_count: 1
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
onClose();
|
|
40
|
+
if (props.onSuccess) {
|
|
41
|
+
props.onSuccess(...args);
|
|
35
42
|
}
|
|
36
|
-
}
|
|
37
|
-
onClose
|
|
38
|
-
|
|
43
|
+
},
|
|
44
|
+
[onClose, notify]
|
|
45
|
+
);
|
|
39
46
|
const { save, saving } = useEditController({
|
|
47
|
+
...props,
|
|
40
48
|
resource,
|
|
41
49
|
id,
|
|
42
|
-
mutationMode
|
|
50
|
+
mutationMode,
|
|
43
51
|
mutationOptions: {
|
|
52
|
+
...props?.mutationOptions,
|
|
44
53
|
onSuccess: handleSuccess
|
|
45
54
|
}
|
|
46
55
|
});
|
|
@@ -67,7 +76,7 @@ const EditInDialogContent = ({ onClose, children }: EditInDialogContentProps) =>
|
|
|
67
76
|
);
|
|
68
77
|
};
|
|
69
78
|
|
|
70
|
-
export type EditInDialogButtonProps = {
|
|
79
|
+
export type EditInDialogButtonProps = EditControllerProps & {
|
|
71
80
|
fullWidth?: boolean;
|
|
72
81
|
maxWidth?: false | Breakpoint | undefined;
|
|
73
82
|
label?: string;
|
|
@@ -80,6 +89,7 @@ export function EditInDialogButton({
|
|
|
80
89
|
maxWidth = 'md',
|
|
81
90
|
label = 'ra.action.edit',
|
|
82
91
|
style,
|
|
92
|
+
children,
|
|
83
93
|
...props
|
|
84
94
|
}: EditInDialogButtonProps): JSX.Element {
|
|
85
95
|
const [open, setOpen] = useState(false);
|
|
@@ -108,7 +118,9 @@ export function EditInDialogButton({
|
|
|
108
118
|
fullWidth={fullWidth}
|
|
109
119
|
maxWidth={maxWidth}
|
|
110
120
|
>
|
|
111
|
-
<EditInDialogContent onClose={handleClose}>
|
|
121
|
+
<EditInDialogContent {...props} onClose={handleClose}>
|
|
122
|
+
{children}
|
|
123
|
+
</EditInDialogContent>
|
|
112
124
|
</Dialog>
|
|
113
125
|
</>
|
|
114
126
|
);
|