@strato-admin/faker-ecommerce 0.1.1 → 0.3.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.
- package/dist/dataProvider.js +1 -2
- package/dist/generate.d.ts +2 -1
- package/dist/generate.js +15 -8
- package/dist/ra-core/src/auth/LogoutOnMount.d.ts +8 -0
- package/dist/ra-core/src/auth/LogoutOnMount.js +16 -0
- package/dist/ra-core/src/auth/addRefreshAuthToAuthProvider.d.ts +22 -0
- package/dist/ra-core/src/auth/addRefreshAuthToAuthProvider.js +41 -0
- package/dist/ra-core/src/auth/addRefreshAuthToDataProvider.d.ts +21 -0
- package/dist/ra-core/src/auth/addRefreshAuthToDataProvider.js +30 -0
- package/dist/ra-core/src/auth/convertLegacyAuthProvider.d.ts +12 -0
- package/dist/ra-core/src/auth/convertLegacyAuthProvider.js +19 -0
- package/dist/ra-core/src/auth/index.d.ts +27 -0
- package/dist/ra-core/src/auth/index.js +34 -0
- package/dist/ra-core/src/auth/types.d.ts +7 -0
- package/dist/ra-core/src/auth/types.js +5 -0
- package/dist/ra-core/src/auth/useAuthProvider.d.ts +10 -0
- package/dist/ra-core/src/auth/useAuthProvider.js +11 -0
- package/dist/ra-core/src/auth/useAuthState.d.ts +48 -0
- package/dist/ra-core/src/auth/useAuthState.js +171 -0
- package/dist/ra-core/src/auth/useAuthenticated.d.ts +36 -0
- package/dist/ra-core/src/auth/useAuthenticated.js +34 -0
- package/dist/ra-core/src/auth/useCanAccess.d.ts +56 -0
- package/dist/ra-core/src/auth/useCanAccess.js +108 -0
- package/dist/ra-core/src/auth/useCanAccessCallback.d.ts +39 -0
- package/dist/ra-core/src/auth/useCanAccessCallback.js +45 -0
- package/dist/ra-core/src/auth/useCanAccessResources.d.ts +67 -0
- package/dist/ra-core/src/auth/useCanAccessResources.js +92 -0
- package/dist/ra-core/src/auth/useCheckAuth.d.ts +48 -0
- package/dist/ra-core/src/auth/useCheckAuth.js +76 -0
- package/dist/ra-core/src/auth/useGetIdentity.d.ts +41 -0
- package/dist/ra-core/src/auth/useGetIdentity.js +86 -0
- package/dist/ra-core/src/auth/useGetPermissions.d.ts +41 -0
- package/dist/ra-core/src/auth/useGetPermissions.js +47 -0
- package/dist/ra-core/src/auth/useHandleAuthCallback.d.ts +20 -0
- package/dist/ra-core/src/auth/useHandleAuthCallback.js +83 -0
- package/dist/ra-core/src/auth/useIsAuthPending.d.ts +13 -0
- package/dist/ra-core/src/auth/useIsAuthPending.js +30 -0
- package/dist/ra-core/src/auth/useLogin.d.ts +34 -0
- package/dist/ra-core/src/auth/useLogin.js +78 -0
- package/dist/ra-core/src/auth/useLogout.d.ts +31 -0
- package/dist/ra-core/src/auth/useLogout.js +117 -0
- package/dist/ra-core/src/auth/useLogoutIfAccessDenied.d.ts +42 -0
- package/dist/ra-core/src/auth/useLogoutIfAccessDenied.js +111 -0
- package/dist/ra-core/src/auth/usePermissions.d.ts +41 -0
- package/dist/ra-core/src/auth/usePermissions.js +123 -0
- package/dist/ra-core/src/controller/button/index.d.ts +7 -0
- package/dist/ra-core/src/controller/button/index.js +7 -0
- package/dist/ra-core/src/controller/button/useBulkDeleteController.d.ts +14 -0
- package/dist/ra-core/src/controller/button/useBulkDeleteController.js +66 -0
- package/dist/ra-core/src/controller/create/index.d.ts +6 -0
- package/dist/ra-core/src/controller/create/index.js +6 -0
- package/dist/ra-core/src/controller/create/useCreateController.d.ts +50 -0
- package/dist/ra-core/src/controller/create/useCreateController.js +149 -0
- package/dist/ra-core/src/controller/edit/index.d.ts +6 -0
- package/dist/ra-core/src/controller/edit/index.js +6 -0
- package/dist/ra-core/src/controller/edit/useEditController.d.ts +72 -0
- package/dist/ra-core/src/controller/edit/useEditController.js +206 -0
- package/dist/ra-core/src/controller/field/index.d.ts +12 -0
- package/dist/ra-core/src/controller/field/index.js +12 -0
- package/dist/ra-core/src/controller/field/sanitizeFieldRestProps.d.ts +1 -0
- package/dist/ra-core/src/controller/field/sanitizeFieldRestProps.js +1 -0
- package/dist/ra-core/src/controller/field/types.d.ts +28 -0
- package/dist/ra-core/src/controller/field/types.js +1 -0
- package/dist/ra-core/src/controller/field/useReferenceArrayFieldController.d.ts +39 -0
- package/dist/ra-core/src/controller/field/useReferenceArrayFieldController.js +82 -0
- package/dist/ra-core/src/controller/field/useReferenceFieldController.d.ts +14 -0
- package/dist/ra-core/src/controller/field/useReferenceFieldController.js +31 -0
- package/dist/ra-core/src/controller/field/useReferenceManyFieldController.d.ts +49 -0
- package/dist/ra-core/src/controller/field/useReferenceManyFieldController.js +264 -0
- package/dist/ra-core/src/controller/index.d.ts +17 -0
- package/dist/ra-core/src/controller/index.js +16 -0
- package/dist/ra-core/src/controller/input/ArrayInputContext.d.ts +9 -0
- package/dist/ra-core/src/controller/input/ArrayInputContext.js +8 -0
- package/dist/ra-core/src/controller/input/SimpleFormIteratorContext.d.ts +15 -0
- package/dist/ra-core/src/controller/input/SimpleFormIteratorContext.js +8 -0
- package/dist/ra-core/src/controller/input/SimpleFormIteratorItemContext.d.ts +13 -0
- package/dist/ra-core/src/controller/input/SimpleFormIteratorItemContext.js +8 -0
- package/dist/ra-core/src/controller/input/index.d.ts +17 -0
- package/dist/ra-core/src/controller/input/index.js +17 -0
- package/dist/ra-core/src/controller/input/referenceDataStatus.d.ts +32 -0
- package/dist/ra-core/src/controller/input/referenceDataStatus.js +74 -0
- package/dist/ra-core/src/controller/input/sanitizeInputRestProps.d.ts +1 -0
- package/dist/ra-core/src/controller/input/sanitizeInputRestProps.js +1 -0
- package/dist/ra-core/src/controller/input/types.d.ts +3 -0
- package/dist/ra-core/src/controller/input/types.js +1 -0
- package/dist/ra-core/src/controller/input/useArrayInput.d.ts +8 -0
- package/dist/ra-core/src/controller/input/useArrayInput.js +29 -0
- package/dist/ra-core/src/controller/input/useGetArrayInputNewItemDefaults.d.ts +3 -0
- package/dist/ra-core/src/controller/input/useGetArrayInputNewItemDefaults.js +37 -0
- package/dist/ra-core/src/controller/input/useReferenceArrayInputController.d.ts +48 -0
- package/dist/ra-core/src/controller/input/useReferenceArrayInputController.js +137 -0
- package/dist/ra-core/src/controller/input/useReferenceInputController.d.ts +54 -0
- package/dist/ra-core/src/controller/input/useReferenceInputController.js +208 -0
- package/dist/ra-core/src/controller/input/useReferenceParams.d.ts +106 -0
- package/dist/ra-core/src/controller/input/useReferenceParams.js +226 -0
- package/dist/ra-core/src/controller/input/useSimpleFormIterator.d.ts +7 -0
- package/dist/ra-core/src/controller/input/useSimpleFormIterator.js +15 -0
- package/dist/ra-core/src/controller/input/useSimpleFormIteratorItem.d.ts +7 -0
- package/dist/ra-core/src/controller/input/useSimpleFormIteratorItem.js +15 -0
- package/dist/ra-core/src/controller/list/InfinitePaginationContext.d.ts +25 -0
- package/dist/ra-core/src/controller/list/InfinitePaginationContext.js +32 -0
- package/dist/ra-core/src/controller/list/index.d.ts +30 -0
- package/dist/ra-core/src/controller/list/index.js +30 -0
- package/dist/ra-core/src/controller/list/queryReducer.d.ts +45 -0
- package/dist/ra-core/src/controller/list/queryReducer.js +85 -0
- package/dist/ra-core/src/controller/list/useFilterContext.d.ts +2 -0
- package/dist/ra-core/src/controller/list/useFilterContext.js +5 -0
- package/dist/ra-core/src/controller/list/useInfiniteListController.d.ts +44 -0
- package/dist/ra-core/src/controller/list/useInfiniteListController.js +175 -0
- package/dist/ra-core/src/controller/list/useInfinitePaginationContext.d.ts +16 -0
- package/dist/ra-core/src/controller/list/useInfinitePaginationContext.js +17 -0
- package/dist/ra-core/src/controller/list/useList.d.ts +55 -0
- package/dist/ra-core/src/controller/list/useList.js +223 -0
- package/dist/ra-core/src/controller/list/useListContext.d.ts +59 -0
- package/dist/ra-core/src/controller/list/useListContext.js +65 -0
- package/dist/ra-core/src/controller/list/useListContextWithProps.d.ts +44 -0
- package/dist/ra-core/src/controller/list/useListContextWithProps.js +84 -0
- package/dist/ra-core/src/controller/list/useListController.d.ts +296 -0
- package/dist/ra-core/src/controller/list/useListController.js +234 -0
- package/dist/ra-core/src/controller/list/useListFilterContext.d.ts +11 -0
- package/dist/ra-core/src/controller/list/useListFilterContext.js +18 -0
- package/dist/ra-core/src/controller/list/useListPaginationContext.d.ts +12 -0
- package/dist/ra-core/src/controller/list/useListPaginationContext.js +19 -0
- package/dist/ra-core/src/controller/list/useListParams.d.ts +116 -0
- package/dist/ra-core/src/controller/list/useListParams.js +281 -0
- package/dist/ra-core/src/controller/list/useListSortContext.d.ts +12 -0
- package/dist/ra-core/src/controller/list/useListSortContext.js +19 -0
- package/dist/ra-core/src/controller/list/useRecordSelection.d.ts +32 -0
- package/dist/ra-core/src/controller/list/useRecordSelection.js +93 -0
- package/dist/ra-core/src/controller/list/useSavedQueries.d.ts +14 -0
- package/dist/ra-core/src/controller/list/useSavedQueries.js +29 -0
- package/dist/ra-core/src/controller/list/useUnselect.d.ts +10 -0
- package/dist/ra-core/src/controller/list/useUnselect.js +18 -0
- package/dist/ra-core/src/controller/list/useUnselectAll.d.ts +9 -0
- package/dist/ra-core/src/controller/list/useUnselectAll.js +18 -0
- package/dist/ra-core/src/controller/record/index.d.ts +5 -0
- package/dist/ra-core/src/controller/record/index.js +5 -0
- package/dist/ra-core/src/controller/record/useRecordContext.d.ts +34 -0
- package/dist/ra-core/src/controller/record/useRecordContext.js +36 -0
- package/dist/ra-core/src/controller/saveContext/SaveContext.d.ts +20 -0
- package/dist/ra-core/src/controller/saveContext/SaveContext.js +2 -0
- package/dist/ra-core/src/controller/saveContext/index.d.ts +6 -0
- package/dist/ra-core/src/controller/saveContext/index.js +6 -0
- package/dist/ra-core/src/controller/saveContext/useMutationMiddlewares.d.ts +39 -0
- package/dist/ra-core/src/controller/saveContext/useMutationMiddlewares.js +79 -0
- package/dist/ra-core/src/controller/saveContext/usePickSaveContext.d.ts +5 -0
- package/dist/ra-core/src/controller/saveContext/usePickSaveContext.js +25 -0
- package/dist/ra-core/src/controller/saveContext/useRegisterMutationMiddleware.d.ts +6 -0
- package/dist/ra-core/src/controller/saveContext/useRegisterMutationMiddleware.js +18 -0
- package/dist/ra-core/src/controller/saveContext/useSaveContext.d.ts +14 -0
- package/dist/ra-core/src/controller/saveContext/useSaveContext.js +17 -0
- package/dist/ra-core/src/controller/show/index.d.ts +6 -0
- package/dist/ra-core/src/controller/show/index.js +6 -0
- package/dist/ra-core/src/controller/show/useShowController.d.ts +75 -0
- package/dist/ra-core/src/controller/show/useShowController.js +110 -0
- package/dist/ra-core/src/controller/useFilterState.d.ts +46 -0
- package/dist/ra-core/src/controller/useFilterState.js +70 -0
- package/dist/ra-core/src/controller/usePaginationState.d.ts +33 -0
- package/dist/ra-core/src/controller/usePaginationState.js +45 -0
- package/dist/ra-core/src/controller/usePrevNextController.d.ts +127 -0
- package/dist/ra-core/src/controller/usePrevNextController.js +215 -0
- package/dist/ra-core/src/controller/useReference.d.ts +49 -0
- package/dist/ra-core/src/controller/useReference.js +42 -0
- package/dist/ra-core/src/controller/useSortState.d.ts +61 -0
- package/dist/ra-core/src/controller/useSortState.js +96 -0
- package/dist/ra-core/src/core/DefaultTitleContext.d.ts +15 -0
- package/dist/ra-core/src/core/DefaultTitleContext.js +15 -0
- package/dist/ra-core/src/core/HasDashboardContext.d.ts +21 -0
- package/dist/ra-core/src/core/HasDashboardContext.js +22 -0
- package/dist/ra-core/src/core/ResourceContext.d.ts +19 -0
- package/dist/ra-core/src/core/ResourceContext.js +19 -0
- package/dist/ra-core/src/core/UserMenuContext.d.ts +34 -0
- package/dist/ra-core/src/core/UserMenuContext.js +28 -0
- package/dist/ra-core/src/core/index.d.ts +27 -0
- package/dist/ra-core/src/core/index.js +27 -0
- package/dist/ra-core/src/core/useGetRecordRepresentation.d.ts +13 -0
- package/dist/ra-core/src/core/useGetRecordRepresentation.js +44 -0
- package/dist/ra-core/src/core/useGetResourceLabel.d.ts +22 -0
- package/dist/ra-core/src/core/useGetResourceLabel.js +42 -0
- package/dist/ra-core/src/core/useIsOffline.d.ts +7 -0
- package/dist/ra-core/src/core/useIsOffline.js +18 -0
- package/dist/ra-core/src/core/useResourceContext.d.ts +36 -0
- package/dist/ra-core/src/core/useResourceContext.js +38 -0
- package/dist/ra-core/src/core/useResourceDefinition.d.ts +31 -0
- package/dist/ra-core/src/core/useResourceDefinition.js +48 -0
- package/dist/ra-core/src/core/useResourceDefinitionContext.d.ts +1 -0
- package/dist/ra-core/src/core/useResourceDefinitionContext.js +3 -0
- package/dist/ra-core/src/core/useResourceDefinitions.d.ts +21 -0
- package/dist/ra-core/src/core/useResourceDefinitions.js +20 -0
- package/dist/ra-core/src/core/useUserMenu.d.ts +28 -0
- package/dist/ra-core/src/core/useUserMenu.js +30 -0
- package/dist/ra-core/src/core/useWrappedSource.d.ts +11 -0
- package/dist/ra-core/src/core/useWrappedSource.js +15 -0
- package/dist/ra-core/src/dataProvider/DataProviderContext.d.ts +3 -0
- package/dist/ra-core/src/dataProvider/DataProviderContext.js +4 -0
- package/dist/ra-core/src/dataProvider/HttpError.d.ts +6 -0
- package/dist/ra-core/src/dataProvider/HttpError.js +19 -0
- package/dist/ra-core/src/dataProvider/combineDataProviders.d.ts +21 -0
- package/dist/ra-core/src/dataProvider/combineDataProviders.js +32 -0
- package/dist/ra-core/src/dataProvider/convertLegacyDataProvider.d.ts +12 -0
- package/dist/ra-core/src/dataProvider/convertLegacyDataProvider.js +40 -0
- package/dist/ra-core/src/dataProvider/dataFetchActions.d.ts +15 -0
- package/dist/ra-core/src/dataProvider/dataFetchActions.js +49 -0
- package/dist/ra-core/src/dataProvider/defaultDataProvider.d.ts +2 -0
- package/dist/ra-core/src/dataProvider/defaultDataProvider.js +12 -0
- package/dist/ra-core/src/dataProvider/fetch.d.ts +32 -0
- package/dist/ra-core/src/dataProvider/fetch.js +78 -0
- package/dist/ra-core/src/dataProvider/index.d.ts +34 -0
- package/dist/ra-core/src/dataProvider/index.js +33 -0
- package/dist/ra-core/src/dataProvider/populateQueryCache.d.ts +22 -0
- package/dist/ra-core/src/dataProvider/populateQueryCache.js +30 -0
- package/dist/ra-core/src/dataProvider/testDataProvider.d.ts +2 -0
- package/dist/ra-core/src/dataProvider/testDataProvider.js +41 -0
- package/dist/ra-core/src/dataProvider/undo/index.d.ts +6 -0
- package/dist/ra-core/src/dataProvider/undo/index.js +6 -0
- package/dist/ra-core/src/dataProvider/undo/types.d.ts +3 -0
- package/dist/ra-core/src/dataProvider/undo/types.js +1 -0
- package/dist/ra-core/src/dataProvider/undoableEventEmitter.d.ts +3 -0
- package/dist/ra-core/src/dataProvider/undoableEventEmitter.js +2 -0
- package/dist/ra-core/src/dataProvider/useCreate.d.ts +89 -0
- package/dist/ra-core/src/dataProvider/useCreate.js +155 -0
- package/dist/ra-core/src/dataProvider/useDataProvider.d.ts +2 -0
- package/dist/ra-core/src/dataProvider/useDataProvider.js +140 -0
- package/dist/ra-core/src/dataProvider/useDelete.d.ts +83 -0
- package/dist/ra-core/src/dataProvider/useDelete.js +171 -0
- package/dist/ra-core/src/dataProvider/useDeleteMany.d.ts +81 -0
- package/dist/ra-core/src/dataProvider/useDeleteMany.js +193 -0
- package/dist/ra-core/src/dataProvider/useGetList.d.ts +58 -0
- package/dist/ra-core/src/dataProvider/useGetList.js +131 -0
- package/dist/ra-core/src/dataProvider/useGetMany.d.ts +49 -0
- package/dist/ra-core/src/dataProvider/useGetMany.js +143 -0
- package/dist/ra-core/src/dataProvider/useGetManyAggregate.d.ts +62 -0
- package/dist/ra-core/src/dataProvider/useGetManyAggregate.js +295 -0
- package/dist/ra-core/src/dataProvider/useGetManyReference.d.ts +62 -0
- package/dist/ra-core/src/dataProvider/useGetManyReference.js +117 -0
- package/dist/ra-core/src/dataProvider/useGetOne.d.ts +48 -0
- package/dist/ra-core/src/dataProvider/useGetOne.js +94 -0
- package/dist/ra-core/src/dataProvider/useGetRecordId.d.ts +14 -0
- package/dist/ra-core/src/dataProvider/useGetRecordId.js +22 -0
- package/dist/ra-core/src/dataProvider/useInfiniteGetList.d.ts +64 -0
- package/dist/ra-core/src/dataProvider/useInfiniteGetList.js +177 -0
- package/dist/ra-core/src/dataProvider/useIsDataLoaded.d.ts +13 -0
- package/dist/ra-core/src/dataProvider/useIsDataLoaded.js +35 -0
- package/dist/ra-core/src/dataProvider/useLoading.d.ts +12 -0
- package/dist/ra-core/src/dataProvider/useLoading.js +41 -0
- package/dist/ra-core/src/dataProvider/useMutationWithMutationMode.d.ts +51 -0
- package/dist/ra-core/src/dataProvider/useMutationWithMutationMode.js +238 -0
- package/dist/ra-core/src/dataProvider/useRefresh.d.ts +14 -0
- package/dist/ra-core/src/dataProvider/useRefresh.js +21 -0
- package/dist/ra-core/src/dataProvider/useUpdate.d.ts +89 -0
- package/dist/ra-core/src/dataProvider/useUpdate.js +183 -0
- package/dist/ra-core/src/dataProvider/useUpdateMany.d.ts +81 -0
- package/dist/ra-core/src/dataProvider/useUpdateMany.js +171 -0
- package/dist/ra-core/src/dataProvider/validateResponseFormat.d.ts +5 -0
- package/dist/ra-core/src/dataProvider/validateResponseFormat.js +35 -0
- package/dist/ra-core/src/dataProvider/withLifecycleCallbacks.d.ts +162 -0
- package/dist/ra-core/src/dataProvider/withLifecycleCallbacks.js +377 -0
- package/dist/ra-core/src/dataTable/DataTableCallbacksContext.d.ts +18 -0
- package/dist/ra-core/src/dataTable/DataTableCallbacksContext.js +3 -0
- package/dist/ra-core/src/dataTable/DataTableColumnFilterContext.d.ts +2 -0
- package/dist/ra-core/src/dataTable/DataTableColumnFilterContext.js +3 -0
- package/dist/ra-core/src/dataTable/DataTableColumnRankContext.d.ts +2 -0
- package/dist/ra-core/src/dataTable/DataTableColumnRankContext.js +3 -0
- package/dist/ra-core/src/dataTable/DataTableConfigContext.d.ts +22 -0
- package/dist/ra-core/src/dataTable/DataTableConfigContext.js +7 -0
- package/dist/ra-core/src/dataTable/DataTableDataContext.d.ts +4 -0
- package/dist/ra-core/src/dataTable/DataTableDataContext.js +3 -0
- package/dist/ra-core/src/dataTable/DataTableRenderContext.d.ts +3 -0
- package/dist/ra-core/src/dataTable/DataTableRenderContext.js +3 -0
- package/dist/ra-core/src/dataTable/DataTableSelectedIdsContext.d.ts +3 -0
- package/dist/ra-core/src/dataTable/DataTableSelectedIdsContext.js +3 -0
- package/dist/ra-core/src/dataTable/DataTableSortContext.d.ts +3 -0
- package/dist/ra-core/src/dataTable/DataTableSortContext.js +3 -0
- package/dist/ra-core/src/dataTable/DataTableStoreContext.d.ts +8 -0
- package/dist/ra-core/src/dataTable/DataTableStoreContext.js +6 -0
- package/dist/ra-core/src/dataTable/index.d.ts +11 -0
- package/dist/ra-core/src/dataTable/index.js +11 -0
- package/dist/ra-core/src/dataTable/types.d.ts +2 -0
- package/dist/ra-core/src/dataTable/types.js +1 -0
- package/dist/ra-core/src/export/ExporterContext.d.ts +2 -0
- package/dist/ra-core/src/export/ExporterContext.js +4 -0
- package/dist/ra-core/src/export/defaultExporter.d.ts +2 -0
- package/dist/ra-core/src/export/defaultExporter.js +3 -0
- package/dist/ra-core/src/export/downloadCSV.d.ts +1 -0
- package/dist/ra-core/src/export/downloadCSV.js +17 -0
- package/dist/ra-core/src/export/fetchRelatedRecords.d.ts +14 -0
- package/dist/ra-core/src/export/fetchRelatedRecords.js +19 -0
- package/dist/ra-core/src/export/getRelatedIds.d.ts +24 -0
- package/dist/ra-core/src/export/getRelatedIds.js +26 -0
- package/dist/ra-core/src/export/index.d.ts +5 -0
- package/dist/ra-core/src/export/index.js +5 -0
- package/dist/ra-core/src/export/useBulkExport.d.ts +11 -0
- package/dist/ra-core/src/export/useBulkExport.js +30 -0
- package/dist/ra-core/src/form/WarnWhenUnsavedChanges.d.ts +5 -0
- package/dist/ra-core/src/form/WarnWhenUnsavedChanges.js +5 -0
- package/dist/ra-core/src/form/choices/ChoicesContext.d.ts +65 -0
- package/dist/ra-core/src/form/choices/ChoicesContext.js +7 -0
- package/dist/ra-core/src/form/choices/index.d.ts +4 -0
- package/dist/ra-core/src/form/choices/index.js +4 -0
- package/dist/ra-core/src/form/choices/useChoicesContext.d.ts +5 -0
- package/dist/ra-core/src/form/choices/useChoicesContext.js +62 -0
- package/dist/ra-core/src/form/getFormInitialValues.d.ts +8 -0
- package/dist/ra-core/src/form/getFormInitialValues.js +14 -0
- package/dist/ra-core/src/form/groups/FormGroupContext.d.ts +9 -0
- package/dist/ra-core/src/form/groups/FormGroupContext.js +9 -0
- package/dist/ra-core/src/form/groups/index.d.ts +6 -0
- package/dist/ra-core/src/form/groups/index.js +6 -0
- package/dist/ra-core/src/form/groups/useFormGroup.d.ts +67 -0
- package/dist/ra-core/src/form/groups/useFormGroup.js +146 -0
- package/dist/ra-core/src/form/groups/useFormGroupContext.d.ts +4 -0
- package/dist/ra-core/src/form/groups/useFormGroupContext.js +9 -0
- package/dist/ra-core/src/form/groups/useFormGroups.d.ts +4 -0
- package/dist/ra-core/src/form/groups/useFormGroups.js +9 -0
- package/dist/ra-core/src/form/index.d.ts +14 -0
- package/dist/ra-core/src/form/index.js +14 -0
- package/dist/ra-core/src/form/sanitizeEmptyValues.d.ts +7 -0
- package/dist/ra-core/src/form/sanitizeEmptyValues.js +26 -0
- package/dist/ra-core/src/form/useApplyInputDefaultValues.d.ts +19 -0
- package/dist/ra-core/src/form/useApplyInputDefaultValues.js +71 -0
- package/dist/ra-core/src/form/useAugmentedForm.d.ts +32 -0
- package/dist/ra-core/src/form/useAugmentedForm.js +101 -0
- package/dist/ra-core/src/form/useFormIsDirty.d.ts +4 -0
- package/dist/ra-core/src/form/useFormIsDirty.js +39 -0
- package/dist/ra-core/src/form/useInput.d.ts +33 -0
- package/dist/ra-core/src/form/useInput.js +100 -0
- package/dist/ra-core/src/form/useRecordFromLocation.d.ts +22 -0
- package/dist/ra-core/src/form/useRecordFromLocation.js +59 -0
- package/dist/ra-core/src/form/useSuggestions.d.ts +43 -0
- package/dist/ra-core/src/form/useSuggestions.js +186 -0
- package/dist/ra-core/src/form/validation/getSimpleValidationResolver.d.ts +31 -0
- package/dist/ra-core/src/form/validation/getSimpleValidationResolver.js +87 -0
- package/dist/ra-core/src/form/validation/index.d.ts +7 -0
- package/dist/ra-core/src/form/validation/index.js +7 -0
- package/dist/ra-core/src/form/validation/setSubmissionErrors.d.ts +21 -0
- package/dist/ra-core/src/form/validation/setSubmissionErrors.js +34 -0
- package/dist/ra-core/src/form/validation/useGetValidationErrorMessage.d.ts +26 -0
- package/dist/ra-core/src/form/validation/useGetValidationErrorMessage.js +35 -0
- package/dist/ra-core/src/form/validation/useNotifyIsFormInvalid.d.ts +9 -0
- package/dist/ra-core/src/form/validation/useNotifyIsFormInvalid.js +30 -0
- package/dist/ra-core/src/form/validation/useUnique.d.ts +57 -0
- package/dist/ra-core/src/form/validation/useUnique.js +107 -0
- package/dist/ra-core/src/form/validation/validate.d.ts +168 -0
- package/dist/ra-core/src/form/validation/validate.js +218 -0
- package/dist/ra-core/src/i18n/I18nContext.d.ts +3 -0
- package/dist/ra-core/src/i18n/I18nContext.js +11 -0
- package/dist/ra-core/src/i18n/TranslatableContext.d.ts +16 -0
- package/dist/ra-core/src/i18n/TranslatableContext.js +2 -0
- package/dist/ra-core/src/i18n/TranslationMessages.d.ts +221 -0
- package/dist/ra-core/src/i18n/TranslationMessages.js +1 -0
- package/dist/ra-core/src/i18n/TranslationUtils.d.ts +60 -0
- package/dist/ra-core/src/i18n/TranslationUtils.js +70 -0
- package/dist/ra-core/src/i18n/index.d.ts +20 -0
- package/dist/ra-core/src/i18n/index.js +20 -0
- package/dist/ra-core/src/i18n/substituteTokens.d.ts +8 -0
- package/dist/ra-core/src/i18n/substituteTokens.js +18 -0
- package/dist/ra-core/src/i18n/useI18nProvider.d.ts +12 -0
- package/dist/ra-core/src/i18n/useI18nProvider.js +14 -0
- package/dist/ra-core/src/i18n/useLocales.d.ts +31 -0
- package/dist/ra-core/src/i18n/useLocales.js +28 -0
- package/dist/ra-core/src/i18n/useResourceTranslation.d.ts +8 -0
- package/dist/ra-core/src/i18n/useResourceTranslation.js +18 -0
- package/dist/ra-core/src/i18n/useTranslatable.d.ts +29 -0
- package/dist/ra-core/src/i18n/useTranslatable.js +98 -0
- package/dist/ra-core/src/i18n/useTranslatableContext.d.ts +31 -0
- package/dist/ra-core/src/i18n/useTranslatableContext.js +38 -0
- package/dist/ra-core/src/i18n/useTranslate.d.ts +21 -0
- package/dist/ra-core/src/i18n/useTranslate.js +29 -0
- package/dist/ra-core/src/i18n/useTranslateLabel.d.ts +6 -0
- package/dist/ra-core/src/i18n/useTranslateLabel.js +26 -0
- package/dist/ra-core/src/index.d.ts +16 -0
- package/dist/ra-core/src/index.js +16 -0
- package/dist/ra-core/src/inference/InferredElement.d.ts +12 -0
- package/dist/ra-core/src/inference/InferredElement.js +40 -0
- package/dist/ra-core/src/inference/assertions.d.ts +26 -0
- package/dist/ra-core/src/inference/assertions.js +38 -0
- package/dist/ra-core/src/inference/getElementsFromRecords.d.ts +35 -0
- package/dist/ra-core/src/inference/getElementsFromRecords.js +39 -0
- package/dist/ra-core/src/inference/getValuesFromRecords.d.ts +28 -0
- package/dist/ra-core/src/inference/getValuesFromRecords.js +40 -0
- package/dist/ra-core/src/inference/index.d.ts +6 -0
- package/dist/ra-core/src/inference/index.js +6 -0
- package/dist/ra-core/src/inference/inferTypeFromValues.d.ts +21 -0
- package/dist/ra-core/src/inference/inferTypeFromValues.js +141 -0
- package/dist/ra-core/src/inference/types.d.ts +9 -0
- package/dist/ra-core/src/inference/types.js +1 -0
- package/dist/ra-core/src/notification/CloseNotificationContext.d.ts +2 -0
- package/dist/ra-core/src/notification/CloseNotificationContext.js +2 -0
- package/dist/ra-core/src/notification/NotificationContext.d.ts +37 -0
- package/dist/ra-core/src/notification/NotificationContext.js +35 -0
- package/dist/ra-core/src/notification/index.d.ts +9 -0
- package/dist/ra-core/src/notification/index.js +9 -0
- package/dist/ra-core/src/notification/types.d.ts +14 -0
- package/dist/ra-core/src/notification/types.js +1 -0
- package/dist/ra-core/src/notification/useCloseNotification.d.ts +1 -0
- package/dist/ra-core/src/notification/useCloseNotification.js +9 -0
- package/dist/ra-core/src/notification/useNotificationContext.d.ts +1 -0
- package/dist/ra-core/src/notification/useNotificationContext.js +3 -0
- package/dist/ra-core/src/notification/useNotify.d.ts +20 -0
- package/dist/ra-core/src/notification/useNotify.js +28 -0
- package/dist/ra-core/src/preferences/index.d.ts +7 -0
- package/dist/ra-core/src/preferences/index.js +7 -0
- package/dist/ra-core/src/preferences/usePreference.d.ts +18 -0
- package/dist/ra-core/src/preferences/usePreference.js +10 -0
- package/dist/ra-core/src/preferences/usePreferenceInput.d.ts +22 -0
- package/dist/ra-core/src/preferences/usePreferenceInput.js +43 -0
- package/dist/ra-core/src/preferences/usePreferencesEditor.d.ts +2 -0
- package/dist/ra-core/src/preferences/usePreferencesEditor.js +9 -0
- package/dist/ra-core/src/preferences/useSetInspectorTitle.d.ts +7 -0
- package/dist/ra-core/src/preferences/useSetInspectorTitle.js +19 -0
- package/dist/ra-core/src/routing/BasenameContext.d.ts +1 -0
- package/dist/ra-core/src/routing/BasenameContext.js +2 -0
- package/dist/ra-core/src/routing/RouterProvider.d.ts +163 -0
- package/dist/ra-core/src/routing/RouterProvider.js +1 -0
- package/dist/ra-core/src/routing/index.d.ts +28 -0
- package/dist/ra-core/src/routing/index.js +28 -0
- package/dist/ra-core/src/routing/types.d.ts +3 -0
- package/dist/ra-core/src/routing/types.js +1 -0
- package/dist/ra-core/src/routing/useBasename.d.ts +21 -0
- package/dist/ra-core/src/routing/useBasename.js +23 -0
- package/dist/ra-core/src/routing/useBlocker.d.ts +14 -0
- package/dist/ra-core/src/routing/useBlocker.js +17 -0
- package/dist/ra-core/src/routing/useCanBlock.d.ts +7 -0
- package/dist/ra-core/src/routing/useCanBlock.js +11 -0
- package/dist/ra-core/src/routing/useCreatePath.d.ts +42 -0
- package/dist/ra-core/src/routing/useCreatePath.js +69 -0
- package/dist/ra-core/src/routing/useGetPathForRecord.d.ts +42 -0
- package/dist/ra-core/src/routing/useGetPathForRecord.js +135 -0
- package/dist/ra-core/src/routing/useGetPathForRecordCallback.d.ts +6 -0
- package/dist/ra-core/src/routing/useGetPathForRecordCallback.js +82 -0
- package/dist/ra-core/src/routing/useInRouterContext.d.ts +11 -0
- package/dist/ra-core/src/routing/useInRouterContext.js +15 -0
- package/dist/ra-core/src/routing/useLocation.d.ts +10 -0
- package/dist/ra-core/src/routing/useLocation.js +13 -0
- package/dist/ra-core/src/routing/useMatch.d.ts +15 -0
- package/dist/ra-core/src/routing/useMatch.js +15 -0
- package/dist/ra-core/src/routing/useMatchPath.d.ts +17 -0
- package/dist/ra-core/src/routing/useMatchPath.js +17 -0
- package/dist/ra-core/src/routing/useNavigate.d.ts +12 -0
- package/dist/ra-core/src/routing/useNavigate.js +15 -0
- package/dist/ra-core/src/routing/useParams.d.ts +9 -0
- package/dist/ra-core/src/routing/useParams.js +13 -0
- package/dist/ra-core/src/routing/useRedirect.d.ts +30 -0
- package/dist/ra-core/src/routing/useRedirect.js +66 -0
- package/dist/ra-core/src/routing/useResetErrorBoundaryOnLocationChange.d.ts +7 -0
- package/dist/ra-core/src/routing/useResetErrorBoundaryOnLocationChange.js +17 -0
- package/dist/ra-core/src/routing/useRestoreScrollPosition.d.ts +40 -0
- package/dist/ra-core/src/routing/useRestoreScrollPosition.js +70 -0
- package/dist/ra-core/src/routing/useSplatPathBase.d.ts +13 -0
- package/dist/ra-core/src/routing/useSplatPathBase.js +21 -0
- package/dist/ra-core/src/store/index.d.ts +11 -0
- package/dist/ra-core/src/store/index.js +11 -0
- package/dist/ra-core/src/store/localStorageStore.d.ts +27 -0
- package/dist/ra-core/src/store/localStorageStore.js +198 -0
- package/dist/ra-core/src/store/types.d.ts +11 -0
- package/dist/ra-core/src/store/types.js +1 -0
- package/dist/ra-core/src/store/useRemoveFromStore.d.ts +17 -0
- package/dist/ra-core/src/store/useRemoveFromStore.js +29 -0
- package/dist/ra-core/src/store/useRemoveItemsFromStore.d.ts +17 -0
- package/dist/ra-core/src/store/useRemoveItemsFromStore.js +29 -0
- package/dist/ra-core/src/store/useResetStore.d.ts +17 -0
- package/dist/ra-core/src/store/useResetStore.js +21 -0
- package/dist/ra-core/src/store/useStore.d.ts +48 -0
- package/dist/ra-core/src/store/useStore.js +32 -0
- package/dist/ra-core/src/store/useStoreContext.d.ts +4 -0
- package/dist/ra-core/src/store/useStoreContext.js +6 -0
- package/dist/ra-core/src/test-ui/defaultI18nProvider.d.ts +2 -0
- package/dist/ra-core/src/test-ui/defaultI18nProvider.js +10 -0
- package/dist/ra-core/src/test-ui/index.d.ts +21 -0
- package/dist/ra-core/src/test-ui/index.js +21 -0
- package/dist/ra-core/src/types.d.ts +284 -0
- package/dist/ra-core/src/types.js +5 -0
- package/dist/ra-core/src/util/asyncDebounce.d.ts +7 -0
- package/dist/ra-core/src/util/asyncDebounce.js +29 -0
- package/dist/ra-core/src/util/escapePath.d.ts +11 -0
- package/dist/ra-core/src/util/escapePath.js +10 -0
- package/dist/ra-core/src/util/genericMemo.d.ts +5 -0
- package/dist/ra-core/src/util/genericMemo.js +14 -0
- package/dist/ra-core/src/util/getFieldLabelTranslationArgs.d.ts +22 -0
- package/dist/ra-core/src/util/getFieldLabelTranslationArgs.js +73 -0
- package/dist/ra-core/src/util/getMutationMode.d.ts +1 -0
- package/dist/ra-core/src/util/getMutationMode.js +13 -0
- package/dist/ra-core/src/util/hooks.d.ts +15 -0
- package/dist/ra-core/src/util/hooks.js +73 -0
- package/dist/ra-core/src/util/index.d.ts +20 -0
- package/dist/ra-core/src/util/index.js +19 -0
- package/dist/ra-core/src/util/mergeRefs.d.ts +2 -0
- package/dist/ra-core/src/util/mergeRefs.js +13 -0
- package/dist/ra-core/src/util/removeEmpty.d.ts +2 -0
- package/dist/ra-core/src/util/removeEmpty.js +16 -0
- package/dist/ra-core/src/util/removeKey.d.ts +2 -0
- package/dist/ra-core/src/util/removeKey.js +22 -0
- package/dist/ra-core/src/util/shallowEqual.d.ts +1 -0
- package/dist/ra-core/src/util/shallowEqual.js +29 -0
- package/dist/ra-core/src/util/useCheckForApplicationUpdate.d.ts +21 -0
- package/dist/ra-core/src/util/useCheckForApplicationUpdate.js +84 -0
- package/dist/ra-core/src/util/useDebouncedEvent.d.ts +8 -0
- package/dist/ra-core/src/util/useDebouncedEvent.js +28 -0
- package/dist/ra-core/src/util/useEvent.d.ts +7 -0
- package/dist/ra-core/src/util/useEvent.js +19 -0
- package/dist/ra-core/src/util/useFieldValue.d.ts +21 -0
- package/dist/ra-core/src/util/useFieldValue.js +27 -0
- package/dist/ra-core/src/util/useWhyDidYouUpdate.d.ts +12 -0
- package/dist/ra-core/src/util/useWhyDidYouUpdate.js +42 -0
- package/dist/ra-core/src/util/warning.d.ts +2 -0
- package/dist/ra-core/src/util/warning.js +5 -0
- package/dist/strato-faker-ecommerce/src/dataProvider.d.ts +2 -0
- package/dist/strato-faker-ecommerce/src/dataProvider.js +6 -0
- package/dist/strato-faker-ecommerce/src/generate.d.ts +8 -0
- package/dist/strato-faker-ecommerce/src/generate.js +148 -0
- package/dist/strato-faker-ecommerce/src/index.d.ts +3 -0
- package/dist/strato-faker-ecommerce/src/index.js +3 -0
- package/dist/strato-faker-ecommerce/src/types.d.ts +69 -0
- package/dist/strato-faker-ecommerce/src/types.js +1 -0
- package/dist/types.d.ts +1 -1
- package/package.json +5 -4
- package/src/dataProvider.ts +3 -3
- package/src/generate.test.ts +12 -12
- package/src/generate.ts +21 -14
- package/src/types.ts +1 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { InfiniteData, QueryKey, UseInfiniteQueryOptions, UseInfiniteQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import { RaRecord, GetListParams, GetInfiniteListResult } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Call the dataProvider.getList() method and return the resolved result
|
|
5
|
+
* as well as the loading state. The return from useInfiniteGetList is equivalent to the return from react-hook form useInfiniteQuery.
|
|
6
|
+
*
|
|
7
|
+
* @see https://tanstack.com/query/v5/docs/react/reference/useInfiniteQuery
|
|
8
|
+
*
|
|
9
|
+
* This hook will return the cached result when called a second time
|
|
10
|
+
* with the same parameters, until the response arrives.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} resource The resource name, e.g. 'posts'
|
|
13
|
+
* @param {Params} params The getList parameters { pagination, sort, filter, meta }
|
|
14
|
+
* @param {Object} options Options object to pass to the queryClient.
|
|
15
|
+
* May include side effects to be executed upon success or failure, e.g. { onSuccess: () => { fetchNextPage(); } }
|
|
16
|
+
*
|
|
17
|
+
* @typedef Params
|
|
18
|
+
* @prop params.pagination The request pagination { page, perPage }, e.g. { page: 1, perPage: 10 }
|
|
19
|
+
* @prop params.sort The request sort { field, order }, e.g. { field: 'id', order: 'DESC' }
|
|
20
|
+
* @prop params.filter The request filters, e.g. { title: 'hello, world' }
|
|
21
|
+
* @prop params.meta Optional meta parameters
|
|
22
|
+
*
|
|
23
|
+
* @returns The current request state. Destructure as { data, total, error, isPending, isSuccess, hasNextPage, fetchNextPage }.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
*
|
|
27
|
+
* import { useInfiniteGetList } from 'react-admin';
|
|
28
|
+
*
|
|
29
|
+
* const LatestNews = () => {
|
|
30
|
+
* const { data, total, isPending, error, hasNextPage, fetchNextPage } = useInfiniteGetList(
|
|
31
|
+
* 'posts',
|
|
32
|
+
* { pagination: { page: 1, perPage: 10 }, sort: { field: 'published_at', order: 'DESC' } }
|
|
33
|
+
* );
|
|
34
|
+
* if (isPending) { return <Loading />; }
|
|
35
|
+
* if (error) { return <p>ERROR</p>; }
|
|
36
|
+
* return (
|
|
37
|
+
* <>
|
|
38
|
+
* <ul>
|
|
39
|
+
* {data?.pages.map(page => {
|
|
40
|
+
* return page.data.map(post => (
|
|
41
|
+
* <li key={post.id}>{post.title}</li>
|
|
42
|
+
* ));
|
|
43
|
+
* })}
|
|
44
|
+
* </ul>
|
|
45
|
+
* <div>
|
|
46
|
+
* <button disabled={!hasNextPage} onClick={() => fetchNextPage()}>
|
|
47
|
+
* Fetch next page
|
|
48
|
+
* </button>
|
|
49
|
+
* </div>
|
|
50
|
+
* </>
|
|
51
|
+
* );
|
|
52
|
+
* };
|
|
53
|
+
*/
|
|
54
|
+
export declare const useInfiniteGetList: <RecordType extends RaRecord = any, ErrorType = Error>(resource: string, params?: Partial<GetListParams>, options?: UseInfiniteGetListOptions<RecordType, ErrorType>) => UseInfiniteGetListHookValue<RecordType, ErrorType>;
|
|
55
|
+
export type UseInfiniteGetListOptions<RecordType extends RaRecord = any, ErrorType = Error> = Omit<UseInfiniteQueryOptions<GetInfiniteListResult<RecordType>, ErrorType, InfiniteData<GetInfiniteListResult<RecordType>>, QueryKey, number>, 'queryKey' | 'queryFn' | 'getNextPageParam' | 'getPreviousPageParam' | 'initialPageParam'> & {
|
|
56
|
+
onSuccess?: (data: InfiniteData<GetInfiniteListResult<RecordType>>) => void;
|
|
57
|
+
onError?: (error: ErrorType) => void;
|
|
58
|
+
onSettled?: (data?: InfiniteData<GetInfiniteListResult<RecordType>>, error?: ErrorType | null) => void;
|
|
59
|
+
};
|
|
60
|
+
export type UseInfiniteGetListHookValue<RecordType extends RaRecord = any, ErrorType = Error> = UseInfiniteQueryResult<InfiniteData<GetInfiniteListResult<RecordType>>, ErrorType> & {
|
|
61
|
+
total?: number;
|
|
62
|
+
pageParam?: number;
|
|
63
|
+
meta?: any;
|
|
64
|
+
};
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { useInfiniteQuery, useQueryClient, } from '@tanstack/react-query';
|
|
2
|
+
import { useDataProvider } from './useDataProvider';
|
|
3
|
+
import { useEffect, useRef } from 'react';
|
|
4
|
+
import { useEvent } from '../util';
|
|
5
|
+
const MAX_DATA_LENGTH_TO_CACHE = 100;
|
|
6
|
+
/**
|
|
7
|
+
* Call the dataProvider.getList() method and return the resolved result
|
|
8
|
+
* as well as the loading state. The return from useInfiniteGetList is equivalent to the return from react-hook form useInfiniteQuery.
|
|
9
|
+
*
|
|
10
|
+
* @see https://tanstack.com/query/v5/docs/react/reference/useInfiniteQuery
|
|
11
|
+
*
|
|
12
|
+
* This hook will return the cached result when called a second time
|
|
13
|
+
* with the same parameters, until the response arrives.
|
|
14
|
+
*
|
|
15
|
+
* @param {string} resource The resource name, e.g. 'posts'
|
|
16
|
+
* @param {Params} params The getList parameters { pagination, sort, filter, meta }
|
|
17
|
+
* @param {Object} options Options object to pass to the queryClient.
|
|
18
|
+
* May include side effects to be executed upon success or failure, e.g. { onSuccess: () => { fetchNextPage(); } }
|
|
19
|
+
*
|
|
20
|
+
* @typedef Params
|
|
21
|
+
* @prop params.pagination The request pagination { page, perPage }, e.g. { page: 1, perPage: 10 }
|
|
22
|
+
* @prop params.sort The request sort { field, order }, e.g. { field: 'id', order: 'DESC' }
|
|
23
|
+
* @prop params.filter The request filters, e.g. { title: 'hello, world' }
|
|
24
|
+
* @prop params.meta Optional meta parameters
|
|
25
|
+
*
|
|
26
|
+
* @returns The current request state. Destructure as { data, total, error, isPending, isSuccess, hasNextPage, fetchNextPage }.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
*
|
|
30
|
+
* import { useInfiniteGetList } from 'react-admin';
|
|
31
|
+
*
|
|
32
|
+
* const LatestNews = () => {
|
|
33
|
+
* const { data, total, isPending, error, hasNextPage, fetchNextPage } = useInfiniteGetList(
|
|
34
|
+
* 'posts',
|
|
35
|
+
* { pagination: { page: 1, perPage: 10 }, sort: { field: 'published_at', order: 'DESC' } }
|
|
36
|
+
* );
|
|
37
|
+
* if (isPending) { return <Loading />; }
|
|
38
|
+
* if (error) { return <p>ERROR</p>; }
|
|
39
|
+
* return (
|
|
40
|
+
* <>
|
|
41
|
+
* <ul>
|
|
42
|
+
* {data?.pages.map(page => {
|
|
43
|
+
* return page.data.map(post => (
|
|
44
|
+
* <li key={post.id}>{post.title}</li>
|
|
45
|
+
* ));
|
|
46
|
+
* })}
|
|
47
|
+
* </ul>
|
|
48
|
+
* <div>
|
|
49
|
+
* <button disabled={!hasNextPage} onClick={() => fetchNextPage()}>
|
|
50
|
+
* Fetch next page
|
|
51
|
+
* </button>
|
|
52
|
+
* </div>
|
|
53
|
+
* </>
|
|
54
|
+
* );
|
|
55
|
+
* };
|
|
56
|
+
*/
|
|
57
|
+
export const useInfiniteGetList = (resource, params = {}, options = {}) => {
|
|
58
|
+
const { pagination = { page: 1, perPage: 25 }, sort = { field: 'id', order: 'DESC' }, filter = {}, meta, } = params;
|
|
59
|
+
const dataProvider = useDataProvider();
|
|
60
|
+
const queryClient = useQueryClient();
|
|
61
|
+
const { onSuccess = noop, onError = noop, onSettled = noop, ...queryOptions } = options;
|
|
62
|
+
const onSuccessEvent = useEvent(onSuccess);
|
|
63
|
+
const onErrorEvent = useEvent(onError);
|
|
64
|
+
const onSettledEvent = useEvent(onSettled);
|
|
65
|
+
const result = useInfiniteQuery({
|
|
66
|
+
queryKey: [
|
|
67
|
+
resource,
|
|
68
|
+
'getInfiniteList',
|
|
69
|
+
{ pagination, sort, filter, meta },
|
|
70
|
+
],
|
|
71
|
+
queryFn: queryParams => {
|
|
72
|
+
const { pageParam = pagination.page } = queryParams;
|
|
73
|
+
return dataProvider
|
|
74
|
+
.getList(resource, {
|
|
75
|
+
pagination: {
|
|
76
|
+
page: pageParam,
|
|
77
|
+
perPage: pagination.perPage,
|
|
78
|
+
},
|
|
79
|
+
sort,
|
|
80
|
+
filter,
|
|
81
|
+
meta,
|
|
82
|
+
signal: dataProvider.supportAbortSignal === true
|
|
83
|
+
? queryParams.signal
|
|
84
|
+
: undefined,
|
|
85
|
+
})
|
|
86
|
+
.then(({ data, pageInfo, total, meta }) => ({
|
|
87
|
+
data,
|
|
88
|
+
total,
|
|
89
|
+
pageParam,
|
|
90
|
+
pageInfo,
|
|
91
|
+
meta,
|
|
92
|
+
}));
|
|
93
|
+
},
|
|
94
|
+
initialPageParam: pagination.page,
|
|
95
|
+
...queryOptions,
|
|
96
|
+
getNextPageParam: lastLoadedPage => {
|
|
97
|
+
if (lastLoadedPage.pageInfo) {
|
|
98
|
+
return lastLoadedPage.pageInfo.hasNextPage
|
|
99
|
+
? lastLoadedPage.pageParam + 1
|
|
100
|
+
: undefined;
|
|
101
|
+
}
|
|
102
|
+
const totalPages = Math.ceil((lastLoadedPage.total || 0) / pagination.perPage);
|
|
103
|
+
return lastLoadedPage.pageParam < totalPages
|
|
104
|
+
? Number(lastLoadedPage.pageParam) + 1
|
|
105
|
+
: undefined;
|
|
106
|
+
},
|
|
107
|
+
getPreviousPageParam: lastLoadedPage => {
|
|
108
|
+
if (lastLoadedPage.pageInfo) {
|
|
109
|
+
return lastLoadedPage.pageInfo.hasPreviousPage
|
|
110
|
+
? lastLoadedPage.pageParam - 1
|
|
111
|
+
: undefined;
|
|
112
|
+
}
|
|
113
|
+
return lastLoadedPage.pageParam === 1
|
|
114
|
+
? undefined
|
|
115
|
+
: lastLoadedPage.pageParam - 1;
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
const metaValue = useRef(meta);
|
|
119
|
+
const resourceValue = useRef(resource);
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
metaValue.current = meta;
|
|
122
|
+
}, [meta]);
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
resourceValue.current = resource;
|
|
125
|
+
}, [resource]);
|
|
126
|
+
useEffect(() => {
|
|
127
|
+
if (result.data === undefined ||
|
|
128
|
+
result.error != null ||
|
|
129
|
+
result.isFetching)
|
|
130
|
+
return;
|
|
131
|
+
// optimistically populate the getOne cache
|
|
132
|
+
const allPagesDataLength = result.data.pages.reduce((acc, page) => acc + page.data.length, 0);
|
|
133
|
+
if (allPagesDataLength <= MAX_DATA_LENGTH_TO_CACHE) {
|
|
134
|
+
result.data.pages.forEach(page => {
|
|
135
|
+
page.data.forEach(record => {
|
|
136
|
+
queryClient.setQueryData([
|
|
137
|
+
resourceValue.current,
|
|
138
|
+
'getOne',
|
|
139
|
+
{ id: String(record.id), meta: metaValue.current },
|
|
140
|
+
], oldRecord => oldRecord ?? record);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
onSuccessEvent(result.data);
|
|
145
|
+
}, [
|
|
146
|
+
onSuccessEvent,
|
|
147
|
+
queryClient,
|
|
148
|
+
result.data,
|
|
149
|
+
result.error,
|
|
150
|
+
result.isFetching,
|
|
151
|
+
]);
|
|
152
|
+
useEffect(() => {
|
|
153
|
+
if (result.error == null || result.isFetching)
|
|
154
|
+
return;
|
|
155
|
+
onErrorEvent(result.error);
|
|
156
|
+
}, [onErrorEvent, result.error, result.isFetching]);
|
|
157
|
+
useEffect(() => {
|
|
158
|
+
if (result.status === 'pending' || result.isFetching)
|
|
159
|
+
return;
|
|
160
|
+
onSettledEvent(result.data, result.error);
|
|
161
|
+
}, [
|
|
162
|
+
onSettledEvent,
|
|
163
|
+
result.data,
|
|
164
|
+
result.error,
|
|
165
|
+
result.status,
|
|
166
|
+
result.isFetching,
|
|
167
|
+
]);
|
|
168
|
+
return (result.data
|
|
169
|
+
? {
|
|
170
|
+
...result,
|
|
171
|
+
data: result.data,
|
|
172
|
+
total: result.data?.pages[0]?.total ?? undefined,
|
|
173
|
+
meta: result.data?.pages[0]?.meta,
|
|
174
|
+
}
|
|
175
|
+
: result);
|
|
176
|
+
};
|
|
177
|
+
const noop = () => undefined;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if react-query has already fetched data for a query key.
|
|
3
|
+
*
|
|
4
|
+
* This hook is reactive.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* const isCustomerLoaded = useIsDataLoaded(['customers', 'getOne', { id: customerId }]);
|
|
8
|
+
*
|
|
9
|
+
* @returns {boolean} true if the data is loaded, false otherwise
|
|
10
|
+
*/
|
|
11
|
+
export declare const useIsDataLoaded: (queryKey: any, options?: {
|
|
12
|
+
enabled?: boolean;
|
|
13
|
+
}) => boolean;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { useQueryClient, QueryObserver } from '@tanstack/react-query';
|
|
3
|
+
/**
|
|
4
|
+
* Check if react-query has already fetched data for a query key.
|
|
5
|
+
*
|
|
6
|
+
* This hook is reactive.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const isCustomerLoaded = useIsDataLoaded(['customers', 'getOne', { id: customerId }]);
|
|
10
|
+
*
|
|
11
|
+
* @returns {boolean} true if the data is loaded, false otherwise
|
|
12
|
+
*/
|
|
13
|
+
export const useIsDataLoaded = (queryKey, options = {}) => {
|
|
14
|
+
const { enabled = true } = options;
|
|
15
|
+
const queryClient = useQueryClient();
|
|
16
|
+
const [isDataLoaded, setDataLoaded] = useState(() => {
|
|
17
|
+
if (!enabled) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return queryClient.getQueryData(queryKey) !== undefined;
|
|
21
|
+
});
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!enabled)
|
|
24
|
+
return;
|
|
25
|
+
if (queryClient.getQueryData(queryKey) === undefined) {
|
|
26
|
+
const observer = new QueryObserver(queryClient, { queryKey });
|
|
27
|
+
const unsubscribe = observer.subscribe(result => {
|
|
28
|
+
setDataLoaded(!result.isPending);
|
|
29
|
+
unsubscribe();
|
|
30
|
+
});
|
|
31
|
+
return unsubscribe;
|
|
32
|
+
}
|
|
33
|
+
}, [enabled, queryKey, queryClient]);
|
|
34
|
+
return isDataLoaded;
|
|
35
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the state of the dataProvider connection.
|
|
3
|
+
*
|
|
4
|
+
* Returns true if a query or a mutation is pending.
|
|
5
|
+
*
|
|
6
|
+
* Custom implementation because react-query's useIsFetching and useIsMutating
|
|
7
|
+
* render each time the number of active queries changes, which is too often.
|
|
8
|
+
*
|
|
9
|
+
* @see useIsFetching
|
|
10
|
+
* @see useIsMutating
|
|
11
|
+
*/
|
|
12
|
+
export declare const useLoading: () => boolean;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { notifyManager, useQueryClient } from '@tanstack/react-query';
|
|
3
|
+
/**
|
|
4
|
+
* Get the state of the dataProvider connection.
|
|
5
|
+
*
|
|
6
|
+
* Returns true if a query or a mutation is pending.
|
|
7
|
+
*
|
|
8
|
+
* Custom implementation because react-query's useIsFetching and useIsMutating
|
|
9
|
+
* render each time the number of active queries changes, which is too often.
|
|
10
|
+
*
|
|
11
|
+
* @see useIsFetching
|
|
12
|
+
* @see useIsMutating
|
|
13
|
+
*/
|
|
14
|
+
export const useLoading = () => {
|
|
15
|
+
const client = useQueryClient();
|
|
16
|
+
const mountedRef = React.useRef(false);
|
|
17
|
+
const isFetchingRef = React.useRef(client.isFetching() > 0);
|
|
18
|
+
const isMutatingRef = React.useRef(client.isMutating() > 0);
|
|
19
|
+
const [isLoading, setIsLoading] = React.useState(isFetchingRef.current || isMutatingRef.current);
|
|
20
|
+
React.useEffect(() => {
|
|
21
|
+
mountedRef.current = true;
|
|
22
|
+
const unsubscribeQueryCache = client.getQueryCache().subscribe(notifyManager.batchCalls(() => {
|
|
23
|
+
if (mountedRef.current) {
|
|
24
|
+
isFetchingRef.current = client.isFetching() > 0;
|
|
25
|
+
setIsLoading(isFetchingRef.current || isMutatingRef.current);
|
|
26
|
+
}
|
|
27
|
+
}));
|
|
28
|
+
const unsubscribeMutationCache = client.getMutationCache().subscribe(notifyManager.batchCalls(() => {
|
|
29
|
+
if (mountedRef.current) {
|
|
30
|
+
isMutatingRef.current = client.isMutating() > 0;
|
|
31
|
+
setIsLoading(isFetchingRef.current || isMutatingRef.current);
|
|
32
|
+
}
|
|
33
|
+
}));
|
|
34
|
+
return () => {
|
|
35
|
+
mountedRef.current = false;
|
|
36
|
+
unsubscribeQueryCache();
|
|
37
|
+
unsubscribeMutationCache();
|
|
38
|
+
};
|
|
39
|
+
}, [client]);
|
|
40
|
+
return isLoading;
|
|
41
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { UseMutationOptions, UseMutationResult, MutateOptions, QueryKey } from '@tanstack/react-query';
|
|
2
|
+
import { MutationMode } from '../types';
|
|
3
|
+
export declare const useMutationWithMutationMode: <ErrorType = Error, TData extends {
|
|
4
|
+
data?: unknown;
|
|
5
|
+
} = {
|
|
6
|
+
data?: unknown;
|
|
7
|
+
}, TVariables = unknown>(params: TVariables | undefined, options: UseMutationWithMutationModeOptions<ErrorType, TData, TVariables>) => UseMutationWithMutationModeResult<boolean, ErrorType, TData, TVariables>;
|
|
8
|
+
export type Snapshot = [key: QueryKey, value: any][];
|
|
9
|
+
type MutationFunction<TData extends {
|
|
10
|
+
data?: unknown;
|
|
11
|
+
} = {
|
|
12
|
+
data?: unknown;
|
|
13
|
+
}, TVariables = unknown> = (variables: TVariables) => Promise<TData>;
|
|
14
|
+
export type UseMutationWithMutationModeOptions<ErrorType = Error, TData extends {
|
|
15
|
+
data?: unknown;
|
|
16
|
+
} = {
|
|
17
|
+
data?: unknown;
|
|
18
|
+
}, TVariables = unknown> = Omit<UseMutationOptions<TData['data'], ErrorType, Partial<TVariables>>, 'mutationFn'> & {
|
|
19
|
+
getMutateWithMiddlewares?: (mutate: MutationFunction<TData, TVariables>) => (params: TVariables) => Promise<TData>;
|
|
20
|
+
mutationFn?: MutationFunction<TData, TVariables>;
|
|
21
|
+
mutationMode?: MutationMode;
|
|
22
|
+
returnPromise?: boolean;
|
|
23
|
+
updateCache: <OptionsType extends {
|
|
24
|
+
mutationMode: MutationMode;
|
|
25
|
+
}>(params: Partial<TVariables>, options: OptionsType, mutationResult: TData['data'] | undefined) => TData['data'];
|
|
26
|
+
getQueryKeys: <OptionsType extends {
|
|
27
|
+
mutationMode: MutationMode;
|
|
28
|
+
}>(params: Partial<TVariables>, options: OptionsType) => Array<QueryKey>;
|
|
29
|
+
onUndo?: <OptionsType extends {
|
|
30
|
+
mutationMode: MutationMode;
|
|
31
|
+
}>(params: Partial<TVariables>, options: OptionsType) => void;
|
|
32
|
+
};
|
|
33
|
+
export type MutationFunctionWithOptions<TReturnPromise extends boolean = boolean, ErrorType = Error, TData extends {
|
|
34
|
+
data?: unknown;
|
|
35
|
+
} = {
|
|
36
|
+
data?: unknown;
|
|
37
|
+
}, TVariables = unknown> = (params?: Partial<TVariables>, options?: MutateOptions<TData['data'], ErrorType, Partial<TVariables>, unknown> & {
|
|
38
|
+
mutationMode?: MutationMode;
|
|
39
|
+
returnPromise?: TReturnPromise;
|
|
40
|
+
}) => Promise<TReturnPromise extends true ? TData['data'] : void>;
|
|
41
|
+
export type UseMutationWithMutationModeResult<TReturnPromise extends boolean = boolean, ErrorType = Error, TData extends {
|
|
42
|
+
data?: unknown;
|
|
43
|
+
} = {
|
|
44
|
+
data?: unknown;
|
|
45
|
+
}, TVariables = unknown> = [
|
|
46
|
+
MutationFunctionWithOptions<TReturnPromise, ErrorType, TData, TVariables>,
|
|
47
|
+
UseMutationResult<TData['data'], ErrorType, Partial<TVariables>, unknown> & {
|
|
48
|
+
isLoading: boolean;
|
|
49
|
+
}
|
|
50
|
+
];
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef } from 'react';
|
|
2
|
+
import { useMutation, useQueryClient, } from '@tanstack/react-query';
|
|
3
|
+
import { useAddUndoableMutation } from './undo/useAddUndoableMutation';
|
|
4
|
+
import { useEvent } from '../util';
|
|
5
|
+
export const useMutationWithMutationMode = (params = {}, options) => {
|
|
6
|
+
const queryClient = useQueryClient();
|
|
7
|
+
const addUndoableMutation = useAddUndoableMutation();
|
|
8
|
+
const { mutationKey, mutationMode = 'pessimistic', mutationFn, getMutateWithMiddlewares, updateCache, getQueryKeys, onUndo, ...mutationOptions } = options;
|
|
9
|
+
if (mutationFn == null) {
|
|
10
|
+
throw new Error('useMutationWithMutationMode mutation requires a mutationFn');
|
|
11
|
+
}
|
|
12
|
+
const mutationFnEvent = useEvent(mutationFn);
|
|
13
|
+
const updateCacheEvent = useEvent(updateCache);
|
|
14
|
+
const getQueryKeysEvent = useEvent(getQueryKeys);
|
|
15
|
+
const getSnapshotEvent = useEvent(
|
|
16
|
+
/**
|
|
17
|
+
* Snapshot the previous values via queryClient.getQueriesData()
|
|
18
|
+
*
|
|
19
|
+
* The snapshotData ref will contain an array of tuples [query key, associated data]
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* [
|
|
23
|
+
* [['posts', 'getList'], { data: [{ id: 1, title: 'Hello' }], total: 1 }],
|
|
24
|
+
* [['posts', 'getMany'], [{ id: 1, title: 'Hello' }]],
|
|
25
|
+
* ]
|
|
26
|
+
*
|
|
27
|
+
* @see https://tanstack.com/query/v5/docs/react/reference/QueryClient#queryclientgetqueriesdata
|
|
28
|
+
*/
|
|
29
|
+
(queryKeys) => queryKeys.reduce((prev, queryKey) => prev.concat(queryClient.getQueriesData({ queryKey })), []));
|
|
30
|
+
const onUndoEvent = useEvent(onUndo ?? noop);
|
|
31
|
+
const getMutateWithMiddlewaresEvent = useEvent(getMutateWithMiddlewares ??
|
|
32
|
+
noop);
|
|
33
|
+
const mode = useRef(mutationMode);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
mode.current = mutationMode;
|
|
36
|
+
}, [mutationMode]);
|
|
37
|
+
// This ref won't be updated when params change in an effect, only when the mutate callback is called (See L247)
|
|
38
|
+
// This ensures that for undoable and optimistic mutations, the params are not changed by side effects (unselectAll for instance)
|
|
39
|
+
// _after_ the mutate function has been called, while keeping the ability to change declaration time params _until_ the mutation is called.
|
|
40
|
+
const paramsRef = useRef(params);
|
|
41
|
+
// Ref that stores the snapshot of the state before the mutation to allow reverting it
|
|
42
|
+
const snapshot = useRef([]);
|
|
43
|
+
// Ref that stores the mutation with middlewares to avoid losing them if the calling component is unmounted
|
|
44
|
+
const mutateWithMiddlewares = useRef(mutationFnEvent);
|
|
45
|
+
// We need to store the call-time onError and onSettled in refs to be able to call them in the useMutation hook even
|
|
46
|
+
// when the calling component is unmounted
|
|
47
|
+
const callTimeOnError = useRef(undefined);
|
|
48
|
+
const callTimeOnSettled = useRef(undefined);
|
|
49
|
+
// We don't need to keep a ref on the onSuccess callback as we call it ourselves for optimistic and
|
|
50
|
+
// undoable mutations. There is a limitation though: if one of the side effects applied by the onSuccess callback
|
|
51
|
+
// unmounts the component that called the useUpdate hook (redirect for instance), it must be the last one applied,
|
|
52
|
+
// otherwise the other side effects may not applied.
|
|
53
|
+
const hasCallTimeOnSuccess = useRef(false);
|
|
54
|
+
const mutation = useMutation({
|
|
55
|
+
mutationKey,
|
|
56
|
+
mutationFn: async (params) => {
|
|
57
|
+
if (params == null) {
|
|
58
|
+
throw new Error('useMutationWithMutationMode mutation requires parameters');
|
|
59
|
+
}
|
|
60
|
+
return (mutateWithMiddlewares
|
|
61
|
+
.current(params)
|
|
62
|
+
// Middlewares expect the data property of the dataProvider response
|
|
63
|
+
.then(({ data }) => data));
|
|
64
|
+
},
|
|
65
|
+
...mutationOptions,
|
|
66
|
+
onMutate: async (...args) => {
|
|
67
|
+
if (mutationOptions.onMutate) {
|
|
68
|
+
const userContext = (await mutationOptions.onMutate(...args)) || {};
|
|
69
|
+
return {
|
|
70
|
+
snapshot: snapshot.current,
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
...userContext,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
// Return a context object with the snapshot value
|
|
77
|
+
return { snapshot: snapshot.current };
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
onError: (...args) => {
|
|
81
|
+
if (mode.current === 'optimistic' ||
|
|
82
|
+
mode.current === 'undoable') {
|
|
83
|
+
const [, , onMutateResult] = args;
|
|
84
|
+
// If the mutation fails, use the context returned from onMutate to rollback
|
|
85
|
+
onMutateResult.snapshot.forEach(([key, value]) => {
|
|
86
|
+
queryClient.setQueryData(key, value);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (callTimeOnError.current) {
|
|
90
|
+
return callTimeOnError.current(...args);
|
|
91
|
+
}
|
|
92
|
+
if (mutationOptions.onError) {
|
|
93
|
+
return mutationOptions.onError(...args);
|
|
94
|
+
}
|
|
95
|
+
// call-time error callback is executed by react-query
|
|
96
|
+
},
|
|
97
|
+
onSuccess: (...args) => {
|
|
98
|
+
if (mode.current === 'pessimistic') {
|
|
99
|
+
const [data, variables] = args;
|
|
100
|
+
// update the getOne and getList query cache with the new result
|
|
101
|
+
updateCacheEvent({ ...paramsRef.current, ...variables }, {
|
|
102
|
+
mutationMode: mode.current,
|
|
103
|
+
}, data);
|
|
104
|
+
if (mutationOptions.onSuccess &&
|
|
105
|
+
!hasCallTimeOnSuccess.current) {
|
|
106
|
+
mutationOptions.onSuccess(...args);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
onSettled: (...args) => {
|
|
111
|
+
if (mode.current === 'optimistic' ||
|
|
112
|
+
mode.current === 'undoable') {
|
|
113
|
+
const [, , variables] = args;
|
|
114
|
+
// Always refetch after error or success:
|
|
115
|
+
getQueryKeysEvent({ ...paramsRef.current, ...variables }, {
|
|
116
|
+
mutationMode: mode.current,
|
|
117
|
+
}).forEach(queryKey => {
|
|
118
|
+
queryClient.invalidateQueries({ queryKey });
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
if (callTimeOnSettled.current) {
|
|
122
|
+
return callTimeOnSettled.current(...args);
|
|
123
|
+
}
|
|
124
|
+
if (mutationOptions.onSettled) {
|
|
125
|
+
return mutationOptions.onSettled(...args);
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
const mutate = async (callTimeParams = {}, callTimeOptions = {}) => {
|
|
130
|
+
const { mutationMode, returnPromise = mutationOptions.returnPromise, onError, onSettled, onSuccess, ...otherCallTimeOptions } = callTimeOptions;
|
|
131
|
+
// store the hook time params *at the moment of the call*
|
|
132
|
+
// because they may change afterwards, which would break the undoable mode
|
|
133
|
+
// as the previousData would be overwritten by the optimistic update
|
|
134
|
+
paramsRef.current = params;
|
|
135
|
+
// Store the mutation with middlewares to avoid losing them if the calling component is unmounted
|
|
136
|
+
if (getMutateWithMiddlewares) {
|
|
137
|
+
mutateWithMiddlewares.current = getMutateWithMiddlewaresEvent((params) => {
|
|
138
|
+
return mutationFnEvent(params);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
mutateWithMiddlewares.current = mutationFnEvent;
|
|
143
|
+
}
|
|
144
|
+
// We need to keep the onSuccess callback here and not in the useMutation for undoable mutations
|
|
145
|
+
hasCallTimeOnSuccess.current = !!onSuccess;
|
|
146
|
+
// We need to store the onError and onSettled callbacks here to be able to call them in the useMutation hook
|
|
147
|
+
// so that they are called even when the calling component is unmounted
|
|
148
|
+
callTimeOnError.current = onError;
|
|
149
|
+
callTimeOnSettled.current = onSettled;
|
|
150
|
+
if (mutationMode) {
|
|
151
|
+
mode.current = mutationMode;
|
|
152
|
+
}
|
|
153
|
+
if (returnPromise && mode.current !== 'pessimistic') {
|
|
154
|
+
console.warn('The returnPromise parameter can only be used if the mutationMode is set to pessimistic');
|
|
155
|
+
}
|
|
156
|
+
snapshot.current = getSnapshotEvent(getQueryKeysEvent({ ...paramsRef.current, ...callTimeParams }, {
|
|
157
|
+
mutationMode: mode.current,
|
|
158
|
+
}));
|
|
159
|
+
if (mode.current === 'pessimistic') {
|
|
160
|
+
if (returnPromise) {
|
|
161
|
+
return mutation.mutateAsync({ ...paramsRef.current, ...callTimeParams },
|
|
162
|
+
// We don't pass onError and onSettled here as we will call them in the useMutation hook side effects
|
|
163
|
+
{ onSuccess, ...otherCallTimeOptions });
|
|
164
|
+
}
|
|
165
|
+
return mutation.mutate({ ...paramsRef.current, ...callTimeParams },
|
|
166
|
+
// We don't pass onError and onSettled here as we will call them in the useMutation hook side effects
|
|
167
|
+
{ onSuccess, ...otherCallTimeOptions });
|
|
168
|
+
}
|
|
169
|
+
// Cancel any outgoing re-fetches (so they don't overwrite our optimistic update)
|
|
170
|
+
await Promise.all(snapshot.current.map(([queryKey]) => queryClient.cancelQueries({ queryKey })));
|
|
171
|
+
// Optimistically update to the new value
|
|
172
|
+
const optimisticResult = updateCacheEvent({ ...paramsRef.current, ...callTimeParams }, {
|
|
173
|
+
mutationMode: mode.current,
|
|
174
|
+
}, undefined);
|
|
175
|
+
// run the success callbacks during the next tick
|
|
176
|
+
setTimeout(() => {
|
|
177
|
+
if (onSuccess) {
|
|
178
|
+
onSuccess(optimisticResult, { ...paramsRef.current, ...callTimeParams }, {
|
|
179
|
+
snapshot: snapshot.current,
|
|
180
|
+
}, {
|
|
181
|
+
client: queryClient,
|
|
182
|
+
mutationKey,
|
|
183
|
+
meta: mutationOptions.meta,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
else if (mutationOptions.onSuccess &&
|
|
187
|
+
!hasCallTimeOnSuccess.current) {
|
|
188
|
+
mutationOptions.onSuccess(optimisticResult, { ...paramsRef.current, ...callTimeParams }, {
|
|
189
|
+
snapshot: snapshot.current,
|
|
190
|
+
}, {
|
|
191
|
+
client: queryClient,
|
|
192
|
+
mutationKey,
|
|
193
|
+
meta: mutationOptions.meta,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
}, 0);
|
|
197
|
+
if (mode.current === 'optimistic') {
|
|
198
|
+
// call the mutate method without success side effects
|
|
199
|
+
return mutation.mutate({
|
|
200
|
+
...paramsRef.current,
|
|
201
|
+
...callTimeParams,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
// Undoable mutation: add the mutation to the undoable queue.
|
|
206
|
+
// The Notification component will dequeue it when the user confirms or cancels the message.
|
|
207
|
+
addUndoableMutation(({ isUndo }) => {
|
|
208
|
+
if (isUndo) {
|
|
209
|
+
if (onUndo) {
|
|
210
|
+
onUndoEvent({
|
|
211
|
+
...paramsRef.current,
|
|
212
|
+
...callTimeParams,
|
|
213
|
+
}, {
|
|
214
|
+
mutationMode: mode.current,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
// rollback
|
|
218
|
+
snapshot.current.forEach(([key, value]) => {
|
|
219
|
+
queryClient.setQueryData(key, value);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
// call the mutate method without success side effects
|
|
224
|
+
mutation.mutate({
|
|
225
|
+
...paramsRef.current,
|
|
226
|
+
...callTimeParams,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
const mutationResult = useMemo(() => ({
|
|
233
|
+
isLoading: mutation.isPending,
|
|
234
|
+
...mutation,
|
|
235
|
+
}), [mutation]);
|
|
236
|
+
return [useEvent(mutate), mutationResult];
|
|
237
|
+
};
|
|
238
|
+
const noop = () => { };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook for triggering a page refresh. Returns a callback function.
|
|
3
|
+
*
|
|
4
|
+
* The callback invalidates all queries and refetches the active ones.
|
|
5
|
+
* Any component depending on react-query data will be re-rendered.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
*
|
|
9
|
+
* const refresh = useRefresh();
|
|
10
|
+
* const handleClick = () => {
|
|
11
|
+
* refresh();
|
|
12
|
+
* };
|
|
13
|
+
*/
|
|
14
|
+
export declare const useRefresh: () => () => void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
3
|
+
/**
|
|
4
|
+
* Hook for triggering a page refresh. Returns a callback function.
|
|
5
|
+
*
|
|
6
|
+
* The callback invalidates all queries and refetches the active ones.
|
|
7
|
+
* Any component depending on react-query data will be re-rendered.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
*
|
|
11
|
+
* const refresh = useRefresh();
|
|
12
|
+
* const handleClick = () => {
|
|
13
|
+
* refresh();
|
|
14
|
+
* };
|
|
15
|
+
*/
|
|
16
|
+
export const useRefresh = () => {
|
|
17
|
+
const queryClient = useQueryClient();
|
|
18
|
+
return useCallback(() => {
|
|
19
|
+
queryClient.invalidateQueries();
|
|
20
|
+
}, [queryClient]);
|
|
21
|
+
};
|