@refinedev/core 4.47.2 → 4.48.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 (409) hide show
  1. package/CHANGELOG.md +2944 -2919
  2. package/dist/components/authenticated/index.d.ts.map +1 -1
  3. package/dist/components/autoSaveIndicator/index.d.ts.map +1 -1
  4. package/dist/components/canAccess/index.d.ts.map +1 -1
  5. package/dist/components/containers/refine/index.d.ts.map +1 -1
  6. package/dist/components/layoutWrapper/index.d.ts.map +1 -1
  7. package/dist/components/pages/auth/components/forgotPassword/index.d.ts.map +1 -1
  8. package/dist/components/pages/auth/components/login/index.d.ts.map +1 -1
  9. package/dist/components/pages/auth/components/register/index.d.ts.map +1 -1
  10. package/dist/components/pages/auth/components/updatePassword/index.d.ts.map +1 -1
  11. package/dist/components/pages/auth/index.d.ts.map +1 -1
  12. package/dist/components/pages/config-error/index.d.ts.map +1 -1
  13. package/dist/components/pages/config-success/index.d.ts.map +1 -1
  14. package/dist/components/pages/login/index.d.ts.map +1 -1
  15. package/dist/components/pages/ready/index.d.ts.map +1 -1
  16. package/dist/components/undoableQueue/index.d.ts.map +1 -1
  17. package/dist/contexts/accessControl/IAccessControlContext.d.ts.map +1 -1
  18. package/dist/contexts/accessControl/index.d.ts.map +1 -1
  19. package/dist/contexts/auditLog/IAuditLogContext.d.ts.map +1 -1
  20. package/dist/contexts/auditLog/index.d.ts.map +1 -1
  21. package/dist/contexts/auth/IAuthContext.d.ts +1 -1
  22. package/dist/contexts/auth/IAuthContext.d.ts.map +1 -1
  23. package/dist/contexts/auth/index.d.ts.map +1 -1
  24. package/dist/contexts/data/IDataContext.d.ts.map +1 -1
  25. package/dist/contexts/data/index.d.ts.map +1 -1
  26. package/dist/contexts/legacy-router/IRouterContext.d.ts.map +1 -1
  27. package/dist/contexts/legacy-router/index.d.ts.map +1 -1
  28. package/dist/contexts/live/ILiveContext.d.ts.map +1 -1
  29. package/dist/contexts/live/index.d.ts.map +1 -1
  30. package/dist/contexts/notification/INotificationContext.d.ts.map +1 -1
  31. package/dist/contexts/notification/index.d.ts.map +1 -1
  32. package/dist/contexts/refine/IRefineContext.d.ts.map +1 -1
  33. package/dist/contexts/refine/index.d.ts.map +1 -1
  34. package/dist/contexts/resource/IResourceContext.d.ts.map +1 -1
  35. package/dist/contexts/resource/index.d.ts.map +1 -1
  36. package/dist/contexts/router/index.d.ts.map +1 -1
  37. package/dist/contexts/translation/ITranslationContext.d.ts.map +1 -1
  38. package/dist/contexts/translation/index.d.ts.map +1 -1
  39. package/dist/contexts/undoableQueue/IUndoableQueueContext.d.ts.map +1 -1
  40. package/dist/contexts/undoableQueue/actionTypes.d.ts.map +1 -1
  41. package/dist/contexts/undoableQueue/index.d.ts.map +1 -1
  42. package/dist/contexts/undoableQueue/undoableQueueContext.d.ts.map +1 -1
  43. package/dist/contexts/unsavedWarn/IUnsavedWarnContext.d.ts.map +1 -1
  44. package/dist/definitions/helpers/check-router-prop-misuse/index.d.ts.map +1 -1
  45. package/dist/definitions/helpers/downloadInBrowser/index.d.ts.map +1 -1
  46. package/dist/definitions/helpers/flatten-object-keys/index.d.ts.map +1 -1
  47. package/dist/definitions/helpers/generateDocumentTitle/index.d.ts.map +1 -1
  48. package/dist/definitions/helpers/handlePaginationParams/index.d.ts.map +1 -1
  49. package/dist/definitions/helpers/handleRefineOptions/index.d.ts.map +1 -1
  50. package/dist/definitions/helpers/hasPermission/index.d.ts.map +1 -1
  51. package/dist/definitions/helpers/importCSVMapper/index.d.ts.map +1 -1
  52. package/dist/definitions/helpers/index.d.ts.map +1 -1
  53. package/dist/definitions/helpers/keys/index.d.ts +0 -11
  54. package/dist/definitions/helpers/keys/index.d.ts.map +1 -1
  55. package/dist/definitions/helpers/legacy-resource-transform/index.d.ts.map +1 -1
  56. package/dist/definitions/helpers/menu/create-resource-key.d.ts.map +1 -1
  57. package/dist/definitions/helpers/menu/create-tree.d.ts.map +1 -1
  58. package/dist/definitions/helpers/pick-resource/index.d.ts.map +1 -1
  59. package/dist/definitions/helpers/pickDataProvider/index.d.ts.map +1 -1
  60. package/dist/definitions/helpers/queryKeys/index.d.ts.map +1 -1
  61. package/dist/definitions/helpers/redirectPage/index.d.ts.map +1 -1
  62. package/dist/definitions/helpers/routeGenerator/index.d.ts.map +1 -1
  63. package/dist/definitions/helpers/router/compose-route.d.ts.map +1 -1
  64. package/dist/definitions/helpers/router/get-action-routes-from-resource.d.ts.map +1 -1
  65. package/dist/definitions/helpers/router/get-default-action-path.d.ts.map +1 -1
  66. package/dist/definitions/helpers/router/get-parent-prefix-for-resource.d.ts.map +1 -1
  67. package/dist/definitions/helpers/router/get-parent-resource.d.ts.map +1 -1
  68. package/dist/definitions/helpers/router/match-resource-from-route.d.ts.map +1 -1
  69. package/dist/definitions/helpers/router/pick-matched-route.d.ts.map +1 -1
  70. package/dist/definitions/helpers/router/prepare-route-params.d.ts.map +1 -1
  71. package/dist/definitions/helpers/safe-translate/index.d.ts.map +1 -1
  72. package/dist/definitions/helpers/sanitize-resource/index.d.ts.map +1 -1
  73. package/dist/definitions/helpers/sequentialPromises/index.d.ts.map +1 -1
  74. package/dist/definitions/helpers/treeView/createTreeView/index.d.ts.map +1 -1
  75. package/dist/definitions/helpers/useActiveAuthProvider/index.d.ts +2 -2
  76. package/dist/definitions/helpers/useUserFriendlyName/index.d.ts.map +1 -1
  77. package/dist/definitions/helpers/userFriendlyResourceName/index.d.ts.map +1 -1
  78. package/dist/definitions/table/index.d.ts.map +1 -1
  79. package/dist/esm/index.js +18 -18
  80. package/dist/esm/index.js.map +1 -1
  81. package/dist/hooks/accessControl/useCan/index.d.ts.map +1 -1
  82. package/dist/hooks/accessControl/useCanWithoutCache.d.ts.map +1 -1
  83. package/dist/hooks/auditLog/useLog/index.d.ts.map +1 -1
  84. package/dist/hooks/auditLog/useLogList/index.d.ts.map +1 -1
  85. package/dist/hooks/auth/useForgotPassword/index.d.ts.map +1 -1
  86. package/dist/hooks/auth/useGetIdentity/index.d.ts.map +1 -1
  87. package/dist/hooks/auth/useIsAuthenticated/index.d.ts.map +1 -1
  88. package/dist/hooks/auth/useLogin/index.d.ts.map +1 -1
  89. package/dist/hooks/auth/useLogout/index.d.ts.map +1 -1
  90. package/dist/hooks/auth/useOnError/index.d.ts.map +1 -1
  91. package/dist/hooks/auth/usePermissions/index.d.ts +9 -6
  92. package/dist/hooks/auth/usePermissions/index.d.ts.map +1 -1
  93. package/dist/hooks/auth/useRegister/index.d.ts.map +1 -1
  94. package/dist/hooks/auth/useUpdatePassword/index.d.ts.map +1 -1
  95. package/dist/hooks/breadcrumb/index.d.ts.map +1 -1
  96. package/dist/hooks/data/useApiUrl.d.ts.map +1 -1
  97. package/dist/hooks/data/useCreate.d.ts.map +1 -1
  98. package/dist/hooks/data/useCreateMany.d.ts.map +1 -1
  99. package/dist/hooks/data/useCustom.d.ts.map +1 -1
  100. package/dist/hooks/data/useCustomMutation.d.ts.map +1 -1
  101. package/dist/hooks/data/useDataProvider.d.ts.map +1 -1
  102. package/dist/hooks/data/useDelete.d.ts.map +1 -1
  103. package/dist/hooks/data/useDeleteMany.d.ts.map +1 -1
  104. package/dist/hooks/data/useInfiniteList.d.ts.map +1 -1
  105. package/dist/hooks/data/useList.d.ts.map +1 -1
  106. package/dist/hooks/data/useMany.d.ts.map +1 -1
  107. package/dist/hooks/data/useOne.d.ts.map +1 -1
  108. package/dist/hooks/data/useUpdate.d.ts.map +1 -1
  109. package/dist/hooks/data/useUpdateMany.d.ts.map +1 -1
  110. package/dist/hooks/export/csvDownload.interface.d.ts.map +1 -1
  111. package/dist/hooks/export/index.d.ts +1 -1
  112. package/dist/hooks/export/index.d.ts.map +1 -1
  113. package/dist/hooks/form/useForm.d.ts.map +1 -1
  114. package/dist/hooks/import/index.d.ts.map +1 -1
  115. package/dist/hooks/invalidate/index.d.ts.map +1 -1
  116. package/dist/hooks/live/useLiveMode/index.d.ts.map +1 -1
  117. package/dist/hooks/live/useResourceSubscription/index.d.ts.map +1 -1
  118. package/dist/hooks/live/useSubscription/index.d.ts.map +1 -1
  119. package/dist/hooks/menu/useMenu.d.ts.map +1 -1
  120. package/dist/hooks/modal/useModal/index.d.ts.map +1 -1
  121. package/dist/hooks/navigation/index.d.ts.map +1 -1
  122. package/dist/hooks/notification/useCancelNotification/index.d.ts.map +1 -1
  123. package/dist/hooks/notification/useHandleNotification/index.d.ts.map +1 -1
  124. package/dist/hooks/redirection/index.d.ts.map +1 -1
  125. package/dist/hooks/refine/useMutationMode.d.ts.map +1 -1
  126. package/dist/hooks/refine/useSyncWithLocation.d.ts.map +1 -1
  127. package/dist/hooks/refine/useWarnAboutChange/index.d.ts.map +1 -1
  128. package/dist/hooks/resource/useResource/index.d.ts.map +1 -1
  129. package/dist/hooks/router/use-get-to-path/index.d.ts.map +1 -1
  130. package/dist/hooks/router/use-go/index.d.ts.map +1 -1
  131. package/dist/hooks/router/use-link/index.d.ts.map +1 -1
  132. package/dist/hooks/router/use-parse/index.d.ts.map +1 -1
  133. package/dist/hooks/router/use-to-path/index.d.ts.map +1 -1
  134. package/dist/hooks/show/useShow.d.ts.map +1 -1
  135. package/dist/hooks/translate/useSetLocale.d.ts.map +1 -1
  136. package/dist/hooks/translate/useTranslate.d.ts.map +1 -1
  137. package/dist/hooks/useLoadingOvertime/index.d.ts.map +1 -1
  138. package/dist/hooks/useSelect/index.d.ts +18 -4
  139. package/dist/hooks/useSelect/index.d.ts.map +1 -1
  140. package/dist/hooks/useTable/index.d.ts.map +1 -1
  141. package/dist/iife/index.js +18 -18
  142. package/dist/iife/index.js.map +1 -1
  143. package/dist/index.d.ts.map +1 -1
  144. package/dist/index.js +18 -18
  145. package/dist/index.js.map +1 -1
  146. package/dist/interfaces/actions.d.ts.map +1 -1
  147. package/dist/interfaces/auditLog/logData.d.ts.map +1 -1
  148. package/dist/interfaces/auth.d.ts.map +1 -1
  149. package/dist/interfaces/autoSave.d.ts.map +1 -1
  150. package/dist/interfaces/bindings/access-control.d.ts.map +1 -1
  151. package/dist/interfaces/bindings/auth.d.ts +1 -1
  152. package/dist/interfaces/bindings/auth.d.ts.map +1 -1
  153. package/dist/interfaces/bindings/data.d.ts.map +1 -1
  154. package/dist/interfaces/bindings/i18n.d.ts.map +1 -1
  155. package/dist/interfaces/bindings/index.d.ts.map +1 -1
  156. package/dist/interfaces/bindings/live.d.ts.map +1 -1
  157. package/dist/interfaces/bindings/notifications.d.ts.map +1 -1
  158. package/dist/interfaces/bindings/resource.d.ts.map +1 -1
  159. package/dist/interfaces/bindings/router.d.ts.map +1 -1
  160. package/dist/interfaces/customComponents.d.ts.map +1 -1
  161. package/dist/interfaces/errors/HttpError.d.ts.map +1 -1
  162. package/dist/interfaces/form-url-params.d.ts.map +1 -1
  163. package/dist/interfaces/index.d.ts.map +1 -1
  164. package/dist/interfaces/live/LiveEvent.d.ts.map +1 -1
  165. package/dist/interfaces/live/LiveModeProps.d.ts.map +1 -1
  166. package/dist/interfaces/mapDataFn.d.ts.map +1 -1
  167. package/dist/interfaces/metaData/graphqlQueryOptions.d.ts.map +1 -1
  168. package/dist/interfaces/metaData/metaDataQuery.d.ts.map +1 -1
  169. package/dist/interfaces/metaData/metaQuery.d.ts.map +1 -1
  170. package/dist/interfaces/metaData/nestedField.d.ts.map +1 -1
  171. package/dist/interfaces/metaData/queryBuilderOptions.d.ts.map +1 -1
  172. package/dist/interfaces/metaData/variableOptions.d.ts.map +1 -1
  173. package/dist/interfaces/mutationMode.d.ts.map +1 -1
  174. package/dist/interfaces/notification.d.ts.map +1 -1
  175. package/dist/interfaces/optimistic-update-map.d.ts.map +1 -1
  176. package/dist/interfaces/prettify.d.ts.map +1 -1
  177. package/dist/interfaces/queryKey.d.ts.map +1 -1
  178. package/dist/interfaces/resourceErrorRouterParams.d.ts.map +1 -1
  179. package/dist/interfaces/resourceRouterParams.d.ts.map +1 -1
  180. package/dist/interfaces/successErrorNotification.d.ts +4 -4
  181. package/dist/interfaces/successErrorNotification.d.ts.map +1 -1
  182. package/dist/interfaces/telemetry.d.ts.map +1 -1
  183. package/dist/interfaces/textTransformers.d.ts.map +1 -1
  184. package/package.json +2 -2
  185. package/refine.config.js +99 -102
  186. package/src/components/authenticated/index.tsx +157 -159
  187. package/src/components/autoSaveIndicator/index.tsx +23 -27
  188. package/src/components/canAccess/index.tsx +93 -93
  189. package/src/components/containers/refine/index.tsx +312 -353
  190. package/src/components/gh-banner/index.tsx +235 -242
  191. package/src/components/gh-banner/styles.ts +5 -5
  192. package/src/components/layoutWrapper/defaultLayout/index.tsx +1 -1
  193. package/src/components/layoutWrapper/index.tsx +87 -87
  194. package/src/components/pages/auth/components/forgotPassword/index.tsx +87 -96
  195. package/src/components/pages/auth/components/login/index.tsx +166 -181
  196. package/src/components/pages/auth/components/register/index.tsx +141 -159
  197. package/src/components/pages/auth/components/updatePassword/index.tsx +81 -87
  198. package/src/components/pages/auth/index.tsx +28 -28
  199. package/src/components/pages/config-error/index.tsx +422 -422
  200. package/src/components/pages/config-success/index.tsx +249 -260
  201. package/src/components/pages/error/index.tsx +48 -48
  202. package/src/components/pages/login/index.tsx +59 -73
  203. package/src/components/pages/ready/index.tsx +21 -29
  204. package/src/components/pages/welcome/index.tsx +7 -7
  205. package/src/components/routeChangeHandler/index.tsx +7 -7
  206. package/src/components/telemetry/index.tsx +31 -31
  207. package/src/components/undoableQueue/index.tsx +49 -49
  208. package/src/contexts/accessControl/IAccessControlContext.ts +34 -34
  209. package/src/contexts/accessControl/index.tsx +35 -35
  210. package/src/contexts/auditLog/IAuditLogContext.ts +22 -22
  211. package/src/contexts/auditLog/index.tsx +8 -8
  212. package/src/contexts/auth/IAuthContext.ts +10 -10
  213. package/src/contexts/auth/index.tsx +169 -169
  214. package/src/contexts/data/IDataContext.ts +203 -203
  215. package/src/contexts/data/index.tsx +18 -18
  216. package/src/contexts/legacy-router/IRouterContext.ts +23 -27
  217. package/src/contexts/legacy-router/index.tsx +30 -30
  218. package/src/contexts/live/ILiveContext.ts +49 -49
  219. package/src/contexts/live/index.tsx +5 -7
  220. package/src/contexts/notification/INotificationContext.ts +8 -8
  221. package/src/contexts/notification/index.tsx +8 -8
  222. package/src/contexts/refine/IRefineContext.ts +119 -119
  223. package/src/contexts/refine/index.tsx +80 -80
  224. package/src/contexts/resource/IResourceContext.ts +35 -35
  225. package/src/contexts/resource/index.tsx +16 -16
  226. package/src/contexts/router/index.tsx +7 -7
  227. package/src/contexts/router-picker/index.tsx +2 -2
  228. package/src/contexts/translation/ITranslationContext.ts +7 -7
  229. package/src/contexts/translation/index.tsx +12 -12
  230. package/src/contexts/undoableQueue/IUndoableQueueContext.ts +2 -2
  231. package/src/contexts/undoableQueue/actionTypes.ts +3 -3
  232. package/src/contexts/undoableQueue/index.ts +2 -2
  233. package/src/contexts/undoableQueue/undoableQueueContext.tsx +59 -60
  234. package/src/contexts/unsavedWarn/IUnsavedWarnContext.ts +2 -2
  235. package/src/contexts/unsavedWarn/index.tsx +7 -7
  236. package/src/definitions/helpers/check-router-prop-misuse/index.ts +20 -20
  237. package/src/definitions/helpers/downloadInBrowser/index.ts +19 -20
  238. package/src/definitions/helpers/flatten-object-keys/index.ts +26 -29
  239. package/src/definitions/helpers/generateDocumentTitle/index.ts +39 -45
  240. package/src/definitions/helpers/handleMultiple/index.ts +4 -4
  241. package/src/definitions/helpers/handlePaginationParams/index.ts +17 -18
  242. package/src/definitions/helpers/handleRefineOptions/index.ts +88 -90
  243. package/src/definitions/helpers/handleUseParams/index.tsx +7 -7
  244. package/src/definitions/helpers/hasPermission/index.ts +6 -6
  245. package/src/definitions/helpers/humanizeString/index.ts +9 -9
  246. package/src/definitions/helpers/importCSVMapper/index.ts +8 -8
  247. package/src/definitions/helpers/index.ts +2 -2
  248. package/src/definitions/helpers/keys/index.ts +205 -258
  249. package/src/definitions/helpers/legacy-resource-transform/index.ts +14 -14
  250. package/src/definitions/helpers/menu/create-resource-key.ts +20 -23
  251. package/src/definitions/helpers/menu/create-tree.ts +61 -63
  252. package/src/definitions/helpers/pick-resource/index.ts +25 -25
  253. package/src/definitions/helpers/pickDataProvider/index.ts +15 -15
  254. package/src/definitions/helpers/pickNotDeprecated/index.ts +2 -2
  255. package/src/definitions/helpers/property-path-to-array/index.ts +3 -3
  256. package/src/definitions/helpers/queryKeys/index.ts +92 -92
  257. package/src/definitions/helpers/redirectPage/index.ts +19 -19
  258. package/src/definitions/helpers/routeGenerator/index.ts +15 -15
  259. package/src/definitions/helpers/router/__tests__/check-by-segments.ts +12 -15
  260. package/src/definitions/helpers/router/__tests__/compose-route.ts +48 -48
  261. package/src/definitions/helpers/router/__tests__/get-action-routes-from-resource.ts +152 -152
  262. package/src/definitions/helpers/router/__tests__/get-default-action-path.ts +39 -41
  263. package/src/definitions/helpers/router/__tests__/get-parent-prefix-for-resource.ts +69 -73
  264. package/src/definitions/helpers/router/__tests__/get-parent-resource.ts +40 -40
  265. package/src/definitions/helpers/router/__tests__/is-segment-counts-same.ts +11 -14
  266. package/src/definitions/helpers/router/__tests__/match-resource-from-route.ts +55 -55
  267. package/src/definitions/helpers/router/__tests__/pick-matched-route.ts +74 -74
  268. package/src/definitions/helpers/router/__tests__/pick-route-params.ts +12 -12
  269. package/src/definitions/helpers/router/__tests__/prepare-route-params.ts +18 -18
  270. package/src/definitions/helpers/router/__tests__/remove-leading-trailing-slashes.ts +9 -9
  271. package/src/definitions/helpers/router/__tests__/split-to-segments.ts +9 -9
  272. package/src/definitions/helpers/router/check-by-segments.ts +12 -12
  273. package/src/definitions/helpers/router/compose-route.ts +25 -27
  274. package/src/definitions/helpers/router/get-action-routes-from-resource.ts +41 -47
  275. package/src/definitions/helpers/router/get-default-action-path.ts +19 -19
  276. package/src/definitions/helpers/router/get-parent-prefix-for-resource.ts +22 -24
  277. package/src/definitions/helpers/router/get-parent-resource.ts +18 -18
  278. package/src/definitions/helpers/router/is-parameter.ts +1 -1
  279. package/src/definitions/helpers/router/is-segment-counts-same.ts +3 -3
  280. package/src/definitions/helpers/router/match-resource-from-route.ts +19 -19
  281. package/src/definitions/helpers/router/pick-matched-route.ts +44 -44
  282. package/src/definitions/helpers/router/pick-route-params.ts +7 -7
  283. package/src/definitions/helpers/router/prepare-route-params.ts +13 -10
  284. package/src/definitions/helpers/router/remove-leading-trailing-slashes.ts +1 -1
  285. package/src/definitions/helpers/router/split-to-segments.ts +2 -2
  286. package/src/definitions/helpers/safe-translate/index.ts +12 -12
  287. package/src/definitions/helpers/sanitize-resource/index.ts +26 -27
  288. package/src/definitions/helpers/sequentialPromises/index.ts +21 -21
  289. package/src/definitions/helpers/treeView/createTreeView/index.ts +33 -33
  290. package/src/definitions/helpers/useActiveAuthProvider/index.ts +18 -18
  291. package/src/definitions/helpers/useInfinitePagination/index.ts +16 -16
  292. package/src/definitions/helpers/useMediaQuery/index.ts +11 -11
  293. package/src/definitions/helpers/useUserFriendlyName/index.ts +11 -14
  294. package/src/definitions/helpers/userFriendlyResourceName/index.ts +7 -7
  295. package/src/definitions/helpers/userFriendlySeconds/index.ts +1 -1
  296. package/src/definitions/table/index.ts +127 -130
  297. package/src/definitions/upload/file2Base64/index.ts +15 -15
  298. package/src/hooks/accessControl/useCan/index.ts +52 -54
  299. package/src/hooks/accessControl/useCanWithoutCache.ts +25 -26
  300. package/src/hooks/auditLog/useLog/index.ts +114 -114
  301. package/src/hooks/auditLog/useLogList/index.ts +44 -44
  302. package/src/hooks/auth/useForgotPassword/index.ts +158 -163
  303. package/src/hooks/auth/useGetIdentity/index.ts +55 -57
  304. package/src/hooks/auth/useInvalidateAuthStore/index.ts +12 -12
  305. package/src/hooks/auth/useIsAuthenticated/index.ts +44 -48
  306. package/src/hooks/auth/useIsExistAuthentication/index.ts +3 -3
  307. package/src/hooks/auth/useLogin/index.ts +181 -194
  308. package/src/hooks/auth/useLogout/index.ts +175 -177
  309. package/src/hooks/auth/useOnError/index.ts +76 -76
  310. package/src/hooks/auth/usePermissions/index.ts +94 -61
  311. package/src/hooks/auth/useRegister/index.ts +166 -178
  312. package/src/hooks/auth/useUpdatePassword/index.ts +183 -194
  313. package/src/hooks/breadcrumb/index.ts +99 -106
  314. package/src/hooks/data/useApiUrl.ts +7 -8
  315. package/src/hooks/data/useCreate.ts +241 -241
  316. package/src/hooks/data/useCreateMany.ts +219 -226
  317. package/src/hooks/data/useCustom.ts +181 -182
  318. package/src/hooks/data/useCustomMutation.ts +174 -174
  319. package/src/hooks/data/useDataProvider.tsx +27 -29
  320. package/src/hooks/data/useDelete.ts +447 -454
  321. package/src/hooks/data/useDeleteMany.ts +475 -484
  322. package/src/hooks/data/useInfiniteList.ts +280 -280
  323. package/src/hooks/data/useList.ts +280 -283
  324. package/src/hooks/data/useMany.ts +215 -216
  325. package/src/hooks/data/useOne.ts +210 -211
  326. package/src/hooks/data/useUpdate.ts +529 -556
  327. package/src/hooks/data/useUpdateMany.ts +556 -584
  328. package/src/hooks/deepMemo/index.tsx +5 -5
  329. package/src/hooks/export/csvDownload.interface.ts +13 -13
  330. package/src/hooks/export/index.ts +223 -217
  331. package/src/hooks/form/useForm.ts +543 -560
  332. package/src/hooks/import/index.tsx +254 -260
  333. package/src/hooks/invalidate/index.tsx +75 -75
  334. package/src/hooks/legacy-router/useRouterContext.ts +11 -11
  335. package/src/hooks/live/useLiveMode/index.ts +4 -4
  336. package/src/hooks/live/usePublish/index.ts +2 -2
  337. package/src/hooks/live/useResourceSubscription/index.ts +103 -103
  338. package/src/hooks/live/useSubscription/index.ts +77 -77
  339. package/src/hooks/memoized/index.tsx +6 -6
  340. package/src/hooks/menu/useMenu.tsx +113 -120
  341. package/src/hooks/modal/useModal/index.tsx +16 -16
  342. package/src/hooks/navigation/index.ts +362 -392
  343. package/src/hooks/notification/useCancelNotification/index.tsx +5 -5
  344. package/src/hooks/notification/useHandleNotification/index.ts +17 -17
  345. package/src/hooks/notification/useNotification/index.ts +2 -2
  346. package/src/hooks/redirection/index.ts +45 -46
  347. package/src/hooks/refine/useMutationMode.ts +4 -4
  348. package/src/hooks/refine/useRefineContext.ts +36 -36
  349. package/src/hooks/refine/useSyncWithLocation.ts +3 -3
  350. package/src/hooks/refine/useTitle.tsx +2 -2
  351. package/src/hooks/refine/useWarnAboutChange/index.ts +12 -12
  352. package/src/hooks/resource/useResource/index.ts +141 -146
  353. package/src/hooks/resource/useResourceWithRoute/index.ts +12 -12
  354. package/src/hooks/router/use-back/index.tsx +7 -7
  355. package/src/hooks/router/use-get-to-path/index.ts +35 -35
  356. package/src/hooks/router/use-go/index.tsx +66 -66
  357. package/src/hooks/router/use-link/index.tsx +8 -9
  358. package/src/hooks/router/use-parse/index.tsx +13 -13
  359. package/src/hooks/router/use-parsed/index.tsx +4 -4
  360. package/src/hooks/router/use-router-misuse-warning/index.ts +10 -10
  361. package/src/hooks/router/use-to-path/index.ts +10 -10
  362. package/src/hooks/show/useShow.ts +135 -135
  363. package/src/hooks/translate/useGetLocale.ts +2 -2
  364. package/src/hooks/translate/useSetLocale.ts +2 -2
  365. package/src/hooks/translate/useTranslate.ts +24 -25
  366. package/src/hooks/useKeys/index.tsx +7 -7
  367. package/src/hooks/useLoadingOvertime/index.ts +74 -76
  368. package/src/hooks/useMeta/index.ts +20 -20
  369. package/src/hooks/useSelect/index.ts +317 -277
  370. package/src/hooks/useTable/index.ts +483 -507
  371. package/src/hooks/useTelemetryData/index.ts +48 -48
  372. package/src/index.tsx +125 -125
  373. package/src/interfaces/actions.ts +2 -2
  374. package/src/interfaces/auditLog/logData.ts +9 -9
  375. package/src/interfaces/auth.tsx +176 -176
  376. package/src/interfaces/autoSave.ts +37 -37
  377. package/src/interfaces/bindings/access-control.ts +21 -21
  378. package/src/interfaces/bindings/auth.ts +27 -25
  379. package/src/interfaces/bindings/data.ts +2 -2
  380. package/src/interfaces/bindings/i18n.ts +8 -8
  381. package/src/interfaces/bindings/index.ts +15 -15
  382. package/src/interfaces/bindings/live.ts +28 -28
  383. package/src/interfaces/bindings/notifications.ts +8 -8
  384. package/src/interfaces/bindings/resource.ts +127 -127
  385. package/src/interfaces/bindings/router.ts +26 -26
  386. package/src/interfaces/customComponents.ts +17 -17
  387. package/src/interfaces/errors/HttpError.ts +8 -8
  388. package/src/interfaces/form-url-params.ts +6 -6
  389. package/src/interfaces/index.ts +8 -10
  390. package/src/interfaces/live/LiveEvent.ts +10 -10
  391. package/src/interfaces/live/LiveModeProps.ts +21 -21
  392. package/src/interfaces/mapDataFn.ts +1 -1
  393. package/src/interfaces/metaData/graphqlQueryOptions.ts +49 -49
  394. package/src/interfaces/metaData/metaDataQuery.ts +2 -2
  395. package/src/interfaces/metaData/metaQuery.ts +3 -3
  396. package/src/interfaces/metaData/nestedField.ts +3 -3
  397. package/src/interfaces/metaData/queryBuilderOptions.ts +3 -3
  398. package/src/interfaces/metaData/variableOptions.ts +8 -8
  399. package/src/interfaces/mutationMode.ts +14 -14
  400. package/src/interfaces/notification.ts +7 -7
  401. package/src/interfaces/optimistic-update-map.ts +42 -42
  402. package/src/interfaces/prettify.ts +1 -1
  403. package/src/interfaces/queryKey.ts +16 -16
  404. package/src/interfaces/resourceErrorRouterParams.ts +2 -2
  405. package/src/interfaces/resourceRouterParams.ts +3 -3
  406. package/src/interfaces/successErrorNotification.ts +24 -24
  407. package/src/interfaces/telemetry.ts +13 -13
  408. package/src/interfaces/textTransformers.ts +18 -18
  409. package/tsconfig.json +26 -26
