@refinedev/core 4.46.1 → 4.46.3-alpha.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.
Files changed (270) hide show
  1. package/CHANGELOG.md +70 -1
  2. package/README.md +1 -1
  3. package/dist/components/authenticated/index.d.ts +3 -3
  4. package/dist/components/authenticated/index.d.ts.map +1 -1
  5. package/dist/components/canAccess/index.d.ts +5 -5
  6. package/dist/components/canAccess/index.d.ts.map +1 -1
  7. package/dist/components/containers/refine/index.d.ts +3 -3
  8. package/dist/components/gh-banner/index.d.ts +2 -2
  9. package/dist/components/gh-banner/index.d.ts.map +1 -1
  10. package/dist/components/pages/auth/components/forgotPassword/index.d.ts +1 -1
  11. package/dist/components/pages/auth/components/forgotPassword/index.d.ts.map +1 -1
  12. package/dist/components/pages/auth/components/login/index.d.ts +1 -1
  13. package/dist/components/pages/auth/components/login/index.d.ts.map +1 -1
  14. package/dist/components/pages/auth/components/register/index.d.ts +1 -1
  15. package/dist/components/pages/auth/components/register/index.d.ts.map +1 -1
  16. package/dist/components/pages/auth/components/updatePassword/index.d.ts +1 -1
  17. package/dist/components/pages/auth/components/updatePassword/index.d.ts.map +1 -1
  18. package/dist/components/pages/auth/index.d.ts +3 -3
  19. package/dist/components/pages/auth/index.d.ts.map +1 -1
  20. package/dist/components/routeChangeHandler/index.d.ts +0 -1
  21. package/dist/components/routeChangeHandler/index.d.ts.map +1 -1
  22. package/dist/contexts/accessControl/IAccessControlContext.d.ts +3 -3
  23. package/dist/contexts/accessControl/IAccessControlContext.d.ts.map +1 -1
  24. package/dist/contexts/auditLog/IAuditLogContext.d.ts +3 -3
  25. package/dist/contexts/auditLog/IAuditLogContext.d.ts.map +1 -1
  26. package/dist/contexts/auth/IAuthContext.d.ts +6 -6
  27. package/dist/contexts/auth/IAuthContext.d.ts.map +1 -1
  28. package/dist/contexts/data/IDataContext.d.ts +9 -9
  29. package/dist/contexts/data/IDataContext.d.ts.map +1 -1
  30. package/dist/contexts/legacy-router/IRouterContext.d.ts +1 -1
  31. package/dist/contexts/legacy-router/IRouterContext.d.ts.map +1 -1
  32. package/dist/contexts/live/ILiveContext.d.ts +2 -3
  33. package/dist/contexts/live/ILiveContext.d.ts.map +1 -1
  34. package/dist/contexts/notification/INotificationContext.d.ts +1 -1
  35. package/dist/contexts/notification/INotificationContext.d.ts.map +1 -1
  36. package/dist/contexts/resource/IResourceContext.d.ts +5 -5
  37. package/dist/contexts/resource/IResourceContext.d.ts.map +1 -1
  38. package/dist/contexts/translation/ITranslationContext.d.ts +2 -2
  39. package/dist/contexts/translation/ITranslationContext.d.ts.map +1 -1
  40. package/dist/contexts/undoableQueue/IUndoableQueueContext.d.ts +0 -1
  41. package/dist/contexts/undoableQueue/IUndoableQueueContext.d.ts.map +1 -1
  42. package/dist/definitions/helpers/flatten-object-keys/index.d.ts.map +1 -1
  43. package/dist/definitions/helpers/handlePaginationParams/index.d.ts +1 -1
  44. package/dist/definitions/helpers/handlePaginationParams/index.d.ts.map +1 -1
  45. package/dist/definitions/helpers/handleRefineOptions/index.d.ts +2 -2
  46. package/dist/definitions/helpers/handleRefineOptions/index.d.ts.map +1 -1
  47. package/dist/definitions/helpers/keys/index.d.ts +10 -10
  48. package/dist/definitions/helpers/keys/index.d.ts.map +1 -1
  49. package/dist/definitions/helpers/menu/create-tree.d.ts +2 -2
  50. package/dist/definitions/helpers/menu/create-tree.d.ts.map +1 -1
  51. package/dist/definitions/helpers/redirectPage/index.d.ts +1 -1
  52. package/dist/definitions/helpers/redirectPage/index.d.ts.map +1 -1
  53. package/dist/definitions/helpers/router/get-action-routes-from-resource.d.ts +1 -1
  54. package/dist/definitions/helpers/router/get-action-routes-from-resource.d.ts.map +1 -1
  55. package/dist/definitions/helpers/sequentialPromises/index.d.ts +2 -2
  56. package/dist/definitions/helpers/sequentialPromises/index.d.ts.map +1 -1
  57. package/dist/esm/index.js +7 -6
  58. package/dist/esm/index.js.map +1 -1
  59. package/dist/hooks/accessControl/useCan/index.d.ts +1 -1
  60. package/dist/hooks/accessControl/useCan/index.d.ts.map +1 -1
  61. package/dist/hooks/auditLog/useLog/index.d.ts +3 -3
  62. package/dist/hooks/auditLog/useLog/index.d.ts.map +1 -1
  63. package/dist/hooks/auditLog/useLogList/index.d.ts +1 -1
  64. package/dist/hooks/auditLog/useLogList/index.d.ts.map +1 -1
  65. package/dist/hooks/auth/useForgotPassword/index.d.ts +6 -6
  66. package/dist/hooks/auth/useForgotPassword/index.d.ts.map +1 -1
  67. package/dist/hooks/auth/useGetIdentity/index.d.ts +6 -6
  68. package/dist/hooks/auth/useGetIdentity/index.d.ts.map +1 -1
  69. package/dist/hooks/auth/useIsAuthenticated/index.d.ts +6 -6
  70. package/dist/hooks/auth/useIsAuthenticated/index.d.ts.map +1 -1
  71. package/dist/hooks/auth/useLogin/index.d.ts +6 -6
  72. package/dist/hooks/auth/useLogin/index.d.ts.map +1 -1
  73. package/dist/hooks/auth/useLogout/index.d.ts +7 -7
  74. package/dist/hooks/auth/useLogout/index.d.ts.map +1 -1
  75. package/dist/hooks/auth/useOnError/index.d.ts +6 -6
  76. package/dist/hooks/auth/useOnError/index.d.ts.map +1 -1
  77. package/dist/hooks/auth/usePermissions/index.d.ts +6 -6
  78. package/dist/hooks/auth/usePermissions/index.d.ts.map +1 -1
  79. package/dist/hooks/auth/useRegister/index.d.ts +6 -6
  80. package/dist/hooks/auth/useRegister/index.d.ts.map +1 -1
  81. package/dist/hooks/auth/useUpdatePassword/index.d.ts +6 -6
  82. package/dist/hooks/auth/useUpdatePassword/index.d.ts.map +1 -1
  83. package/dist/hooks/breadcrumb/index.d.ts +3 -3
  84. package/dist/hooks/breadcrumb/index.d.ts.map +1 -1
  85. package/dist/hooks/data/useCreate.d.ts +3 -3
  86. package/dist/hooks/data/useCreate.d.ts.map +1 -1
  87. package/dist/hooks/data/useCreateMany.d.ts +3 -3
  88. package/dist/hooks/data/useCreateMany.d.ts.map +1 -1
  89. package/dist/hooks/data/useCustom.d.ts +1 -1
  90. package/dist/hooks/data/useCustom.d.ts.map +1 -1
  91. package/dist/hooks/data/useCustomMutation.d.ts +3 -3
  92. package/dist/hooks/data/useCustomMutation.d.ts.map +1 -1
  93. package/dist/hooks/data/useDelete.d.ts +3 -3
  94. package/dist/hooks/data/useDelete.d.ts.map +1 -1
  95. package/dist/hooks/data/useDeleteMany.d.ts +3 -3
  96. package/dist/hooks/data/useDeleteMany.d.ts.map +1 -1
  97. package/dist/hooks/data/useInfiniteList.d.ts +2 -2
  98. package/dist/hooks/data/useInfiniteList.d.ts.map +1 -1
  99. package/dist/hooks/data/useList.d.ts +2 -2
  100. package/dist/hooks/data/useList.d.ts.map +1 -1
  101. package/dist/hooks/data/useMany.d.ts +1 -1
  102. package/dist/hooks/data/useMany.d.ts.map +1 -1
  103. package/dist/hooks/data/useOne.d.ts +1 -1
  104. package/dist/hooks/data/useOne.d.ts.map +1 -1
  105. package/dist/hooks/data/useUpdate.d.ts +3 -3
  106. package/dist/hooks/data/useUpdate.d.ts.map +1 -1
  107. package/dist/hooks/data/useUpdateMany.d.ts +3 -3
  108. package/dist/hooks/data/useUpdateMany.d.ts.map +1 -1
  109. package/dist/hooks/export/csvDownload.interface.d.ts +4 -4
  110. package/dist/hooks/export/csvDownload.interface.d.ts.map +1 -1
  111. package/dist/hooks/export/index.d.ts +2 -2
  112. package/dist/hooks/export/index.d.ts.map +1 -1
  113. package/dist/hooks/form/useForm.d.ts +4 -4
  114. package/dist/hooks/form/useForm.d.ts.map +1 -1
  115. package/dist/hooks/import/index.d.ts +9 -10
  116. package/dist/hooks/import/index.d.ts.map +1 -1
  117. package/dist/hooks/invalidate/index.d.ts +1 -1
  118. package/dist/hooks/invalidate/index.d.ts.map +1 -1
  119. package/dist/hooks/legacy-router/useRouterContext.d.ts +0 -1
  120. package/dist/hooks/legacy-router/useRouterContext.d.ts.map +1 -1
  121. package/dist/hooks/live/useResourceSubscription/index.d.ts +2 -2
  122. package/dist/hooks/live/useResourceSubscription/index.d.ts.map +1 -1
  123. package/dist/hooks/live/useSubscription/index.d.ts +1 -1
  124. package/dist/hooks/live/useSubscription/index.d.ts.map +1 -1
  125. package/dist/hooks/menu/useMenu.d.ts +3 -3
  126. package/dist/hooks/menu/useMenu.d.ts.map +1 -1
  127. package/dist/hooks/modal/useModal/index.d.ts +2 -2
  128. package/dist/hooks/modal/useModal/index.d.ts.map +1 -1
  129. package/dist/hooks/navigation/index.d.ts +1 -1
  130. package/dist/hooks/navigation/index.d.ts.map +1 -1
  131. package/dist/hooks/notification/useCancelNotification/index.d.ts +1 -2
  132. package/dist/hooks/notification/useCancelNotification/index.d.ts.map +1 -1
  133. package/dist/hooks/redirection/index.d.ts +1 -1
  134. package/dist/hooks/redirection/index.d.ts.map +1 -1
  135. package/dist/hooks/refine/useMutationMode.d.ts +1 -1
  136. package/dist/hooks/refine/useMutationMode.d.ts.map +1 -1
  137. package/dist/hooks/refine/useRefineContext.d.ts +0 -1
  138. package/dist/hooks/refine/useRefineContext.d.ts.map +1 -1
  139. package/dist/hooks/refine/useSyncWithLocation.d.ts +1 -1
  140. package/dist/hooks/refine/useSyncWithLocation.d.ts.map +1 -1
  141. package/dist/hooks/refine/useTitle.d.ts +0 -1
  142. package/dist/hooks/refine/useTitle.d.ts.map +1 -1
  143. package/dist/hooks/refine/useWarnAboutChange/index.d.ts +1 -1
  144. package/dist/hooks/refine/useWarnAboutChange/index.d.ts.map +1 -1
  145. package/dist/hooks/resource/useResource/index.d.ts +5 -5
  146. package/dist/hooks/resource/useResource/index.d.ts.map +1 -1
  147. package/dist/hooks/resource/useResourceWithRoute/index.d.ts +1 -1
  148. package/dist/hooks/resource/useResourceWithRoute/index.d.ts.map +1 -1
  149. package/dist/hooks/router/use-get-to-path/index.d.ts +2 -2
  150. package/dist/hooks/router/use-get-to-path/index.d.ts.map +1 -1
  151. package/dist/hooks/router/use-go/index.d.ts +6 -4
  152. package/dist/hooks/router/use-go/index.d.ts.map +1 -1
  153. package/dist/hooks/router/use-parse/index.d.ts +1 -1
  154. package/dist/hooks/router/use-parse/index.d.ts.map +1 -1
  155. package/dist/hooks/router/use-to-path/index.d.ts +1 -1
  156. package/dist/hooks/router/use-to-path/index.d.ts.map +1 -1
  157. package/dist/hooks/show/useShow.d.ts +2 -2
  158. package/dist/hooks/show/useShow.d.ts.map +1 -1
  159. package/dist/hooks/translate/useGetLocale.d.ts +1 -1
  160. package/dist/hooks/translate/useGetLocale.d.ts.map +1 -1
  161. package/dist/hooks/useLoadingOvertime/index.d.ts +6 -6
  162. package/dist/hooks/useLoadingOvertime/index.d.ts.map +1 -1
  163. package/dist/hooks/useSelect/index.d.ts +2 -2
  164. package/dist/hooks/useSelect/index.d.ts.map +1 -1
  165. package/dist/hooks/useTable/index.d.ts +5 -5
  166. package/dist/hooks/useTable/index.d.ts.map +1 -1
  167. package/dist/iife/index.js +7 -6
  168. package/dist/iife/index.js.map +1 -1
  169. package/dist/index.d.ts +1 -1
  170. package/dist/index.d.ts.map +1 -1
  171. package/dist/index.js +7 -6
  172. package/dist/index.js.map +1 -1
  173. package/dist/interfaces/actions.d.ts +6 -6
  174. package/dist/interfaces/actions.d.ts.map +1 -1
  175. package/dist/interfaces/auditLog/logData.d.ts +1 -1
  176. package/dist/interfaces/auditLog/logData.d.ts.map +1 -1
  177. package/dist/interfaces/auth.d.ts +12 -12
  178. package/dist/interfaces/auth.d.ts.map +1 -1
  179. package/dist/interfaces/autoSave.d.ts +4 -4
  180. package/dist/interfaces/autoSave.d.ts.map +1 -1
  181. package/dist/interfaces/bindings/access-control.d.ts +3 -3
  182. package/dist/interfaces/bindings/access-control.d.ts.map +1 -1
  183. package/dist/interfaces/bindings/auth.d.ts +8 -7
  184. package/dist/interfaces/bindings/auth.d.ts.map +1 -1
  185. package/dist/interfaces/bindings/data.d.ts +3 -3
  186. package/dist/interfaces/bindings/data.d.ts.map +1 -1
  187. package/dist/interfaces/bindings/i18n.d.ts +4 -4
  188. package/dist/interfaces/bindings/i18n.d.ts.map +1 -1
  189. package/dist/interfaces/bindings/index.d.ts +1 -1
  190. package/dist/interfaces/bindings/index.d.ts.map +1 -1
  191. package/dist/interfaces/bindings/live.d.ts +5 -5
  192. package/dist/interfaces/bindings/live.d.ts.map +1 -1
  193. package/dist/interfaces/bindings/notifications.d.ts +1 -1
  194. package/dist/interfaces/bindings/notifications.d.ts.map +1 -1
  195. package/dist/interfaces/bindings/resource.d.ts +7 -7
  196. package/dist/interfaces/bindings/resource.d.ts.map +1 -1
  197. package/dist/interfaces/bindings/router.d.ts +7 -8
  198. package/dist/interfaces/bindings/router.d.ts.map +1 -1
  199. package/dist/interfaces/customComponents.d.ts +3 -3
  200. package/dist/interfaces/customComponents.d.ts.map +1 -1
  201. package/dist/interfaces/errors/RefineError.d.ts +1 -1
  202. package/dist/interfaces/errors/RefineError.d.ts.map +1 -1
  203. package/dist/interfaces/form-url-params.d.ts +1 -1
  204. package/dist/interfaces/form-url-params.d.ts.map +1 -1
  205. package/dist/interfaces/index.d.ts +5 -5
  206. package/dist/interfaces/index.d.ts.map +1 -1
  207. package/dist/interfaces/live/LiveEvent.d.ts +1 -1
  208. package/dist/interfaces/live/LiveEvent.d.ts.map +1 -1
  209. package/dist/interfaces/live/LiveModeProps.d.ts +2 -2
  210. package/dist/interfaces/live/LiveModeProps.d.ts.map +1 -1
  211. package/dist/interfaces/metaData/fields.d.ts +1 -1
  212. package/dist/interfaces/metaData/fields.d.ts.map +1 -1
  213. package/dist/interfaces/metaData/graphqlQueryOptions.d.ts +48 -1
  214. package/dist/interfaces/metaData/graphqlQueryOptions.d.ts.map +1 -1
  215. package/dist/interfaces/metaData/metaDataQuery.d.ts +1 -1
  216. package/dist/interfaces/metaData/metaDataQuery.d.ts.map +1 -1
  217. package/dist/interfaces/metaData/metaQuery.d.ts +1 -1
  218. package/dist/interfaces/metaData/metaQuery.d.ts.map +1 -1
  219. package/dist/interfaces/metaData/nestedField.d.ts +1 -1
  220. package/dist/interfaces/metaData/nestedField.d.ts.map +1 -1
  221. package/dist/interfaces/metaData/variableOptions.d.ts +1 -1
  222. package/dist/interfaces/metaData/variableOptions.d.ts.map +1 -1
  223. package/dist/interfaces/mutationMode.d.ts +6 -6
  224. package/dist/interfaces/mutationMode.d.ts.map +1 -1
  225. package/dist/interfaces/optimistic-update-map.d.ts +2 -2
  226. package/dist/interfaces/optimistic-update-map.d.ts.map +1 -1
  227. package/dist/interfaces/prettify.d.ts +1 -1
  228. package/dist/interfaces/prettify.d.ts.map +1 -1
  229. package/dist/interfaces/resourceErrorRouterParams.d.ts +1 -1
  230. package/dist/interfaces/resourceErrorRouterParams.d.ts.map +1 -1
  231. package/dist/interfaces/resourceRouterParams.d.ts +1 -1
  232. package/dist/interfaces/resourceRouterParams.d.ts.map +1 -1
  233. package/dist/interfaces/successErrorNotification.d.ts +1 -1
  234. package/dist/interfaces/successErrorNotification.d.ts.map +1 -1
  235. package/dist/interfaces/telemetry.d.ts +1 -1
  236. package/dist/interfaces/telemetry.d.ts.map +1 -1
  237. package/dist/interfaces/textTransformers.d.ts +1 -1
  238. package/dist/interfaces/textTransformers.d.ts.map +1 -1
  239. package/package.json +1 -1
  240. package/src/components/containers/refine/index.tsx +3 -3
  241. package/src/contexts/auth/IAuthContext.ts +1 -1
  242. package/src/definitions/helpers/flatten-object-keys/index.ts +2 -0
  243. package/src/hooks/accessControl/useCan/index.ts +10 -12
  244. package/src/hooks/auditLog/useLogList/index.ts +10 -12
  245. package/src/hooks/auth/useForgotPassword/index.ts +51 -54
  246. package/src/hooks/auth/useGetIdentity/index.ts +23 -26
  247. package/src/hooks/auth/useIsAuthenticated/index.ts +20 -20
  248. package/src/hooks/auth/useLogin/index.ts +33 -35
  249. package/src/hooks/auth/useLogout/index.ts +32 -34
  250. package/src/hooks/auth/useOnError/index.ts +29 -33
  251. package/src/hooks/auth/usePermissions/index.ts +19 -22
  252. package/src/hooks/auth/useRegister/index.ts +60 -66
  253. package/src/hooks/auth/useUpdatePassword/index.ts +51 -54
  254. package/src/hooks/data/useCreate.ts +115 -117
  255. package/src/hooks/data/useCreateMany.ts +113 -118
  256. package/src/hooks/data/useDelete.ts +212 -227
  257. package/src/hooks/data/useDeleteMany.ts +230 -248
  258. package/src/hooks/data/useInfiniteList.ts +36 -42
  259. package/src/hooks/data/useList.ts +56 -62
  260. package/src/hooks/data/useMany.ts +36 -37
  261. package/src/hooks/data/useOne.ts +54 -55
  262. package/src/hooks/data/useUpdate.ts +288 -315
  263. package/src/hooks/data/useUpdateMany.ts +294 -325
  264. package/src/hooks/menu/useMenu.tsx +1 -1
  265. package/src/hooks/router/use-go/index.tsx +3 -0
  266. package/src/index.tsx +1 -0
  267. package/src/interfaces/auth.tsx +6 -6
  268. package/src/interfaces/bindings/auth.ts +3 -1
  269. package/src/interfaces/bindings/index.ts +1 -0
  270. package/src/interfaces/metaData/graphqlQueryOptions.ts +47 -0
