@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
|
@@ -22,6 +22,11 @@ import {
|
|
|
22
22
|
Prettify,
|
|
23
23
|
SuccessErrorNotification,
|
|
24
24
|
} from "../../interfaces";
|
|
25
|
+
import {
|
|
26
|
+
useLoadingOvertime,
|
|
27
|
+
UseLoadingOvertimeOptionsProps,
|
|
28
|
+
UseLoadingOvertimeReturnType,
|
|
29
|
+
} from "../useLoadingOvertime";
|
|
25
30
|
|
|
26
31
|
interface UseCustomConfig<TQuery, TPayload> {
|
|
27
32
|
/**
|
|
@@ -73,7 +78,8 @@ export type UseCustomProps<TQueryFnData, TError, TQuery, TPayload, TData> = {
|
|
|
73
78
|
CustomResponse<TData>,
|
|
74
79
|
TError,
|
|
75
80
|
Prettify<UseCustomConfig<TQuery, TPayload> & MetaQuery>
|
|
76
|
-
|
|
81
|
+
> &
|
|
82
|
+
UseLoadingOvertimeOptionsProps;
|
|
77
83
|
|
|
78
84
|
/**
|
|
79
85
|
* `useCustom` is a modified version of `react-query`'s {@link https://react-query.tanstack.com/guides/queries `useQuery`} used for custom requests.
|
|
@@ -106,13 +112,15 @@ export const useCustom = <
|
|
|
106
112
|
meta,
|
|
107
113
|
metaData,
|
|
108
114
|
dataProviderName,
|
|
115
|
+
overtimeOptions,
|
|
109
116
|
}: UseCustomProps<
|
|
110
117
|
TQueryFnData,
|
|
111
118
|
TError,
|
|
112
119
|
TQuery,
|
|
113
120
|
TPayload,
|
|
114
121
|
TData
|
|
115
|
-
>): QueryObserverResult<CustomResponse<TData>, TError>
|
|
122
|
+
>): QueryObserverResult<CustomResponse<TData>, TError> &
|
|
123
|
+
UseLoadingOvertimeReturnType => {
|
|
116
124
|
const dataProvider = useDataProvider();
|
|
117
125
|
const authProvider = useActiveAuthProvider();
|
|
118
126
|
const { mutate: checkError } = useOnError({
|
|
@@ -201,7 +209,13 @@ export const useCustom = <
|
|
|
201
209
|
});
|
|
202
210
|
},
|
|
203
211
|
});
|
|
204
|
-
|
|
212
|
+
const { elapsedTime } = useLoadingOvertime({
|
|
213
|
+
isLoading: queryResponse.isFetching,
|
|
214
|
+
interval: overtimeOptions?.interval,
|
|
215
|
+
onInterval: overtimeOptions?.onInterval,
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
return { ...queryResponse, overtime: { elapsedTime } };
|
|
205
219
|
} else {
|
|
206
220
|
throw Error("Not implemented custom on data provider.");
|
|
207
221
|
}
|
|
@@ -20,6 +20,11 @@ import {
|
|
|
20
20
|
Prettify,
|
|
21
21
|
} from "../../interfaces";
|
|
22
22
|
import { pickNotDeprecated, useActiveAuthProvider } from "@definitions/helpers";
|
|
23
|
+
import {
|
|
24
|
+
useLoadingOvertime,
|
|
25
|
+
UseLoadingOvertimeOptionsProps,
|
|
26
|
+
UseLoadingOvertimeReturnType,
|
|
27
|
+
} from "../useLoadingOvertime";
|
|
23
28
|
|
|
24
29
|
interface UseCustomMutationConfig {
|
|
25
30
|
headers?: {};
|
|
@@ -71,7 +76,7 @@ export type UseCustomMutationProps<
|
|
|
71
76
|
>,
|
|
72
77
|
"mutationFn" | "onError" | "onSuccess"
|
|
73
78
|
>;
|
|
74
|
-
};
|
|
79
|
+
} & UseLoadingOvertimeOptionsProps;
|
|
75
80
|
|
|
76
81
|
/**
|
|
77
82
|
* `useCustomMutation` is a modified version of `react-query`'s {@link https://react-query.tanstack.com/reference/useMutation `useMutation`} for create mutations.
|
|
@@ -92,11 +97,13 @@ export const useCustomMutation = <
|
|
|
92
97
|
TVariables = {},
|
|
93
98
|
>({
|
|
94
99
|
mutationOptions,
|
|
100
|
+
overtimeOptions,
|
|
95
101
|
}: UseCustomMutationProps<
|
|
96
102
|
TData,
|
|
97
103
|
TError,
|
|
98
104
|
TVariables
|
|
99
|
-
> = {}): UseCustomMutationReturnType<TData, TError, TVariables>
|
|
105
|
+
> = {}): UseCustomMutationReturnType<TData, TError, TVariables> &
|
|
106
|
+
UseLoadingOvertimeReturnType => {
|
|
100
107
|
const authProvider = useActiveAuthProvider();
|
|
101
108
|
const { mutate: checkError } = useOnError({
|
|
102
109
|
v3LegacyAuthProviderCompatible: Boolean(authProvider?.isLegacy),
|
|
@@ -195,5 +202,11 @@ export const useCustomMutation = <
|
|
|
195
202
|
},
|
|
196
203
|
);
|
|
197
204
|
|
|
198
|
-
|
|
205
|
+
const { elapsedTime } = useLoadingOvertime({
|
|
206
|
+
isLoading: mutation.isLoading,
|
|
207
|
+
interval: overtimeOptions?.interval,
|
|
208
|
+
onInterval: overtimeOptions?.onInterval,
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
return { ...mutation, overtime: { elapsedTime } };
|
|
199
212
|
};
|
|
@@ -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 DeleteParams<TData, TError, TVariables> = {
|
|
44
49
|
id: BaseKey;
|
|
@@ -65,7 +70,8 @@ export type UseDeleteReturnType<
|
|
|
65
70
|
TError,
|
|
66
71
|
DeleteParams<TData, TError, TVariables>,
|
|
67
72
|
DeleteContext<TData>
|
|
68
|
-
|
|
73
|
+
> &
|
|
74
|
+
UseLoadingOvertimeReturnType;
|
|
69
75
|
|
|
70
76
|
export type UseDeleteProps<
|
|
71
77
|
TData extends BaseRecord = BaseRecord,
|
|
@@ -81,7 +87,7 @@ export type UseDeleteProps<
|
|
|
81
87
|
>,
|
|
82
88
|
"mutationFn" | "onError" | "onSuccess" | "onSettled" | "onMutate"
|
|
83
89
|
>;
|
|
84
|
-
};
|
|
90
|
+
} & UseLoadingOvertimeOptionsProps;
|
|
85
91
|
|
|
86
92
|
/**
|
|
87
93
|
* `useDelete` is a modified version of `react-query`'s {@link https://react-query.tanstack.com/reference/useMutation `useMutation`} for delete mutations.
|
|
@@ -101,6 +107,7 @@ export const useDelete = <
|
|
|
101
107
|
TVariables = {},
|
|
102
108
|
>({
|
|
103
109
|
mutationOptions,
|
|
110
|
+
overtimeOptions,
|
|
104
111
|
}: UseDeleteProps<TData, TError, TVariables> = {}): UseDeleteReturnType<
|
|
105
112
|
TData,
|
|
106
113
|
TError,
|
|
@@ -112,7 +119,7 @@ export const useDelete = <
|
|
|
112
119
|
});
|
|
113
120
|
const dataProvider = useDataProvider();
|
|
114
121
|
|
|
115
|
-
const { resources } = useResource();
|
|
122
|
+
const { resources, select } = useResource();
|
|
116
123
|
const queryClient = useQueryClient();
|
|
117
124
|
|
|
118
125
|
const {
|
|
@@ -138,14 +145,17 @@ export const useDelete = <
|
|
|
138
145
|
id,
|
|
139
146
|
mutationMode,
|
|
140
147
|
undoableTimeout,
|
|
141
|
-
resource,
|
|
148
|
+
resource: resourceName,
|
|
142
149
|
onCancel,
|
|
143
150
|
meta,
|
|
144
151
|
metaData,
|
|
145
152
|
dataProviderName,
|
|
146
153
|
values,
|
|
147
154
|
}) => {
|
|
155
|
+
const { resource, identifier } = select(resourceName);
|
|
156
|
+
|
|
148
157
|
const combinedMeta = getMeta({
|
|
158
|
+
resource,
|
|
149
159
|
meta: pickNotDeprecated(meta, metaData),
|
|
150
160
|
});
|
|
151
161
|
|
|
@@ -157,9 +167,9 @@ export const useDelete = <
|
|
|
157
167
|
|
|
158
168
|
if (!(mutationModePropOrContext === "undoable")) {
|
|
159
169
|
return dataProvider(
|
|
160
|
-
pickDataProvider(
|
|
170
|
+
pickDataProvider(identifier, dataProviderName, resources),
|
|
161
171
|
).deleteOne<TData, TVariables>({
|
|
162
|
-
resource,
|
|
172
|
+
resource: resource.name,
|
|
163
173
|
id,
|
|
164
174
|
meta: combinedMeta,
|
|
165
175
|
metaData: combinedMeta,
|
|
@@ -172,13 +182,13 @@ export const useDelete = <
|
|
|
172
182
|
const doMutation = () => {
|
|
173
183
|
dataProvider(
|
|
174
184
|
pickDataProvider(
|
|
175
|
-
|
|
185
|
+
identifier,
|
|
176
186
|
dataProviderName,
|
|
177
187
|
resources,
|
|
178
188
|
),
|
|
179
189
|
)
|
|
180
190
|
.deleteOne<TData, TVariables>({
|
|
181
|
-
resource,
|
|
191
|
+
resource: resource.name,
|
|
182
192
|
id,
|
|
183
193
|
meta: combinedMeta,
|
|
184
194
|
metaData: combinedMeta,
|
|
@@ -200,7 +210,7 @@ export const useDelete = <
|
|
|
200
210
|
type: ActionTypes.ADD,
|
|
201
211
|
payload: {
|
|
202
212
|
id,
|
|
203
|
-
resource:
|
|
213
|
+
resource: identifier,
|
|
204
214
|
cancelMutation: cancelMutation,
|
|
205
215
|
doMutation: doMutation,
|
|
206
216
|
seconds: undoableTimeoutPropOrContext,
|
|
@@ -214,17 +224,19 @@ export const useDelete = <
|
|
|
214
224
|
{
|
|
215
225
|
onMutate: async ({
|
|
216
226
|
id,
|
|
217
|
-
resource,
|
|
227
|
+
resource: resourceName,
|
|
218
228
|
mutationMode,
|
|
219
229
|
dataProviderName,
|
|
220
230
|
meta,
|
|
221
231
|
metaData,
|
|
222
232
|
}) => {
|
|
233
|
+
const { identifier } = select(resourceName);
|
|
234
|
+
|
|
223
235
|
const preferredMeta = pickNotDeprecated(meta, metaData);
|
|
236
|
+
|
|
224
237
|
const queryKey = queryKeys(
|
|
225
|
-
|
|
226
|
-
pickDataProvider(
|
|
227
|
-
preferredMeta,
|
|
238
|
+
identifier,
|
|
239
|
+
pickDataProvider(identifier, dataProviderName, resources),
|
|
228
240
|
preferredMeta,
|
|
229
241
|
);
|
|
230
242
|
|
|
@@ -294,16 +306,18 @@ export const useDelete = <
|
|
|
294
306
|
_error,
|
|
295
307
|
{
|
|
296
308
|
id,
|
|
297
|
-
resource,
|
|
309
|
+
resource: resourceName,
|
|
298
310
|
dataProviderName,
|
|
299
311
|
invalidates = ["list", "many"],
|
|
300
312
|
},
|
|
301
313
|
) => {
|
|
314
|
+
const { identifier } = select(resourceName);
|
|
315
|
+
|
|
302
316
|
// invalidate the cache for the list and many queries:
|
|
303
317
|
invalidateStore({
|
|
304
|
-
resource,
|
|
318
|
+
resource: identifier,
|
|
305
319
|
dataProviderName: pickDataProvider(
|
|
306
|
-
|
|
320
|
+
identifier,
|
|
307
321
|
dataProviderName,
|
|
308
322
|
resources,
|
|
309
323
|
),
|
|
@@ -312,14 +326,14 @@ export const useDelete = <
|
|
|
312
326
|
|
|
313
327
|
notificationDispatch({
|
|
314
328
|
type: ActionTypes.REMOVE,
|
|
315
|
-
payload: { id, resource },
|
|
329
|
+
payload: { id, resource: identifier },
|
|
316
330
|
});
|
|
317
331
|
},
|
|
318
332
|
onSuccess: (
|
|
319
333
|
_data,
|
|
320
334
|
{
|
|
321
335
|
id,
|
|
322
|
-
resource,
|
|
336
|
+
resource: resourceName,
|
|
323
337
|
successNotification,
|
|
324
338
|
dataProviderName,
|
|
325
339
|
meta,
|
|
@@ -327,24 +341,26 @@ export const useDelete = <
|
|
|
327
341
|
},
|
|
328
342
|
context,
|
|
329
343
|
) => {
|
|
330
|
-
const
|
|
344
|
+
const { resource, identifier } = select(resourceName);
|
|
345
|
+
|
|
346
|
+
const resourceSingular = pluralize.singular(identifier);
|
|
331
347
|
|
|
332
348
|
// Remove the queries from the cache:
|
|
333
349
|
queryClient.removeQueries(context?.queryKey.detail(id));
|
|
334
350
|
|
|
335
351
|
const notificationConfig =
|
|
336
352
|
typeof successNotification === "function"
|
|
337
|
-
? successNotification(_data, id,
|
|
353
|
+
? successNotification(_data, id, identifier)
|
|
338
354
|
: successNotification;
|
|
339
355
|
|
|
340
356
|
handleNotification(notificationConfig, {
|
|
341
|
-
key: `${id}-${
|
|
357
|
+
key: `${id}-${identifier}-notification`,
|
|
342
358
|
description: translate("notifications.success", "Success"),
|
|
343
359
|
message: translate(
|
|
344
360
|
"notifications.deleteSuccess",
|
|
345
361
|
{
|
|
346
362
|
resource: translate(
|
|
347
|
-
`${
|
|
363
|
+
`${identifier}.${identifier}`,
|
|
348
364
|
resourceSingular,
|
|
349
365
|
),
|
|
350
366
|
},
|
|
@@ -354,7 +370,7 @@ export const useDelete = <
|
|
|
354
370
|
});
|
|
355
371
|
|
|
356
372
|
publish?.({
|
|
357
|
-
channel: `resources/${resource}`,
|
|
373
|
+
channel: `resources/${resource.name}`,
|
|
358
374
|
type: "deleted",
|
|
359
375
|
payload: {
|
|
360
376
|
ids: [id],
|
|
@@ -362,16 +378,21 @@ export const useDelete = <
|
|
|
362
378
|
date: new Date(),
|
|
363
379
|
});
|
|
364
380
|
|
|
381
|
+
const combinedMeta = getMeta({
|
|
382
|
+
resource,
|
|
383
|
+
meta: pickNotDeprecated(meta, metaData),
|
|
384
|
+
});
|
|
385
|
+
|
|
365
386
|
const { fields, operation, variables, ...rest } =
|
|
366
|
-
|
|
387
|
+
combinedMeta || {};
|
|
367
388
|
|
|
368
389
|
log?.mutate({
|
|
369
390
|
action: "delete",
|
|
370
|
-
resource,
|
|
391
|
+
resource: resource.name,
|
|
371
392
|
meta: {
|
|
372
393
|
id,
|
|
373
394
|
dataProviderName: pickDataProvider(
|
|
374
|
-
|
|
395
|
+
identifier,
|
|
375
396
|
dataProviderName,
|
|
376
397
|
resources,
|
|
377
398
|
),
|
|
@@ -384,9 +405,11 @@ export const useDelete = <
|
|
|
384
405
|
},
|
|
385
406
|
onError: (
|
|
386
407
|
err: TError,
|
|
387
|
-
{ id, resource, errorNotification },
|
|
408
|
+
{ id, resource: resourceName, errorNotification },
|
|
388
409
|
context,
|
|
389
410
|
) => {
|
|
411
|
+
const { identifier } = select(resourceName);
|
|
412
|
+
|
|
390
413
|
// set back the queries to the context:
|
|
391
414
|
if (context) {
|
|
392
415
|
for (const query of context.previousQueries) {
|
|
@@ -397,15 +420,15 @@ export const useDelete = <
|
|
|
397
420
|
if (err.message !== "mutationCancelled") {
|
|
398
421
|
checkError(err);
|
|
399
422
|
|
|
400
|
-
const resourceSingular = pluralize.singular(
|
|
423
|
+
const resourceSingular = pluralize.singular(identifier);
|
|
401
424
|
|
|
402
425
|
const notificationConfig =
|
|
403
426
|
typeof errorNotification === "function"
|
|
404
|
-
? errorNotification(err, id,
|
|
427
|
+
? errorNotification(err, id, identifier)
|
|
405
428
|
: errorNotification;
|
|
406
429
|
|
|
407
430
|
handleNotification(notificationConfig, {
|
|
408
|
-
key: `${id}-${
|
|
431
|
+
key: `${id}-${identifier}-notification`,
|
|
409
432
|
message: translate(
|
|
410
433
|
"notifications.deleteError",
|
|
411
434
|
{
|
|
@@ -423,5 +446,11 @@ export const useDelete = <
|
|
|
423
446
|
},
|
|
424
447
|
);
|
|
425
448
|
|
|
426
|
-
|
|
449
|
+
const { elapsedTime } = useLoadingOvertime({
|
|
450
|
+
isLoading: mutation.isLoading,
|
|
451
|
+
interval: overtimeOptions?.interval,
|
|
452
|
+
onInterval: overtimeOptions?.onInterval,
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
return { ...mutation, overtime: { elapsedTime } };
|
|
427
456
|
};
|
|
@@ -40,6 +40,11 @@ import {
|
|
|
40
40
|
pickNotDeprecated,
|
|
41
41
|
useActiveAuthProvider,
|
|
42
42
|
} from "@definitions";
|
|
43
|
+
import {
|
|
44
|
+
useLoadingOvertime,
|
|
45
|
+
UseLoadingOvertimeOptionsProps,
|
|
46
|
+
UseLoadingOvertimeReturnType,
|
|
47
|
+
} from "../useLoadingOvertime";
|
|
43
48
|
|
|
44
49
|
export type DeleteManyParams<TData, TError, TVariables> = {
|
|
45
50
|
ids: BaseKey[];
|
|
@@ -66,7 +71,8 @@ export type UseDeleteManyReturnType<
|
|
|
66
71
|
TError,
|
|
67
72
|
DeleteManyParams<TData, TError, TVariables>,
|
|
68
73
|
unknown
|
|
69
|
-
|
|
74
|
+
> &
|
|
75
|
+
UseLoadingOvertimeReturnType;
|
|
70
76
|
|
|
71
77
|
export type UseDeleteManyProps<
|
|
72
78
|
TData extends BaseRecord = BaseRecord,
|
|
@@ -82,7 +88,7 @@ export type UseDeleteManyProps<
|
|
|
82
88
|
>,
|
|
83
89
|
"mutationFn" | "onError" | "onSuccess" | "onSettled" | "onMutate"
|
|
84
90
|
>;
|
|
85
|
-
};
|
|
91
|
+
} & UseLoadingOvertimeOptionsProps;
|
|
86
92
|
|
|
87
93
|
/**
|
|
88
94
|
* `useDeleteMany` is a modified version of `react-query`'s {@link https://react-query.tanstack.com/reference/useMutation `useMutation`} for multiple delete mutations.
|
|
@@ -102,6 +108,7 @@ export const useDeleteMany = <
|
|
|
102
108
|
TVariables = {},
|
|
103
109
|
>({
|
|
104
110
|
mutationOptions,
|
|
111
|
+
overtimeOptions,
|
|
105
112
|
}: UseDeleteManyProps<TData, TError, TVariables> = {}): UseDeleteManyReturnType<
|
|
106
113
|
TData,
|
|
107
114
|
TError,
|
|
@@ -123,7 +130,7 @@ export const useDeleteMany = <
|
|
|
123
130
|
const handleNotification = useHandleNotification();
|
|
124
131
|
const invalidateStore = useInvalidate();
|
|
125
132
|
const { log } = useLog();
|
|
126
|
-
const { resources } = useResource();
|
|
133
|
+
const { resources, select } = useResource();
|
|
127
134
|
const queryClient = useQueryClient();
|
|
128
135
|
const getMeta = useMeta();
|
|
129
136
|
|
|
@@ -134,7 +141,7 @@ export const useDeleteMany = <
|
|
|
134
141
|
DeleteContext<TData>
|
|
135
142
|
>(
|
|
136
143
|
({
|
|
137
|
-
resource,
|
|
144
|
+
resource: resourceName,
|
|
138
145
|
ids,
|
|
139
146
|
mutationMode,
|
|
140
147
|
undoableTimeout,
|
|
@@ -144,7 +151,10 @@ export const useDeleteMany = <
|
|
|
144
151
|
dataProviderName,
|
|
145
152
|
values,
|
|
146
153
|
}: DeleteManyParams<TData, TError, TVariables>) => {
|
|
154
|
+
const { resource, identifier } = select(resourceName);
|
|
155
|
+
|
|
147
156
|
const combinedMeta = getMeta({
|
|
157
|
+
resource,
|
|
148
158
|
meta: pickNotDeprecated(meta, metaData),
|
|
149
159
|
});
|
|
150
160
|
|
|
@@ -155,13 +165,13 @@ export const useDeleteMany = <
|
|
|
155
165
|
undoableTimeout ?? undoableTimeoutContext;
|
|
156
166
|
|
|
157
167
|
const selectedDataProvider = dataProvider(
|
|
158
|
-
pickDataProvider(
|
|
168
|
+
pickDataProvider(identifier, dataProviderName, resources),
|
|
159
169
|
);
|
|
160
170
|
|
|
161
171
|
const mutationFn = () => {
|
|
162
172
|
if (selectedDataProvider.deleteMany) {
|
|
163
173
|
return selectedDataProvider.deleteMany<TData, TVariables>({
|
|
164
|
-
resource,
|
|
174
|
+
resource: resource.name,
|
|
165
175
|
ids,
|
|
166
176
|
meta: combinedMeta,
|
|
167
177
|
metaData: combinedMeta,
|
|
@@ -171,7 +181,7 @@ export const useDeleteMany = <
|
|
|
171
181
|
return handleMultiple(
|
|
172
182
|
ids.map((id) =>
|
|
173
183
|
selectedDataProvider.deleteOne<TData, TVariables>({
|
|
174
|
-
resource,
|
|
184
|
+
resource: resource.name,
|
|
175
185
|
id,
|
|
176
186
|
meta: combinedMeta,
|
|
177
187
|
metaData: combinedMeta,
|
|
@@ -206,7 +216,7 @@ export const useDeleteMany = <
|
|
|
206
216
|
type: ActionTypes.ADD,
|
|
207
217
|
payload: {
|
|
208
218
|
id: ids,
|
|
209
|
-
resource:
|
|
219
|
+
resource: identifier,
|
|
210
220
|
cancelMutation: cancelMutation,
|
|
211
221
|
doMutation: doMutation,
|
|
212
222
|
seconds: undoableTimeoutPropOrContext,
|
|
@@ -220,17 +230,19 @@ export const useDeleteMany = <
|
|
|
220
230
|
{
|
|
221
231
|
onMutate: async ({
|
|
222
232
|
ids,
|
|
223
|
-
resource,
|
|
233
|
+
resource: resourceName,
|
|
224
234
|
mutationMode,
|
|
225
235
|
dataProviderName,
|
|
226
236
|
meta,
|
|
227
237
|
metaData,
|
|
228
238
|
}) => {
|
|
239
|
+
const { identifier } = select(resourceName);
|
|
240
|
+
|
|
229
241
|
const preferredMeta = pickNotDeprecated(meta, metaData);
|
|
242
|
+
|
|
230
243
|
const queryKey = queryKeys(
|
|
231
|
-
|
|
232
|
-
pickDataProvider(
|
|
233
|
-
preferredMeta,
|
|
244
|
+
identifier,
|
|
245
|
+
pickDataProvider(identifier, dataProviderName, resources),
|
|
234
246
|
preferredMeta,
|
|
235
247
|
);
|
|
236
248
|
|
|
@@ -322,17 +334,19 @@ export const useDeleteMany = <
|
|
|
322
334
|
_data,
|
|
323
335
|
_error,
|
|
324
336
|
{
|
|
325
|
-
resource,
|
|
337
|
+
resource: resourceName,
|
|
326
338
|
ids,
|
|
327
339
|
dataProviderName,
|
|
328
340
|
invalidates = ["list", "many"],
|
|
329
341
|
},
|
|
330
342
|
) => {
|
|
343
|
+
const { identifier } = select(resourceName);
|
|
344
|
+
|
|
331
345
|
// invalidate the cache for the list and many queries:
|
|
332
346
|
invalidateStore({
|
|
333
|
-
resource,
|
|
347
|
+
resource: identifier,
|
|
334
348
|
dataProviderName: pickDataProvider(
|
|
335
|
-
|
|
349
|
+
identifier,
|
|
336
350
|
dataProviderName,
|
|
337
351
|
resources,
|
|
338
352
|
),
|
|
@@ -341,14 +355,14 @@ export const useDeleteMany = <
|
|
|
341
355
|
|
|
342
356
|
notificationDispatch({
|
|
343
357
|
type: ActionTypes.REMOVE,
|
|
344
|
-
payload: { id: ids, resource },
|
|
358
|
+
payload: { id: ids, resource: identifier },
|
|
345
359
|
});
|
|
346
360
|
},
|
|
347
361
|
onSuccess: (
|
|
348
362
|
_data,
|
|
349
363
|
{
|
|
350
364
|
ids,
|
|
351
|
-
resource,
|
|
365
|
+
resource: resourceName,
|
|
352
366
|
meta,
|
|
353
367
|
metaData,
|
|
354
368
|
dataProviderName,
|
|
@@ -356,6 +370,8 @@ export const useDeleteMany = <
|
|
|
356
370
|
},
|
|
357
371
|
context,
|
|
358
372
|
) => {
|
|
373
|
+
const { resource, identifier } = select(resourceName);
|
|
374
|
+
|
|
359
375
|
// Remove the queries from the cache:
|
|
360
376
|
ids.forEach((id) =>
|
|
361
377
|
queryClient.removeQueries(context?.queryKey.detail(id)),
|
|
@@ -363,42 +379,47 @@ export const useDeleteMany = <
|
|
|
363
379
|
|
|
364
380
|
const notificationConfig =
|
|
365
381
|
typeof successNotification === "function"
|
|
366
|
-
? successNotification(_data, ids,
|
|
382
|
+
? successNotification(_data, ids, identifier)
|
|
367
383
|
: successNotification;
|
|
368
384
|
|
|
369
385
|
handleNotification(notificationConfig, {
|
|
370
|
-
key: `${ids}-${
|
|
386
|
+
key: `${ids}-${identifier}-notification`,
|
|
371
387
|
description: translate("notifications.success", "Success"),
|
|
372
388
|
message: translate(
|
|
373
389
|
"notifications.deleteSuccess",
|
|
374
390
|
{
|
|
375
391
|
resource: translate(
|
|
376
|
-
`${
|
|
377
|
-
|
|
392
|
+
`${identifier}.${identifier}`,
|
|
393
|
+
identifier,
|
|
378
394
|
),
|
|
379
395
|
},
|
|
380
|
-
`Successfully deleted ${
|
|
396
|
+
`Successfully deleted ${identifier}`,
|
|
381
397
|
),
|
|
382
398
|
type: "success",
|
|
383
399
|
});
|
|
384
400
|
|
|
385
401
|
publish?.({
|
|
386
|
-
channel: `resources/${resource}`,
|
|
402
|
+
channel: `resources/${resource.name}`,
|
|
387
403
|
type: "deleted",
|
|
388
404
|
payload: { ids },
|
|
389
405
|
date: new Date(),
|
|
390
406
|
});
|
|
391
407
|
|
|
408
|
+
const combinedMeta = getMeta({
|
|
409
|
+
resource,
|
|
410
|
+
meta: pickNotDeprecated(meta, metaData),
|
|
411
|
+
});
|
|
412
|
+
|
|
392
413
|
const { fields, operation, variables, ...rest } =
|
|
393
|
-
|
|
414
|
+
combinedMeta || {};
|
|
394
415
|
|
|
395
416
|
log?.mutate({
|
|
396
417
|
action: "deleteMany",
|
|
397
|
-
resource,
|
|
418
|
+
resource: resource.name,
|
|
398
419
|
meta: {
|
|
399
420
|
ids,
|
|
400
421
|
dataProviderName: pickDataProvider(
|
|
401
|
-
|
|
422
|
+
identifier,
|
|
402
423
|
dataProviderName,
|
|
403
424
|
resources,
|
|
404
425
|
),
|
|
@@ -411,7 +432,13 @@ export const useDeleteMany = <
|
|
|
411
432
|
queryClient.removeQueries(context?.queryKey.detail(id)),
|
|
412
433
|
);
|
|
413
434
|
},
|
|
414
|
-
onError: (
|
|
435
|
+
onError: (
|
|
436
|
+
err,
|
|
437
|
+
{ ids, resource: resourceName, errorNotification },
|
|
438
|
+
context,
|
|
439
|
+
) => {
|
|
440
|
+
const { identifier } = select(resourceName);
|
|
441
|
+
|
|
415
442
|
// set back the queries to the context:
|
|
416
443
|
if (context) {
|
|
417
444
|
for (const query of context.previousQueries) {
|
|
@@ -421,15 +448,15 @@ export const useDeleteMany = <
|
|
|
421
448
|
|
|
422
449
|
if (err.message !== "mutationCancelled") {
|
|
423
450
|
checkError(err);
|
|
424
|
-
const resourceSingular = pluralize.singular(
|
|
451
|
+
const resourceSingular = pluralize.singular(identifier);
|
|
425
452
|
|
|
426
453
|
const notificationConfig =
|
|
427
454
|
typeof errorNotification === "function"
|
|
428
|
-
? errorNotification(err, ids,
|
|
455
|
+
? errorNotification(err, ids, identifier)
|
|
429
456
|
: errorNotification;
|
|
430
457
|
|
|
431
458
|
handleNotification(notificationConfig, {
|
|
432
|
-
key: `${ids}-${
|
|
459
|
+
key: `${ids}-${identifier}-notification`,
|
|
433
460
|
message: translate(
|
|
434
461
|
"notifications.deleteError",
|
|
435
462
|
{
|
|
@@ -447,5 +474,11 @@ export const useDeleteMany = <
|
|
|
447
474
|
},
|
|
448
475
|
);
|
|
449
476
|
|
|
450
|
-
|
|
477
|
+
const { elapsedTime } = useLoadingOvertime({
|
|
478
|
+
isLoading: mutation.isLoading,
|
|
479
|
+
interval: overtimeOptions?.interval,
|
|
480
|
+
onInterval: overtimeOptions?.onInterval,
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
return { ...mutation, overtime: { elapsedTime } };
|
|
451
484
|
};
|