@@ -4,223 +4,223 @@ import warnOnce from "warn-once";
4
4
  import debounce from "lodash/debounce";
5
5
 
6
6
  import {
7
- useWarnAboutChange,
8
- useCreate,
9
- useUpdate,
10
- useRedirectionAfterSubmission,
11
- useMutationMode,
12
- useOne,
13
- useRefineContext,
14
- useMeta,
15
- useInvalidate,
7
+ useWarnAboutChange,
8
+ useCreate,
9
+ useUpdate,
10
+ useRedirectionAfterSubmission,
11
+ useMutationMode,
12
+ useOne,
13
+ useRefineContext,
14
+ useMeta,
15
+ useInvalidate,
16
16
  } from "@hooks";
17
17
 
18
18
  import {
19
- BaseRecord,
20
- CreateResponse,
21
- GetOneResponse,
22
- HttpError,
23
- LiveModeProps,
24
- RedirectAction,
25
- SuccessErrorNotification,
26
- UpdateResponse,
27
- MutationMode,
28
- BaseKey,
29
- IQueryKeys,
30
- FormAction,
31
- MetaQuery,
32
- AutoSaveProps,
33
- AutoSaveReturnType,
34
- OptimisticUpdateMapType,
19
+ BaseRecord,
20
+ CreateResponse,
21
+ GetOneResponse,
22
+ HttpError,
23
+ LiveModeProps,
24
+ RedirectAction,
25
+ SuccessErrorNotification,
26
+ UpdateResponse,
27
+ MutationMode,
28
+ BaseKey,
29
+ IQueryKeys,
30
+ FormAction,
31
+ MetaQuery,
32
+ AutoSaveProps,
33
+ AutoSaveReturnType,
34
+ OptimisticUpdateMapType,
35
35
  } from "../../interfaces";
