@refinedev/core 4.46.1 → 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 +69 -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/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/package.json +1 -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 -227
- package/src/hooks/data/useDeleteMany.ts +230 -248
- 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 -315
- package/src/hooks/data/useUpdateMany.ts +294 -325
- 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
|
@@ -189,8 +189,8 @@ export const useUpdate = <
|
|
|
189
189
|
TError,
|
|
190
190
|
UpdateParams<TData, TError, TVariables>,
|
|
191
191
|
UpdateContext<TData>
|
|
192
|
-
>(
|
|
193
|
-
({
|
|
192
|
+
>({
|
|
193
|
+
mutationFn: ({
|
|
194
194
|
id,
|
|
195
195
|
values,
|
|
196
196
|
resource: resourceName,
|
|
@@ -269,363 +269,336 @@ export const useUpdate = <
|
|
|
269
269
|
);
|
|
270
270
|
return updatePromise;
|
|
271
271
|
},
|
|
272
|
-
{
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
}
|
|
283
|
-
|
|
272
|
+
onMutate: async ({
|
|
273
|
+
resource: resourceName,
|
|
274
|
+
id,
|
|
275
|
+
mutationMode,
|
|
276
|
+
values,
|
|
277
|
+
dataProviderName,
|
|
278
|
+
meta,
|
|
279
|
+
metaData,
|
|
280
|
+
optimisticUpdateMap = { list: true, many: true, detail: true },
|
|
281
|
+
}) => {
|
|
282
|
+
const { identifier } = select(resourceName);
|
|
283
|
+
|
|
284
|
+
const {
|
|
285
|
+
gqlMutation: _,
|
|
286
|
+
gqlQuery: __,
|
|
287
|
+
...preferredMeta
|
|
288
|
+
} = pickNotDeprecated(meta, metaData) ?? {};
|
|
289
|
+
|
|
290
|
+
const queryKey = queryKeysReplacement(preferLegacyKeys)(
|
|
291
|
+
identifier,
|
|
292
|
+
pickDataProvider(identifier, dataProviderName, resources),
|
|
293
|
+
preferredMeta,
|
|
294
|
+
);
|
|
284
295
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
...preferredMeta
|
|
289
|
-
} = pickNotDeprecated(meta, metaData) ?? {};
|
|
296
|
+
const resourceKeys = keys()
|
|
297
|
+
.data(pickDataProvider(identifier, dataProviderName, resources))
|
|
298
|
+
.resource(identifier);
|
|
290
299
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
pickDataProvider(identifier, dataProviderName, resources),
|
|
294
|
-
preferredMeta,
|
|
295
|
-
);
|
|
300
|
+
const previousQueries: PreviousQuery<TData>[] =
|
|
301
|
+
queryClient.getQueriesData(resourceKeys.get(preferLegacyKeys));
|
|
296
302
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
pickDataProvider(
|
|
300
|
-
identifier,
|
|
301
|
-
dataProviderName,
|
|
302
|
-
resources,
|
|
303
|
-
),
|
|
304
|
-
)
|
|
305
|
-
.resource(identifier);
|
|
303
|
+
const mutationModePropOrContext =
|
|
304
|
+
mutationMode ?? mutationModeContext;
|
|
306
305
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
306
|
+
await queryClient.cancelQueries(
|
|
307
|
+
resourceKeys.get(preferLegacyKeys),
|
|
308
|
+
undefined,
|
|
309
|
+
{
|
|
310
|
+
silent: true,
|
|
311
|
+
},
|
|
312
|
+
);
|
|
311
313
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
+
if (mutationModePropOrContext !== "pessimistic") {
|
|
315
|
+
if (optimisticUpdateMap.list) {
|
|
316
|
+
// Set the previous queries to the new ones:
|
|
317
|
+
queryClient.setQueriesData(
|
|
318
|
+
resourceKeys
|
|
319
|
+
.action("list")
|
|
320
|
+
.params(preferredMeta ?? {})
|
|
321
|
+
.get(preferLegacyKeys),
|
|
322
|
+
(previous?: GetListResponse<TData> | null) => {
|
|
323
|
+
if (
|
|
324
|
+
typeof optimisticUpdateMap.list === "function"
|
|
325
|
+
) {
|
|
326
|
+
return optimisticUpdateMap.list(
|
|
327
|
+
previous,
|
|
328
|
+
values,
|
|
329
|
+
id,
|
|
330
|
+
);
|
|
331
|
+
}
|
|
314
332
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
{
|
|
319
|
-
silent: true,
|
|
320
|
-
},
|
|
321
|
-
);
|
|
333
|
+
if (!previous) {
|
|
334
|
+
return null;
|
|
335
|
+
}
|
|
322
336
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
queryClient.setQueriesData(
|
|
327
|
-
resourceKeys
|
|
328
|
-
.action("list")
|
|
329
|
-
.params(preferredMeta ?? {})
|
|
330
|
-
.get(preferLegacyKeys),
|
|
331
|
-
(previous?: GetListResponse<TData> | null) => {
|
|
332
|
-
if (
|
|
333
|
-
typeof optimisticUpdateMap.list ===
|
|
334
|
-
"function"
|
|
335
|
-
) {
|
|
336
|
-
return optimisticUpdateMap.list(
|
|
337
|
-
previous,
|
|
338
|
-
values,
|
|
337
|
+
const data = previous.data.map((record: TData) => {
|
|
338
|
+
if (record.id?.toString() === id?.toString()) {
|
|
339
|
+
return {
|
|
339
340
|
id,
|
|
340
|
-
|
|
341
|
+
...record,
|
|
342
|
+
...values,
|
|
343
|
+
} as unknown as TData;
|
|
341
344
|
}
|
|
345
|
+
return record;
|
|
346
|
+
});
|
|
342
347
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
348
|
+
return {
|
|
349
|
+
...previous,
|
|
350
|
+
data,
|
|
351
|
+
};
|
|
352
|
+
},
|
|
353
|
+
);
|
|
354
|
+
}
|
|
346
355
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
}
|
|
359
|
-
return record;
|
|
360
|
-
},
|
|
356
|
+
if (optimisticUpdateMap.many) {
|
|
357
|
+
queryClient.setQueriesData(
|
|
358
|
+
resourceKeys.action("many").get(preferLegacyKeys),
|
|
359
|
+
(previous?: GetManyResponse<TData> | null) => {
|
|
360
|
+
if (
|
|
361
|
+
typeof optimisticUpdateMap.many === "function"
|
|
362
|
+
) {
|
|
363
|
+
return optimisticUpdateMap.many(
|
|
364
|
+
previous,
|
|
365
|
+
values,
|
|
366
|
+
id,
|
|
361
367
|
);
|
|
368
|
+
}
|
|
362
369
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
};
|
|
367
|
-
},
|
|
368
|
-
);
|
|
369
|
-
}
|
|
370
|
+
if (!previous) {
|
|
371
|
+
return null;
|
|
372
|
+
}
|
|
370
373
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
(previous?: GetManyResponse<TData> | null) => {
|
|
375
|
-
if (
|
|
376
|
-
typeof optimisticUpdateMap.many ===
|
|
377
|
-
"function"
|
|
378
|
-
) {
|
|
379
|
-
return optimisticUpdateMap.many(
|
|
380
|
-
previous,
|
|
381
|
-
values,
|
|
374
|
+
const data = previous.data.map((record: TData) => {
|
|
375
|
+
if (record.id?.toString() === id?.toString()) {
|
|
376
|
+
record = {
|
|
382
377
|
id,
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
if (!previous) {
|
|
387
|
-
return null;
|
|
378
|
+
...record,
|
|
379
|
+
...values,
|
|
380
|
+
} as unknown as TData;
|
|
388
381
|
}
|
|
382
|
+
return record;
|
|
383
|
+
});
|
|
384
|
+
return {
|
|
385
|
+
...previous,
|
|
386
|
+
data,
|
|
387
|
+
};
|
|
388
|
+
},
|
|
389
|
+
);
|
|
390
|
+
}
|
|
389
391
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
392
|
+
if (optimisticUpdateMap.detail) {
|
|
393
|
+
queryClient.setQueriesData(
|
|
394
|
+
resourceKeys
|
|
395
|
+
.action("one")
|
|
396
|
+
.id(id)
|
|
397
|
+
.params(preferredMeta ?? {})
|
|
398
|
+
.get(preferLegacyKeys),
|
|
399
|
+
(previous?: GetOneResponse<TData> | null) => {
|
|
400
|
+
if (
|
|
401
|
+
typeof optimisticUpdateMap.detail === "function"
|
|
402
|
+
) {
|
|
403
|
+
return optimisticUpdateMap.detail(
|
|
404
|
+
previous,
|
|
405
|
+
values,
|
|
406
|
+
id,
|
|
404
407
|
);
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
typeof optimisticUpdateMap.detail ===
|
|
423
|
-
"function"
|
|
424
|
-
) {
|
|
425
|
-
return optimisticUpdateMap.detail(
|
|
426
|
-
previous,
|
|
427
|
-
values,
|
|
428
|
-
id,
|
|
429
|
-
);
|
|
430
|
-
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
if (!previous) {
|
|
411
|
+
return null;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
return {
|
|
415
|
+
...previous,
|
|
416
|
+
data: {
|
|
417
|
+
...previous.data,
|
|
418
|
+
...values,
|
|
419
|
+
},
|
|
420
|
+
};
|
|
421
|
+
},
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
431
425
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
426
|
+
return {
|
|
427
|
+
previousQueries,
|
|
428
|
+
queryKey,
|
|
429
|
+
};
|
|
430
|
+
},
|
|
431
|
+
onSettled: (
|
|
432
|
+
_data,
|
|
433
|
+
_error,
|
|
434
|
+
{
|
|
435
|
+
id,
|
|
436
|
+
resource: resourceName,
|
|
437
|
+
dataProviderName,
|
|
438
|
+
invalidates = ["list", "many", "detail"],
|
|
439
|
+
},
|
|
440
|
+
) => {
|
|
441
|
+
const { identifier } = select(resourceName);
|
|
435
442
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
}
|
|
443
|
+
invalidateStore({
|
|
444
|
+
resource: identifier,
|
|
445
|
+
dataProviderName: pickDataProvider(
|
|
446
|
+
identifier,
|
|
447
|
+
dataProviderName,
|
|
448
|
+
resources,
|
|
449
|
+
),
|
|
450
|
+
invalidates,
|
|
451
|
+
id,
|
|
452
|
+
});
|
|
447
453
|
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
454
|
+
notificationDispatch({
|
|
455
|
+
type: ActionTypes.REMOVE,
|
|
456
|
+
payload: { id, resource: identifier },
|
|
457
|
+
});
|
|
458
|
+
},
|
|
459
|
+
onSuccess: (
|
|
460
|
+
data,
|
|
461
|
+
{
|
|
462
|
+
id,
|
|
463
|
+
resource: resourceName,
|
|
464
|
+
successNotification,
|
|
465
|
+
dataProviderName: dataProviderNameFromProp,
|
|
466
|
+
values,
|
|
467
|
+
meta,
|
|
468
|
+
metaData,
|
|
452
469
|
},
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
470
|
+
context,
|
|
471
|
+
) => {
|
|
472
|
+
const { resource, identifier } = select(resourceName);
|
|
473
|
+
const resourceSingular = textTransformers.singular(identifier);
|
|
474
|
+
|
|
475
|
+
const dataProviderName = pickDataProvider(
|
|
476
|
+
identifier,
|
|
477
|
+
dataProviderNameFromProp,
|
|
478
|
+
resources,
|
|
479
|
+
);
|
|
480
|
+
|
|
481
|
+
const combinedMeta = getMeta({
|
|
482
|
+
resource,
|
|
483
|
+
meta: pickNotDeprecated(meta, metaData),
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
const notificationConfig =
|
|
487
|
+
typeof successNotification === "function"
|
|
488
|
+
? successNotification(data, { id, values }, identifier)
|
|
489
|
+
: successNotification;
|
|
490
|
+
|
|
491
|
+
handleNotification(notificationConfig, {
|
|
492
|
+
key: `${id}-${identifier}-notification`,
|
|
493
|
+
description: translate("notifications.success", "Successful"),
|
|
494
|
+
message: translate(
|
|
495
|
+
"notifications.editSuccess",
|
|
496
|
+
{
|
|
497
|
+
resource: translate(
|
|
498
|
+
`${identifier}.${identifier}`,
|
|
499
|
+
resourceSingular,
|
|
500
|
+
),
|
|
501
|
+
},
|
|
502
|
+
`Successfully updated ${resourceSingular}`,
|
|
503
|
+
),
|
|
504
|
+
type: "success",
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
publish?.({
|
|
508
|
+
channel: `resources/${resource.name}`,
|
|
509
|
+
type: "updated",
|
|
510
|
+
payload: {
|
|
511
|
+
ids: data.data?.id ? [data.data.id] : undefined,
|
|
512
|
+
},
|
|
513
|
+
date: new Date(),
|
|
514
|
+
meta: {
|
|
515
|
+
...combinedMeta,
|
|
459
516
|
dataProviderName,
|
|
460
|
-
invalidates = ["list", "many", "detail"],
|
|
461
517
|
},
|
|
462
|
-
)
|
|
463
|
-
const { identifier } = select(resourceName);
|
|
464
|
-
|
|
465
|
-
invalidateStore({
|
|
466
|
-
resource: identifier,
|
|
467
|
-
dataProviderName: pickDataProvider(
|
|
468
|
-
identifier,
|
|
469
|
-
dataProviderName,
|
|
470
|
-
resources,
|
|
471
|
-
),
|
|
472
|
-
invalidates,
|
|
473
|
-
id,
|
|
474
|
-
});
|
|
518
|
+
});
|
|
475
519
|
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
520
|
+
let previousData: any;
|
|
521
|
+
if (context) {
|
|
522
|
+
const queryData = queryClient.getQueryData<
|
|
523
|
+
UpdateResponse<TData>
|
|
524
|
+
>(context.queryKey.detail(id));
|
|
525
|
+
|
|
526
|
+
previousData = Object.keys(values || {}).reduce<any>(
|
|
527
|
+
(acc, item) => {
|
|
528
|
+
acc[item] = queryData?.data?.[item];
|
|
529
|
+
return acc;
|
|
530
|
+
},
|
|
531
|
+
{},
|
|
532
|
+
);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
const {
|
|
536
|
+
fields: _fields,
|
|
537
|
+
operation: _operation,
|
|
538
|
+
variables: _variables,
|
|
539
|
+
...rest
|
|
540
|
+
} = combinedMeta || {};
|
|
541
|
+
log?.mutate({
|
|
542
|
+
action: "update",
|
|
543
|
+
resource: resource.name,
|
|
544
|
+
data: values,
|
|
545
|
+
previousData,
|
|
546
|
+
meta: {
|
|
484
547
|
id,
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
dataProviderName: dataProviderNameFromProp,
|
|
488
|
-
values,
|
|
489
|
-
meta,
|
|
490
|
-
metaData,
|
|
548
|
+
dataProviderName,
|
|
549
|
+
...rest,
|
|
491
550
|
},
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
551
|
+
});
|
|
552
|
+
},
|
|
553
|
+
onError: (
|
|
554
|
+
err: TError,
|
|
555
|
+
{ id, resource: resourceName, errorNotification, values },
|
|
556
|
+
context,
|
|
557
|
+
) => {
|
|
558
|
+
const { identifier } = select(resourceName);
|
|
559
|
+
|
|
560
|
+
// set back the queries to the context:
|
|
561
|
+
if (context) {
|
|
562
|
+
for (const query of context.previousQueries) {
|
|
563
|
+
queryClient.setQueryData(query[0], query[1]);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
496
566
|
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
dataProviderNameFromProp,
|
|
500
|
-
resources,
|
|
501
|
-
);
|
|
567
|
+
if (err.message !== "mutationCancelled") {
|
|
568
|
+
checkError?.(err);
|
|
502
569
|
|
|
503
|
-
const
|
|
504
|
-
resource,
|
|
505
|
-
meta: pickNotDeprecated(meta, metaData),
|
|
506
|
-
});
|
|
570
|
+
const resourceSingular = textTransformers.singular(identifier);
|
|
507
571
|
|
|
508
572
|
const notificationConfig =
|
|
509
|
-
typeof
|
|
510
|
-
?
|
|
511
|
-
:
|
|
573
|
+
typeof errorNotification === "function"
|
|
574
|
+
? errorNotification(err, { id, values }, identifier)
|
|
575
|
+
: errorNotification;
|
|
512
576
|
|
|
513
577
|
handleNotification(notificationConfig, {
|
|
514
578
|
key: `${id}-${identifier}-notification`,
|
|
515
|
-
description: translate(
|
|
516
|
-
"notifications.success",
|
|
517
|
-
"Successful",
|
|
518
|
-
),
|
|
519
579
|
message: translate(
|
|
520
|
-
"notifications.
|
|
580
|
+
"notifications.editError",
|
|
521
581
|
{
|
|
522
582
|
resource: translate(
|
|
523
583
|
`${identifier}.${identifier}`,
|
|
524
584
|
resourceSingular,
|
|
525
585
|
),
|
|
586
|
+
statusCode: err.statusCode,
|
|
526
587
|
},
|
|
527
|
-
`
|
|
588
|
+
`Error when updating ${resourceSingular} (status code: ${err.statusCode})`,
|
|
528
589
|
),
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
publish?.({
|
|
533
|
-
channel: `resources/${resource.name}`,
|
|
534
|
-
type: "updated",
|
|
535
|
-
payload: {
|
|
536
|
-
ids: data.data?.id ? [data.data.id] : undefined,
|
|
537
|
-
},
|
|
538
|
-
date: new Date(),
|
|
539
|
-
meta: {
|
|
540
|
-
...combinedMeta,
|
|
541
|
-
dataProviderName,
|
|
542
|
-
},
|
|
543
|
-
});
|
|
544
|
-
|
|
545
|
-
let previousData: any;
|
|
546
|
-
if (context) {
|
|
547
|
-
const queryData = queryClient.getQueryData<
|
|
548
|
-
UpdateResponse<TData>
|
|
549
|
-
>(context.queryKey.detail(id));
|
|
550
|
-
|
|
551
|
-
previousData = Object.keys(values || {}).reduce<any>(
|
|
552
|
-
(acc, item) => {
|
|
553
|
-
acc[item] = queryData?.data?.[item];
|
|
554
|
-
return acc;
|
|
555
|
-
},
|
|
556
|
-
{},
|
|
557
|
-
);
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
const {
|
|
561
|
-
fields: _fields,
|
|
562
|
-
operation: _operation,
|
|
563
|
-
variables: _variables,
|
|
564
|
-
...rest
|
|
565
|
-
} = combinedMeta || {};
|
|
566
|
-
log?.mutate({
|
|
567
|
-
action: "update",
|
|
568
|
-
resource: resource.name,
|
|
569
|
-
data: values,
|
|
570
|
-
previousData,
|
|
571
|
-
meta: {
|
|
572
|
-
id,
|
|
573
|
-
dataProviderName,
|
|
574
|
-
...rest,
|
|
575
|
-
},
|
|
590
|
+
description: err.message,
|
|
591
|
+
type: "error",
|
|
576
592
|
});
|
|
577
|
-
}
|
|
578
|
-
onError: (
|
|
579
|
-
err: TError,
|
|
580
|
-
{ id, resource: resourceName, errorNotification, values },
|
|
581
|
-
context,
|
|
582
|
-
) => {
|
|
583
|
-
const { identifier } = select(resourceName);
|
|
584
|
-
|
|
585
|
-
// set back the queries to the context:
|
|
586
|
-
if (context) {
|
|
587
|
-
for (const query of context.previousQueries) {
|
|
588
|
-
queryClient.setQueryData(query[0], query[1]);
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
if (err.message !== "mutationCancelled") {
|
|
593
|
-
checkError?.(err);
|
|
594
|
-
|
|
595
|
-
const resourceSingular =
|
|
596
|
-
textTransformers.singular(identifier);
|
|
597
|
-
|
|
598
|
-
const notificationConfig =
|
|
599
|
-
typeof errorNotification === "function"
|
|
600
|
-
? errorNotification(err, { id, values }, identifier)
|
|
601
|
-
: errorNotification;
|
|
602
|
-
|
|
603
|
-
handleNotification(notificationConfig, {
|
|
604
|
-
key: `${id}-${identifier}-notification`,
|
|
605
|
-
message: translate(
|
|
606
|
-
"notifications.editError",
|
|
607
|
-
{
|
|
608
|
-
resource: translate(
|
|
609
|
-
`${identifier}.${identifier}`,
|
|
610
|
-
resourceSingular,
|
|
611
|
-
),
|
|
612
|
-
statusCode: err.statusCode,
|
|
613
|
-
},
|
|
614
|
-
`Error when updating ${resourceSingular} (status code: ${err.statusCode})`,
|
|
615
|
-
),
|
|
616
|
-
description: err.message,
|
|
617
|
-
type: "error",
|
|
618
|
-
});
|
|
619
|
-
}
|
|
620
|
-
},
|
|
621
|
-
mutationKey: keys().data().mutation("update").get(preferLegacyKeys),
|
|
622
|
-
...mutationOptions,
|
|
623
|
-
meta: {
|
|
624
|
-
...mutationOptions?.meta,
|
|
625
|
-
...getXRay("useUpdate", preferLegacyKeys),
|
|
626
|
-
},
|
|
593
|
+
}
|
|
627
594
|
},
|
|
628
|
-
|
|
595
|
+
mutationKey: keys().data().mutation("update").get(preferLegacyKeys),
|
|
596
|
+
...mutationOptions,
|
|
597
|
+
meta: {
|
|
598
|
+
...mutationOptions?.meta,
|
|
599
|
+
...getXRay("useUpdate", preferLegacyKeys),
|
|
600
|
+
},
|
|
601
|
+
});
|
|
629
602
|
|
|
630
603
|
const { elapsedTime } = useLoadingOvertime({
|
|
631
604
|
isLoading: mutation.isLoading,
|