@refinedev/core 4.22.0 → 4.24.0
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 +180 -0
- package/dist/components/canAccess/index.d.ts.map +1 -1
- package/dist/contexts/refine/IRefineContext.d.ts +3 -0
- package/dist/contexts/refine/IRefineContext.d.ts.map +1 -1
- package/dist/contexts/refine/index.d.ts.map +1 -1
- package/dist/definitions/helpers/generateDocumentTitle/index.d.ts.map +1 -1
- package/dist/definitions/helpers/handleRefineOptions/index.d.ts.map +1 -1
- package/dist/definitions/helpers/pick-resource/index.d.ts.map +1 -1
- package/dist/esm/index.js +6 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/hooks/data/useCreate.d.ts +3 -2
- package/dist/hooks/data/useCreate.d.ts.map +1 -1
- package/dist/hooks/data/useCreateMany.d.ts +3 -2
- package/dist/hooks/data/useCreateMany.d.ts.map +1 -1
- package/dist/hooks/data/useCustom.d.ts +3 -2
- package/dist/hooks/data/useCustom.d.ts.map +1 -1
- package/dist/hooks/data/useCustomMutation.d.ts +3 -2
- package/dist/hooks/data/useCustomMutation.d.ts.map +1 -1
- package/dist/hooks/data/useDelete.d.ts +4 -3
- package/dist/hooks/data/useDelete.d.ts.map +1 -1
- package/dist/hooks/data/useDeleteMany.d.ts +4 -3
- package/dist/hooks/data/useDeleteMany.d.ts.map +1 -1
- package/dist/hooks/data/useInfiniteList.d.ts +3 -2
- package/dist/hooks/data/useInfiniteList.d.ts.map +1 -1
- package/dist/hooks/data/useList.d.ts +3 -2
- package/dist/hooks/data/useList.d.ts.map +1 -1
- package/dist/hooks/data/useMany.d.ts +3 -2
- package/dist/hooks/data/useMany.d.ts.map +1 -1
- package/dist/hooks/data/useOne.d.ts +3 -2
- package/dist/hooks/data/useOne.d.ts.map +1 -1
- package/dist/hooks/data/useUpdate.d.ts +4 -3
- package/dist/hooks/data/useUpdate.d.ts.map +1 -1
- package/dist/hooks/data/useUpdateMany.d.ts +4 -3
- package/dist/hooks/data/useUpdateMany.d.ts.map +1 -1
- package/dist/hooks/export/index.d.ts.map +1 -1
- package/dist/hooks/form/useForm.d.ts +4 -3
- package/dist/hooks/form/useForm.d.ts.map +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/live/useResourceSubscription/index.d.ts +1 -1
- package/dist/hooks/live/useResourceSubscription/index.d.ts.map +1 -1
- package/dist/hooks/resource/useResource/index.d.ts +11 -1
- package/dist/hooks/resource/useResource/index.d.ts.map +1 -1
- package/dist/hooks/show/useShow.d.ts +4 -3
- package/dist/hooks/show/useShow.d.ts.map +1 -1
- package/dist/hooks/useLoadingOvertime/index.d.ts +49 -0
- package/dist/hooks/useLoadingOvertime/index.d.ts.map +1 -0
- package/dist/hooks/useSelect/index.d.ts +3 -2
- package/dist/hooks/useSelect/index.d.ts.map +1 -1
- package/dist/hooks/useTable/index.d.ts +4 -3
- package/dist/hooks/useTable/index.d.ts.map +1 -1
- package/dist/iife/index.js +6 -6
- package/dist/iife/index.js.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/canAccess/index.tsx +17 -92
- package/src/contexts/refine/IRefineContext.ts +3 -0
- package/src/contexts/refine/index.tsx +3 -0
- package/src/definitions/helpers/generateDocumentTitle/index.ts +5 -3
- package/src/definitions/helpers/handleRefineOptions/index.ts +1 -0
- package/src/definitions/helpers/pick-resource/index.ts +4 -3
- package/src/hooks/data/useCreate.ts +49 -23
- package/src/hooks/data/useCreateMany.ts +54 -26
- package/src/hooks/data/useCustom.ts +17 -3
- package/src/hooks/data/useCustomMutation.ts +16 -3
- package/src/hooks/data/useDelete.ts +60 -31
- package/src/hooks/data/useDeleteMany.ts +64 -31
- package/src/hooks/data/useInfiniteList.ts +30 -14
- package/src/hooks/data/useList.ts +30 -20
- package/src/hooks/data/useMany.ts +34 -23
- package/src/hooks/data/useOne.ts +36 -22
- package/src/hooks/data/useUpdate.ts +55 -32
- package/src/hooks/data/useUpdateMany.ts +69 -33
- package/src/hooks/export/index.ts +12 -11
- package/src/hooks/form/useForm.ts +46 -98
- package/src/hooks/import/index.tsx +17 -17
- package/src/hooks/index.ts +1 -0
- package/src/hooks/live/useResourceSubscription/index.ts +6 -3
- package/src/hooks/resource/useResource/index.ts +48 -1
- package/src/hooks/show/useShow.ts +34 -80
- package/src/hooks/useLoadingOvertime/index.ts +114 -0
- package/src/hooks/useSelect/index.ts +21 -14
- package/src/hooks/useTable/index.ts +22 -8
|
@@ -39,6 +39,11 @@ import {
|
|
|
39
39
|
pickNotDeprecated,
|
|
40
40
|
useActiveAuthProvider,
|
|
41
41
|
} from "@definitions/helpers";
|
|
42
|
+
import {
|
|
43
|
+
useLoadingOvertime,
|
|
44
|
+
UseLoadingOvertimeOptionsProps,
|
|
45
|
+
UseLoadingOvertimeReturnType,
|
|
46
|
+
} from "../useLoadingOvertime";
|
|
42
47
|
|
|
43
48
|
export type UpdateParams<TData, TError, TVariables> = {
|
|
44
49
|
/**
|
|
@@ -98,7 +103,8 @@ export type UseUpdateReturnType<
|
|
|
98
103
|
TError,
|
|
99
104
|
UpdateParams<TData, TError, TVariables>,
|
|
100
105
|
UpdateContext<TData>
|
|
101
|
-
|
|
106
|
+
> &
|
|
107
|
+
UseLoadingOvertimeReturnType;
|
|
102
108
|
|
|
103
109
|
export type UseUpdateProps<
|
|
104
110
|
TData extends BaseRecord = BaseRecord,
|
|
@@ -114,7 +120,7 @@ export type UseUpdateProps<
|
|
|
114
120
|
>,
|
|
115
121
|
"mutationFn" | "onError" | "onSuccess" | "onSettled" | "onMutate"
|
|
116
122
|
>;
|
|
117
|
-
};
|
|
123
|
+
} & UseLoadingOvertimeOptionsProps;
|
|
118
124
|
|
|
119
125
|
/**
|
|
120
126
|
* `useUpdate` is a modified version of `react-query`'s {@link https://react-query.tanstack.com/reference/useMutation `useMutation`} for update mutations.
|
|
@@ -134,12 +140,13 @@ export const useUpdate = <
|
|
|
134
140
|
TVariables = {},
|
|
135
141
|
>({
|
|
136
142
|
mutationOptions,
|
|
143
|
+
overtimeOptions,
|
|
137
144
|
}: UseUpdateProps<TData, TError, TVariables> = {}): UseUpdateReturnType<
|
|
138
145
|
TData,
|
|
139
146
|
TError,
|
|
140
147
|
TVariables
|
|
141
148
|
> => {
|
|
142
|
-
const { resources } = useResource();
|
|
149
|
+
const { resources, select } = useResource();
|
|
143
150
|
const queryClient = useQueryClient();
|
|
144
151
|
const dataProvider = useDataProvider();
|
|
145
152
|
|
|
@@ -168,7 +175,7 @@ export const useUpdate = <
|
|
|
168
175
|
({
|
|
169
176
|
id,
|
|
170
177
|
values,
|
|
171
|
-
resource,
|
|
178
|
+
resource: resourceName,
|
|
172
179
|
mutationMode,
|
|
173
180
|
undoableTimeout,
|
|
174
181
|
onCancel,
|
|
@@ -176,7 +183,10 @@ export const useUpdate = <
|
|
|
176
183
|
metaData,
|
|
177
184
|
dataProviderName,
|
|
178
185
|
}) => {
|
|
186
|
+
const { resource, identifier } = select(resourceName);
|
|
187
|
+
|
|
179
188
|
const combinedMeta = getMeta({
|
|
189
|
+
resource,
|
|
180
190
|
meta: pickNotDeprecated(meta, metaData),
|
|
181
191
|
});
|
|
182
192
|
|
|
@@ -188,9 +198,9 @@ export const useUpdate = <
|
|
|
188
198
|
|
|
189
199
|
if (!(mutationModePropOrContext === "undoable")) {
|
|
190
200
|
return dataProvider(
|
|
191
|
-
pickDataProvider(
|
|
201
|
+
pickDataProvider(identifier, dataProviderName, resources),
|
|
192
202
|
).update<TData, TVariables>({
|
|
193
|
-
resource,
|
|
203
|
+
resource: resource.name,
|
|
194
204
|
id,
|
|
195
205
|
variables: values,
|
|
196
206
|
meta: combinedMeta,
|
|
@@ -202,13 +212,13 @@ export const useUpdate = <
|
|
|
202
212
|
const doMutation = () => {
|
|
203
213
|
dataProvider(
|
|
204
214
|
pickDataProvider(
|
|
205
|
-
|
|
215
|
+
identifier,
|
|
206
216
|
dataProviderName,
|
|
207
217
|
resources,
|
|
208
218
|
),
|
|
209
219
|
)
|
|
210
220
|
.update<TData, TVariables>({
|
|
211
|
-
resource,
|
|
221
|
+
resource: resource.name,
|
|
212
222
|
id,
|
|
213
223
|
variables: values,
|
|
214
224
|
meta: combinedMeta,
|
|
@@ -230,7 +240,7 @@ export const useUpdate = <
|
|
|
230
240
|
type: ActionTypes.ADD,
|
|
231
241
|
payload: {
|
|
232
242
|
id: id,
|
|
233
|
-
resource:
|
|
243
|
+
resource: identifier,
|
|
234
244
|
cancelMutation: cancelMutation,
|
|
235
245
|
doMutation: doMutation,
|
|
236
246
|
seconds: undoableTimeoutPropOrContext,
|
|
@@ -243,7 +253,7 @@ export const useUpdate = <
|
|
|
243
253
|
},
|
|
244
254
|
{
|
|
245
255
|
onMutate: async ({
|
|
246
|
-
resource,
|
|
256
|
+
resource: resourceName,
|
|
247
257
|
id,
|
|
248
258
|
mutationMode,
|
|
249
259
|
values,
|
|
@@ -251,11 +261,13 @@ export const useUpdate = <
|
|
|
251
261
|
meta,
|
|
252
262
|
metaData,
|
|
253
263
|
}) => {
|
|
264
|
+
const { identifier } = select(resourceName);
|
|
265
|
+
|
|
254
266
|
const preferredMeta = pickNotDeprecated(meta, metaData);
|
|
267
|
+
|
|
255
268
|
const queryKey = queryKeys(
|
|
256
|
-
|
|
257
|
-
pickDataProvider(
|
|
258
|
-
preferredMeta,
|
|
269
|
+
identifier,
|
|
270
|
+
pickDataProvider(identifier, dataProviderName, resources),
|
|
259
271
|
preferredMeta,
|
|
260
272
|
);
|
|
261
273
|
|
|
@@ -351,15 +363,17 @@ export const useUpdate = <
|
|
|
351
363
|
_error,
|
|
352
364
|
{
|
|
353
365
|
id,
|
|
354
|
-
resource,
|
|
366
|
+
resource: resourceName,
|
|
355
367
|
dataProviderName,
|
|
356
368
|
invalidates = ["list", "many", "detail"],
|
|
357
369
|
},
|
|
358
370
|
) => {
|
|
371
|
+
const { identifier } = select(resourceName);
|
|
372
|
+
|
|
359
373
|
invalidateStore({
|
|
360
|
-
resource,
|
|
374
|
+
resource: identifier,
|
|
361
375
|
dataProviderName: pickDataProvider(
|
|
362
|
-
|
|
376
|
+
identifier,
|
|
363
377
|
dataProviderName,
|
|
364
378
|
resources,
|
|
365
379
|
),
|
|
@@ -369,14 +383,14 @@ export const useUpdate = <
|
|
|
369
383
|
|
|
370
384
|
notificationDispatch({
|
|
371
385
|
type: ActionTypes.REMOVE,
|
|
372
|
-
payload: { id, resource },
|
|
386
|
+
payload: { id, resource: identifier },
|
|
373
387
|
});
|
|
374
388
|
},
|
|
375
389
|
onSuccess: (
|
|
376
390
|
data,
|
|
377
391
|
{
|
|
378
392
|
id,
|
|
379
|
-
resource,
|
|
393
|
+
resource: resourceName,
|
|
380
394
|
successNotification,
|
|
381
395
|
dataProviderName,
|
|
382
396
|
values,
|
|
@@ -385,15 +399,17 @@ export const useUpdate = <
|
|
|
385
399
|
},
|
|
386
400
|
context,
|
|
387
401
|
) => {
|
|
388
|
-
const
|
|
402
|
+
const { resource, identifier } = select(resourceName);
|
|
403
|
+
|
|
404
|
+
const resourceSingular = pluralize.singular(identifier);
|
|
389
405
|
|
|
390
406
|
const notificationConfig =
|
|
391
407
|
typeof successNotification === "function"
|
|
392
|
-
? successNotification(data, { id, values },
|
|
408
|
+
? successNotification(data, { id, values }, identifier)
|
|
393
409
|
: successNotification;
|
|
394
410
|
|
|
395
411
|
handleNotification(notificationConfig, {
|
|
396
|
-
key: `${id}-${
|
|
412
|
+
key: `${id}-${identifier}-notification`,
|
|
397
413
|
description: translate(
|
|
398
414
|
"notifications.success",
|
|
399
415
|
"Successful",
|
|
@@ -402,7 +418,7 @@ export const useUpdate = <
|
|
|
402
418
|
"notifications.editSuccess",
|
|
403
419
|
{
|
|
404
420
|
resource: translate(
|
|
405
|
-
`${
|
|
421
|
+
`${identifier}.${identifier}`,
|
|
406
422
|
resourceSingular,
|
|
407
423
|
),
|
|
408
424
|
},
|
|
@@ -412,7 +428,7 @@ export const useUpdate = <
|
|
|
412
428
|
});
|
|
413
429
|
|
|
414
430
|
publish?.({
|
|
415
|
-
channel: `resources/${resource}`,
|
|
431
|
+
channel: `resources/${resource.name}`,
|
|
416
432
|
type: "updated",
|
|
417
433
|
payload: {
|
|
418
434
|
ids: data.data?.id ? [data.data.id] : undefined,
|
|
@@ -440,13 +456,13 @@ export const useUpdate = <
|
|
|
440
456
|
|
|
441
457
|
log?.mutate({
|
|
442
458
|
action: "update",
|
|
443
|
-
resource,
|
|
459
|
+
resource: resource.name,
|
|
444
460
|
data: values,
|
|
445
461
|
previousData,
|
|
446
462
|
meta: {
|
|
447
463
|
id,
|
|
448
464
|
dataProviderName: pickDataProvider(
|
|
449
|
-
|
|
465
|
+
identifier,
|
|
450
466
|
dataProviderName,
|
|
451
467
|
resources,
|
|
452
468
|
),
|
|
@@ -456,11 +472,12 @@ export const useUpdate = <
|
|
|
456
472
|
},
|
|
457
473
|
onError: (
|
|
458
474
|
err: TError,
|
|
459
|
-
{ id, resource, errorNotification, values },
|
|
475
|
+
{ id, resource: resourceName, errorNotification, values },
|
|
460
476
|
context,
|
|
461
477
|
) => {
|
|
462
|
-
|
|
478
|
+
const { identifier } = select(resourceName);
|
|
463
479
|
|
|
480
|
+
// set back the queries to the context:
|
|
464
481
|
if (context) {
|
|
465
482
|
for (const query of context.previousQueries) {
|
|
466
483
|
queryClient.setQueryData(query[0], query[1]);
|
|
@@ -470,20 +487,20 @@ export const useUpdate = <
|
|
|
470
487
|
if (err.message !== "mutationCancelled") {
|
|
471
488
|
checkError?.(err);
|
|
472
489
|
|
|
473
|
-
const resourceSingular = pluralize.singular(
|
|
490
|
+
const resourceSingular = pluralize.singular(identifier);
|
|
474
491
|
|
|
475
492
|
const notificationConfig =
|
|
476
493
|
typeof errorNotification === "function"
|
|
477
|
-
? errorNotification(err, { id, values },
|
|
494
|
+
? errorNotification(err, { id, values }, identifier)
|
|
478
495
|
: errorNotification;
|
|
479
496
|
|
|
480
497
|
handleNotification(notificationConfig, {
|
|
481
|
-
key: `${id}-${
|
|
498
|
+
key: `${id}-${identifier}-notification`,
|
|
482
499
|
message: translate(
|
|
483
500
|
"notifications.editError",
|
|
484
501
|
{
|
|
485
502
|
resource: translate(
|
|
486
|
-
`${
|
|
503
|
+
`${identifier}.${identifier}`,
|
|
487
504
|
resourceSingular,
|
|
488
505
|
),
|
|
489
506
|
statusCode: err.statusCode,
|
|
@@ -499,5 +516,11 @@ export const useUpdate = <
|
|
|
499
516
|
},
|
|
500
517
|
);
|
|
501
518
|
|
|
502
|
-
|
|
519
|
+
const { elapsedTime } = useLoadingOvertime({
|
|
520
|
+
isLoading: mutation.isLoading,
|
|
521
|
+
interval: overtimeOptions?.interval,
|
|
522
|
+
onInterval: overtimeOptions?.onInterval,
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
return { ...mutation, overtime: { elapsedTime } };
|
|
503
526
|
};
|
|
@@ -40,6 +40,11 @@ import {
|
|
|
40
40
|
pickNotDeprecated,
|
|
41
41
|
useActiveAuthProvider,
|
|
42
42
|
} from "@definitions/helpers";
|
|
43
|
+
import {
|
|
44
|
+
useLoadingOvertime,
|
|
45
|
+
UseLoadingOvertimeOptionsProps,
|
|
46
|
+
UseLoadingOvertimeReturnType,
|
|
47
|
+
} from "../useLoadingOvertime";
|
|
43
48
|
|
|
44
49
|
type UpdateManyParams<TData, TError, TVariables> = {
|
|
45
50
|
ids: BaseKey[];
|
|
@@ -74,7 +79,8 @@ type UseUpdateManyReturnType<
|
|
|
74
79
|
TError,
|
|
75
80
|
UpdateManyParams<TData, TError, TVariables>,
|
|
76
81
|
UpdateContext<TData>
|
|
77
|
-
|
|
82
|
+
> &
|
|
83
|
+
UseLoadingOvertimeReturnType;
|
|
78
84
|
|
|
79
85
|
export type UseUpdateManyProps<
|
|
80
86
|
TData extends BaseRecord = BaseRecord,
|
|
@@ -90,7 +96,7 @@ export type UseUpdateManyProps<
|
|
|
90
96
|
>,
|
|
91
97
|
"mutationFn" | "onError" | "onSuccess" | "onSettled" | "onMutate"
|
|
92
98
|
>;
|
|
93
|
-
};
|
|
99
|
+
} & UseLoadingOvertimeOptionsProps;
|
|
94
100
|
|
|
95
101
|
/**
|
|
96
102
|
* `useUpdateMany` is a modified version of `react-query`'s {@link https://react-query.tanstack.com/reference/useMutation `useMutation`} for multiple update mutations.
|
|
@@ -110,12 +116,13 @@ export const useUpdateMany = <
|
|
|
110
116
|
TVariables = {},
|
|
111
117
|
>({
|
|
112
118
|
mutationOptions,
|
|
119
|
+
overtimeOptions,
|
|
113
120
|
}: UseUpdateManyProps<TData, TError, TVariables> = {}): UseUpdateManyReturnType<
|
|
114
121
|
TData,
|
|
115
122
|
TError,
|
|
116
123
|
TVariables
|
|
117
124
|
> => {
|
|
118
|
-
const { resources } = useResource();
|
|
125
|
+
const { resources, select } = useResource();
|
|
119
126
|
const queryClient = useQueryClient();
|
|
120
127
|
const dataProvider = useDataProvider();
|
|
121
128
|
const translate = useTranslate();
|
|
@@ -143,7 +150,7 @@ export const useUpdateMany = <
|
|
|
143
150
|
({
|
|
144
151
|
ids,
|
|
145
152
|
values,
|
|
146
|
-
resource,
|
|
153
|
+
resource: resourceName,
|
|
147
154
|
onCancel,
|
|
148
155
|
mutationMode,
|
|
149
156
|
undoableTimeout,
|
|
@@ -151,7 +158,10 @@ export const useUpdateMany = <
|
|
|
151
158
|
metaData,
|
|
152
159
|
dataProviderName,
|
|
153
160
|
}: UpdateManyParams<TData, TError, TVariables>) => {
|
|
161
|
+
const { resource, identifier } = select(resourceName);
|
|
162
|
+
|
|
154
163
|
const combinedMeta = getMeta({
|
|
164
|
+
resource,
|
|
155
165
|
meta: pickNotDeprecated(meta, metaData),
|
|
156
166
|
});
|
|
157
167
|
|
|
@@ -162,13 +172,13 @@ export const useUpdateMany = <
|
|
|
162
172
|
undoableTimeout ?? undoableTimeoutContext;
|
|
163
173
|
|
|
164
174
|
const selectedDataProvider = dataProvider(
|
|
165
|
-
pickDataProvider(
|
|
175
|
+
pickDataProvider(identifier, dataProviderName, resources),
|
|
166
176
|
);
|
|
167
177
|
|
|
168
178
|
const mutationFn = () => {
|
|
169
179
|
if (selectedDataProvider.updateMany) {
|
|
170
180
|
return selectedDataProvider.updateMany<TData, TVariables>({
|
|
171
|
-
resource,
|
|
181
|
+
resource: resource.name,
|
|
172
182
|
ids,
|
|
173
183
|
variables: values,
|
|
174
184
|
meta: combinedMeta,
|
|
@@ -178,7 +188,7 @@ export const useUpdateMany = <
|
|
|
178
188
|
return handleMultiple(
|
|
179
189
|
ids.map((id) =>
|
|
180
190
|
selectedDataProvider.update<TData, TVariables>({
|
|
181
|
-
resource,
|
|
191
|
+
resource: resource.name,
|
|
182
192
|
id,
|
|
183
193
|
variables: values,
|
|
184
194
|
meta: combinedMeta,
|
|
@@ -213,7 +223,7 @@ export const useUpdateMany = <
|
|
|
213
223
|
type: ActionTypes.ADD,
|
|
214
224
|
payload: {
|
|
215
225
|
id: ids,
|
|
216
|
-
resource:
|
|
226
|
+
resource: identifier,
|
|
217
227
|
cancelMutation: cancelMutation,
|
|
218
228
|
doMutation: doMutation,
|
|
219
229
|
seconds: undoableTimeoutPropOrContext,
|
|
@@ -227,7 +237,7 @@ export const useUpdateMany = <
|
|
|
227
237
|
|
|
228
238
|
{
|
|
229
239
|
onMutate: async ({
|
|
230
|
-
resource,
|
|
240
|
+
resource: resourceName,
|
|
231
241
|
ids,
|
|
232
242
|
values,
|
|
233
243
|
mutationMode,
|
|
@@ -235,10 +245,11 @@ export const useUpdateMany = <
|
|
|
235
245
|
meta,
|
|
236
246
|
metaData,
|
|
237
247
|
}) => {
|
|
248
|
+
const { identifier } = select(resourceName);
|
|
249
|
+
|
|
238
250
|
const queryKey = queryKeys(
|
|
239
|
-
|
|
240
|
-
pickDataProvider(
|
|
241
|
-
pickNotDeprecated(meta, metaData),
|
|
251
|
+
identifier,
|
|
252
|
+
pickDataProvider(identifier, dataProviderName, resources),
|
|
242
253
|
pickNotDeprecated(meta, metaData),
|
|
243
254
|
);
|
|
244
255
|
|
|
@@ -344,13 +355,19 @@ export const useUpdateMany = <
|
|
|
344
355
|
queryKey,
|
|
345
356
|
};
|
|
346
357
|
},
|
|
347
|
-
onSettled: (
|
|
358
|
+
onSettled: (
|
|
359
|
+
_data,
|
|
360
|
+
_error,
|
|
361
|
+
{ ids, resource: resourceName, dataProviderName },
|
|
362
|
+
) => {
|
|
363
|
+
const { identifier } = select(resourceName);
|
|
364
|
+
|
|
348
365
|
// invalidate the cache for the list and many queries:
|
|
349
366
|
invalidateStore({
|
|
350
|
-
resource,
|
|
367
|
+
resource: identifier,
|
|
351
368
|
invalidates: ["list", "many"],
|
|
352
369
|
dataProviderName: pickDataProvider(
|
|
353
|
-
|
|
370
|
+
identifier,
|
|
354
371
|
dataProviderName,
|
|
355
372
|
resources,
|
|
356
373
|
),
|
|
@@ -358,10 +375,10 @@ export const useUpdateMany = <
|
|
|
358
375
|
|
|
359
376
|
ids.forEach((id) =>
|
|
360
377
|
invalidateStore({
|
|
361
|
-
resource,
|
|
378
|
+
resource: identifier,
|
|
362
379
|
invalidates: ["detail"],
|
|
363
380
|
dataProviderName: pickDataProvider(
|
|
364
|
-
|
|
381
|
+
identifier,
|
|
365
382
|
dataProviderName,
|
|
366
383
|
resources,
|
|
367
384
|
),
|
|
@@ -371,14 +388,14 @@ export const useUpdateMany = <
|
|
|
371
388
|
|
|
372
389
|
notificationDispatch({
|
|
373
390
|
type: ActionTypes.REMOVE,
|
|
374
|
-
payload: { id: ids, resource },
|
|
391
|
+
payload: { id: ids, resource: identifier },
|
|
375
392
|
});
|
|
376
393
|
},
|
|
377
394
|
onSuccess: (
|
|
378
395
|
data,
|
|
379
396
|
{
|
|
380
397
|
ids,
|
|
381
|
-
resource,
|
|
398
|
+
resource: resourceName,
|
|
382
399
|
meta,
|
|
383
400
|
metaData,
|
|
384
401
|
dataProviderName,
|
|
@@ -387,15 +404,17 @@ export const useUpdateMany = <
|
|
|
387
404
|
},
|
|
388
405
|
context,
|
|
389
406
|
) => {
|
|
390
|
-
const
|
|
407
|
+
const { resource, identifier } = select(resourceName);
|
|
408
|
+
|
|
409
|
+
const resourceSingular = pluralize.singular(identifier);
|
|
391
410
|
|
|
392
411
|
const notificationConfig =
|
|
393
412
|
typeof successNotification === "function"
|
|
394
|
-
? successNotification(data, { ids, values },
|
|
413
|
+
? successNotification(data, { ids, values }, identifier)
|
|
395
414
|
: successNotification;
|
|
396
415
|
|
|
397
416
|
handleNotification(notificationConfig, {
|
|
398
|
-
key: `${ids}-${
|
|
417
|
+
key: `${ids}-${identifier}-notification`,
|
|
399
418
|
description: translate(
|
|
400
419
|
"notifications.success",
|
|
401
420
|
"Successful",
|
|
@@ -404,8 +423,8 @@ export const useUpdateMany = <
|
|
|
404
423
|
"notifications.editSuccess",
|
|
405
424
|
{
|
|
406
425
|
resource: translate(
|
|
407
|
-
`${
|
|
408
|
-
|
|
426
|
+
`${identifier}.${identifier}`,
|
|
427
|
+
identifier,
|
|
409
428
|
),
|
|
410
429
|
},
|
|
411
430
|
`Successfully updated ${resourceSingular}`,
|
|
@@ -414,7 +433,7 @@ export const useUpdateMany = <
|
|
|
414
433
|
});
|
|
415
434
|
|
|
416
435
|
publish?.({
|
|
417
|
-
channel: `resources/${resource}`,
|
|
436
|
+
channel: `resources/${resource.name}`,
|
|
418
437
|
type: "updated",
|
|
419
438
|
payload: {
|
|
420
439
|
ids: ids.map(String),
|
|
@@ -441,18 +460,23 @@ export const useUpdateMany = <
|
|
|
441
460
|
});
|
|
442
461
|
}
|
|
443
462
|
|
|
463
|
+
const combinedMeta = getMeta({
|
|
464
|
+
resource,
|
|
465
|
+
meta: pickNotDeprecated(meta, metaData),
|
|
466
|
+
});
|
|
467
|
+
|
|
444
468
|
const { fields, operation, variables, ...rest } =
|
|
445
|
-
|
|
469
|
+
combinedMeta || {};
|
|
446
470
|
|
|
447
471
|
log?.mutate({
|
|
448
472
|
action: "updateMany",
|
|
449
|
-
resource,
|
|
473
|
+
resource: resource.name,
|
|
450
474
|
data: values,
|
|
451
475
|
previousData,
|
|
452
476
|
meta: {
|
|
453
477
|
ids,
|
|
454
478
|
dataProviderName: pickDataProvider(
|
|
455
|
-
|
|
479
|
+
identifier,
|
|
456
480
|
dataProviderName,
|
|
457
481
|
resources,
|
|
458
482
|
),
|
|
@@ -462,9 +486,11 @@ export const useUpdateMany = <
|
|
|
462
486
|
},
|
|
463
487
|
onError: (
|
|
464
488
|
err: TError,
|
|
465
|
-
{ ids, resource, errorNotification, values },
|
|
489
|
+
{ ids, resource: resourceName, errorNotification, values },
|
|
466
490
|
context,
|
|
467
491
|
) => {
|
|
492
|
+
const { identifier } = select(resourceName);
|
|
493
|
+
|
|
468
494
|
// set back the queries to the context:
|
|
469
495
|
if (context) {
|
|
470
496
|
for (const query of context.previousQueries) {
|
|
@@ -475,15 +501,19 @@ export const useUpdateMany = <
|
|
|
475
501
|
if (err.message !== "mutationCancelled") {
|
|
476
502
|
checkError?.(err);
|
|
477
503
|
|
|
478
|
-
const resourceSingular = pluralize.singular(
|
|
504
|
+
const resourceSingular = pluralize.singular(identifier);
|
|
479
505
|
|
|
480
506
|
const notificationConfig =
|
|
481
507
|
typeof errorNotification === "function"
|
|
482
|
-
? errorNotification(
|
|
508
|
+
? errorNotification(
|
|
509
|
+
err,
|
|
510
|
+
{ ids, values },
|
|
511
|
+
identifier,
|
|
512
|
+
)
|
|
483
513
|
: errorNotification;
|
|
484
514
|
|
|
485
515
|
handleNotification(notificationConfig, {
|
|
486
|
-
key: `${ids}-${
|
|
516
|
+
key: `${ids}-${identifier}-updateMany-error-notification`,
|
|
487
517
|
message: translate(
|
|
488
518
|
"notifications.editError",
|
|
489
519
|
{
|
|
@@ -501,5 +531,11 @@ export const useUpdateMany = <
|
|
|
501
531
|
},
|
|
502
532
|
);
|
|
503
533
|
|
|
504
|
-
|
|
534
|
+
const { elapsedTime } = useLoadingOvertime({
|
|
535
|
+
isLoading: mutation.isLoading,
|
|
536
|
+
interval: overtimeOptions?.interval,
|
|
537
|
+
onInterval: overtimeOptions?.onInterval,
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
return { ...mutation, overtime: { elapsedTime } };
|
|
505
541
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useState } from "react";
|
|
2
|
-
import { useResource, useDataProvider } from "@hooks";
|
|
2
|
+
import { useResource, useDataProvider, useMeta } from "@hooks";
|
|
3
3
|
import {
|
|
4
4
|
BaseRecord,
|
|
5
5
|
MapDataFn,
|
|
@@ -110,24 +110,25 @@ export const useExport = <
|
|
|
110
110
|
const [isLoading, setIsLoading] = useState(false);
|
|
111
111
|
|
|
112
112
|
const dataProvider = useDataProvider();
|
|
113
|
-
|
|
114
|
-
const { resource, resources } = useResource(
|
|
113
|
+
const getMeta = useMeta();
|
|
114
|
+
const { resource, resources, identifier } = useResource(
|
|
115
115
|
pickNotDeprecated(resourceFromProps, resourceName),
|
|
116
116
|
);
|
|
117
117
|
|
|
118
118
|
const filename = `${userFriendlyResourceName(
|
|
119
|
-
|
|
119
|
+
identifier,
|
|
120
120
|
"plural",
|
|
121
121
|
)}-${new Date().toLocaleString()}`;
|
|
122
122
|
|
|
123
123
|
const { getList } = dataProvider(
|
|
124
|
-
pickDataProvider(
|
|
125
|
-
resource?.identifier ?? resource?.name,
|
|
126
|
-
dataProviderName,
|
|
127
|
-
resources,
|
|
128
|
-
),
|
|
124
|
+
pickDataProvider(identifier, dataProviderName, resources),
|
|
129
125
|
);
|
|
130
126
|
|
|
127
|
+
const combinedMeta = getMeta({
|
|
128
|
+
resource,
|
|
129
|
+
meta: pickNotDeprecated(meta, metaData),
|
|
130
|
+
});
|
|
131
|
+
|
|
131
132
|
const triggerExport = async () => {
|
|
132
133
|
setIsLoading(true);
|
|
133
134
|
|
|
@@ -147,8 +148,8 @@ export const useExport = <
|
|
|
147
148
|
pageSize,
|
|
148
149
|
mode: "server",
|
|
149
150
|
},
|
|
150
|
-
meta:
|
|
151
|
-
metaData:
|
|
151
|
+
meta: combinedMeta,
|
|
152
|
+
metaData: combinedMeta,
|
|
152
153
|
});
|
|
153
154
|
|
|
154
155
|
current++;
|