36
36
  import {
37
- UpdateParams,
38
- UseUpdateProps,
39
- UseUpdateReturnType,
37
+ UpdateParams,
38
+ UseUpdateProps,
39
+ UseUpdateReturnType,
40
40
  } from "../data/useUpdate";
41
41
  import { UseCreateProps, UseCreateReturnType } from "../data/useCreate";
42
42
  import { redirectPage } from "@definitions/helpers";
43
43
  import { useResource } from "../resource/useResource";
44
44
  import { pickNotDeprecated } from "@definitions/helpers";
45
45
  import {
46
- useLoadingOvertime,
47
- UseLoadingOvertimeOptionsProps,
48
- UseLoadingOvertimeReturnType,
46
+ useLoadingOvertime,
47
+ UseLoadingOvertimeOptionsProps,
48
+ UseLoadingOvertimeReturnType,
49
49
  } from "../useLoadingOvertime";
50
50
 
51
51
  export type ActionParams = {
52
- /**
53
- * Type of the form mode
54
- * @default Action that it reads from route otherwise "create" is used
55
- */
56
- action?: FormAction;
52
+ /**
53
+ * Type of the form mode
54
+ * @default Action that it reads from route otherwise "create" is used
55
+ */
56
+ action?: FormAction;
57
57
  };