@@ -174,8 +174,8 @@ export const useDelete = <
174
174
  TError,
175
175
  DeleteParams<TData, TError, TVariables>,
176
176
  DeleteContext<TData>
177
- >(
178
- ({
177
+ >({
178
+ mutationFn: ({
179
179
  id,
180
180
  mutationMode,
181
181
  undoableTimeout,
@@ -255,263 +255,248 @@ export const useDelete = <
255
255
  );
256
256
  return deletePromise;
257
257
  },
258
- {
259
- onMutate: async ({
258
+ onMutate: async ({
259
+ id,
260
+ resource: resourceName,
261
+ mutationMode,
262
+ dataProviderName,
263
+ meta,
264
+ metaData,
265
+ }) => {
266
+ const { identifier } = select(resourceName);
267
+
268
+ const {
269
+ gqlMutation: _,
270
+ gqlQuery: __,
271
+ ...preferredMeta
272
+ } = pickNotDeprecated(meta, metaData) ?? {};
273
+
274
+ const queryKey = queryKeysReplacement(preferLegacyKeys)(
275
+ identifier,
276
+ pickDataProvider(identifier, dataProviderName, resources),
277
+ preferredMeta,
278
+ );
279
+
280
+ const resourceKeys = keys()
281
+ .data(pickDataProvider(identifier, dataProviderName, resources))
282
+ .resource(identifier);
283
+
284
+ const mutationModePropOrContext =
285
+ mutationMode ?? mutationModeContext;
286
+
287
+ await queryClient.cancelQueries(
288
+ resourceKeys.get(preferLegacyKeys),
289
+ undefined,
290
+ {
291
+ silent: true,
292
+ },
293
+ );
294
+
295
+ const previousQueries: PreviousQuery<TData>[] =
296
+ queryClient.getQueriesData(resourceKeys.get(preferLegacyKeys));
297
+
298
+ if (mutationModePropOrContext !== "pessimistic") {
299
+ // Set the previous queries to the new ones:
300
+ queryClient.setQueriesData(
301
+ resourceKeys
302
+ .action("list")
303
+ .params(preferredMeta ?? {})
304
+ .get(preferLegacyKeys),
305
+ (previous?: GetListResponse<TData> | null) => {
306
+ if (!previous) {
307
+ return null;
308
+ }
309
+ const data = previous.data.filter(
310
+ (record: TData) =>
311
+ record.id?.toString() !== id.toString(),
312
+ );
313
+
314
+ return {
315
+ data,
316
+ total: previous.total - 1,
317
+ };
318
+ },
319
+ );
320
+
321
+ queryClient.setQueriesData(
322
+ resourceKeys.action("many").get(preferLegacyKeys),
323
+ (previous?: GetListResponse<TData> | null) => {
324
+ if (!previous) {
325
+ return null;
326
+ }
327
+ const data = previous.data.filter((record: TData) => {
328
+ return record.id?.toString() !== id?.toString();
329
+ });
330
+
331
+ return {
332
+ ...previous,
333
+ data,
334
+ };
335
+ },
336
+ );
337
+ }
338
+
339
+ return {
340
+ previousQueries,
341
+ queryKey,
342
+ };
343
+ },
344
+ onSettled: (
345
+ _data,
346
+ _error,
347
+ {
260
348
  id,
261
349
  resource: resourceName,
262
- mutationMode,
263
350
  dataProviderName,
351
+ invalidates = ["list", "many"],
352
+ },
353
+ ) => {
354
+ const { identifier } = select(resourceName);
355
+
356
+ // invalidate the cache for the list and many queries:
357
+ invalidateStore({
358
+ resource: identifier,
359
+ dataProviderName: pickDataProvider(
360
+ identifier,
361
+ dataProviderName,
362
+ resources,
363
+ ),
364
+ invalidates,
365
+ });
366
+
367
+ notificationDispatch({
368
+ type: ActionTypes.REMOVE,
369
+ payload: { id, resource: identifier },
370
+ });
371
+ },
372
+ onSuccess: (
373
+ _data,
374
+ {
375
+ id,
376
+ resource: resourceName,
377
+ successNotification,
378
+ dataProviderName: dataProviderNameFromProp,
264
379
  meta,
265
380
  metaData,
266
- }) => {
267
- const { identifier } = select(resourceName);
381
+ },
382
+ context,
383
+ ) => {
384
+ const { resource, identifier } = select(resourceName);
385
+ const resourceSingular = textTransformers.singular(identifier);
268
386
 
269
- const {
270
- gqlMutation: _,
271
- gqlQuery: __,
272
- ...preferredMeta
273
- } = pickNotDeprecated(meta, metaData) ?? {};
387
+ const dataProviderName = pickDataProvider(
388
+ identifier,
389
+ dataProviderNameFromProp,
390
+ resources,
391
+ );
274
392
 
275
- const queryKey = queryKeysReplacement(preferLegacyKeys)(
276
- identifier,
277
- pickDataProvider(identifier, dataProviderName, resources),
278
- preferredMeta,
279
- );
393
+ const combinedMeta = getMeta({
394
+ resource,
395
+ meta: pickNotDeprecated(meta, metaData),
396
+ });
280
397
 
281
- const resourceKeys = keys()
282
- .data(
283
- pickDataProvider(
284
- identifier,
285
- dataProviderName,
286
- resources,
287
- ),
288
- )
289
- .resource(identifier);
398
+ // Remove the queries from the cache:
399
+ queryClient.removeQueries(context?.queryKey.detail(id));
290
400
 
291
- const mutationModePropOrContext =
292
- mutationMode ?? mutationModeContext;
401
+ const notificationConfig =
402
+ typeof successNotification === "function"
403
+ ? successNotification(_data, id, identifier)
404
+ : successNotification;
293
405
 
294
- await queryClient.cancelQueries(
295
- resourceKeys.get(preferLegacyKeys),
296
- undefined,
406
+ handleNotification(notificationConfig, {
407
+ key: `${id}-${identifier}-notification`,
408
+ description: translate("notifications.success", "Success"),
409
+ message: translate(
410
+ "notifications.deleteSuccess",
297
411
  {
298
- silent: true,
412
+ resource: translate(
413
+ `${identifier}.${identifier}`,
414
+ resourceSingular,
415
+ ),
299
416
  },
300
- );
301
-
302
- const previousQueries: PreviousQuery<TData>[] =
303
- queryClient.getQueriesData(
304
- resourceKeys.get(preferLegacyKeys),
305
- );
306
-
307
- if (mutationModePropOrContext !== "pessimistic") {
308
- // Set the previous queries to the new ones:
309
- queryClient.setQueriesData(
310
- resourceKeys
311
- .action("list")
312
- .params(preferredMeta ?? {})
313
- .get(preferLegacyKeys),
314
- (previous?: GetListResponse<TData> | null) => {
315
- if (!previous) {
316
- return null;
317
- }
318
- const data = previous.data.filter(
319
- (record: TData) =>
320
- record.id?.toString() !== id.toString(),
321
- );
322
-
323
- return {
324
- data,
325
- total: previous.total - 1,
326
- };
327
- },
328
- );
329
-
330
- queryClient.setQueriesData(
331
- resourceKeys.action("many").get(preferLegacyKeys),
332
- (previous?: GetListResponse<TData> | null) => {
333
- if (!previous) {
334
- return null;
335
- }
336
- const data = previous.data.filter(
337
- (record: TData) => {
338
- return (
339
- record.id?.toString() !== id?.toString()
340
- );
341
- },
342
- );
343
-
344
- return {
345
- ...previous,
346
- data,
347
- };
348
- },
349
- );
350
- }
417
+ `Successfully deleted a ${resourceSingular}`,
418
+ ),
419
+ type: "success",
420
+ });
351
421
 
352
- return {
353
- previousQueries,
354
- queryKey,
355
- };
356
- },
357
- onSettled: (
358
- _data,
359
- _error,
360
- {
361
- id,
362
- resource: resourceName,
422
+ publish?.({
423
+ channel: `resources/${resource.name}`,
424
+ type: "deleted",
425
+ payload: {
426
+ ids: [id],
427
+ },
428
+ date: new Date(),
429
+ meta: {
430
+ ...combinedMeta,
363
431
  dataProviderName,
364
- invalidates = ["list", "many"],
365
432
  },
366
- ) => {
367
- const { identifier } = select(resourceName);
368
-
369
- // invalidate the cache for the list and many queries:
370
- invalidateStore({
371
- resource: identifier,
372
- dataProviderName: pickDataProvider(
373
- identifier,
374
- dataProviderName,
375
- resources,
376
- ),
377
- invalidates,
378
- });
433
+ });
379
434
 
380
- notificationDispatch({
381
- type: ActionTypes.REMOVE,
382
- payload: { id, resource: identifier },
383
- });
384
- },
385
- onSuccess: (
386
- _data,
387
- {
435
+ const {
436
+ fields: _fields,
437
+ operation: _operation,
438
+ variables: _variables,
439
+ ...rest
440
+ } = combinedMeta || {};
441
+ log?.mutate({
442
+ action: "delete",
443
+ resource: resource.name,
444
+ meta: {
388
445
  id,
389
- resource: resourceName,
390
- successNotification,
391
- dataProviderName: dataProviderNameFromProp,
392
- meta,
393
- metaData,
446
+ dataProviderName,
447
+ ...rest,
394
448
  },
395
- context,
396
- ) => {
397
- const { resource, identifier } = select(resourceName);
398
- const resourceSingular = textTransformers.singular(identifier);
449
+ });
399
450
 
400
- const dataProviderName = pickDataProvider(
401
- identifier,
402
- dataProviderNameFromProp,
403
- resources,
404
- );
451
+ // Remove the queries from the cache:
452
+ queryClient.removeQueries(context?.queryKey.detail(id));
453
+ },
454
+ onError: (
455
+ err: TError,
456
+ { id, resource: resourceName, errorNotification },
457
+ context,
458
+ ) => {
459
+ const { identifier } = select(resourceName);
460
+
461
+ // set back the queries to the context:
462
+ if (context) {
463
+ for (const query of context.previousQueries) {
464
+ queryClient.setQueryData(query[0], query[1]);
465
+ }
466
+ }
405
467
 
406
- const combinedMeta = getMeta({
407
- resource,
408
- meta: pickNotDeprecated(meta, metaData),
409
- });
468
+ if (err.message !== "mutationCancelled") {
469
+ checkError(err);
410
470
 
411
- // Remove the queries from the cache:
412
- queryClient.removeQueries(context?.queryKey.detail(id));
471
+ const resourceSingular = textTransformers.singular(identifier);
413
472
 
414
473
  const notificationConfig =
415
- typeof successNotification === "function"
416
- ? successNotification(_data, id, identifier)
417
- : successNotification;
474
+ typeof errorNotification === "function"
475
+ ? errorNotification(err, id, identifier)
476
+ : errorNotification;
418
477
 
419
478
  handleNotification(notificationConfig, {
420
479
  key: `${id}-${identifier}-notification`,
421
- description: translate("notifications.success", "Success"),
422
480
  message: translate(
423
- "notifications.deleteSuccess",
481
+ "notifications.deleteError",
424
482
  {
425
- resource: translate(
426
- `${identifier}.${identifier}`,
427
- resourceSingular,
428
- ),
483
+ resource: resourceSingular,
484
+ statusCode: err.statusCode,
429
485
  },
430
- `Successfully deleted a ${resourceSingular}`,
486
+ `Error (status code: ${err.statusCode})`,
431
487
  ),
432
- type: "success",
433
- });
434
-
435
- publish?.({
436
- channel: `resources/${resource.name}`,
437
- type: "deleted",
438
- payload: {
439
- ids: [id],
440
- },
441
- date: new Date(),
442
- meta: {
443
- ...combinedMeta,
444
- dataProviderName,
445
- },
446
- });
447
-
448
- const {
449
- fields: _fields,
450
- operation: _operation,
451
- variables: _variables,
452
- ...rest
453
- } = combinedMeta || {};
454
- log?.mutate({
455
- action: "delete",
456
- resource: resource.name,
457
- meta: {
458
- id,
459
- dataProviderName,
460
- ...rest,
461
- },
488
+ description: err.message,
489
+ type: "error",
462
490
  });
463
-
464
- // Remove the queries from the cache:
465
- queryClient.removeQueries(context?.queryKey.detail(id));
466
- },
467
- onError: (
468
- err: TError,
469
- { id, resource: resourceName, errorNotification },
470
- context,
471
- ) => {
472
- const { identifier } = select(resourceName);
473
-
474
- // set back the queries to the context:
475
- if (context) {
476
- for (const query of context.previousQueries) {
477
- queryClient.setQueryData(query[0], query[1]);
478
- }
479
- }
480
-
481
- if (err.message !== "mutationCancelled") {
482
- checkError(err);
483
-
484
- const resourceSingular =
485
- textTransformers.singular(identifier);
486
-
487
- const notificationConfig =
488
- typeof errorNotification === "function"
489
- ? errorNotification(err, id, identifier)
490
- : errorNotification;
491
-
492
- handleNotification(notificationConfig, {
493
- key: `${id}-${identifier}-notification`,
494
- message: translate(
495
- "notifications.deleteError",
496
- {
497
- resource: resourceSingular,
498
- statusCode: err.statusCode,
499
- },
500
- `Error (status code: ${err.statusCode})`,
501
- ),
502
- description: err.message,
503
- type: "error",
504
- });
505
- }
506
- },
507
- mutationKey: keys().data().mutation("delete").get(preferLegacyKeys),
508
- ...mutationOptions,
509
- meta: {
510
- ...mutationOptions?.meta,
511
- ...getXRay("useDelete", preferLegacyKeys),
512
- },
491
+ }
492
+ },
493
+ mutationKey: keys().data().mutation("delete").get(preferLegacyKeys),
494
+ ...mutationOptions,
495
+ meta: {
496
+ ...mutationOptions?.meta,
497
+ ...getXRay("useDelete", preferLegacyKeys),
513
498
  },
514
- );
499
+ });
515
500
 
516
501
  const { elapsedTime } = useLoadingOvertime({
517
502
  isLoading: mutation.isLoading,