@strato-admin/faker-ecommerce 0.1.0 → 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 +6 -5
- 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,193 @@
|
|
|
1
|
+
import { useQueryClient, } from '@tanstack/react-query';
|
|
2
|
+
import { useDataProvider } from './useDataProvider';
|
|
3
|
+
import { useEvent } from '../util';
|
|
4
|
+
import { useMutationWithMutationMode, } from './useMutationWithMutationMode';
|
|
5
|
+
/**
|
|
6
|
+
* Get a callback to call the dataProvider.delete() method, the result and the loading state.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} resource
|
|
9
|
+
* @param {Params} params The delete parameters { ids }
|
|
10
|
+
* @param {Object} options Options object to pass to the queryClient.
|
|
11
|
+
* May include side effects to be executed upon success or failure, e.g. { onSuccess: () => { refresh(); } }
|
|
12
|
+
* May include a mutation mode (optimistic/pessimistic/undoable), e.g. { mutationMode: 'undoable' }
|
|
13
|
+
*
|
|
14
|
+
* @typedef Params
|
|
15
|
+
* @prop params.ids The resource identifiers, e.g. [123, 456]
|
|
16
|
+
*
|
|
17
|
+
* @returns The current mutation state. Destructure as [deleteMany, { data, error, isPending }].
|
|
18
|
+
*
|
|
19
|
+
* The return value updates according to the request state:
|
|
20
|
+
*
|
|
21
|
+
* - initial: [deleteMany, { isPending: false, isIdle: true }]
|
|
22
|
+
* - start: [deleteMany, { isPending: true }]
|
|
23
|
+
* - success: [deleteMany, { data: [data from response], isPending: false, isSuccess: true }]
|
|
24
|
+
* - error: [deleteMany, { error: [error from response], isPending: false, isError: true }]
|
|
25
|
+
*
|
|
26
|
+
* The deleteMany() function must be called with a resource and a parameter object: deleteMany(resource, { ids, meta }, options)
|
|
27
|
+
*
|
|
28
|
+
* This hook uses react-query useMutation under the hood.
|
|
29
|
+
* This means the state object contains mutate, isIdle, reset and other react-query methods.
|
|
30
|
+
*
|
|
31
|
+
* @see https://tanstack.com/query/v5/docs/react/reference/useMutation
|
|
32
|
+
*
|
|
33
|
+
* @example // set params when calling the deleteMany callback
|
|
34
|
+
*
|
|
35
|
+
* import { useDeleteMany } from 'react-admin';
|
|
36
|
+
*
|
|
37
|
+
* const BulkDeletePostsButton = ({ selectedIds }) => {
|
|
38
|
+
* const [deleteMany, { isPending, error }] = useDeleteMany();
|
|
39
|
+
* const handleClick = () => {
|
|
40
|
+
* deleteMany('posts', { ids: selectedIds })
|
|
41
|
+
* }
|
|
42
|
+
* if (error) { return <p>ERROR</p>; }
|
|
43
|
+
* return <button disabled={isPending} onClick={handleClick}>Delete selected posts</button>;
|
|
44
|
+
* };
|
|
45
|
+
*
|
|
46
|
+
* @example // set params when calling the hook
|
|
47
|
+
*
|
|
48
|
+
* import { useDeleteMany } from 'react-admin';
|
|
49
|
+
*
|
|
50
|
+
* const BulkDeletePostsButton = ({ selectedIds }) => {
|
|
51
|
+
* const [deleteMany, { isPending, error }] = useDeleteMany('posts', { ids: selectedIds });
|
|
52
|
+
* const handleClick = () => {
|
|
53
|
+
* deleteMany()
|
|
54
|
+
* }
|
|
55
|
+
* if (error) { return <p>ERROR</p>; }
|
|
56
|
+
* return <button disabled={isPending} onClick={handleClick}>Delete selected posts</button>;
|
|
57
|
+
* };
|
|
58
|
+
*
|
|
59
|
+
* @example // TypeScript
|
|
60
|
+
* const [deleteMany, { data }] = useDeleteMany<Product>('products', { ids });
|
|
61
|
+
* \-- data is Product
|
|
62
|
+
*/
|
|
63
|
+
export const useDeleteMany = (resource, params = {}, options = {}) => {
|
|
64
|
+
const dataProvider = useDataProvider();
|
|
65
|
+
const queryClient = useQueryClient();
|
|
66
|
+
const { mutationMode = 'pessimistic', onSettled, ...mutationOptions } = options;
|
|
67
|
+
const [mutate, mutationResult] = useMutationWithMutationMode({ resource, ...params }, {
|
|
68
|
+
...mutationOptions,
|
|
69
|
+
mutationKey: [resource, 'deleteMany', params],
|
|
70
|
+
mutationMode,
|
|
71
|
+
mutationFn: ({ resource, ...params }) => {
|
|
72
|
+
if (resource == null) {
|
|
73
|
+
throw new Error('useDeleteMany mutation requires a resource');
|
|
74
|
+
}
|
|
75
|
+
if (params.ids == null) {
|
|
76
|
+
throw new Error('useDeleteMany mutation requires an array of ids');
|
|
77
|
+
}
|
|
78
|
+
return dataProvider.deleteMany(resource, params);
|
|
79
|
+
},
|
|
80
|
+
updateCache: ({ resource, ...params }, { mutationMode }) => {
|
|
81
|
+
// hack: only way to tell react-query not to fetch this query for the next 5 seconds
|
|
82
|
+
// because setQueryData doesn't accept a stale time option
|
|
83
|
+
const now = Date.now();
|
|
84
|
+
const updatedAt = mutationMode === 'undoable' ? now + 5 * 1000 : now;
|
|
85
|
+
const updateColl = (old) => {
|
|
86
|
+
if (!old)
|
|
87
|
+
return old;
|
|
88
|
+
let newCollection = [...old];
|
|
89
|
+
params.ids?.forEach(id => {
|
|
90
|
+
const index = newCollection.findIndex(
|
|
91
|
+
// eslint-disable-next-line eqeqeq
|
|
92
|
+
record => record.id == id);
|
|
93
|
+
if (index === -1) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
newCollection = [
|
|
97
|
+
...newCollection.slice(0, index),
|
|
98
|
+
...newCollection.slice(index + 1),
|
|
99
|
+
];
|
|
100
|
+
});
|
|
101
|
+
return newCollection;
|
|
102
|
+
};
|
|
103
|
+
queryClient.setQueriesData({ queryKey: [resource, 'getList'] }, (res) => {
|
|
104
|
+
if (!res || !res.data)
|
|
105
|
+
return res;
|
|
106
|
+
const newCollection = updateColl(res.data);
|
|
107
|
+
const recordWasFound = newCollection.length < res.data.length;
|
|
108
|
+
return recordWasFound
|
|
109
|
+
? {
|
|
110
|
+
...res,
|
|
111
|
+
data: newCollection,
|
|
112
|
+
total: res.total
|
|
113
|
+
? res.total -
|
|
114
|
+
(res.data.length - newCollection.length)
|
|
115
|
+
: undefined,
|
|
116
|
+
}
|
|
117
|
+
: res;
|
|
118
|
+
}, { updatedAt });
|
|
119
|
+
queryClient.setQueriesData({ queryKey: [resource, 'getInfiniteList'] }, (res) => {
|
|
120
|
+
if (!res || !res.pages)
|
|
121
|
+
return res;
|
|
122
|
+
return {
|
|
123
|
+
...res,
|
|
124
|
+
pages: res.pages.map(page => {
|
|
125
|
+
const newCollection = updateColl(page.data);
|
|
126
|
+
const recordWasFound = newCollection.length < page.data.length;
|
|
127
|
+
return recordWasFound
|
|
128
|
+
? {
|
|
129
|
+
...page,
|
|
130
|
+
data: newCollection,
|
|
131
|
+
total: page.total
|
|
132
|
+
? page.total -
|
|
133
|
+
(page.data.length -
|
|
134
|
+
newCollection.length)
|
|
135
|
+
: undefined,
|
|
136
|
+
}
|
|
137
|
+
: page;
|
|
138
|
+
}),
|
|
139
|
+
};
|
|
140
|
+
}, { updatedAt });
|
|
141
|
+
queryClient.setQueriesData({ queryKey: [resource, 'getMany'] }, (coll) => coll && coll.length > 0 ? updateColl(coll) : coll, { updatedAt });
|
|
142
|
+
queryClient.setQueriesData({ queryKey: [resource, 'getManyReference'] }, (res) => {
|
|
143
|
+
if (!res || !res.data)
|
|
144
|
+
return res;
|
|
145
|
+
const newCollection = updateColl(res.data);
|
|
146
|
+
const recordWasFound = newCollection.length < res.data.length;
|
|
147
|
+
if (!recordWasFound) {
|
|
148
|
+
return res;
|
|
149
|
+
}
|
|
150
|
+
if (res.total) {
|
|
151
|
+
return {
|
|
152
|
+
...res,
|
|
153
|
+
data: newCollection,
|
|
154
|
+
total: res.total -
|
|
155
|
+
(res.data.length - newCollection.length),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
if (res.pageInfo) {
|
|
159
|
+
return {
|
|
160
|
+
...res,
|
|
161
|
+
data: newCollection,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
throw new Error('Found getManyReference result in cache without total or pageInfo');
|
|
165
|
+
}, { updatedAt });
|
|
166
|
+
return params.ids;
|
|
167
|
+
},
|
|
168
|
+
getQueryKeys: ({ resource }) => {
|
|
169
|
+
const queryKeys = [
|
|
170
|
+
[resource, 'getList'],
|
|
171
|
+
[resource, 'getInfiniteList'],
|
|
172
|
+
[resource, 'getMany'],
|
|
173
|
+
[resource, 'getManyReference'],
|
|
174
|
+
];
|
|
175
|
+
return queryKeys;
|
|
176
|
+
},
|
|
177
|
+
onSettled: (...args) => {
|
|
178
|
+
const [, , , mutateResult] = args;
|
|
179
|
+
// For deletion, we always refetch after error or success:
|
|
180
|
+
mutateResult.snapshot.forEach(([queryKey]) => {
|
|
181
|
+
queryClient.invalidateQueries({ queryKey });
|
|
182
|
+
});
|
|
183
|
+
onSettled?.(...args);
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
const deleteMany = useEvent((callTimeResource = resource, callTimeParams = {}, callTimeOptions = {}) => {
|
|
187
|
+
return mutate({
|
|
188
|
+
resource: callTimeResource,
|
|
189
|
+
...callTimeParams,
|
|
190
|
+
}, callTimeOptions);
|
|
191
|
+
});
|
|
192
|
+
return [deleteMany, mutationResult];
|
|
193
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import { RaRecord, GetListParams, GetListResult } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Call the dataProvider.getList() method and return the resolved result
|
|
5
|
+
* as well as the loading state.
|
|
6
|
+
*
|
|
7
|
+
* The return value updates according to the request state:
|
|
8
|
+
*
|
|
9
|
+
* - start: { isPending: true, refetch }
|
|
10
|
+
* - success: { data: [data from store], total: [total from response], isPending: false, refetch }
|
|
11
|
+
* - error: { error: [error from response], isPending: false, refetch }
|
|
12
|
+
*
|
|
13
|
+
* This hook will return the cached result when called a second time
|
|
14
|
+
* with the same parameters, until the response arrives.
|
|
15
|
+
*
|
|
16
|
+
* @param {string} resource The resource name, e.g. 'posts'
|
|
17
|
+
* @param {Params} params The getList parameters { pagination, sort, filter, meta }
|
|
18
|
+
* @param {Object} options Options object to pass to the queryClient.
|
|
19
|
+
* May include side effects to be executed upon success or failure, e.g. { onSuccess: () => { refresh(); } }
|
|
20
|
+
*
|
|
21
|
+
* @typedef Params
|
|
22
|
+
* @prop params.pagination The request pagination { page, perPage }, e.g. { page: 1, perPage: 10 }
|
|
23
|
+
* @prop params.sort The request sort { field, order }, e.g. { field: 'id', order: 'DESC' }
|
|
24
|
+
* @prop params.filter The request filters, e.g. { title: 'hello, world' }
|
|
25
|
+
* @prop params.meta Optional meta parameters
|
|
26
|
+
*
|
|
27
|
+
* @returns The current request state. Destructure as { data, total, error, isPending, refetch }.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
*
|
|
31
|
+
* import { useGetList } from 'react-admin';
|
|
32
|
+
*
|
|
33
|
+
* const LatestNews = () => {
|
|
34
|
+
* const { data, total, isPending, error } = useGetList(
|
|
35
|
+
* 'posts',
|
|
36
|
+
* { pagination: { page: 1, perPage: 10 }, sort: { field: 'published_at', order: 'DESC' } }
|
|
37
|
+
* );
|
|
38
|
+
* if (isPending) { return <Loading />; }
|
|
39
|
+
* if (error) { return <p>ERROR</p>; }
|
|
40
|
+
* return <ul>{data.map(item =>
|
|
41
|
+
* <li key={item.id}>{item.title}</li>
|
|
42
|
+
* )}</ul>;
|
|
43
|
+
* };
|
|
44
|
+
*/
|
|
45
|
+
export declare const useGetList: <RecordType extends RaRecord = any, ErrorType = Error>(resource: string, params?: Partial<GetListParams>, options?: UseGetListOptions<RecordType, ErrorType>) => UseGetListHookValue<RecordType>;
|
|
46
|
+
export type UseGetListOptions<RecordType extends RaRecord = any, ErrorType = Error> = Omit<UseQueryOptions<GetListResult<RecordType>, ErrorType>, 'queryKey' | 'queryFn'> & {
|
|
47
|
+
onSuccess?: (value: GetListResult<RecordType>) => void;
|
|
48
|
+
onError?: (error: ErrorType) => void;
|
|
49
|
+
onSettled?: (data?: GetListResult<RecordType>, error?: ErrorType | null) => void;
|
|
50
|
+
};
|
|
51
|
+
export type UseGetListHookValue<RecordType extends RaRecord = any> = UseQueryResult<RecordType[], Error> & {
|
|
52
|
+
total?: number;
|
|
53
|
+
pageInfo?: {
|
|
54
|
+
hasNextPage?: boolean;
|
|
55
|
+
hasPreviousPage?: boolean;
|
|
56
|
+
};
|
|
57
|
+
meta?: any;
|
|
58
|
+
};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef } from 'react';
|
|
2
|
+
import { useQuery, useQueryClient, } from '@tanstack/react-query';
|
|
3
|
+
import { useDataProvider } from './useDataProvider';
|
|
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.
|
|
9
|
+
*
|
|
10
|
+
* The return value updates according to the request state:
|
|
11
|
+
*
|
|
12
|
+
* - start: { isPending: true, refetch }
|
|
13
|
+
* - success: { data: [data from store], total: [total from response], isPending: false, refetch }
|
|
14
|
+
* - error: { error: [error from response], isPending: false, refetch }
|
|
15
|
+
*
|
|
16
|
+
* This hook will return the cached result when called a second time
|
|
17
|
+
* with the same parameters, until the response arrives.
|
|
18
|
+
*
|
|
19
|
+
* @param {string} resource The resource name, e.g. 'posts'
|
|
20
|
+
* @param {Params} params The getList parameters { pagination, sort, filter, meta }
|
|
21
|
+
* @param {Object} options Options object to pass to the queryClient.
|
|
22
|
+
* May include side effects to be executed upon success or failure, e.g. { onSuccess: () => { refresh(); } }
|
|
23
|
+
*
|
|
24
|
+
* @typedef Params
|
|
25
|
+
* @prop params.pagination The request pagination { page, perPage }, e.g. { page: 1, perPage: 10 }
|
|
26
|
+
* @prop params.sort The request sort { field, order }, e.g. { field: 'id', order: 'DESC' }
|
|
27
|
+
* @prop params.filter The request filters, e.g. { title: 'hello, world' }
|
|
28
|
+
* @prop params.meta Optional meta parameters
|
|
29
|
+
*
|
|
30
|
+
* @returns The current request state. Destructure as { data, total, error, isPending, refetch }.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
*
|
|
34
|
+
* import { useGetList } from 'react-admin';
|
|
35
|
+
*
|
|
36
|
+
* const LatestNews = () => {
|
|
37
|
+
* const { data, total, isPending, error } = useGetList(
|
|
38
|
+
* 'posts',
|
|
39
|
+
* { pagination: { page: 1, perPage: 10 }, sort: { field: 'published_at', order: 'DESC' } }
|
|
40
|
+
* );
|
|
41
|
+
* if (isPending) { return <Loading />; }
|
|
42
|
+
* if (error) { return <p>ERROR</p>; }
|
|
43
|
+
* return <ul>{data.map(item =>
|
|
44
|
+
* <li key={item.id}>{item.title}</li>
|
|
45
|
+
* )}</ul>;
|
|
46
|
+
* };
|
|
47
|
+
*/
|
|
48
|
+
export const useGetList = (resource, params = {}, options = {}) => {
|
|
49
|
+
const { pagination = { page: 1, perPage: 25 }, sort = { field: 'id', order: 'DESC' }, filter = {}, meta, } = params;
|
|
50
|
+
const dataProvider = useDataProvider();
|
|
51
|
+
const queryClient = useQueryClient();
|
|
52
|
+
const { onError = noop, onSuccess = noop, onSettled = noop, ...queryOptions } = options;
|
|
53
|
+
const onSuccessEvent = useEvent(onSuccess);
|
|
54
|
+
const onErrorEvent = useEvent(onError);
|
|
55
|
+
const onSettledEvent = useEvent(onSettled);
|
|
56
|
+
const result = useQuery({
|
|
57
|
+
queryKey: [resource, 'getList', { pagination, sort, filter, meta }],
|
|
58
|
+
queryFn: queryParams => dataProvider
|
|
59
|
+
.getList(resource, {
|
|
60
|
+
pagination,
|
|
61
|
+
sort,
|
|
62
|
+
filter,
|
|
63
|
+
meta,
|
|
64
|
+
signal: dataProvider.supportAbortSignal === true
|
|
65
|
+
? queryParams.signal
|
|
66
|
+
: undefined,
|
|
67
|
+
})
|
|
68
|
+
.then(({ data, total, pageInfo, meta }) => ({
|
|
69
|
+
data,
|
|
70
|
+
total,
|
|
71
|
+
pageInfo,
|
|
72
|
+
meta,
|
|
73
|
+
})),
|
|
74
|
+
...queryOptions,
|
|
75
|
+
});
|
|
76
|
+
const metaValue = useRef(meta);
|
|
77
|
+
const resourceValue = useRef(resource);
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
metaValue.current = meta;
|
|
80
|
+
}, [meta]);
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
resourceValue.current = resource;
|
|
83
|
+
}, [resource]);
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
if (result.data === undefined ||
|
|
86
|
+
result.error != null ||
|
|
87
|
+
result.isFetching)
|
|
88
|
+
return;
|
|
89
|
+
// optimistically populate the getOne cache
|
|
90
|
+
if (result.data?.data &&
|
|
91
|
+
result.data.data.length <= MAX_DATA_LENGTH_TO_CACHE) {
|
|
92
|
+
result.data.data.forEach(record => {
|
|
93
|
+
queryClient.setQueryData([
|
|
94
|
+
resourceValue.current,
|
|
95
|
+
'getOne',
|
|
96
|
+
{ id: String(record.id), meta: metaValue.current },
|
|
97
|
+
], oldRecord => oldRecord ?? record);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
onSuccessEvent(result.data);
|
|
101
|
+
}, [
|
|
102
|
+
onSuccessEvent,
|
|
103
|
+
queryClient,
|
|
104
|
+
result.data,
|
|
105
|
+
result.error,
|
|
106
|
+
result.isFetching,
|
|
107
|
+
]);
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
if (result.error == null || result.isFetching)
|
|
110
|
+
return;
|
|
111
|
+
onErrorEvent(result.error);
|
|
112
|
+
}, [onErrorEvent, result.error, result.isFetching]);
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
if (result.status === 'pending' || result.isFetching)
|
|
115
|
+
return;
|
|
116
|
+
onSettledEvent(result.data, result.error);
|
|
117
|
+
}, [
|
|
118
|
+
onSettledEvent,
|
|
119
|
+
result.data,
|
|
120
|
+
result.error,
|
|
121
|
+
result.status,
|
|
122
|
+
result.isFetching,
|
|
123
|
+
]);
|
|
124
|
+
return useMemo(() => result.data
|
|
125
|
+
? {
|
|
126
|
+
...result,
|
|
127
|
+
...result.data,
|
|
128
|
+
}
|
|
129
|
+
: result, [result]);
|
|
130
|
+
};
|
|
131
|
+
const noop = () => undefined;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import { RaRecord, GetManyParams } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Call the dataProvider.getMany() method and return the resolved result
|
|
5
|
+
* as well as the loading state.
|
|
6
|
+
*
|
|
7
|
+
* The return value updates according to the request state:
|
|
8
|
+
*
|
|
9
|
+
* - start: { isPending: true, refetch }
|
|
10
|
+
* - success: { data: [data from store], isPending: false, refetch }
|
|
11
|
+
* - error: { error: [error from response], isPending: false, refetch }
|
|
12
|
+
*
|
|
13
|
+
* This hook will return the cached result when called a second time
|
|
14
|
+
* with the same parameters, until the response arrives.
|
|
15
|
+
*
|
|
16
|
+
* @param {string} resource The resource name, e.g. 'posts'
|
|
17
|
+
* @param {Params} params The getMany parameters { ids, meta }
|
|
18
|
+
* @param {Object} options Options object to pass to the queryClient.
|
|
19
|
+
* May include side effects to be executed upon success or failure, e.g. { onSuccess: () => { refresh(); } }
|
|
20
|
+
*
|
|
21
|
+
* @typedef Params
|
|
22
|
+
* @prop params.ids The ids to get, e.g. [123, 456, 789]
|
|
23
|
+
* @prop params.meta Optional meta parameters
|
|
24
|
+
*
|
|
25
|
+
* @returns The current request state. Destructure as { data, error, isPending, refetch }.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
*
|
|
29
|
+
* import { useGetMany } from 'react-admin';
|
|
30
|
+
*
|
|
31
|
+
* const PostTags = ({ post }) => {
|
|
32
|
+
* const { data, isPending, error } = useGetMany(
|
|
33
|
+
* 'tags',
|
|
34
|
+
* { ids: post.tags },
|
|
35
|
+
* );
|
|
36
|
+
* if (isPending) { return <Loading />; }
|
|
37
|
+
* if (error) { return <p>ERROR</p>; }
|
|
38
|
+
* return <ul>{data.map(tag =>
|
|
39
|
+
* <li key={tag.id}>{tag.name}</li>
|
|
40
|
+
* )}</ul>;
|
|
41
|
+
* };
|
|
42
|
+
*/
|
|
43
|
+
export declare const useGetMany: <RecordType extends RaRecord = any, ErrorType = Error>(resource: string, params: Partial<GetManyParams<RecordType>>, options?: UseGetManyOptions<RecordType, ErrorType>) => UseGetManyHookValue<RecordType, ErrorType>;
|
|
44
|
+
export type UseGetManyOptions<RecordType extends RaRecord = any, ErrorType = Error> = Omit<UseQueryOptions<RecordType[], ErrorType>, 'queryKey' | 'queryFn'> & {
|
|
45
|
+
onSuccess?: (data: RecordType[]) => void;
|
|
46
|
+
onError?: (error: ErrorType) => void;
|
|
47
|
+
onSettled?: (data?: RecordType[], error?: ErrorType | null) => void;
|
|
48
|
+
};
|
|
49
|
+
export type UseGetManyHookValue<RecordType extends RaRecord = any, ErrorType = Error> = UseQueryResult<RecordType[], ErrorType>;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { useQuery, useQueryClient, } from '@tanstack/react-query';
|
|
3
|
+
import { useDataProvider } from './useDataProvider';
|
|
4
|
+
import { useEvent } from '../util';
|
|
5
|
+
/**
|
|
6
|
+
* Call the dataProvider.getMany() method and return the resolved result
|
|
7
|
+
* as well as the loading state.
|
|
8
|
+
*
|
|
9
|
+
* The return value updates according to the request state:
|
|
10
|
+
*
|
|
11
|
+
* - start: { isPending: true, refetch }
|
|
12
|
+
* - success: { data: [data from store], isPending: false, refetch }
|
|
13
|
+
* - error: { error: [error from response], isPending: false, refetch }
|
|
14
|
+
*
|
|
15
|
+
* This hook will return the cached result when called a second time
|
|
16
|
+
* with the same parameters, until the response arrives.
|
|
17
|
+
*
|
|
18
|
+
* @param {string} resource The resource name, e.g. 'posts'
|
|
19
|
+
* @param {Params} params The getMany parameters { ids, meta }
|
|
20
|
+
* @param {Object} options Options object to pass to the queryClient.
|
|
21
|
+
* May include side effects to be executed upon success or failure, e.g. { onSuccess: () => { refresh(); } }
|
|
22
|
+
*
|
|
23
|
+
* @typedef Params
|
|
24
|
+
* @prop params.ids The ids to get, e.g. [123, 456, 789]
|
|
25
|
+
* @prop params.meta Optional meta parameters
|
|
26
|
+
*
|
|
27
|
+
* @returns The current request state. Destructure as { data, error, isPending, refetch }.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
*
|
|
31
|
+
* import { useGetMany } from 'react-admin';
|
|
32
|
+
*
|
|
33
|
+
* const PostTags = ({ post }) => {
|
|
34
|
+
* const { data, isPending, error } = useGetMany(
|
|
35
|
+
* 'tags',
|
|
36
|
+
* { ids: post.tags },
|
|
37
|
+
* );
|
|
38
|
+
* if (isPending) { return <Loading />; }
|
|
39
|
+
* if (error) { return <p>ERROR</p>; }
|
|
40
|
+
* return <ul>{data.map(tag =>
|
|
41
|
+
* <li key={tag.id}>{tag.name}</li>
|
|
42
|
+
* )}</ul>;
|
|
43
|
+
* };
|
|
44
|
+
*/
|
|
45
|
+
export const useGetMany = (resource, params, options = {}) => {
|
|
46
|
+
const { ids, meta } = params;
|
|
47
|
+
const dataProvider = useDataProvider();
|
|
48
|
+
const queryClient = useQueryClient();
|
|
49
|
+
const { onError = noop, onSuccess = noop, onSettled = noop, enabled, ...queryOptions } = options;
|
|
50
|
+
const onSuccessEvent = useEvent(onSuccess);
|
|
51
|
+
const onErrorEvent = useEvent(onError);
|
|
52
|
+
const onSettledEvent = useEvent(onSettled);
|
|
53
|
+
const result = useQuery({
|
|
54
|
+
queryKey: [
|
|
55
|
+
resource,
|
|
56
|
+
'getMany',
|
|
57
|
+
{
|
|
58
|
+
ids: !ids || ids.length === 0 ? [] : ids.map(id => String(id)),
|
|
59
|
+
meta,
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
queryFn: queryParams => {
|
|
63
|
+
if (!ids || ids.length === 0) {
|
|
64
|
+
// no need to call the dataProvider
|
|
65
|
+
return Promise.resolve([]);
|
|
66
|
+
}
|
|
67
|
+
return dataProvider
|
|
68
|
+
.getMany(resource, {
|
|
69
|
+
ids,
|
|
70
|
+
meta,
|
|
71
|
+
signal: dataProvider.supportAbortSignal === true
|
|
72
|
+
? queryParams.signal
|
|
73
|
+
: undefined,
|
|
74
|
+
})
|
|
75
|
+
.then(({ data }) => data);
|
|
76
|
+
},
|
|
77
|
+
placeholderData: () => {
|
|
78
|
+
const records = !ids || ids.length === 0
|
|
79
|
+
? []
|
|
80
|
+
: ids.map(id => queryClient.getQueryData([
|
|
81
|
+
resource,
|
|
82
|
+
'getOne',
|
|
83
|
+
{ id: String(id), meta },
|
|
84
|
+
]));
|
|
85
|
+
if (records.some(record => record === undefined)) {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
return records;
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
retry: false,
|
|
93
|
+
enabled: enabled ?? ids != null,
|
|
94
|
+
...queryOptions,
|
|
95
|
+
});
|
|
96
|
+
const metaValue = useRef(meta);
|
|
97
|
+
const resourceValue = useRef(resource);
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
metaValue.current = meta;
|
|
100
|
+
}, [meta]);
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
resourceValue.current = resource;
|
|
103
|
+
}, [resource]);
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
if (result.data === undefined ||
|
|
106
|
+
result.error != null ||
|
|
107
|
+
result.isFetching)
|
|
108
|
+
return;
|
|
109
|
+
// optimistically populate the getOne cache
|
|
110
|
+
result.data.forEach(record => {
|
|
111
|
+
queryClient.setQueryData([
|
|
112
|
+
resourceValue.current,
|
|
113
|
+
'getOne',
|
|
114
|
+
{ id: String(record.id), meta: metaValue.current },
|
|
115
|
+
], oldRecord => oldRecord ?? record);
|
|
116
|
+
});
|
|
117
|
+
onSuccessEvent(result.data);
|
|
118
|
+
}, [
|
|
119
|
+
queryClient,
|
|
120
|
+
onSuccessEvent,
|
|
121
|
+
result.data,
|
|
122
|
+
result.error,
|
|
123
|
+
result.isFetching,
|
|
124
|
+
]);
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
if (result.error == null || result.isFetching)
|
|
127
|
+
return;
|
|
128
|
+
onErrorEvent(result.error);
|
|
129
|
+
}, [onErrorEvent, result.error, result.isFetching]);
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
if (result.status === 'pending' || result.isFetching)
|
|
132
|
+
return;
|
|
133
|
+
onSettledEvent(result.data, result.error);
|
|
134
|
+
}, [
|
|
135
|
+
onSettledEvent,
|
|
136
|
+
result.data,
|
|
137
|
+
result.error,
|
|
138
|
+
result.status,
|
|
139
|
+
result.isFetching,
|
|
140
|
+
]);
|
|
141
|
+
return result;
|
|
142
|
+
};
|
|
143
|
+
const noop = () => undefined;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { UseQueryOptions } from '@tanstack/react-query';
|
|
2
|
+
import { UseGetManyHookValue } from './useGetMany';
|
|
3
|
+
import { RaRecord, GetManyParams } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Call the dataProvider.getMany() method and return the resolved result
|
|
6
|
+
* as well as the loading state.
|
|
7
|
+
*
|
|
8
|
+
* The return value updates according to the request state:
|
|
9
|
+
*
|
|
10
|
+
* - start: { isPending: true, isFetching: true, refetch }
|
|
11
|
+
* - success: { data: [data from response], isPending: false, isFetching: false, refetch }
|
|
12
|
+
* - error: { error: [error from response], isPending: false, isFetching: false, refetch }
|
|
13
|
+
*
|
|
14
|
+
* This hook will return the cached result when called a second time
|
|
15
|
+
* with the same parameters, until the response arrives.
|
|
16
|
+
*
|
|
17
|
+
* This hook aggregates and deduplicates calls to the same resource, so for instance, if an app calls:
|
|
18
|
+
*
|
|
19
|
+
* useGetManyAggregate('tags', [1, 2, 3]);
|
|
20
|
+
* useGetManyAggregate('tags', [3, 4]);
|
|
21
|
+
*
|
|
22
|
+
* during the same tick, the hook will only call the dataProvider once with the following parameters:
|
|
23
|
+
*
|
|
24
|
+
* dataProvider.getMany('tags', [1, 2, 3, 4])
|
|
25
|
+
*
|
|
26
|
+
* @param resource The resource name, e.g. 'posts'
|
|
27
|
+
* @param {Params} params The getMany parameters { ids, meta }
|
|
28
|
+
* @param {Object} options Options object to pass to the dataProvider.
|
|
29
|
+
* @param {boolean} options.enabled Flag to conditionally run the query. If it's false, the query will not run
|
|
30
|
+
* @param {Function} options.onSuccess Side effect function to be executed upon success, e.g. { onSuccess: { refresh: true } }
|
|
31
|
+
* @param {Function} options.onError Side effect function to be executed upon failure, e.g. { onError: error => notify(error.message) }
|
|
32
|
+
*
|
|
33
|
+
* @typedef Params
|
|
34
|
+
* @prop params.ids The ids to get, e.g. [123, 456, 789]
|
|
35
|
+
* @prop params.meta Optional meta parameters
|
|
36
|
+
|
|
37
|
+
* @returns The current request state. Destructure as { data, error, isPending, isFetching, refetch }.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
*
|
|
41
|
+
* import { useGetManyAggregate, useRecordContext } from 'react-admin';
|
|
42
|
+
*
|
|
43
|
+
* const PostTags = () => {
|
|
44
|
+
* const record = useRecordContext();
|
|
45
|
+
* const { data, isPending, error } = useGetManyAggregate('tags', { ids: record.tagIds });
|
|
46
|
+
* if (isPending) { return <Loading />; }
|
|
47
|
+
* if (error) { return <p>ERROR</p>; }
|
|
48
|
+
* return (
|
|
49
|
+
* <ul>
|
|
50
|
+
* {data.map(tag => (
|
|
51
|
+
* <li key={tag.id}>{tag.name}</li>
|
|
52
|
+
* ))}
|
|
53
|
+
* </ul>
|
|
54
|
+
* );
|
|
55
|
+
* };
|
|
56
|
+
*/
|
|
57
|
+
export declare const useGetManyAggregate: <RecordType extends RaRecord = any, ErrorType = Error>(resource: string, params: Partial<GetManyParams<RecordType>>, options?: UseGetManyAggregateOptions<RecordType, ErrorType>) => UseGetManyHookValue<RecordType, ErrorType>;
|
|
58
|
+
export type UseGetManyAggregateOptions<RecordType extends RaRecord = any, ErrorType = Error> = Omit<UseQueryOptions<RecordType[], ErrorType>, 'queryKey' | 'queryFn'> & {
|
|
59
|
+
onSuccess?: (data: RecordType[]) => void;
|
|
60
|
+
onError?: (error: ErrorType) => void;
|
|
61
|
+
onSettled?: (data?: RecordType[], error?: ErrorType | null) => void;
|
|
62
|
+
};
|