58
58
 
59
59
  type ActionFormProps<
60
- TQueryFnData extends BaseRecord = BaseRecord,
61
- TError extends HttpError = HttpError,
62
- TVariables = {},
63
- TData extends BaseRecord = TQueryFnData,
64
- TResponse extends BaseRecord = TData,
65
- TResponseError extends HttpError = TError,
60
+ TQueryFnData extends BaseRecord = BaseRecord,
61
+ TError extends HttpError = HttpError,
62
+ TVariables = {},
63
+ TData extends BaseRecord = TQueryFnData,
64
+ TResponse extends BaseRecord = TData,
65
+ TResponseError extends HttpError = TError,
66
66
  > = {
67
- /**
68
- * Resource name for API data interactions
69
- * @default Resource name that it reads from route
70
- */
71
- resource?: string;
72
- /**
73
- * Record id for fetching
74
- * @default Id that it reads from the URL
75
- */
76
- id?: BaseKey;
77
- /**
78
- * Page to redirect after a succesfull mutation
79
- * @type `"show" | "edit" | "list" | "create" | false`
80
- * @default `"list"`
81
- */
82
- redirect?: RedirectAction;
83
- /**
84
- * Metadata query for dataProvider
85
- */
86
- meta?: MetaQuery;
87
- /**
88
- * Metadata query for dataProvider
89
- * @deprecated `metaData` is deprecated with refine@4, refine will pass `meta` instead, however, we still support `metaData` for backward compatibility.
90
- */
91
- metaData?: MetaQuery;
92
- /**
93
- * Metadata to pass for the `useOne` query
94
- */
95
- queryMeta?: MetaQuery;
96
- /**
97
- * Metadata to pass for the mutation (`useCreate` for `create` and `clone` actions, `useUpdate` for `edit` action)
98
- */
99
- mutationMeta?: MetaQuery;
100
- /**
101
- * [Determines when mutations are executed](/advanced-tutorials/mutation-mode.md)
102
- * @default `"pessimistic"*`
103
- */
104
- mutationMode?: MutationMode;
105
- /**
106
- * Called when a mutation is successful
107
- */
108
- onMutationSuccess?: (
109
- data: CreateResponse<TResponse> | UpdateResponse<TResponse>,
110
- variables: TVariables,
111
- context: any,
112
- isAutoSave?: boolean,
113
- ) => void;
114
- /**
115
- * Called when a mutation encounters an error
116
- */
117
- onMutationError?: (
118
- error: TResponseError,
119
- variables: TVariables,
120
- context: any,
121
- isAutoSave?: boolean,
122
- ) => void;
123
- /**
124
- * Duration to wait before executing mutations when `mutationMode = "undoable"`
125
- * @default `5000*`
126
- */
127
- undoableTimeout?: number;
128
- /**
129
- * If there is more than one `dataProvider`, you should use the `dataProviderName` that you will use.
130
- */
131
- dataProviderName?: string;
132
- /**
133
- * You can use it to manage the invalidations that will occur at the end of the mutation.
134
- * @type `all`, `resourceAll`, `list`, `many`, `detail`, `false`
135
- * @default `["list", "many", "detail"]`
136
- */
137
- invalidates?: Array<keyof IQueryKeys>;
138
- /**
139
- * react-query's [useQuery](https://tanstack.com/query/v4/docs/reference/useQuery) options of useOne hook used while in edit mode.
140
- */
141
- queryOptions?: UseQueryOptions<
142
- GetOneResponse<TQueryFnData>,
143
- TError,
144
- GetOneResponse<TData>
145
- >;
146
- /**
147
- * react-query's [useMutation](https://tanstack.com/query/v4/docs/reference/useMutation) options of useCreate hook used while submitting in create and clone modes.
148
- */
149
- createMutationOptions?: UseCreateProps<
150
- TResponse,
151
- TResponseError,
152
- TVariables
153
- >["mutationOptions"];
154
- /**
155
- * react-query's [useMutation](https://tanstack.com/query/v4/docs/reference/useMutation) options of useUpdate hook used while submitting in edit mode.
156
- */
157
- updateMutationOptions?: UseUpdateProps<
158
- TResponse,
159
- TResponseError,
160
- TVariables
161
- >["mutationOptions"];
162
- /**
163
- * If you customize the [`optimisticUpdateMap`](https://refine.dev/docs/api-reference/core/hooks/data/useUpdateMany/#optimisticupdatemap) option, you can use it to manage the invalidations that will occur at the end of the mutation.
164
- * @default {
165
- * list: true,
166
- * many: true,
167
- * detail: true,
168
- * }
169
- */
170
- optimisticUpdateMap?: OptimisticUpdateMapType<TResponse, TVariables>;
171
- } & SuccessErrorNotification<
172
- UpdateResponse<TResponse> | CreateResponse<TResponse>,
67
+ /**
68
+ * Resource name for API data interactions
69
+ * @default Resource name that it reads from route
70
+ */
71
+ resource?: string;
72
+ /**
73
+ * Record id for fetching
74
+ * @default Id that it reads from the URL
75
+ */
76
+ id?: BaseKey;
77
+ /**
78
+ * Page to redirect after a succesfull mutation
79
+ * @type `"show" | "edit" | "list" | "create" | false`
80
+ * @default `"list"`
81
+ */
82
+ redirect?: RedirectAction;
83
+ /**
84
+ * Metadata query for dataProvider
85
+ */
86
+ meta?: MetaQuery;
87
+ /**
88
+ * Metadata query for dataProvider
89
+ * @deprecated `metaData` is deprecated with refine@4, refine will pass `meta` instead, however, we still support `metaData` for backward compatibility.
90
+ */
91
+ metaData?: MetaQuery;
92
+ /**
93
+ * Metadata to pass for the `useOne` query
94
+ */
95
+ queryMeta?: MetaQuery;
96
+ /**
97
+ * Metadata to pass for the mutation (`useCreate` for `create` and `clone` actions, `useUpdate` for `edit` action)
98
+ */
99
+ mutationMeta?: MetaQuery;
100
+ /**
101
+ * [Determines when mutations are executed](/advanced-tutorials/mutation-mode.md)
102
+ * @default `"pessimistic"*`
103
+ */
104
+ mutationMode?: MutationMode;
105
+ /**
106
+ * Called when a mutation is successful
107
+ */
108
+ onMutationSuccess?: (
109
+ data: CreateResponse<TResponse> | UpdateResponse<TResponse>,
110
+ variables: TVariables,
111
+ context: any,
112
+ isAutoSave?: boolean,
113
+ ) => void;
114
+ /**
115
+ * Called when a mutation encounters an error
116
+ */
117
+ onMutationError?: (
118
+ error: TResponseError,
119
+ variables: TVariables,
120
+ context: any,
121
+ isAutoSave?: boolean,
122
+ ) => void;
123
+ /**
124
+ * Duration to wait before executing mutations when `mutationMode = "undoable"`
125
+ * @default `5000*`
126
+ */
127
+ undoableTimeout?: number;
128
+ /**
129
+ * If there is more than one `dataProvider`, you should use the `dataProviderName` that you will use.
130
+ */
131
+ dataProviderName?: string;
132
+ /**
133
+ * You can use it to manage the invalidations that will occur at the end of the mutation.
134
+ * @type `all`, `resourceAll`, `list`, `many`, `detail`, `false`
135
+ * @default `["list", "many", "detail"]`
136
+ */
137
+ invalidates?: Array<keyof IQueryKeys>;
138
+ /**
139
+ * react-query's [useQuery](https://tanstack.com/query/v4/docs/reference/useQuery) options of useOne hook used while in edit mode.
140
+ */
141
+ queryOptions?: UseQueryOptions<
142
+ GetOneResponse<TQueryFnData>,
143
+ TError,
144
+ GetOneResponse<TData>
145
+ >;
146
+ /**
147
+ * react-query's [useMutation](https://tanstack.com/query/v4/docs/reference/useMutation) options of useCreate hook used while submitting in create and clone modes.
148
+ */
149
+ createMutationOptions?: UseCreateProps<
150
+ TResponse,
151
+ TResponseError,
152
+ TVariables
153
+ >["mutationOptions"];
154
+ /**
155
+ * react-query's [useMutation](https://tanstack.com/query/v4/docs/reference/useMutation) options of useUpdate hook used while submitting in edit mode.
156
+ */
157
+ updateMutationOptions?: UseUpdateProps<
158
+ TResponse,
173
159
  TResponseError,
