@refinedev/core 4.46.0 → 4.46.2
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 +109 -0
- package/dist/definitions/helpers/flatten-object-keys/index.d.ts.map +1 -1
- package/dist/esm/index.js +6 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/hooks/accessControl/useCan/index.d.ts.map +1 -1
- package/dist/hooks/auditLog/useLogList/index.d.ts.map +1 -1
- package/dist/hooks/auth/useOnError/index.d.ts.map +1 -1
- package/dist/hooks/data/useCreate.d.ts.map +1 -1
- package/dist/hooks/data/useCreateMany.d.ts.map +1 -1
- package/dist/hooks/data/useDelete.d.ts.map +1 -1
- package/dist/hooks/data/useDeleteMany.d.ts.map +1 -1
- package/dist/hooks/data/useInfiniteList.d.ts.map +1 -1
- package/dist/hooks/data/useList.d.ts.map +1 -1
- package/dist/hooks/data/useMany.d.ts.map +1 -1
- package/dist/hooks/data/useOne.d.ts.map +1 -1
- package/dist/hooks/data/useUpdate.d.ts.map +1 -1
- package/dist/hooks/data/useUpdateMany.d.ts.map +1 -1
- package/dist/hooks/router/use-go/index.d.ts +2 -0
- package/dist/hooks/router/use-go/index.d.ts.map +1 -1
- package/dist/hooks/useMeta/index.d.ts +2 -0
- package/dist/hooks/useMeta/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/dist/interfaces/auth.d.ts +6 -6
- package/dist/interfaces/auth.d.ts.map +1 -1
- package/dist/interfaces/metaData/graphqlQueryOptions.d.ts +6 -0
- package/dist/interfaces/metaData/graphqlQueryOptions.d.ts.map +1 -0
- package/dist/interfaces/metaData/metaQuery.d.ts +2 -1
- package/dist/interfaces/metaData/metaQuery.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/definitions/helpers/flatten-object-keys/index.ts +2 -0
- package/src/hooks/accessControl/useCan/index.ts +10 -12
- package/src/hooks/auditLog/useLogList/index.ts +10 -12
- package/src/hooks/auth/useForgotPassword/index.ts +51 -54
- package/src/hooks/auth/useGetIdentity/index.ts +23 -26
- package/src/hooks/auth/useIsAuthenticated/index.ts +20 -20
- package/src/hooks/auth/useLogin/index.ts +33 -35
- package/src/hooks/auth/useLogout/index.ts +32 -34
- package/src/hooks/auth/useOnError/index.ts +29 -33
- package/src/hooks/auth/usePermissions/index.ts +19 -22
- package/src/hooks/auth/useRegister/index.ts +60 -66
- package/src/hooks/auth/useUpdatePassword/index.ts +51 -54
- package/src/hooks/data/useCreate.ts +115 -117
- package/src/hooks/data/useCreateMany.ts +113 -118
- package/src/hooks/data/useDelete.ts +212 -223
- package/src/hooks/data/useDeleteMany.ts +230 -244
- package/src/hooks/data/useInfiniteList.ts +36 -42
- package/src/hooks/data/useList.ts +56 -62
- package/src/hooks/data/useMany.ts +36 -37
- package/src/hooks/data/useOne.ts +54 -55
- package/src/hooks/data/useUpdate.ts +288 -311
- package/src/hooks/data/useUpdateMany.ts +294 -320
- package/src/hooks/menu/useMenu.tsx +1 -1
- package/src/hooks/router/use-go/index.tsx +3 -0
- package/src/interfaces/auth.tsx +6 -6
- package/src/interfaces/metaData/graphqlQueryOptions.ts +6 -0
- package/src/interfaces/metaData/metaQuery.ts +3 -1
|
@@ -189,8 +189,8 @@ export const useUpdateMany = <
|
|
|
189
189
|
TError,
|
|
190
190
|
UpdateManyParams<TData, TError, TVariables>,
|
|
191
191
|
UpdateContext<TData>
|
|
192
|
-
>(
|
|
193
|
-
({
|
|
192
|
+
>({
|
|
193
|
+
mutationFn: ({
|
|
194
194
|
ids,
|
|
195
195
|
values,
|
|
196
196
|
resource: resourceName,
|
|
@@ -277,117 +277,154 @@ export const useUpdateMany = <
|
|
|
277
277
|
);
|
|
278
278
|
return updatePromise;
|
|
279
279
|
},
|
|
280
|
+
onMutate: async ({
|
|
281
|
+
resource: resourceName,
|
|
282
|
+
ids,
|
|
283
|
+
values,
|
|
284
|
+
mutationMode,
|
|
285
|
+
dataProviderName,
|
|
286
|
+
meta,
|
|
287
|
+
metaData,
|
|
288
|
+
optimisticUpdateMap = { list: true, many: true, detail: true },
|
|
289
|
+
}) => {
|
|
290
|
+
const { identifier } = select(resourceName);
|
|
291
|
+
const {
|
|
292
|
+
gqlMutation: _,
|
|
293
|
+
gqlQuery: __,
|
|
294
|
+
...preferredMeta
|
|
295
|
+
} = pickNotDeprecated(meta, metaData) ?? {};
|
|
296
|
+
|
|
297
|
+
const queryKey = queryKeysReplacement(preferLegacyKeys)(
|
|
298
|
+
identifier,
|
|
299
|
+
pickDataProvider(identifier, dataProviderName, resources),
|
|
300
|
+
preferredMeta,
|
|
301
|
+
);
|
|
280
302
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
resource
|
|
284
|
-
ids,
|
|
285
|
-
values,
|
|
286
|
-
mutationMode,
|
|
287
|
-
dataProviderName,
|
|
288
|
-
meta,
|
|
289
|
-
metaData,
|
|
290
|
-
optimisticUpdateMap = { list: true, many: true, detail: true },
|
|
291
|
-
}) => {
|
|
292
|
-
const { identifier } = select(resourceName);
|
|
293
|
-
const preferredMeta = pickNotDeprecated(meta, metaData);
|
|
294
|
-
|
|
295
|
-
const queryKey = queryKeysReplacement(preferLegacyKeys)(
|
|
296
|
-
identifier,
|
|
297
|
-
pickDataProvider(identifier, dataProviderName, resources),
|
|
298
|
-
pickNotDeprecated(meta, metaData),
|
|
299
|
-
);
|
|
303
|
+
const resourceKeys = keys()
|
|
304
|
+
.data(pickDataProvider(identifier, dataProviderName, resources))
|
|
305
|
+
.resource(identifier);
|
|
300
306
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
pickDataProvider(
|
|
304
|
-
identifier,
|
|
305
|
-
dataProviderName,
|
|
306
|
-
resources,
|
|
307
|
-
),
|
|
308
|
-
)
|
|
309
|
-
.resource(identifier);
|
|
307
|
+
const mutationModePropOrContext =
|
|
308
|
+
mutationMode ?? mutationModeContext;
|
|
310
309
|
|
|
311
|
-
|
|
312
|
-
|
|
310
|
+
await queryClient.cancelQueries(
|
|
311
|
+
resourceKeys.get(preferLegacyKeys),
|
|
312
|
+
undefined,
|
|
313
|
+
{
|
|
314
|
+
silent: true,
|
|
315
|
+
},
|
|
316
|
+
);
|
|
313
317
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
318
|
+
const previousQueries = queryClient.getQueriesData<
|
|
319
|
+
QueryResponse<TData>
|
|
320
|
+
>(resourceKeys.get(preferLegacyKeys));
|
|
321
|
+
|
|
322
|
+
if (mutationModePropOrContext !== "pessimistic") {
|
|
323
|
+
if (optimisticUpdateMap.list) {
|
|
324
|
+
// Set the previous queries to the new ones:
|
|
325
|
+
queryClient.setQueriesData(
|
|
326
|
+
resourceKeys
|
|
327
|
+
.action("list")
|
|
328
|
+
.params(preferredMeta ?? {})
|
|
329
|
+
.get(preferLegacyKeys),
|
|
330
|
+
(previous?: GetListResponse<TData> | null) => {
|
|
331
|
+
if (
|
|
332
|
+
typeof optimisticUpdateMap.list === "function"
|
|
333
|
+
) {
|
|
334
|
+
return optimisticUpdateMap.list(
|
|
335
|
+
previous,
|
|
336
|
+
values,
|
|
337
|
+
ids,
|
|
338
|
+
);
|
|
339
|
+
}
|
|
321
340
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
341
|
+
if (!previous) {
|
|
342
|
+
return null;
|
|
343
|
+
}
|
|
325
344
|
|
|
326
|
-
|
|
327
|
-
if (optimisticUpdateMap.list) {
|
|
328
|
-
// Set the previous queries to the new ones:
|
|
329
|
-
queryClient.setQueriesData(
|
|
330
|
-
resourceKeys
|
|
331
|
-
.action("list")
|
|
332
|
-
.params(preferredMeta ?? {})
|
|
333
|
-
.get(preferLegacyKeys),
|
|
334
|
-
(previous?: GetListResponse<TData> | null) => {
|
|
345
|
+
const data = previous.data.map((record: TData) => {
|
|
335
346
|
if (
|
|
336
|
-
|
|
337
|
-
|
|
347
|
+
record.id !== undefined &&
|
|
348
|
+
ids
|
|
349
|
+
.filter((id) => id !== undefined)
|
|
350
|
+
.map(String)
|
|
351
|
+
.includes(record.id.toString())
|
|
338
352
|
) {
|
|
339
|
-
return
|
|
340
|
-
|
|
341
|
-
values,
|
|
342
|
-
|
|
343
|
-
);
|
|
353
|
+
return {
|
|
354
|
+
...record,
|
|
355
|
+
...values,
|
|
356
|
+
};
|
|
344
357
|
}
|
|
345
358
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
359
|
+
return record;
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
return {
|
|
363
|
+
...previous,
|
|
364
|
+
data,
|
|
365
|
+
};
|
|
366
|
+
},
|
|
367
|
+
);
|
|
368
|
+
}
|
|
349
369
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
return {
|
|
362
|
-
...record,
|
|
363
|
-
...values,
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
return record;
|
|
368
|
-
},
|
|
370
|
+
if (optimisticUpdateMap.many) {
|
|
371
|
+
queryClient.setQueriesData(
|
|
372
|
+
resourceKeys.action("many").get(preferLegacyKeys),
|
|
373
|
+
(previous?: GetManyResponse<TData> | null) => {
|
|
374
|
+
if (
|
|
375
|
+
typeof optimisticUpdateMap.many === "function"
|
|
376
|
+
) {
|
|
377
|
+
return optimisticUpdateMap.many(
|
|
378
|
+
previous,
|
|
379
|
+
values,
|
|
380
|
+
ids,
|
|
369
381
|
);
|
|
382
|
+
}
|
|
370
383
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
384
|
+
if (!previous) {
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const data = previous.data.map((record: TData) => {
|
|
389
|
+
if (
|
|
390
|
+
record.id !== undefined &&
|
|
391
|
+
ids
|
|
392
|
+
.filter((id) => id !== undefined)
|
|
393
|
+
.map(String)
|
|
394
|
+
.includes(record.id.toString())
|
|
395
|
+
) {
|
|
396
|
+
return {
|
|
397
|
+
...record,
|
|
398
|
+
...values,
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
return record;
|
|
402
|
+
});
|
|
403
|
+
return {
|
|
404
|
+
...previous,
|
|
405
|
+
data,
|
|
406
|
+
};
|
|
407
|
+
},
|
|
408
|
+
);
|
|
409
|
+
}
|
|
378
410
|
|
|
379
|
-
|
|
411
|
+
if (optimisticUpdateMap.detail) {
|
|
412
|
+
for (const id of ids) {
|
|
380
413
|
queryClient.setQueriesData(
|
|
381
|
-
resourceKeys
|
|
382
|
-
|
|
414
|
+
resourceKeys
|
|
415
|
+
.action("one")
|
|
416
|
+
.id(id)
|
|
417
|
+
.params(preferredMeta ?? {})
|
|
418
|
+
.get(preferLegacyKeys),
|
|
419
|
+
(previous?: GetOneResponse<TData> | null) => {
|
|
383
420
|
if (
|
|
384
|
-
typeof optimisticUpdateMap.
|
|
421
|
+
typeof optimisticUpdateMap.detail ===
|
|
385
422
|
"function"
|
|
386
423
|
) {
|
|
387
|
-
return optimisticUpdateMap.
|
|
424
|
+
return optimisticUpdateMap.detail(
|
|
388
425
|
previous,
|
|
389
426
|
values,
|
|
390
|
-
|
|
427
|
+
id,
|
|
391
428
|
);
|
|
392
429
|
}
|
|
393
430
|
|
|
@@ -395,25 +432,10 @@ export const useUpdateMany = <
|
|
|
395
432
|
return null;
|
|
396
433
|
}
|
|
397
434
|
|
|
398
|
-
const data =
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
ids
|
|
403
|
-
.filter(
|
|
404
|
-
(id) => id !== undefined,
|
|
405
|
-
)
|
|
406
|
-
.map(String)
|
|
407
|
-
.includes(record.id.toString())
|
|
408
|
-
) {
|
|
409
|
-
return {
|
|
410
|
-
...record,
|
|
411
|
-
...values,
|
|
412
|
-
};
|
|
413
|
-
}
|
|
414
|
-
return record;
|
|
415
|
-
},
|
|
416
|
-
);
|
|
435
|
+
const data = {
|
|
436
|
+
...previous.data,
|
|
437
|
+
...values,
|
|
438
|
+
};
|
|
417
439
|
return {
|
|
418
440
|
...previous,
|
|
419
441
|
data,
|
|
@@ -421,242 +443,194 @@ export const useUpdateMany = <
|
|
|
421
443
|
},
|
|
422
444
|
);
|
|
423
445
|
}
|
|
424
|
-
|
|
425
|
-
if (optimisticUpdateMap.detail) {
|
|
426
|
-
for (const id of ids) {
|
|
427
|
-
queryClient.setQueriesData(
|
|
428
|
-
resourceKeys
|
|
429
|
-
.action("one")
|
|
430
|
-
.id(id)
|
|
431
|
-
.params(preferredMeta ?? {})
|
|
432
|
-
.get(preferLegacyKeys),
|
|
433
|
-
(previous?: GetOneResponse<TData> | null) => {
|
|
434
|
-
if (
|
|
435
|
-
typeof optimisticUpdateMap.detail ===
|
|
436
|
-
"function"
|
|
437
|
-
) {
|
|
438
|
-
return optimisticUpdateMap.detail(
|
|
439
|
-
previous,
|
|
440
|
-
values,
|
|
441
|
-
id,
|
|
442
|
-
);
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
if (!previous) {
|
|
446
|
-
return null;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
const data = {
|
|
450
|
-
...previous.data,
|
|
451
|
-
...values,
|
|
452
|
-
};
|
|
453
|
-
return {
|
|
454
|
-
...previous,
|
|
455
|
-
data,
|
|
456
|
-
};
|
|
457
|
-
},
|
|
458
|
-
);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
446
|
}
|
|
447
|
+
}
|
|
462
448
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
449
|
+
return {
|
|
450
|
+
previousQueries,
|
|
451
|
+
queryKey,
|
|
452
|
+
};
|
|
453
|
+
},
|
|
454
|
+
onSettled: (
|
|
455
|
+
_data,
|
|
456
|
+
_error,
|
|
457
|
+
{ ids, resource: resourceName, dataProviderName },
|
|
458
|
+
) => {
|
|
459
|
+
const { identifier } = select(resourceName);
|
|
460
|
+
|
|
461
|
+
// invalidate the cache for the list and many queries:
|
|
462
|
+
invalidateStore({
|
|
463
|
+
resource: identifier,
|
|
464
|
+
invalidates: ["list", "many"],
|
|
465
|
+
dataProviderName: pickDataProvider(
|
|
466
|
+
identifier,
|
|
467
|
+
dataProviderName,
|
|
468
|
+
resources,
|
|
469
|
+
),
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
ids.forEach((id) =>
|
|
476
473
|
invalidateStore({
|
|
477
474
|
resource: identifier,
|
|
478
|
-
invalidates: ["
|
|
475
|
+
invalidates: ["detail"],
|
|
479
476
|
dataProviderName: pickDataProvider(
|
|
480
477
|
identifier,
|
|
481
478
|
dataProviderName,
|
|
482
479
|
resources,
|
|
483
480
|
),
|
|
484
|
-
|
|
481
|
+
id,
|
|
482
|
+
}),
|
|
483
|
+
);
|
|
484
|
+
|
|
485
|
+
notificationDispatch({
|
|
486
|
+
type: ActionTypes.REMOVE,
|
|
487
|
+
payload: { id: ids, resource: identifier },
|
|
488
|
+
});
|
|
489
|
+
},
|
|
490
|
+
onSuccess: (
|
|
491
|
+
data,
|
|
492
|
+
{
|
|
493
|
+
ids,
|
|
494
|
+
resource: resourceName,
|
|
495
|
+
meta,
|
|
496
|
+
metaData,
|
|
497
|
+
dataProviderName: dataProviderNameFromProp,
|
|
498
|
+
successNotification,
|
|
499
|
+
values,
|
|
500
|
+
},
|
|
501
|
+
context,
|
|
502
|
+
) => {
|
|
503
|
+
const { resource, identifier } = select(resourceName);
|
|
504
|
+
const resourceSingular = textTransformers.singular(identifier);
|
|
505
|
+
|
|
506
|
+
const dataProviderName = pickDataProvider(
|
|
507
|
+
identifier,
|
|
508
|
+
dataProviderNameFromProp,
|
|
509
|
+
resources,
|
|
510
|
+
);
|
|
511
|
+
|
|
512
|
+
const combinedMeta = getMeta({
|
|
513
|
+
resource,
|
|
514
|
+
meta: pickNotDeprecated(meta, metaData),
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
const notificationConfig =
|
|
518
|
+
typeof successNotification === "function"
|
|
519
|
+
? successNotification(data, { ids, values }, identifier)
|
|
520
|
+
: successNotification;
|
|
485
521
|
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
522
|
+
handleNotification(notificationConfig, {
|
|
523
|
+
key: `${ids}-${identifier}-notification`,
|
|
524
|
+
description: translate("notifications.success", "Successful"),
|
|
525
|
+
message: translate(
|
|
526
|
+
"notifications.editSuccess",
|
|
527
|
+
{
|
|
528
|
+
resource: translate(
|
|
529
|
+
`${identifier}.${identifier}`,
|
|
491
530
|
identifier,
|
|
492
|
-
dataProviderName,
|
|
493
|
-
resources,
|
|
494
531
|
),
|
|
495
|
-
|
|
496
|
-
}
|
|
497
|
-
)
|
|
532
|
+
},
|
|
533
|
+
`Successfully updated ${resourceSingular}`,
|
|
534
|
+
),
|
|
535
|
+
type: "success",
|
|
536
|
+
});
|
|
498
537
|
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
538
|
+
publish?.({
|
|
539
|
+
channel: `resources/${resource.name}`,
|
|
540
|
+
type: "updated",
|
|
541
|
+
payload: {
|
|
542
|
+
ids: ids.map(String),
|
|
543
|
+
},
|
|
544
|
+
date: new Date(),
|
|
545
|
+
meta: {
|
|
546
|
+
...combinedMeta,
|
|
547
|
+
dataProviderName,
|
|
548
|
+
},
|
|
549
|
+
});
|
|
550
|
+
|
|
551
|
+
const previousData: any[] = [];
|
|
552
|
+
if (context) {
|
|
553
|
+
ids.forEach((id) => {
|
|
554
|
+
const queryData = queryClient.getQueryData<
|
|
555
|
+
UpdateManyResponse<TData>
|
|
556
|
+
>(context.queryKey.detail(id));
|
|
557
|
+
|
|
558
|
+
previousData.push(
|
|
559
|
+
Object.keys(values || {}).reduce<any>(
|
|
560
|
+
(acc, item: any) => {
|
|
561
|
+
acc[item] = queryData?.data?.[item];
|
|
562
|
+
return acc;
|
|
563
|
+
},
|
|
564
|
+
{},
|
|
565
|
+
),
|
|
566
|
+
);
|
|
502
567
|
});
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
const {
|
|
571
|
+
fields: _fields,
|
|
572
|
+
operation: _operation,
|
|
573
|
+
variables: _variables,
|
|
574
|
+
...rest
|
|
575
|
+
} = combinedMeta || {};
|
|
576
|
+
log?.mutate({
|
|
577
|
+
action: "updateMany",
|
|
578
|
+
resource: resource.name,
|
|
579
|
+
data: values,
|
|
580
|
+
previousData,
|
|
581
|
+
meta: {
|
|
507
582
|
ids,
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
metaData,
|
|
511
|
-
dataProviderName: dataProviderNameFromProp,
|
|
512
|
-
successNotification,
|
|
513
|
-
values,
|
|
583
|
+
dataProviderName,
|
|
584
|
+
...rest,
|
|
514
585
|
},
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
586
|
+
});
|
|
587
|
+
},
|
|
588
|
+
onError: (
|
|
589
|
+
err: TError,
|
|
590
|
+
{ ids, resource: resourceName, errorNotification, values },
|
|
591
|
+
context,
|
|
592
|
+
) => {
|
|
593
|
+
const { identifier } = select(resourceName);
|
|
594
|
+
|
|
595
|
+
// set back the queries to the context:
|
|
596
|
+
if (context) {
|
|
597
|
+
for (const query of context.previousQueries) {
|
|
598
|
+
queryClient.setQueryData(query[0], query[1]);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
519
601
|
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
dataProviderNameFromProp,
|
|
523
|
-
resources,
|
|
524
|
-
);
|
|
602
|
+
if (err.message !== "mutationCancelled") {
|
|
603
|
+
checkError?.(err);
|
|
525
604
|
|
|
526
|
-
const
|
|
527
|
-
resource,
|
|
528
|
-
meta: pickNotDeprecated(meta, metaData),
|
|
529
|
-
});
|
|
605
|
+
const resourceSingular = textTransformers.singular(identifier);
|
|
530
606
|
|
|
531
607
|
const notificationConfig =
|
|
532
|
-
typeof
|
|
533
|
-
?
|
|
534
|
-
:
|
|
608
|
+
typeof errorNotification === "function"
|
|
609
|
+
? errorNotification(err, { ids, values }, identifier)
|
|
610
|
+
: errorNotification;
|
|
535
611
|
|
|
536
612
|
handleNotification(notificationConfig, {
|
|
537
|
-
key: `${ids}-${identifier}-notification`,
|
|
538
|
-
description: translate(
|
|
539
|
-
"notifications.success",
|
|
540
|
-
"Successful",
|
|
541
|
-
),
|
|
613
|
+
key: `${ids}-${identifier}-updateMany-error-notification`,
|
|
542
614
|
message: translate(
|
|
543
|
-
"notifications.
|
|
615
|
+
"notifications.editError",
|
|
544
616
|
{
|
|
545
|
-
resource:
|
|
546
|
-
|
|
547
|
-
identifier,
|
|
548
|
-
),
|
|
617
|
+
resource: resourceSingular,
|
|
618
|
+
statusCode: err.statusCode,
|
|
549
619
|
},
|
|
550
|
-
`
|
|
620
|
+
`Error when updating ${resourceSingular} (status code: ${err.statusCode})`,
|
|
551
621
|
),
|
|
552
|
-
|
|
622
|
+
description: err.message,
|
|
623
|
+
type: "error",
|
|
553
624
|
});
|
|
554
|
-
|
|
555
|
-
publish?.({
|
|
556
|
-
channel: `resources/${resource.name}`,
|
|
557
|
-
type: "updated",
|
|
558
|
-
payload: {
|
|
559
|
-
ids: ids.map(String),
|
|
560
|
-
},
|
|
561
|
-
date: new Date(),
|
|
562
|
-
meta: {
|
|
563
|
-
...combinedMeta,
|
|
564
|
-
dataProviderName,
|
|
565
|
-
},
|
|
566
|
-
});
|
|
567
|
-
|
|
568
|
-
const previousData: any[] = [];
|
|
569
|
-
if (context) {
|
|
570
|
-
ids.forEach((id) => {
|
|
571
|
-
const queryData = queryClient.getQueryData<
|
|
572
|
-
UpdateManyResponse<TData>
|
|
573
|
-
>(context.queryKey.detail(id));
|
|
574
|
-
|
|
575
|
-
previousData.push(
|
|
576
|
-
Object.keys(values || {}).reduce<any>(
|
|
577
|
-
(acc, item: any) => {
|
|
578
|
-
acc[item] = queryData?.data?.[item];
|
|
579
|
-
return acc;
|
|
580
|
-
},
|
|
581
|
-
{},
|
|
582
|
-
),
|
|
583
|
-
);
|
|
584
|
-
});
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
const {
|
|
588
|
-
fields: _fields,
|
|
589
|
-
operation: _operation,
|
|
590
|
-
variables: _variables,
|
|
591
|
-
...rest
|
|
592
|
-
} = combinedMeta || {};
|
|
593
|
-
log?.mutate({
|
|
594
|
-
action: "updateMany",
|
|
595
|
-
resource: resource.name,
|
|
596
|
-
data: values,
|
|
597
|
-
previousData,
|
|
598
|
-
meta: {
|
|
599
|
-
ids,
|
|
600
|
-
dataProviderName,
|
|
601
|
-
...rest,
|
|
602
|
-
},
|
|
603
|
-
});
|
|
604
|
-
},
|
|
605
|
-
onError: (
|
|
606
|
-
err: TError,
|
|
607
|
-
{ ids, resource: resourceName, errorNotification, values },
|
|
608
|
-
context,
|
|
609
|
-
) => {
|
|
610
|
-
const { identifier } = select(resourceName);
|
|
611
|
-
|
|
612
|
-
// set back the queries to the context:
|
|
613
|
-
if (context) {
|
|
614
|
-
for (const query of context.previousQueries) {
|
|
615
|
-
queryClient.setQueryData(query[0], query[1]);
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
if (err.message !== "mutationCancelled") {
|
|
620
|
-
checkError?.(err);
|
|
621
|
-
|
|
622
|
-
const resourceSingular =
|
|
623
|
-
textTransformers.singular(identifier);
|
|
624
|
-
|
|
625
|
-
const notificationConfig =
|
|
626
|
-
typeof errorNotification === "function"
|
|
627
|
-
? errorNotification(
|
|
628
|
-
err,
|
|
629
|
-
{ ids, values },
|
|
630
|
-
identifier,
|
|
631
|
-
)
|
|
632
|
-
: errorNotification;
|
|
633
|
-
|
|
634
|
-
handleNotification(notificationConfig, {
|
|
635
|
-
key: `${ids}-${identifier}-updateMany-error-notification`,
|
|
636
|
-
message: translate(
|
|
637
|
-
"notifications.editError",
|
|
638
|
-
{
|
|
639
|
-
resource: resourceSingular,
|
|
640
|
-
statusCode: err.statusCode,
|
|
641
|
-
},
|
|
642
|
-
`Error when updating ${resourceSingular} (status code: ${err.statusCode})`,
|
|
643
|
-
),
|
|
644
|
-
description: err.message,
|
|
645
|
-
type: "error",
|
|
646
|
-
});
|
|
647
|
-
}
|
|
648
|
-
},
|
|
649
|
-
mutationKey: keys()
|
|
650
|
-
.data()
|
|
651
|
-
.mutation("updateMany")
|
|
652
|
-
.get(preferLegacyKeys),
|
|
653
|
-
...mutationOptions,
|
|
654
|
-
meta: {
|
|
655
|
-
...mutationOptions?.meta,
|
|
656
|
-
...getXRay("useUpdateMany", preferLegacyKeys),
|
|
657
|
-
},
|
|
625
|
+
}
|
|
658
626
|
},
|
|
659
|
-
|
|
627
|
+
mutationKey: keys().data().mutation("updateMany").get(preferLegacyKeys),
|
|
628
|
+
...mutationOptions,
|
|
629
|
+
meta: {
|
|
630
|
+
...mutationOptions?.meta,
|
|
631
|
+
...getXRay("useUpdateMany", preferLegacyKeys),
|
|
632
|
+
},
|
|
633
|
+
});
|
|
660
634
|
|
|
661
635
|
const { elapsedTime } = useLoadingOvertime({
|
|
662
636
|
isLoading: mutation.isLoading,
|