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