174
- { id: BaseKey; values: TVariables } | TVariables
160
+ TVariables
161
+ >["mutationOptions"];
162
+ /**
163
+ * If you customize the [`optimisticUpdateMap`](https://refine.dev/docs/api-reference/core/hooks/data/useUpdateMany/#optimisticupdatemap) option, you can use it to manage the invalidations that will occur at the end of the mutation.
164
+ * @default {
165
+ * list: true,
166
+ * many: true,
167
+ * detail: true,
168
+ * }
169
+ */
170
+ optimisticUpdateMap?: OptimisticUpdateMapType<TResponse, TVariables>;
171
+ } & SuccessErrorNotification<
172
+ UpdateResponse<TResponse> | CreateResponse<TResponse>,
173
+ TResponseError,
174
+ { id: BaseKey; values: TVariables } | TVariables
175
175
  > &
176
- ActionParams &
177
- LiveModeProps;
176
+ ActionParams &
177
+ LiveModeProps;
178
178
 
179
179
  export type UseFormProps<
180
- TQueryFnData extends BaseRecord = BaseRecord,
181
- TError extends HttpError = HttpError,
182
- TVariables = {},
183
- TData extends BaseRecord = TQueryFnData,
184
- TResponse extends BaseRecord = TData,
185
- TResponseError extends HttpError = TError,
180
+ TQueryFnData extends BaseRecord = BaseRecord,
181
+ TError extends HttpError = HttpError,
182
+ TVariables = {},
183
+ TData extends BaseRecord = TQueryFnData,
184
+ TResponse extends BaseRecord = TData,
185
+ TResponseError extends HttpError = TError,
186
186
  > = ActionFormProps<
187
- TQueryFnData,
188
- TError,
189
- TVariables,
190
- TData,
191
- TResponse,
192
- TResponseError
187
+ TQueryFnData,
188
+ TError,
189
+ TVariables,
190
+ TData,
191
+ TResponse,
192
+ TResponseError
193
193
  > &
194
- ActionParams &
195
- LiveModeProps &
196
- UseLoadingOvertimeOptionsProps &
197
- AutoSaveProps<TVariables>;
194
+ ActionParams &
195
+ LiveModeProps &
196
+ UseLoadingOvertimeOptionsProps &
197
+ AutoSaveProps<TVariables>;
198
198
 
199
199
  export type UseFormReturnType<
