@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,264 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
3
|
+
import get from 'lodash/get.js';
|
|
4
|
+
import isEqual from 'lodash/isEqual.js';
|
|
5
|
+
import lodashDebounce from 'lodash/debounce.js';
|
|
6
|
+
import { removeEmpty, useEvent } from '../../util';
|
|
7
|
+
import { useDataProvider, useGetManyReference } from '../../dataProvider';
|
|
8
|
+
import { useNotify } from '../../notification';
|
|
9
|
+
import { DEFAULT_MAX_RESULTS } from '../list/useListController';
|
|
10
|
+
import usePaginationState from '../usePaginationState';
|
|
11
|
+
import { useRecordSelection } from '../list/useRecordSelection';
|
|
12
|
+
import useSortState from '../useSortState';
|
|
13
|
+
import { useResourceContext, useGetResourceLabel } from '../../core';
|
|
14
|
+
import { useRecordContext } from '../record';
|
|
15
|
+
import { defaultExporter } from '../../export';
|
|
16
|
+
import { useTranslate } from '../../i18n';
|
|
17
|
+
/**
|
|
18
|
+
* Fetch reference records, and return them when available
|
|
19
|
+
*
|
|
20
|
+
* Uses dataProvider.getManyReference() internally.
|
|
21
|
+
*
|
|
22
|
+
* @example // fetch the comments related to the current post
|
|
23
|
+
* const { isPending, data } = useReferenceManyFieldController({
|
|
24
|
+
* reference: 'comments',
|
|
25
|
+
* target: 'post_id',
|
|
26
|
+
* record: { id: 123, title: 'hello, world' },
|
|
27
|
+
* resource: 'posts',
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* @param {Object} props
|
|
31
|
+
* @param {string} props.reference The linked resource name. Required.
|
|
32
|
+
* @param {string} props.target The target resource key. Required.
|
|
33
|
+
* @param {Object} props.filter The filter applied on the recorded records list
|
|
34
|
+
* @param {number} props.page the page number
|
|
35
|
+
* @param {number} props.perPage the number of item per page
|
|
36
|
+
* @param {Object} props.record The current resource record
|
|
37
|
+
* @param {string} props.resource The current resource name
|
|
38
|
+
* @param {Object} props.sort the sort to apply to the referenced records
|
|
39
|
+
* @param {string} props.source The key of the linked resource identifier
|
|
40
|
+
* @param {UseQuery Options} props.queryOptions `react-query` options`
|
|
41
|
+
*
|
|
42
|
+
* @returns {ListControllerResult} The reference many props
|
|
43
|
+
*/
|
|
44
|
+
export const useReferenceManyFieldController = (props) => {
|
|
45
|
+
const { debounce = 500, reference, target, filter = defaultFilter, exporter = defaultExporter, source = 'id', page: initialPage, perPage: initialPerPage, sort: initialSort = { field: 'id', order: 'DESC' }, queryOptions = {}, } = props;
|
|
46
|
+
const notify = useNotify();
|
|
47
|
+
const translate = useTranslate();
|
|
48
|
+
const record = useRecordContext(props);
|
|
49
|
+
const resource = useResourceContext(props);
|
|
50
|
+
const dataProvider = useDataProvider();
|
|
51
|
+
const queryClient = useQueryClient();
|
|
52
|
+
const { meta, ...otherQueryOptions } = queryOptions;
|
|
53
|
+
// pagination logic
|
|
54
|
+
const { page, setPage, perPage, setPerPage } = usePaginationState({
|
|
55
|
+
page: initialPage,
|
|
56
|
+
perPage: initialPerPage,
|
|
57
|
+
});
|
|
58
|
+
// sort logic
|
|
59
|
+
const { sort, setSort: setSortState } = useSortState(initialSort);
|
|
60
|
+
const setSort = useCallback((sort) => {
|
|
61
|
+
setSortState(sort);
|
|
62
|
+
setPage(1);
|
|
63
|
+
}, [setPage, setSortState]);
|
|
64
|
+
// selection logic
|
|
65
|
+
const [selectedIds, selectionModifiers] = useRecordSelection({
|
|
66
|
+
resource: reference,
|
|
67
|
+
storeKey: props.storeKey ?? `${resource}.${record?.id}.${reference}`,
|
|
68
|
+
});
|
|
69
|
+
const onUnselectItems = useCallback((fromAllStoreKeys) => {
|
|
70
|
+
return selectionModifiers.unselect(selectedIds, fromAllStoreKeys);
|
|
71
|
+
}, [selectedIds, selectionModifiers]);
|
|
72
|
+
// filter logic
|
|
73
|
+
const filterRef = useRef(filter);
|
|
74
|
+
const [displayedFilters, setDisplayedFilters] = useState({});
|
|
75
|
+
const [filterValues, setFilterValues] = useState(filter);
|
|
76
|
+
const hideFilter = useCallback((filterName) => {
|
|
77
|
+
setDisplayedFilters(previousState => {
|
|
78
|
+
const { [filterName]: _, ...newState } = previousState;
|
|
79
|
+
return newState;
|
|
80
|
+
});
|
|
81
|
+
setFilterValues(previousState => {
|
|
82
|
+
const { [filterName]: _, ...newState } = previousState;
|
|
83
|
+
return newState;
|
|
84
|
+
});
|
|
85
|
+
}, [setDisplayedFilters, setFilterValues]);
|
|
86
|
+
const showFilter = useCallback((filterName, defaultValue) => {
|
|
87
|
+
setDisplayedFilters(previousState => ({
|
|
88
|
+
...previousState,
|
|
89
|
+
[filterName]: true,
|
|
90
|
+
}));
|
|
91
|
+
setFilterValues(previousState => ({
|
|
92
|
+
...previousState,
|
|
93
|
+
[filterName]: defaultValue,
|
|
94
|
+
}));
|
|
95
|
+
}, [setDisplayedFilters, setFilterValues]);
|
|
96
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
97
|
+
const debouncedSetFilters = useCallback(lodashDebounce((filters, displayedFilters) => {
|
|
98
|
+
setFilterValues(removeEmpty(filters));
|
|
99
|
+
setDisplayedFilters(displayedFilters);
|
|
100
|
+
setPage(1);
|
|
101
|
+
}, debounce), [setDisplayedFilters, setFilterValues, setPage]);
|
|
102
|
+
const setFilters = useCallback((filters, displayedFilters, debounce = false) => {
|
|
103
|
+
if (debounce) {
|
|
104
|
+
debouncedSetFilters(filters, displayedFilters);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
setFilterValues(removeEmpty(filters));
|
|
108
|
+
setDisplayedFilters(displayedFilters);
|
|
109
|
+
setPage(1);
|
|
110
|
+
}
|
|
111
|
+
}, [setDisplayedFilters, setFilterValues, setPage, debouncedSetFilters]);
|
|
112
|
+
// handle filter prop change
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
if (!isEqual(filter, filterRef.current)) {
|
|
115
|
+
filterRef.current = filter;
|
|
116
|
+
setFilterValues(filter);
|
|
117
|
+
}
|
|
118
|
+
}, [filter]);
|
|
119
|
+
const recordValue = get(record, source);
|
|
120
|
+
const { data, total, meta: responseMeta, pageInfo, error, isFetching, isLoading, isPaused, isPending, isPlaceholderData, refetch, } = useGetManyReference(reference, {
|
|
121
|
+
target,
|
|
122
|
+
id: recordValue,
|
|
123
|
+
pagination: { page, perPage },
|
|
124
|
+
sort,
|
|
125
|
+
filter: filterValues,
|
|
126
|
+
meta,
|
|
127
|
+
}, {
|
|
128
|
+
enabled: recordValue != null,
|
|
129
|
+
placeholderData: previousData => previousData,
|
|
130
|
+
onError: error => notify(typeof error === 'string'
|
|
131
|
+
? error
|
|
132
|
+
: error?.message ||
|
|
133
|
+
"strato.notification.http_error', {
|
|
134
|
+
type: 'error',
|
|
135
|
+
messageArgs: {
|
|
136
|
+
_: typeof error === 'string'
|
|
137
|
+
? error
|
|
138
|
+
: error?.message
|
|
139
|
+
? error.message
|
|
140
|
+
: undefined,
|
|
141
|
+
},
|
|
142
|
+
}),
|
|
143
|
+
...otherQueryOptions,
|
|
144
|
+
});
|
|
145
|
+
const onSelectAll = useEvent(async ({ limit = 250, queryOptions = {}, } = {}) => {
|
|
146
|
+
const { meta, onSuccess, onError } = queryOptions;
|
|
147
|
+
try {
|
|
148
|
+
const results = await queryClient.fetchQuery({
|
|
149
|
+
queryKey: [
|
|
150
|
+
reference,
|
|
151
|
+
'getManyReference',
|
|
152
|
+
{
|
|
153
|
+
target,
|
|
154
|
+
id: get(record, source),
|
|
155
|
+
pagination: { page: 1, perPage: limit },
|
|
156
|
+
sort,
|
|
157
|
+
filter,
|
|
158
|
+
meta,
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
queryFn: () => dataProvider.getManyReference(reference, {
|
|
162
|
+
target,
|
|
163
|
+
id: get(record, source),
|
|
164
|
+
pagination: { page: 1, perPage: limit },
|
|
165
|
+
sort,
|
|
166
|
+
filter,
|
|
167
|
+
meta,
|
|
168
|
+
}),
|
|
169
|
+
});
|
|
170
|
+
const allIds = results.data?.map(({ id }) => id) || [];
|
|
171
|
+
selectionModifiers.select(allIds);
|
|
172
|
+
if (allIds.length === limit) {
|
|
173
|
+
notify("strato.message.select_all_limit_reached', {
|
|
174
|
+
messageArgs: { max: limit },
|
|
175
|
+
type: 'warning',
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
if (onSuccess) {
|
|
179
|
+
onSuccess(results);
|
|
180
|
+
}
|
|
181
|
+
return results.data;
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
if (onError) {
|
|
185
|
+
onError(error);
|
|
186
|
+
}
|
|
187
|
+
notify("strato.notification.http_error', { type: 'warning' });
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
const getData = useEvent(async ({ maxResults, meta: metaOverride } = {}) => {
|
|
191
|
+
if (recordValue == null || total === 0) {
|
|
192
|
+
return [];
|
|
193
|
+
}
|
|
194
|
+
const limit = maxResults ?? (total != null ? total : DEFAULT_MAX_RESULTS);
|
|
195
|
+
const { data } = await queryClient.fetchQuery({
|
|
196
|
+
queryKey: [
|
|
197
|
+
reference,
|
|
198
|
+
'getManyReference',
|
|
199
|
+
{
|
|
200
|
+
target,
|
|
201
|
+
id: recordValue,
|
|
202
|
+
pagination: { page: 1, perPage: limit },
|
|
203
|
+
sort,
|
|
204
|
+
filter: filterValues,
|
|
205
|
+
meta: metaOverride ?? meta,
|
|
206
|
+
},
|
|
207
|
+
],
|
|
208
|
+
queryFn: () => dataProvider.getManyReference(reference, {
|
|
209
|
+
target,
|
|
210
|
+
id: recordValue,
|
|
211
|
+
pagination: { page: 1, perPage: limit },
|
|
212
|
+
sort,
|
|
213
|
+
filter: filterValues,
|
|
214
|
+
meta: metaOverride ?? meta,
|
|
215
|
+
}),
|
|
216
|
+
});
|
|
217
|
+
return data;
|
|
218
|
+
});
|
|
219
|
+
const getResourceLabel = useGetResourceLabel();
|
|
220
|
+
const defaultTitle = translate(`resources.${reference}.page.list`, {
|
|
221
|
+
_: translate("strato.page.list', {
|
|
222
|
+
name: getResourceLabel(reference, 2),
|
|
223
|
+
}),
|
|
224
|
+
});
|
|
225
|
+
return {
|
|
226
|
+
sort,
|
|
227
|
+
data,
|
|
228
|
+
meta: responseMeta,
|
|
229
|
+
defaultTitle,
|
|
230
|
+
displayedFilters,
|
|
231
|
+
error,
|
|
232
|
+
exporter,
|
|
233
|
+
filterValues,
|
|
234
|
+
hideFilter,
|
|
235
|
+
isFetching,
|
|
236
|
+
isLoading,
|
|
237
|
+
isPaused,
|
|
238
|
+
isPending,
|
|
239
|
+
isPlaceholderData,
|
|
240
|
+
onSelect: selectionModifiers.select,
|
|
241
|
+
onSelectAll,
|
|
242
|
+
onToggleItem: selectionModifiers.toggle,
|
|
243
|
+
onUnselectItems,
|
|
244
|
+
page,
|
|
245
|
+
perPage,
|
|
246
|
+
refetch,
|
|
247
|
+
resource: reference,
|
|
248
|
+
selectedIds,
|
|
249
|
+
setFilters,
|
|
250
|
+
setPage,
|
|
251
|
+
setPerPage,
|
|
252
|
+
hasNextPage: pageInfo
|
|
253
|
+
? pageInfo.hasNextPage
|
|
254
|
+
: total != null
|
|
255
|
+
? page * perPage < total
|
|
256
|
+
: undefined,
|
|
257
|
+
hasPreviousPage: pageInfo ? pageInfo.hasPreviousPage : page > 1,
|
|
258
|
+
setSort,
|
|
259
|
+
showFilter,
|
|
260
|
+
total,
|
|
261
|
+
getData,
|
|
262
|
+
};
|
|
263
|
+
};
|
|
264
|
+
const defaultFilter = {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import useFilterState from './useFilterState';
|
|
2
|
+
import useSortState, { SortProps } from './useSortState';
|
|
3
|
+
import usePaginationState, { PaginationHookResult } from './usePaginationState';
|
|
4
|
+
import { useCheckMinimumRequiredProps } from './checkMinimumRequiredProps';
|
|
5
|
+
export type { PaginationHookResult, SortProps };
|
|
6
|
+
export { useCheckMinimumRequiredProps, useFilterState, usePaginationState, useSortState, };
|
|
7
|
+
export * from './button';
|
|
8
|
+
export * from './create';
|
|
9
|
+
export * from './edit';
|
|
10
|
+
export * from './field';
|
|
11
|
+
export * from './input';
|
|
12
|
+
export * from './list';
|
|
13
|
+
export * from './record';
|
|
14
|
+
export * from './saveContext';
|
|
15
|
+
export * from './show';
|
|
16
|
+
export * from './useReference';
|
|
17
|
+
export * from './usePrevNextController';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import useFilterState from './useFilterState';
|
|
2
|
+
import useSortState from './useSortState';
|
|
3
|
+
import usePaginationState from './usePaginationState';
|
|
4
|
+
import { useCheckMinimumRequiredProps } from './checkMinimumRequiredProps';
|
|
5
|
+
export { useCheckMinimumRequiredProps, useFilterState, usePaginationState, useSortState, };
|
|
6
|
+
export * from './button';
|
|
7
|
+
export * from './create';
|
|
8
|
+
export * from './edit';
|
|
9
|
+
export * from './field';
|
|
10
|
+
export * from './input';
|
|
11
|
+
export * from './list';
|
|
12
|
+
export * from './record';
|
|
13
|
+
export * from './saveContext';
|
|
14
|
+
export * from './show';
|
|
15
|
+
export * from './useReference';
|
|
16
|
+
export * from './usePrevNextController';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { UseFieldArrayReturn } from 'react-hook-form';
|
|
2
|
+
/**
|
|
3
|
+
* A React context that provides access to an ArrayInput methods as provided by react-hook-form
|
|
4
|
+
* Useful to create custom array input iterators.
|
|
5
|
+
* @see {ArrayInput}
|
|
6
|
+
* @see {@link https://react-hook-form.com/docs/usefieldarray}
|
|
7
|
+
*/
|
|
8
|
+
export declare const ArrayInputContext: import("react").Context<ArrayInputContextValue | undefined>;
|
|
9
|
+
export type ArrayInputContextValue = UseFieldArrayReturn;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createContext } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* A React context that provides access to an ArrayInput methods as provided by react-hook-form
|
|
4
|
+
* Useful to create custom array input iterators.
|
|
5
|
+
* @see {ArrayInput}
|
|
6
|
+
* @see {@link https://react-hook-form.com/docs/usefieldarray}
|
|
7
|
+
*/
|
|
8
|
+
export const ArrayInputContext = createContext(undefined);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A React context that provides access to a SimpleFormIterator data (the total number of items) and mutators (add, reorder and remove).
|
|
3
|
+
* Useful to create custom array input iterators.
|
|
4
|
+
* @see {SimpleFormIterator}
|
|
5
|
+
* @see {ArrayInput}
|
|
6
|
+
*/
|
|
7
|
+
export declare const SimpleFormIteratorContext: import("react").Context<SimpleFormIteratorContextValue | undefined>;
|
|
8
|
+
export type SimpleFormIteratorContextValue = {
|
|
9
|
+
add: (item?: any) => void;
|
|
10
|
+
clear: () => void;
|
|
11
|
+
remove: (index: number) => void;
|
|
12
|
+
reOrder: (index: number, newIndex: number) => void;
|
|
13
|
+
source: string;
|
|
14
|
+
total: number;
|
|
15
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createContext } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* A React context that provides access to a SimpleFormIterator data (the total number of items) and mutators (add, reorder and remove).
|
|
4
|
+
* Useful to create custom array input iterators.
|
|
5
|
+
* @see {SimpleFormIterator}
|
|
6
|
+
* @see {ArrayInput}
|
|
7
|
+
*/
|
|
8
|
+
export const SimpleFormIteratorContext = createContext(undefined);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A React context that provides access to a SimpleFormIterator item meta (its index and the total number of items) and mutators (reorder and remove this remove).
|
|
3
|
+
* Useful to create custom array input iterators.
|
|
4
|
+
* @see {SimpleFormIterator}
|
|
5
|
+
* @see {ArrayInput}
|
|
6
|
+
*/
|
|
7
|
+
export declare const SimpleFormIteratorItemContext: import("react").Context<SimpleFormIteratorItemContextValue | undefined>;
|
|
8
|
+
export type SimpleFormIteratorItemContextValue = {
|
|
9
|
+
index: number;
|
|
10
|
+
total: number;
|
|
11
|
+
remove: () => void;
|
|
12
|
+
reOrder: (newIndex: number) => void;
|
|
13
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createContext } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* A React context that provides access to a SimpleFormIterator item meta (its index and the total number of items) and mutators (reorder and remove this remove).
|
|
4
|
+
* Useful to create custom array input iterators.
|
|
5
|
+
* @see {SimpleFormIterator}
|
|
6
|
+
* @see {ArrayInput}
|
|
7
|
+
*/
|
|
8
|
+
export const SimpleFormIteratorItemContext = createContext(undefined);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from './referenceDataStatus';
|
|
2
|
+
export * from './useReferenceArrayInputController';
|
|
3
|
+
export * from './useReferenceInputController';
|
|
4
|
+
export * from './ReferenceInputBase';
|
|
5
|
+
export * from './ReferenceArrayInputBase';
|
|
6
|
+
export * from './ArrayInputBase';
|
|
7
|
+
export * from './ArrayInputContext';
|
|
8
|
+
export * from './SimpleFormIteratorBase';
|
|
9
|
+
export * from './SimpleFormIteratorItemBase';
|
|
10
|
+
export * from './useArrayInput';
|
|
11
|
+
export * from './sanitizeInputRestProps';
|
|
12
|
+
export * from './SimpleFormIteratorContext';
|
|
13
|
+
export * from './SimpleFormIteratorItemContext';
|
|
14
|
+
export * from './useSimpleFormIterator';
|
|
15
|
+
export * from './useSimpleFormIteratorItem';
|
|
16
|
+
export * from './useGetArrayInputNewItemDefaults';
|
|
17
|
+
export * from './useSupportCreateSuggestion';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from './referenceDataStatus';
|
|
2
|
+
export * from './useReferenceArrayInputController';
|
|
3
|
+
export * from './useReferenceInputController';
|
|
4
|
+
export * from './ReferenceInputBase';
|
|
5
|
+
export * from './ReferenceArrayInputBase';
|
|
6
|
+
export * from './ArrayInputBase';
|
|
7
|
+
export * from './ArrayInputContext';
|
|
8
|
+
export * from './SimpleFormIteratorBase';
|
|
9
|
+
export * from './SimpleFormIteratorItemBase';
|
|
10
|
+
export * from './useArrayInput';
|
|
11
|
+
export * from './sanitizeInputRestProps';
|
|
12
|
+
export * from './SimpleFormIteratorContext';
|
|
13
|
+
export * from './SimpleFormIteratorItemContext';
|
|
14
|
+
export * from './useSimpleFormIterator';
|
|
15
|
+
export * from './useSimpleFormIteratorItem';
|
|
16
|
+
export * from './useGetArrayInputNewItemDefaults';
|
|
17
|
+
export * from './useSupportCreateSuggestion';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { RaRecord, TranslateFunction } from '../../types';
|
|
2
|
+
import { MatchingReferencesError } from './types';
|
|
3
|
+
import { ControllerRenderProps } from 'react-hook-form';
|
|
4
|
+
interface GetStatusForInputParams<RecordType extends RaRecord = RaRecord> {
|
|
5
|
+
field: Pick<ControllerRenderProps, 'value'>;
|
|
6
|
+
matchingReferences: RecordType[] | MatchingReferencesError;
|
|
7
|
+
referenceRecord: RecordType;
|
|
8
|
+
translate: TranslateFunction;
|
|
9
|
+
}
|
|
10
|
+
export declare const getStatusForInput: <RecordType extends RaRecord = RaRecord>({ field, matchingReferences, referenceRecord, translate, }: GetStatusForInputParams<RecordType>) => {
|
|
11
|
+
waiting: any;
|
|
12
|
+
error: string | null;
|
|
13
|
+
warning: string | null;
|
|
14
|
+
choices: RecordType[];
|
|
15
|
+
};
|
|
16
|
+
export declare const REFERENCES_STATUS_READY = "REFERENCES_STATUS_READY";
|
|
17
|
+
export declare const REFERENCES_STATUS_INCOMPLETE = "REFERENCES_STATUS_INCOMPLETE";
|
|
18
|
+
export declare const REFERENCES_STATUS_EMPTY = "REFERENCES_STATUS_EMPTY";
|
|
19
|
+
export declare const getSelectedReferencesStatus: <RecordType extends RaRecord = any>(field: Pick<ControllerRenderProps, "value">, referenceRecords: RecordType[]) => "REFERENCES_STATUS_READY" | "REFERENCES_STATUS_INCOMPLETE" | "REFERENCES_STATUS_EMPTY";
|
|
20
|
+
interface GetStatusForArrayInputParams<RecordType extends RaRecord = any> {
|
|
21
|
+
field: ControllerRenderProps;
|
|
22
|
+
matchingReferences: RecordType[] | MatchingReferencesError;
|
|
23
|
+
referenceRecords: RecordType[];
|
|
24
|
+
translate: TranslateFunction;
|
|
25
|
+
}
|
|
26
|
+
export declare const getStatusForArrayInput: <RecordType extends RaRecord = any>({ field, matchingReferences, referenceRecords, translate, }: GetStatusForArrayInputParams<RecordType>) => {
|
|
27
|
+
waiting: boolean;
|
|
28
|
+
error: string | null;
|
|
29
|
+
warning: string | null;
|
|
30
|
+
choices: RecordType[];
|
|
31
|
+
};
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const isMatchingReferencesError = (matchingReferences) => matchingReferences && matchingReferences.error !== undefined;
|
|
2
|
+
export const getStatusForInput = ({ field, matchingReferences, referenceRecord, translate = x => x, }) => {
|
|
3
|
+
const matchingReferencesError = isMatchingReferencesError(matchingReferences)
|
|
4
|
+
? translate(matchingReferences.error, {
|
|
5
|
+
_: matchingReferences.error,
|
|
6
|
+
})
|
|
7
|
+
: null;
|
|
8
|
+
const selectedReferenceError = field.value && !referenceRecord
|
|
9
|
+
? translate("strato.input.references.single_missing', {
|
|
10
|
+
_: "strato.input.references.single_missing',
|
|
11
|
+
})
|
|
12
|
+
: null;
|
|
13
|
+
return {
|
|
14
|
+
waiting: (field.value && selectedReferenceError && !matchingReferences) ||
|
|
15
|
+
(!field.value && !matchingReferences),
|
|
16
|
+
error: (field.value &&
|
|
17
|
+
selectedReferenceError &&
|
|
18
|
+
matchingReferencesError) ||
|
|
19
|
+
(!field.value && matchingReferencesError)
|
|
20
|
+
? field.value
|
|
21
|
+
? selectedReferenceError
|
|
22
|
+
: matchingReferencesError
|
|
23
|
+
: null,
|
|
24
|
+
warning: selectedReferenceError || matchingReferencesError,
|
|
25
|
+
choices: Array.isArray(matchingReferences)
|
|
26
|
+
? matchingReferences
|
|
27
|
+
: [referenceRecord].filter(choice => choice),
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export const REFERENCES_STATUS_READY = 'REFERENCES_STATUS_READY';
|
|
31
|
+
export const REFERENCES_STATUS_INCOMPLETE = 'REFERENCES_STATUS_INCOMPLETE';
|
|
32
|
+
export const REFERENCES_STATUS_EMPTY = 'REFERENCES_STATUS_EMPTY';
|
|
33
|
+
export const getSelectedReferencesStatus = (field, referenceRecords) => !field.value || field.value.length === referenceRecords.length
|
|
34
|
+
? REFERENCES_STATUS_READY
|
|
35
|
+
: referenceRecords.length > 0
|
|
36
|
+
? REFERENCES_STATUS_INCOMPLETE
|
|
37
|
+
: REFERENCES_STATUS_EMPTY;
|
|
38
|
+
export const getStatusForArrayInput = ({ field, matchingReferences, referenceRecords, translate = x => x, }) => {
|
|
39
|
+
// selectedReferencesDataStatus can be "empty" (no data was found for references from input.value)
|
|
40
|
+
// or "incomplete" (Not all of the reference data was found)
|
|
41
|
+
// or "ready" (all references data was found or there is no references from input.value)
|
|
42
|
+
const selectedReferencesDataStatus = getSelectedReferencesStatus(field, referenceRecords);
|
|
43
|
+
const matchingReferencesError = isMatchingReferencesError(matchingReferences)
|
|
44
|
+
? translate(matchingReferences.error, {
|
|
45
|
+
_: matchingReferences.error,
|
|
46
|
+
})
|
|
47
|
+
: null;
|
|
48
|
+
const choices = Array.isArray(matchingReferences)
|
|
49
|
+
? referenceRecords.concat(matchingReferences.filter(choice => referenceRecords.findIndex(c => c.id === choice.id) === -1))
|
|
50
|
+
: referenceRecords;
|
|
51
|
+
return {
|
|
52
|
+
waiting: (!matchingReferences &&
|
|
53
|
+
field.value &&
|
|
54
|
+
selectedReferencesDataStatus === REFERENCES_STATUS_EMPTY) ||
|
|
55
|
+
(!matchingReferences && !field.value),
|
|
56
|
+
error: matchingReferencesError &&
|
|
57
|
+
(!field.value ||
|
|
58
|
+
(field.value &&
|
|
59
|
+
selectedReferencesDataStatus === REFERENCES_STATUS_EMPTY))
|
|
60
|
+
? translate("strato.input.references.all_missing', {
|
|
61
|
+
_: "strato.input.references.all_missing',
|
|
62
|
+
})
|
|
63
|
+
: null,
|
|
64
|
+
warning: matchingReferencesError ||
|
|
65
|
+
(field.value &&
|
|
66
|
+
selectedReferencesDataStatus !== REFERENCES_STATUS_READY)
|
|
67
|
+
? matchingReferencesError ||
|
|
68
|
+
translate("strato.input.references.many_missing', {
|
|
69
|
+
_: "strato.input.references.many_missing',
|
|
70
|
+
})
|
|
71
|
+
: null,
|
|
72
|
+
choices,
|
|
73
|
+
};
|
|
74
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const sanitizeInputRestProps: ({ afterSubmit, allowNull, alwaysOn, beforeSubmit, component, data, defaultValue, error, format, formatOnBlur, initializeForm, input, isEqual, isRequired, label, limitChoicesToValue, locale, meta, multiple, name, options, optionText, optionValue, parse, record, ref, refetch, render, resource, setFilter, setPagination, setSort, shouldUnregister, source, submitError, subscription, textAlign, translate, translateChoice, validate, validateFields, value, ...rest }: any) => any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const sanitizeInputRestProps = ({ afterSubmit, allowNull, alwaysOn, beforeSubmit, component, data, defaultValue, error, format, formatOnBlur, initializeForm, input, isEqual, isRequired, label, limitChoicesToValue, locale, meta, multiple, name, options, optionText, optionValue, parse, record, ref, refetch, render, resource, setFilter, setPagination, setSort, shouldUnregister, source, submitError, subscription, textAlign, translate, translateChoice, validate, validateFields, value, ...rest }) => rest;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ArrayInputContextValue } from './ArrayInputContext';
|
|
2
|
+
/**
|
|
3
|
+
* A hook to access an array input methods as provided by react-hook-form.
|
|
4
|
+
* Useful to create custom array input iterators.
|
|
5
|
+
* @see {ArrayInput}
|
|
6
|
+
* @see https://react-hook-form.com/docs/usefieldarray
|
|
7
|
+
*/
|
|
8
|
+
export declare const useArrayInput: (props?: Partial<ArrayInputContextValue>) => ArrayInputContextValue;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useContext, useMemo } from 'react';
|
|
2
|
+
import { ArrayInputContext } from './ArrayInputContext';
|
|
3
|
+
/**
|
|
4
|
+
* A hook to access an array input methods as provided by react-hook-form.
|
|
5
|
+
* Useful to create custom array input iterators.
|
|
6
|
+
* @see {ArrayInput}
|
|
7
|
+
* @see https://react-hook-form.com/docs/usefieldarray
|
|
8
|
+
*/
|
|
9
|
+
export const useArrayInput = (props) => {
|
|
10
|
+
const context = useContext(ArrayInputContext);
|
|
11
|
+
const memo = useMemo(() => ({
|
|
12
|
+
append: props?.append,
|
|
13
|
+
fields: props?.fields,
|
|
14
|
+
insert: props?.insert,
|
|
15
|
+
move: props?.move,
|
|
16
|
+
prepend: props?.prepend,
|
|
17
|
+
remove: props?.remove,
|
|
18
|
+
replace: props?.replace,
|
|
19
|
+
swap: props?.swap,
|
|
20
|
+
update: props?.update,
|
|
21
|
+
}), [props]);
|
|
22
|
+
if (props?.fields) {
|
|
23
|
+
return memo;
|
|
24
|
+
}
|
|
25
|
+
if (!context) {
|
|
26
|
+
throw new Error('useArrayInput must be used inside an ArrayInputContextProvider');
|
|
27
|
+
}
|
|
28
|
+
return context;
|
|
29
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Children, isValidElement, useRef } from 'react';
|
|
2
|
+
import { FormDataConsumer } from '../../form/FormDataConsumer';
|
|
3
|
+
import { useEvent } from '../../util';
|
|
4
|
+
export const useGetArrayInputNewItemDefaults = (fields) => {
|
|
5
|
+
const initialDefaultValue = useRef({});
|
|
6
|
+
if (fields.length > 0) {
|
|
7
|
+
const { id, ...rest } = fields[0];
|
|
8
|
+
initialDefaultValue.current = rest;
|
|
9
|
+
for (const k in initialDefaultValue.current)
|
|
10
|
+
initialDefaultValue.current[k] = null;
|
|
11
|
+
}
|
|
12
|
+
return useEvent((inputs) => {
|
|
13
|
+
if (Children.count(inputs) === 1 &&
|
|
14
|
+
isValidElement(Children.only(inputs)) &&
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
!Children.only(inputs).props.source &&
|
|
17
|
+
// Make sure it's not a FormDataConsumer
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
Children.only(inputs).type !== FormDataConsumer) {
|
|
20
|
+
// ArrayInput used for an array of scalar values
|
|
21
|
+
// (e.g. tags: ['foo', 'bar'])
|
|
22
|
+
return '';
|
|
23
|
+
}
|
|
24
|
+
// ArrayInput used for an array of objects
|
|
25
|
+
// (e.g. authors: [{ firstName: 'John', lastName: 'Doe' }, { firstName: 'Jane', lastName: 'Doe' }])
|
|
26
|
+
const defaultValue = initialDefaultValue.current;
|
|
27
|
+
Children.forEach(inputs, input => {
|
|
28
|
+
if (isValidElement(input) &&
|
|
29
|
+
input.type !== FormDataConsumer &&
|
|
30
|
+
input.props.source) {
|
|
31
|
+
defaultValue[input.props.source] =
|
|
32
|
+
input.props.defaultValue ?? null;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return defaultValue;
|
|
36
|
+
});
|
|
37
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { UseQueryOptions } from '@tanstack/react-query';
|
|
2
|
+
import type { FilterPayload, RaRecord, SortPayload } from '../../types';
|
|
3
|
+
import type { ChoicesContextValue } from '../../form';
|
|
4
|
+
/**
|
|
5
|
+
* Prepare data for the ReferenceArrayInput components
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
*
|
|
9
|
+
* const { allChoices, availableChoices, selectedChoices, error, isFetching, isLoading, isPending } = useReferenceArrayInputController({
|
|
10
|
+
* record: { referenceIds: ['id1', 'id2']};
|
|
11
|
+
* reference: 'reference';
|
|
12
|
+
* resource: 'resource';
|
|
13
|
+
* source: 'referenceIds';
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* @param {Object} props
|
|
17
|
+
* @param {Object} props.record The current resource record
|
|
18
|
+
* @param {string} props.reference The linked resource name
|
|
19
|
+
* @param {string} props.resource The current resource name
|
|
20
|
+
* @param {string} props.source The key of the linked resource identifier
|
|
21
|
+
*
|
|
22
|
+
* @param {Props} props
|
|
23
|
+
*
|
|
24
|
+
* @return {Object} controllerProps Fetched data and callbacks for the ReferenceArrayInput components
|
|
25
|
+
*/
|
|
26
|
+
export declare const useReferenceArrayInputController: <RecordType extends RaRecord = any>(props: UseReferenceArrayInputParams<RecordType>) => ChoicesContextValue<RecordType>;
|
|
27
|
+
export interface UseReferenceArrayInputParams<RecordType extends RaRecord = any> {
|
|
28
|
+
debounce?: number;
|
|
29
|
+
filter?: FilterPayload;
|
|
30
|
+
queryOptions?: Omit<UseQueryOptions<{
|
|
31
|
+
data: RecordType[];
|
|
32
|
+
total?: number;
|
|
33
|
+
pageInfo?: {
|
|
34
|
+
hasNextPage?: boolean;
|
|
35
|
+
hasPreviousPage?: boolean;
|
|
36
|
+
};
|
|
37
|
+
}>, 'queryFn' | 'queryKey'> & {
|
|
38
|
+
meta?: any;
|
|
39
|
+
};
|
|
40
|
+
page?: number;
|
|
41
|
+
perPage?: number;
|
|
42
|
+
record?: RecordType;
|
|
43
|
+
reference: string;
|
|
44
|
+
resource?: string;
|
|
45
|
+
sort?: SortPayload;
|
|
46
|
+
source: string;
|
|
47
|
+
enableGetChoices?: (filters: any) => boolean;
|
|
48
|
+
}
|