200
- TQueryFnData extends BaseRecord = BaseRecord,
201
- TError extends HttpError = HttpError,
202
- TVariables = {},
203
- TData extends BaseRecord = TQueryFnData,
204
- TResponse extends BaseRecord = TData,
205
- TResponseError extends HttpError = TError,
200
+ TQueryFnData extends BaseRecord = BaseRecord,
201
+ TError extends HttpError = HttpError,
202
+ TVariables = {},
203
+ TData extends BaseRecord = TQueryFnData,
204
+ TResponse extends BaseRecord = TData,
205
+ TResponseError extends HttpError = TError,
206
206
  > = {
207
- id?: BaseKey;
208
- setId: Dispatch<SetStateAction<BaseKey | undefined>>;
209
- queryResult?: QueryObserverResult<GetOneResponse<TData>, TError>;
210
- mutationResult:
211
- | UseUpdateReturnType<TResponse, TResponseError, TVariables>
212
- | UseCreateReturnType<TResponse, TResponseError, TVariables>;
213
- formLoading: boolean;
214
- onFinish: (
215
- values: TVariables,
216
- ) => Promise<CreateResponse<TResponse> | UpdateResponse<TResponse> | void>;
217
- redirect: (
218
- redirect: RedirectAction,
219
- idFromFunction?: BaseKey | undefined,
220
- routeParams?: Record<string, string | number>,
221
- ) => void;
207
+ id?: BaseKey;
208
+ setId: Dispatch<SetStateAction<BaseKey | undefined>>;
209
+ queryResult?: QueryObserverResult<GetOneResponse<TData>, TError>;
210
+ mutationResult:
211
+ | UseUpdateReturnType<TResponse, TResponseError, TVariables>
212
+ | UseCreateReturnType<TResponse, TResponseError, TVariables>;
213
+ formLoading: boolean;
214
+ onFinish: (
215
+ values: TVariables,
216
+ ) => Promise<CreateResponse<TResponse> | UpdateResponse<TResponse> | void>;
217
+ redirect: (
218
+ redirect: RedirectAction,
219
+ idFromFunction?: BaseKey | undefined,
220
+ routeParams?: Record<string, string | number>,
221
+ ) => void;
222
222
  } & UseLoadingOvertimeReturnType &
223
- AutoSaveReturnType<TResponse, TResponseError, TVariables>;
223
+ AutoSaveReturnType<TResponse, TResponseError, TVariables>;
224
224
 
225
225
  /**
226
226
  * `useForm` is used to manage forms. It uses Ant Design {@link https://ant.design/components/form/ Form} data scope management under the hood and returns the required props for managing the form actions.
@@ -236,404 +236,387 @@ export type UseFormReturnType<
236
236
  *
237
237
  */
238
238
  export const useForm = <
239
- TQueryFnData extends BaseRecord = BaseRecord,
240
- TError extends HttpError = HttpError,
241
- TVariables = {},
242
- TData extends BaseRecord = TQueryFnData,
243
- TResponse extends BaseRecord = TData,
244
- TResponseError extends HttpError = TError,
239
+ TQueryFnData extends BaseRecord = BaseRecord,
240
+ TError extends HttpError = HttpError,
241
+ TVariables = {},
242
+ TData extends BaseRecord = TQueryFnData,
243
+ TResponse extends BaseRecord = TData,
244
+ TResponseError extends HttpError = TError,
245
245
  >({
246
- resource: resourceFromProps,
247
- action: actionFromProps,
248
- id: idFromProps,
249
- onMutationSuccess,
250
- onMutationError,
251
- redirect: redirectFromProps,
252
- successNotification,
253
- errorNotification,
254
- meta,
255
- metaData,
256
- queryMeta,
257
- mutationMeta,
258
- mutationMode: mutationModeProp,
246
+ resource: resourceFromProps,
247
+ action: actionFromProps,
248
+ id: idFromProps,
249
+ onMutationSuccess,
250
+ onMutationError,
251
+ redirect: redirectFromProps,
252
+ successNotification,
253
+ errorNotification,
254
+ meta,
255
+ metaData,
256
+ queryMeta,
257
+ mutationMeta,
258
+ mutationMode: mutationModeProp,
259
+ liveMode,
260
+ onLiveEvent,
261
+ liveParams,
262
+ undoableTimeout,
263
+ dataProviderName,
264
+ invalidates,
265
+ queryOptions,
266
+ createMutationOptions,
267
+ updateMutationOptions,
268
+ overtimeOptions,
269
+ autoSave,
270
+ optimisticUpdateMap,
271
+ }: UseFormProps<
272
+ TQueryFnData,
273
+ TError,
274
+ TVariables,
275
+ TData,
276
+ TResponse,
277
+ TResponseError
278
+ > = {}): UseFormReturnType<
279
+ TQueryFnData,
280
+ TError,
281
+ TVariables,
282
+ TData,
283
+ TResponse,
284
+ TResponseError
285
+ > => {
286
+ const invalidate = useInvalidate();
287
+ const { options } = useRefineContext();
288
+ const getMeta = useMeta();
289
+
290
+ const {
291
+ resource,
292
+ id: idFromRoute,
293
+ action: actionFromRoute,
294
+ identifier,
295
+ } = useResource(resourceFromProps);
296
+ const { identifier: inferredIdentifier } = useResource();
297
+
298
+ /** We only accept `id` from URL params if `resource` is not explicitly passed. */
299
+ /** This is done to avoid sending wrong requests for custom `resource` and an async `id` */
300
+ const getDefaultId = () => {
301
+ const idFromPropsOrRoute = idFromProps ?? idFromRoute;
302
+
303
+ if (resourceFromProps && resourceFromProps !== inferredIdentifier) {
304
+ return idFromProps;
305
+ }
306
+
307
+ return idFromPropsOrRoute;
308
+ };
309
+ const defaultId = getDefaultId();
310
+
311
+ // id state is needed to determine selected record in a context for example useModal
312
+ const [id, setId] = React.useState<BaseKey | undefined>(defaultId);
313
+
314
+ /**
315
+ * In some cases, `id` from the router params is not available at the first render.
316
+ *
317
+ * (e.g. when using `Next.js` and client-side-rendering, `router` is not ready to use at the first render)
318
+ *
319
+ * We're watching for `defaultId` changes and setting `id` state if it's not equal to `defaultId`.
320
+ */
321
+ React.useEffect(() => {
322
+ setId(defaultId);
323
+ }, [defaultId]);
324
+
325
+ const getAction = () => {
326
+ if (actionFromProps) return actionFromProps;
327
+ if (actionFromRoute === "edit" || actionFromRoute === "clone")
328
+ return actionFromRoute;
329
+ return "create";
330
+ };
331
+ const action = getAction();
332
+
333
+ const combinedMeta = getMeta({
334
+ resource,
335
+ meta: pickNotDeprecated(meta, metaData),
336
+ });
337
+
338
+ const { mutationMode: mutationModeContext } = useMutationMode();
339
+ const mutationMode = mutationModeProp ?? mutationModeContext;
340
+
341
+ const isCreate = action === "create";
342
+ const isEdit = action === "edit";
343
+ const isClone = action === "clone";
344
+
345
+ warnOnce(
346
+ (isClone || isEdit) &&
347
+ Boolean(resourceFromProps) &&
348
+ !idFromProps &&
349
+ queryOptions?.enabled !== false,
350
+ `[useForm]: action: "${action}", resource: "${identifier}", id: ${id} \n\nIf you don't use the \`setId\` method to set the \`id\`, you should pass the \`id\` prop to \`useForm\`. Otherwise, \`useForm\` will not be able to infer the \`id\` from the current URL. \n\nSee https://refine.dev/docs/api-reference/core/hooks/useForm/#resource`,
351
+ );
352
+
353
+ /**
354
+ * Designated `redirect` route
355
+ */
356
+ const designatedRedirectAction = redirectPage({
357
+ redirectFromProps,
358
+ action,
359
+ redirectOptions: options.redirect,
360
+ });
361
+
362
+ const enableQuery = id !== undefined && (isEdit || isClone);
363
+
364
+ const queryResult = useOne<TQueryFnData, TError, TData>({
365
+ resource: identifier,
366
+ id: id ?? "",
367
+ queryOptions: {
368
+ enabled: enableQuery,
369
+ ...queryOptions,
370
+ },
259
371
  liveMode,
260
372
  onLiveEvent,
261
373
  liveParams,
262
- undoableTimeout,
374
+ meta: { ...combinedMeta, ...queryMeta },
375
+ metaData: { ...combinedMeta, ...queryMeta },
263
376
  dataProviderName,
264
- invalidates,
265
- queryOptions,
266
- createMutationOptions,
267
- updateMutationOptions,
268
- overtimeOptions,
269
- autoSave,
270
- optimisticUpdateMap,
271
- }: UseFormProps<
272
- TQueryFnData,
273
- TError,
274
- TVariables,
275
- TData,
276
- TResponse,
277
- TResponseError
278
- > = {}): UseFormReturnType<
279
- TQueryFnData,
280
- TError,
281
- TVariables,
282
- TData,
283
- TResponse,
284
- TResponseError
285
- > => {
286
- const invalidate = useInvalidate();
287
- const { options } = useRefineContext();
288
- const getMeta = useMeta();
289
-
290
- const {
291
- resource,
292
- id: idFromRoute,
293
- action: actionFromRoute,
294
- identifier,
295
- } = useResource(resourceFromProps);
296
- const { identifier: inferredIdentifier } = useResource();
297
-
298
- /** We only accept `id` from URL params if `resource` is not explicitly passed. */
299
- /** This is done to avoid sending wrong requests for custom `resource` and an async `id` */
300
- const getDefaultId = () => {
301
- const idFromPropsOrRoute = idFromProps ?? idFromRoute;
302
-
303
- if (resourceFromProps && resourceFromProps !== inferredIdentifier) {
304
- return idFromProps;
305
- }
306
-
307
- return idFromPropsOrRoute;
308
- };
309
- const defaultId = getDefaultId();
310
-
311
- // id state is needed to determine selected record in a context for example useModal
312
- const [id, setId] = React.useState<BaseKey | undefined>(defaultId);
313
-
314
- /**
315
- * In some cases, `id` from the router params is not available at the first render.
316
- *
317
- * (e.g. when using `Next.js` and client-side-rendering, `router` is not ready to use at the first render)
318
- *
319
- * We're watching for `defaultId` changes and setting `id` state if it's not equal to `defaultId`.
320
- */
321
- React.useEffect(() => {
322
- setId(defaultId);
323
- }, [defaultId]);
324
-
325
- const getAction = () => {
326
- if (actionFromProps) return actionFromProps;
327
- else if (actionFromRoute === "edit" || actionFromRoute === "clone")
328
- return actionFromRoute;
329
- else return "create";
330
- };
331
- const action = getAction();
377
+ });
332
378
 
333
- const combinedMeta = getMeta({
334
- resource,
335
- meta: pickNotDeprecated(meta, metaData),
336
- });
337
-
338
- const { mutationMode: mutationModeContext } = useMutationMode();
339
- const mutationMode = mutationModeProp ?? mutationModeContext;
340
-
341
- const isCreate = action === "create";
342
- const isEdit = action === "edit";
343
- const isClone = action === "clone";
344
-
345
- warnOnce(
346
- (isClone || isEdit) &&
347
- Boolean(resourceFromProps) &&
348
- !Boolean(idFromProps) &&
349
- queryOptions?.enabled !== false,
350
- `[useForm]: action: "${action}", resource: "${identifier}", id: ${id} \n\n` +
351
- `If you don't use the \`setId\` method to set the \`id\`, you should pass the \`id\` prop to \`useForm\`. Otherwise, \`useForm\` will not be able to infer the \`id\` from the current URL. \n\n` +
352
- `See https://refine.dev/docs/api-reference/core/hooks/useForm/#resource`,
353
- );
354
-
355
- /**
356
- * Designated `redirect` route
357
- */
358
- const designatedRedirectAction = redirectPage({
359
- redirectFromProps,
360
- action,
361
- redirectOptions: options.redirect,
362
- });
363
-
364
- const enableQuery = id !== undefined && (isEdit || isClone);
379
+ const { isFetching: isFetchingQuery } = queryResult;
365
380
 
366
- const queryResult = useOne<TQueryFnData, TError, TData>({
367
- resource: identifier,
368
- id: id ?? "",
369
- queryOptions: {
370
- enabled: enableQuery,
371
- ...queryOptions,
372
- },
373
- liveMode,
374
- onLiveEvent,
375
- liveParams,
376
- meta: { ...combinedMeta, ...queryMeta },
377
- metaData: { ...combinedMeta, ...queryMeta },
378
- dataProviderName,
379
- });
381
+ const mutationResultCreate = useCreate<TResponse, TResponseError, TVariables>(
382
+ {
383
+ mutationOptions: createMutationOptions,
384
+ },
385
+ );
386
+ const { mutate: mutateCreate, isLoading: isLoadingCreate } =
387
+ mutationResultCreate;
380
388
 
381
- const { isFetching: isFetchingQuery } = queryResult;
389
+ const mutationResultUpdate = useUpdate<TResponse, TResponseError, TVariables>(
390
+ {
391
+ mutationOptions: updateMutationOptions,
392
+ },
393
+ );
394
+ const { mutate: mutateUpdate, isLoading: isLoadingUpdate } =
395
+ mutationResultUpdate;
382
396
 
383
- const mutationResultCreate = useCreate<
384
- TResponse,
385
- TResponseError,
386
- TVariables
387
- >({
388
- mutationOptions: createMutationOptions,
389
- });
390
- const { mutate: mutateCreate, isLoading: isLoadingCreate } =
391
- mutationResultCreate;
392
-
393
- const mutationResultUpdate = useUpdate<
394
- TResponse,
395
- TResponseError,
396
- TVariables
397
- >({
398
- mutationOptions: updateMutationOptions,
399
- });
400
- const { mutate: mutateUpdate, isLoading: isLoadingUpdate } =
401
- mutationResultUpdate;
397
+ const autoSaveMutation = useUpdate<TResponse, TResponseError, TVariables>({});
402
398
 
403
- const autoSaveMutation = useUpdate<TResponse, TResponseError, TVariables>(
404
- {},
405
- );
399
+ const { setWarnWhen } = useWarnAboutChange();
406
400
 
407
- const { setWarnWhen } = useWarnAboutChange();
401
+ const handleSubmitWithRedirect = useRedirectionAfterSubmission();
408
402
 
409
- const handleSubmitWithRedirect = useRedirectionAfterSubmission();
403
+ const onFinishCreate = async (values: TVariables) => {
404
+ setWarnWhen(false);
410
405
 
411
- const onFinishCreate = async (values: TVariables) => {
412
- setWarnWhen(false);
406
+ const onSuccess = (id?: BaseKey) => {
407
+ handleSubmitWithRedirect({
408
+ redirect: designatedRedirectAction,
409
+ resource,
410
+ id,
411
+ meta: pickNotDeprecated(meta, metaData),
412
+ });
413
+ };
413
414
 
414
- const onSuccess = (id?: BaseKey) => {
415
- handleSubmitWithRedirect({
416
- redirect: designatedRedirectAction,
417
- resource,
418
- id,
419
- meta: pickNotDeprecated(meta, metaData),
420
- });
421
- };
415
+ if (mutationMode !== "pessimistic") {
416
+ setTimeout(() => {
417
+ onSuccess();
418
+ });
419
+ }
420
+
421
+ return new Promise<CreateResponse<TResponse> | void>((resolve, reject) => {
422
+ if (mutationMode !== "pessimistic") {
423
+ resolve();
424
+ }
425
+
426
+ if (!resource) return;
427
+
428
+ return mutateCreate(
429
+ {
430
+ values,
431
+ resource: identifier ?? resource.name,
432
+ successNotification,
433
+ errorNotification,
434
+ meta: { ...combinedMeta, ...mutationMeta },
435
+ metaData: { ...combinedMeta, ...mutationMeta },
436
+ dataProviderName,
437
+ invalidates,
438
+ },
439
+ {
440
+ onSuccess: (data, _, context) => {
441
+ if (onMutationSuccess) {
442
+ onMutationSuccess(data, values, context);
443
+ }
422
444
 
423
- if (mutationMode !== "pessimistic") {
424
- setTimeout(() => {
425
- onSuccess();
426
- });
427
- }
445
+ const responseId = data?.data?.id;
428
446
 
429
- return new Promise<CreateResponse<TResponse> | void>(
430
- (resolve, reject) => {
431
- if (mutationMode !== "pessimistic") {
432
- resolve();
433
- }
434
-
435
- if (!resource) return;
436
-
437
- return mutateCreate(
438
- {
439
- values,
440
- resource: identifier ?? resource.name,
441
- successNotification,
442
- errorNotification,
443
- meta: { ...combinedMeta, ...mutationMeta },
444
- metaData: { ...combinedMeta, ...mutationMeta },
445
- dataProviderName,
446
- invalidates,
447
- },
448
- {
449
- onSuccess: (data, _, context) => {
450
- if (onMutationSuccess) {
451
- onMutationSuccess(data, values, context);
452
- }
453
-
454
- const responseId = data?.data?.id;
455
-
456
- onSuccess(responseId);
457
-
458
- resolve(data);
459
- },
460
- onError: (error: TResponseError, _, context) => {
461
- if (onMutationError) {
462
- return onMutationError(error, values, context);
463
- }
464
- reject();
465
- },
466
- },
467
- );
468
- },
469
- );
470
- };
447
+ onSuccess(responseId);
471
448
 
472
- React.useEffect(() => {
473
- return () => {
474
- if (
475
- autoSave?.invalidateOnUnmount &&
476
- autoSaveMutation.status === "success"
477
- ) {
478
- invalidate({
479
- id,
480
- invalidates: invalidates || ["list", "many", "detail"],
481
- dataProviderName,
482
- resource: identifier,
483
- });
449
+ resolve(data);
450
+ },
451
+ onError: (error: TResponseError, _, context) => {
452
+ if (onMutationError) {
453
+ return onMutationError(error, values, context);
484
454
  }
485
- };
486
- }, [autoSave?.invalidateOnUnmount, autoSaveMutation.status]);
487
-
488
- const onFinishAutoSaveMutation = (
489
- values: TVariables,
490
- ): Promise<UpdateResponse<TResponse> | void> | void => {
491
- if (!resource || !isEdit) return;
492
-
493
- const variables: UpdateParams<TResponse, TResponseError, TVariables> = {
494
- id: id ?? "",
495
- values,
496
- resource: identifier ?? resource.name,
497
- successNotification: false,
498
- errorNotification: false,
499
- meta: { ...combinedMeta, ...mutationMeta },
500
- metaData: { ...combinedMeta, ...mutationMeta },
501
- dataProviderName,
502
- invalidates: [],
503
- mutationMode: "pessimistic",
504
- };
505
-
506
- return autoSaveMutation.mutate(variables, {
507
- onSuccess: (data, _, context) => {
508
- if (onMutationSuccess) {
509
- onMutationSuccess(data, values, context, true);
510
- }
511
- },
512
- onError: (error: TResponseError, _, context) => {
513
- if (onMutationError) {
514
- return onMutationError(error, values, context, true);
515
- }
516
- },
455
+ reject();
456
+ },
457
+ },
458
+ );
459
+ });
460
+ };
461
+
462
+ React.useEffect(() => {
463
+ return () => {
464
+ if (
465
+ autoSave?.invalidateOnUnmount &&
466
+ autoSaveMutation.status === "success"
467
+ ) {
468
+ invalidate({
469
+ id,
470
+ invalidates: invalidates || ["list", "many", "detail"],
471
+ dataProviderName,
472
+ resource: identifier,
517
473
  });
474
+ }
475
+ };
476
+ }, [autoSave?.invalidateOnUnmount, autoSaveMutation.status]);
477
+
478
+ const onFinishAutoSaveMutation = (
479
+ values: TVariables,
480
+ ): Promise<UpdateResponse<TResponse> | void> | void => {
481
+ if (!resource || !isEdit) return;
482
+
483
+ const variables: UpdateParams<TResponse, TResponseError, TVariables> = {
484
+ id: id ?? "",
485
+ values,
486
+ resource: identifier ?? resource.name,
487
+ successNotification: false,
488
+ errorNotification: false,
489
+ meta: { ...combinedMeta, ...mutationMeta },
490
+ metaData: { ...combinedMeta, ...mutationMeta },
491
+ dataProviderName,
492
+ invalidates: [],
493
+ mutationMode: "pessimistic",
518
494
  };
519
495
 
520
- const onFinishAutoSave = debounce((allValues) => {
521
- return onFinishAutoSaveMutation(allValues);
522
- }, autoSave?.debounce || 1000);
523
-
524
- const onFinishUpdate = async (values: TVariables) => {
525
- setWarnWhen(false);
526
-
527
- if (!resource) return;
528
-
529
- const variables: UpdateParams<TResponse, TResponseError, TVariables> = {
530
- id: id ?? "",
531
- values,
532
- resource: identifier ?? resource.name,
533
- mutationMode,
534
- undoableTimeout,
535
- successNotification,
536
- errorNotification,
537
- meta: { ...combinedMeta, ...mutationMeta },
538
- metaData: { ...combinedMeta, ...mutationMeta },
539
- dataProviderName,
540
- invalidates,
541
- optimisticUpdateMap,
542
- };
543
-
544
- const onSuccess = () => {
545
- handleSubmitWithRedirect({
546
- redirect: designatedRedirectAction,
547
- resource,
548
- id,
549
- meta: pickNotDeprecated(meta, metaData),
550
- });
551
- };
552
-
553
- // setWarnWhen is set to "false" at the start of the mutation. With the help of setTimeout we guarantee that the value false is set.
554
- if (mutationMode !== "pessimistic") {
555
- setTimeout(() => {
556
- onSuccess();
557
- });
496
+ return autoSaveMutation.mutate(variables, {
497
+ onSuccess: (data, _, context) => {
498
+ if (onMutationSuccess) {
499
+ onMutationSuccess(data, values, context, true);
558
500
  }
559
-
560
- // setTimeout is required to make onSuccess e.g. callbacks to work if component unmounts i.e. on route change
561
- return new Promise<UpdateResponse<TResponse> | void>(
562
- (resolve, reject) => {
563
- if (mutationMode !== "pessimistic") {
564
- resolve();
565
- }
566
- return setTimeout(() => {
567
- mutateUpdate(variables, {
568
- onSuccess: (data, _, context) => {
569
- if (onMutationSuccess) {
570
- onMutationSuccess(data, values, context);
571
- }
572
-
573
- if (mutationMode === "pessimistic") {
574
- onSuccess();
575
- }
576
-
577
- resolve(data);
578
- },
579
- onError: (error: TResponseError, _, context) => {
580
- if (onMutationError) {
581
- return onMutationError(error, values, context);
582
- }
583
- reject();
584
- },
585
- });
586
- });
587
- },
588
- );
501
+ },
502
+ onError: (error: TResponseError, _, context) => {
503
+ if (onMutationError) {
504
+ return onMutationError(error, values, context, true);
505
+ }
506
+ },
507
+ });
508
+ };
509
+
510
+ const onFinishAutoSave = debounce((allValues) => {
511
+ return onFinishAutoSaveMutation(allValues);
512
+ }, autoSave?.debounce || 1000);
513
+
514
+ const onFinishUpdate = async (values: TVariables) => {
515
+ setWarnWhen(false);
516
+
517
+ if (!resource) return;
518
+
519
+ const variables: UpdateParams<TResponse, TResponseError, TVariables> = {
520
+ id: id ?? "",
521
+ values,
522
+ resource: identifier ?? resource.name,
523
+ mutationMode,
524
+ undoableTimeout,
525
+ successNotification,
526
+ errorNotification,
527
+ meta: { ...combinedMeta, ...mutationMeta },
528
+ metaData: { ...combinedMeta, ...mutationMeta },
529
+ dataProviderName,
530
+ invalidates,
531
+ optimisticUpdateMap,
589
532
  };
590
533
 
591
- const createResult = {
592
- formLoading: isFetchingQuery || isLoadingCreate,
593
- mutationResult: mutationResultCreate,
594
- onFinish: onFinishCreate,
534
+ const onSuccess = () => {
535
+ handleSubmitWithRedirect({
536
+ redirect: designatedRedirectAction,
537
+ resource,
538
+ id,
539
+ meta: pickNotDeprecated(meta, metaData),
540
+ });
595
541
  };
596
542
 
597
- const editResult = {
598
- formLoading: isFetchingQuery || isLoadingUpdate,
599
- mutationResult: mutationResultUpdate,
600
- onFinish: onFinishUpdate,
601
- };
543
+ // setWarnWhen is set to "false" at the start of the mutation. With the help of setTimeout we guarantee that the value false is set.
544
+ if (mutationMode !== "pessimistic") {
545
+ setTimeout(() => {
546
+ onSuccess();
547
+ });
548
+ }
549
+
550
+ // setTimeout is required to make onSuccess e.g. callbacks to work if component unmounts i.e. on route change
551
+ return new Promise<UpdateResponse<TResponse> | void>((resolve, reject) => {
552
+ if (mutationMode !== "pessimistic") {
553
+ resolve();
554
+ }
555
+ return setTimeout(() => {
556
+ mutateUpdate(variables, {
557
+ onSuccess: (data, _, context) => {
558
+ if (onMutationSuccess) {
559
+ onMutationSuccess(data, values, context);
560
+ }
602
561
 
603
- const result = isCreate || isClone ? createResult : editResult;
562
+ if (mutationMode === "pessimistic") {
563
+ onSuccess();
564
+ }
604
565
 
605
- const { elapsedTime } = useLoadingOvertime({
606
- isLoading: result.mutationResult.isLoading || queryResult.isFetching,
607
- interval: overtimeOptions?.interval,
608
- onInterval: overtimeOptions?.onInterval,
566
+ resolve(data);
567
+ },
568
+ onError: (error: TResponseError, _, context) => {
569
+ if (onMutationError) {
570
+ return onMutationError(error, values, context);
571
+ }
572
+ reject();
573
+ },
574
+ });
575
+ });
609
576
  });
610
-
611
- return {
612
- ...result,
613
- queryResult,
614
- onFinishAutoSave,
615
- autoSaveProps: {
616
- status: autoSaveMutation.status,
617
- data: autoSaveMutation.data,
618
- error: autoSaveMutation.error,
619
- },
620
- id,
621
- setId,
622
- redirect: (redirect, idFromFunction?: BaseKey | undefined) => {
623
- handleSubmitWithRedirect({
624
- redirect:
625
- redirect !== undefined
626
- ? redirect
627
- : isEdit
628
- ? "list"
629
- : "edit",
630
- resource,
631
- id: idFromFunction ?? id,
632
- meta: pickNotDeprecated(meta, metaData),
633
- });
634
- },
635
- overtime: {
636
- elapsedTime,
637
- },
638
- };
577
+ };
578
+
579
+ const createResult = {
580
+ formLoading: isFetchingQuery || isLoadingCreate,
581
+ mutationResult: mutationResultCreate,
582
+ onFinish: onFinishCreate,
583
+ };
584
+
585
+ const editResult = {
586
+ formLoading: isFetchingQuery || isLoadingUpdate,
587
+ mutationResult: mutationResultUpdate,
588
+ onFinish: onFinishUpdate,
589
+ };
590
+
591
+ const result = isCreate || isClone ? createResult : editResult;
592
+
593
+ const { elapsedTime } = useLoadingOvertime({
594
+ isLoading: result.mutationResult.isLoading || queryResult.isFetching,
595
+ interval: overtimeOptions?.interval,
596
+ onInterval: overtimeOptions?.onInterval,
597
+ });
598
+
599
+ return {
600
+ ...result,
601
+ queryResult,
602
+ onFinishAutoSave,
603
+ autoSaveProps: {
604
+ status: autoSaveMutation.status,
605
+ data: autoSaveMutation.data,
606
+ error: autoSaveMutation.error,
607
+ },
608
+ id,
609
+ setId,
610
+ redirect: (redirect, idFromFunction?: BaseKey | undefined) => {
611
+ handleSubmitWithRedirect({
612
+ redirect: redirect !== undefined ? redirect : isEdit ? "list" : "edit",
613
+ resource,
614
+ id: idFromFunction ?? id,
615
+ meta: pickNotDeprecated(meta, metaData),
616
+ });
617
+ },
618
+ overtime: {
619
+ elapsedTime,
620
+ },
621
+ };
639
622
  };