@headless-adminapp/app 0.0.8-0.0.9-alpha.1.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/LICENSE +21 -0
- package/dist/app/context.d.ts +8 -0
- package/dist/app/context.js +5 -0
- package/dist/app/hooks/index.d.ts +1 -0
- package/dist/app/hooks/index.js +17 -0
- package/dist/app/hooks/useAppContext.d.ts +2 -0
- package/dist/app/hooks/useAppContext.js +12 -0
- package/dist/app/index.d.ts +2 -0
- package/dist/app/index.js +7 -0
- package/dist/appearance/context.d.ts +7 -0
- package/dist/appearance/context.js +5 -0
- package/dist/appearance/hooks/index.d.ts +1 -0
- package/dist/appearance/hooks/index.js +17 -0
- package/dist/appearance/hooks/useAppearanceContext.d.ts +1 -0
- package/dist/appearance/hooks/useAppearanceContext.js +12 -0
- package/dist/appearance/index.d.ts +2 -0
- package/dist/appearance/index.js +20 -0
- package/dist/auth/AuthProvider.d.ts +7 -0
- package/dist/auth/AuthProvider.js +104 -0
- package/dist/auth/context.d.ts +30 -0
- package/dist/auth/context.js +5 -0
- package/dist/auth/hooks/index.d.ts +2 -0
- package/dist/auth/hooks/index.js +18 -0
- package/dist/auth/hooks/useAuthSession.d.ts +2 -0
- package/dist/auth/hooks/useAuthSession.js +16 -0
- package/dist/auth/hooks/useLogout.d.ts +1 -0
- package/dist/auth/hooks/useLogout.js +19 -0
- package/dist/auth/index.d.ts +4 -0
- package/dist/auth/index.js +23 -0
- package/dist/auth/types.d.ts +10 -0
- package/dist/auth/types.js +2 -0
- package/dist/builders/CommandBuilder.d.ts +176 -0
- package/dist/builders/CommandBuilder.js +474 -0
- package/dist/builders/SchemaExperienceBuilder.d.ts +69 -0
- package/dist/builders/SchemaExperienceBuilder.js +267 -0
- package/dist/builders/index.d.ts +2 -0
- package/dist/builders/index.js +7 -0
- package/dist/command/hooks/index.d.ts +2 -0
- package/dist/command/hooks/index.js +18 -0
- package/dist/command/hooks/useBaseCommandHandlerContext.d.ts +4 -0
- package/dist/command/hooks/useBaseCommandHandlerContext.js +42 -0
- package/dist/command/hooks/useCommands.d.ts +7 -0
- package/dist/command/hooks/useCommands.js +16 -0
- package/dist/command/index.d.ts +2 -0
- package/dist/command/index.js +18 -0
- package/dist/command/types.d.ts +76 -0
- package/dist/command/types.js +2 -0
- package/dist/command/utils/index.d.ts +3 -0
- package/dist/command/utils/index.js +63 -0
- package/dist/components/ScrollView/index.d.ts +10 -0
- package/dist/components/ScrollView/index.js +11 -0
- package/dist/dataform/DataFormProvider/DataResolver.d.ts +5 -0
- package/dist/dataform/DataFormProvider/DataResolver.js +143 -0
- package/dist/dataform/DataFormProvider/InitialValueResolver.d.ts +1 -0
- package/dist/dataform/DataFormProvider/InitialValueResolver.js +44 -0
- package/dist/dataform/DataFormProvider/ReadonlyInfoResolver.d.ts +3 -0
- package/dist/dataform/DataFormProvider/ReadonlyInfoResolver.js +27 -0
- package/dist/dataform/DataFormProvider/index.d.ts +10 -0
- package/dist/dataform/DataFormProvider/index.js +72 -0
- package/dist/dataform/context.d.ts +22 -0
- package/dist/dataform/context.js +5 -0
- package/dist/dataform/hooks/index.d.ts +11 -0
- package/dist/dataform/hooks/index.js +27 -0
- package/dist/dataform/hooks/useFormInstance.d.ts +1 -0
- package/dist/dataform/hooks/useFormInstance.js +8 -0
- package/dist/dataform/hooks/useFormIsDirty.d.ts +1 -0
- package/dist/dataform/hooks/useFormIsDirty.js +8 -0
- package/dist/dataform/hooks/useFormIsReadonly.d.ts +1 -0
- package/dist/dataform/hooks/useFormIsReadonly.js +9 -0
- package/dist/dataform/hooks/useFormNotifications.d.ts +4 -0
- package/dist/dataform/hooks/useFormNotifications.js +34 -0
- package/dist/dataform/hooks/useFormRecord.d.ts +1 -0
- package/dist/dataform/hooks/useFormRecord.js +9 -0
- package/dist/dataform/hooks/useFormSave.d.ts +2 -0
- package/dist/dataform/hooks/useFormSave.js +135 -0
- package/dist/dataform/hooks/useFormSchema.d.ts +2 -0
- package/dist/dataform/hooks/useFormSchema.js +8 -0
- package/dist/dataform/hooks/useLoadFormGridPage.d.ts +18 -0
- package/dist/dataform/hooks/useLoadFormGridPage.js +73 -0
- package/dist/dataform/hooks/useMainFormCommands.d.ts +16 -0
- package/dist/dataform/hooks/useMainFormCommands.js +47 -0
- package/dist/dataform/hooks/useRecordId.d.ts +1 -0
- package/dist/dataform/hooks/useRecordId.js +8 -0
- package/dist/dataform/hooks/useRecordTitle.d.ts +1 -0
- package/dist/dataform/hooks/useRecordTitle.js +20 -0
- package/dist/dataform/hooks/useSelectedForm.d.ts +3 -0
- package/dist/dataform/hooks/useSelectedForm.js +8 -0
- package/dist/dataform/utils/index.d.ts +62 -0
- package/dist/dataform/utils/index.js +356 -0
- package/dist/datagrid/DataGridProvider/DataResolver.d.ts +2 -0
- package/dist/datagrid/DataGridProvider/DataResolver.js +208 -0
- package/dist/datagrid/DataGridProvider/index.d.ts +18 -0
- package/dist/datagrid/DataGridProvider/index.js +77 -0
- package/dist/datagrid/DataGridProvider/transformViewColumns.d.ts +5 -0
- package/dist/datagrid/DataGridProvider/transformViewColumns.js +29 -0
- package/dist/datagrid/DataGridProvider/utils.d.ts +3 -0
- package/dist/datagrid/DataGridProvider/utils.js +74 -0
- package/dist/datagrid/column-filter/constants.d.ts +4 -0
- package/dist/datagrid/column-filter/constants.js +482 -0
- package/dist/datagrid/column-filter/index.d.ts +3 -0
- package/dist/datagrid/column-filter/index.js +7 -0
- package/dist/datagrid/column-filter/types.d.ts +65 -0
- package/dist/datagrid/column-filter/types.js +2 -0
- package/dist/datagrid/column-filter/utils.d.ts +3 -0
- package/dist/datagrid/column-filter/utils.js +8 -0
- package/dist/datagrid/context.d.ts +33 -0
- package/dist/datagrid/context.js +5 -0
- package/dist/datagrid/hooks/index.d.ts +19 -0
- package/dist/datagrid/hooks/index.js +35 -0
- package/dist/datagrid/hooks/useChangeView.d.ts +1 -0
- package/dist/datagrid/hooks/useChangeView.js +12 -0
- package/dist/datagrid/hooks/useGridColumnFilter.d.ts +2 -0
- package/dist/datagrid/hooks/useGridColumnFilter.js +16 -0
- package/dist/datagrid/hooks/useGridColumns.d.ts +3 -0
- package/dist/datagrid/hooks/useGridColumns.js +8 -0
- package/dist/datagrid/hooks/useGridCommands.d.ts +3 -0
- package/dist/datagrid/hooks/useGridCommands.js +9 -0
- package/dist/datagrid/hooks/useGridData.d.ts +1 -0
- package/dist/datagrid/hooks/useGridData.js +9 -0
- package/dist/datagrid/hooks/useGridDataState.d.ts +5 -0
- package/dist/datagrid/hooks/useGridDataState.js +9 -0
- package/dist/datagrid/hooks/useGridExtraFilter.d.ts +1 -0
- package/dist/datagrid/hooks/useGridExtraFilter.js +8 -0
- package/dist/datagrid/hooks/useGridOptions.d.ts +1 -0
- package/dist/datagrid/hooks/useGridOptions.js +6 -0
- package/dist/datagrid/hooks/useGridPagination.d.ts +1 -0
- package/dist/datagrid/hooks/useGridPagination.js +6 -0
- package/dist/datagrid/hooks/useGridRefresh.d.ts +1 -0
- package/dist/datagrid/hooks/useGridRefresh.js +18 -0
- package/dist/datagrid/hooks/useGridSchema.d.ts +2 -0
- package/dist/datagrid/hooks/useGridSchema.js +8 -0
- package/dist/datagrid/hooks/useGridSelection.d.ts +1 -0
- package/dist/datagrid/hooks/useGridSelection.js +21 -0
- package/dist/datagrid/hooks/useGridSorting.d.ts +3 -0
- package/dist/datagrid/hooks/useGridSorting.js +14 -0
- package/dist/datagrid/hooks/useGridViewLookupData.d.ts +1 -0
- package/dist/datagrid/hooks/useGridViewLookupData.js +9 -0
- package/dist/datagrid/hooks/useLoadMainGridPage.d.ts +20 -0
- package/dist/datagrid/hooks/useLoadMainGridPage.js +55 -0
- package/dist/datagrid/hooks/useMainGridCommands.d.ts +19 -0
- package/dist/datagrid/hooks/useMainGridCommands.js +228 -0
- package/dist/datagrid/hooks/useMaxRecords.d.ts +1 -0
- package/dist/datagrid/hooks/useMaxRecords.js +8 -0
- package/dist/datagrid/hooks/useSearchText.d.ts +1 -0
- package/dist/datagrid/hooks/useSearchText.js +14 -0
- package/dist/datagrid/hooks/useSelectedView.d.ts +3 -0
- package/dist/datagrid/hooks/useSelectedView.js +8 -0
- package/dist/datagrid/hooks/useSubGridCommands.d.ts +5 -0
- package/dist/datagrid/hooks/useSubGridCommands.js +87 -0
- package/dist/dialog/DialogProvider.d.ts +5 -0
- package/dist/dialog/DialogProvider.js +13 -0
- package/dist/dialog/context.d.ts +6 -0
- package/dist/dialog/context.js +5 -0
- package/dist/dialog/hooks/index.d.ts +8 -0
- package/dist/dialog/hooks/index.js +24 -0
- package/dist/dialog/hooks/useCloseDialog.d.ts +1 -0
- package/dist/dialog/hooks/useCloseDialog.js +30 -0
- package/dist/dialog/hooks/useDialogItem.d.ts +1 -0
- package/dist/dialog/hooks/useDialogItem.js +8 -0
- package/dist/dialog/hooks/useDialogItems.d.ts +1 -0
- package/dist/dialog/hooks/useDialogItems.js +8 -0
- package/dist/dialog/hooks/useOpenAlertDialog.d.ts +2 -0
- package/dist/dialog/hooks/useOpenAlertDialog.js +20 -0
- package/dist/dialog/hooks/useOpenConfirmDialog.d.ts +2 -0
- package/dist/dialog/hooks/useOpenConfirmDialog.js +26 -0
- package/dist/dialog/hooks/useOpenDialog.d.ts +5 -0
- package/dist/dialog/hooks/useOpenDialog.js +27 -0
- package/dist/dialog/hooks/useOpenErrorDialog.d.ts +2 -0
- package/dist/dialog/hooks/useOpenErrorDialog.js +16 -0
- package/dist/dialog/hooks/useOpenPromptDialog.d.ts +3 -0
- package/dist/dialog/hooks/useOpenPromptDialog.js +26 -0
- package/dist/dialog/index.d.ts +3 -0
- package/dist/dialog/index.js +22 -0
- package/dist/form/FormValidationStringContext.d.ts +12 -0
- package/dist/form/FormValidationStringContext.js +19 -0
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/index.js +21 -0
- package/dist/hooks/useDebouncedValue.d.ts +3 -0
- package/dist/hooks/useDebouncedValue.js +32 -0
- package/dist/hooks/useElementLayout.d.ts +7 -0
- package/dist/hooks/useElementLayout.js +34 -0
- package/dist/hooks/useIsMobile.d.ts +1 -0
- package/dist/hooks/useIsMobile.js +21 -0
- package/dist/hooks/useStorageState.d.ts +2 -0
- package/dist/hooks/useStorageState.js +26 -0
- package/dist/hooks/useSystemColorScheme.d.ts +1 -0
- package/dist/hooks/useSystemColorScheme.js +27 -0
- package/dist/insights/context.d.ts +2 -0
- package/dist/insights/context.js +5 -0
- package/dist/locale/context.d.ts +2 -0
- package/dist/locale/context.js +5 -0
- package/dist/locale/index.d.ts +3 -0
- package/dist/locale/index.js +21 -0
- package/dist/locale/types.d.ts +2 -0
- package/dist/locale/types.js +2 -0
- package/dist/locale/useLocale.d.ts +1 -0
- package/dist/locale/useLocale.js +12 -0
- package/dist/metadata/MetadataProvider.d.ts +9 -0
- package/dist/metadata/MetadataProvider.js +29 -0
- package/dist/metadata/context.d.ts +7 -0
- package/dist/metadata/context.js +5 -0
- package/dist/metadata/hooks/index.d.ts +8 -0
- package/dist/metadata/hooks/index.js +24 -0
- package/dist/metadata/hooks/useAppStore.d.ts +1 -0
- package/dist/metadata/hooks/useAppStore.js +8 -0
- package/dist/metadata/hooks/useExperienceStore.d.ts +1 -0
- package/dist/metadata/hooks/useExperienceStore.js +8 -0
- package/dist/metadata/hooks/useExperienceView.d.ts +4 -0
- package/dist/metadata/hooks/useExperienceView.js +37 -0
- package/dist/metadata/hooks/useExperienceViewCommands.d.ts +4 -0
- package/dist/metadata/hooks/useExperienceViewCommands.js +28 -0
- package/dist/metadata/hooks/useExperienceViewLookup.d.ts +4 -0
- package/dist/metadata/hooks/useExperienceViewLookup.js +36 -0
- package/dist/metadata/hooks/useExperienceViewSubgridCommands.d.ts +4 -0
- package/dist/metadata/hooks/useExperienceViewSubgridCommands.js +28 -0
- package/dist/metadata/hooks/useMetadata.d.ts +9 -0
- package/dist/metadata/hooks/useMetadata.js +28 -0
- package/dist/metadata/hooks/useSchema.d.ts +2 -0
- package/dist/metadata/hooks/useSchema.js +8 -0
- package/dist/metadata/index.d.ts +3 -0
- package/dist/metadata/index.js +22 -0
- package/dist/mutable/context.d.ts +11 -0
- package/dist/mutable/context.js +46 -0
- package/dist/mutable/index.d.ts +3 -0
- package/dist/mutable/index.js +26 -0
- package/dist/mutable/state.d.ts +6 -0
- package/dist/mutable/state.js +12 -0
- package/dist/mutable/type.d.ts +11 -0
- package/dist/mutable/type.js +2 -0
- package/dist/mutable/utils.d.ts +3 -0
- package/dist/mutable/utils.js +62 -0
- package/dist/navigation/hooks/useOpenForm.d.ts +4 -0
- package/dist/navigation/hooks/useOpenForm.js +20 -0
- package/dist/progress-indicator/ProgressIndicatorProvider.d.ts +2 -0
- package/dist/progress-indicator/ProgressIndicatorProvider.js +54 -0
- package/dist/progress-indicator/context.d.ts +8 -0
- package/dist/progress-indicator/context.js +5 -0
- package/dist/progress-indicator/hooks/index.d.ts +1 -0
- package/dist/progress-indicator/hooks/index.js +17 -0
- package/dist/progress-indicator/hooks/useProgressIndicator.d.ts +1 -0
- package/dist/progress-indicator/hooks/useProgressIndicator.js +12 -0
- package/dist/progress-indicator/index.d.ts +3 -0
- package/dist/progress-indicator/index.js +22 -0
- package/dist/providers/PageEntityFormProvider/index.d.ts +11 -0
- package/dist/providers/PageEntityFormProvider/index.js +8 -0
- package/dist/providers/PageEntityViewProvider/index.d.ts +13 -0
- package/dist/providers/PageEntityViewProvider/index.js +8 -0
- package/dist/recordset/RecordSetProvider.d.ts +2 -0
- package/dist/recordset/RecordSetProvider.js +40 -0
- package/dist/recordset/context.d.ts +8 -0
- package/dist/recordset/context.js +5 -0
- package/dist/recordset/hooks/index.d.ts +3 -0
- package/dist/recordset/hooks/index.js +19 -0
- package/dist/recordset/hooks/useRecordSetResult.d.ts +7 -0
- package/dist/recordset/hooks/useRecordSetResult.js +81 -0
- package/dist/recordset/hooks/useRecordSetSetter.d.ts +1 -0
- package/dist/recordset/hooks/useRecordSetSetter.js +17 -0
- package/dist/recordset/hooks/useRecordSetVisibility.d.ts +1 -0
- package/dist/recordset/hooks/useRecordSetVisibility.js +16 -0
- package/dist/recordset/index.d.ts +3 -0
- package/dist/recordset/index.js +22 -0
- package/dist/route/RouteProvider.d.ts +13 -0
- package/dist/route/RouteProvider.js +24 -0
- package/dist/route/context.d.ts +23 -0
- package/dist/route/context.js +9 -0
- package/dist/route/hooks/index.d.ts +4 -0
- package/dist/route/hooks/index.js +20 -0
- package/dist/route/hooks/useBasePath.d.ts +1 -0
- package/dist/route/hooks/useBasePath.js +8 -0
- package/dist/route/hooks/usePathname.d.ts +1 -0
- package/dist/route/hooks/usePathname.js +8 -0
- package/dist/route/hooks/useRouteResolver.d.ts +1 -0
- package/dist/route/hooks/useRouteResolver.js +8 -0
- package/dist/route/hooks/useRouter.d.ts +1 -0
- package/dist/route/hooks/useRouter.js +8 -0
- package/dist/route/hooks/useSearchParams.d.ts +1 -0
- package/dist/route/hooks/useSearchParams.js +8 -0
- package/dist/route/index.d.ts +2 -0
- package/dist/route/index.js +20 -0
- package/dist/route/types.d.ts +2 -0
- package/dist/route/types.js +2 -0
- package/dist/store/ClientAppStore.d.ts +7 -0
- package/dist/store/ClientAppStore.js +30 -0
- package/dist/store/ComponentStore.d.ts +6 -0
- package/dist/store/ComponentStore.js +23 -0
- package/dist/store/EventManager.d.ts +7 -0
- package/dist/store/EventManager.js +42 -0
- package/dist/store/SchemaExperienceStore.d.ts +32 -0
- package/dist/store/SchemaExperienceStore.js +264 -0
- package/dist/store/index.d.ts +4 -0
- package/dist/store/index.js +20 -0
- package/dist/toast-notification/ToastNotificationProvider.d.ts +5 -0
- package/dist/toast-notification/ToastNotificationProvider.js +13 -0
- package/dist/toast-notification/context.d.ts +15 -0
- package/dist/toast-notification/context.js +5 -0
- package/dist/toast-notification/hooks/index.d.ts +3 -0
- package/dist/toast-notification/hooks/index.js +19 -0
- package/dist/toast-notification/hooks/useCloseToastNotification.d.ts +1 -0
- package/dist/toast-notification/hooks/useCloseToastNotification.js +30 -0
- package/dist/toast-notification/hooks/useOpenToastNotification.d.ts +5 -0
- package/dist/toast-notification/hooks/useOpenToastNotification.js +27 -0
- package/dist/toast-notification/hooks/useToastNotificationItems.d.ts +1 -0
- package/dist/toast-notification/hooks/useToastNotificationItems.js +8 -0
- package/dist/toast-notification/index.d.ts +3 -0
- package/dist/toast-notification/index.js +22 -0
- package/dist/transport/InMemoryDataService/index.d.ts +25 -0
- package/dist/transport/InMemoryDataService/index.js +112 -0
- package/dist/transport/RestDataService/index.d.ts +25 -0
- package/dist/transport/RestDataService/index.js +124 -0
- package/dist/transport/context.d.ts +2 -0
- package/dist/transport/context.js +5 -0
- package/dist/transport/hooks/index.d.ts +1 -0
- package/dist/transport/hooks/index.js +17 -0
- package/dist/transport/hooks/useDataService.d.ts +1 -0
- package/dist/transport/hooks/useDataService.js +12 -0
- package/dist/transport/index.d.ts +2 -0
- package/dist/transport/index.js +20 -0
- package/dist/utils/calculateColumnWidths.d.ts +14 -0
- package/dist/utils/calculateColumnWidths.js +46 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +17 -0
- package/dist/widget/context.d.ts +2 -0
- package/dist/widget/context.js +5 -0
- package/dist/widget/hooks/index.d.ts +3 -0
- package/dist/widget/hooks/index.js +8 -0
- package/dist/widget/index.d.ts +1 -0
- package/dist/widget/index.js +5 -0
- package/package.json +45 -0
- package/src/app/context.ts +11 -0
- package/src/app/hooks/index.ts +1 -0
- package/src/app/hooks/useAppContext.ts +13 -0
- package/src/app/index.ts +2 -0
- package/src/appearance/context.ts +13 -0
- package/src/appearance/hooks/index.ts +1 -0
- package/src/appearance/hooks/useAppearanceContext.ts +13 -0
- package/src/appearance/index.ts +6 -0
- package/src/auth/AuthProvider.tsx +118 -0
- package/src/auth/context.ts +41 -0
- package/src/auth/hooks/index.ts +2 -0
- package/src/auth/hooks/useAuthSession.ts +17 -0
- package/src/auth/hooks/useLogout.ts +23 -0
- package/src/auth/index.ts +4 -0
- package/src/auth/types.ts +17 -0
- package/src/builders/CommandBuilder.ts +777 -0
- package/src/builders/SchemaExperienceBuilder.ts +488 -0
- package/src/builders/index.ts +2 -0
- package/src/command/hooks/index.ts +2 -0
- package/src/command/hooks/useBaseCommandHandlerContext.ts +51 -0
- package/src/command/hooks/useCommands.ts +26 -0
- package/src/command/index.ts +2 -0
- package/src/command/types.ts +116 -0
- package/src/command/utils/index.ts +142 -0
- package/src/components/ScrollView/index.tsx +26 -0
- package/src/dataform/DataFormProvider/DataResolver.tsx +186 -0
- package/src/dataform/DataFormProvider/InitialValueResolver.tsx +55 -0
- package/src/dataform/DataFormProvider/ReadonlyInfoResolver.tsx +35 -0
- package/src/dataform/DataFormProvider/index.tsx +102 -0
- package/src/dataform/context.ts +53 -0
- package/src/dataform/hooks/index.ts +11 -0
- package/src/dataform/hooks/useFormInstance.ts +6 -0
- package/src/dataform/hooks/useFormIsDirty.ts +7 -0
- package/src/dataform/hooks/useFormIsReadonly.ts +11 -0
- package/src/dataform/hooks/useFormNotifications.ts +46 -0
- package/src/dataform/hooks/useFormRecord.ts +7 -0
- package/src/dataform/hooks/useFormSave.ts +147 -0
- package/src/dataform/hooks/useFormSchema.ts +13 -0
- package/src/dataform/hooks/useLoadFormGridPage.ts +97 -0
- package/src/dataform/hooks/useMainFormCommands.ts +65 -0
- package/src/dataform/hooks/useRecordId.ts +6 -0
- package/src/dataform/hooks/useRecordTitle.ts +22 -0
- package/src/dataform/hooks/useSelectedForm.ts +14 -0
- package/src/dataform/utils/index.ts +582 -0
- package/src/datagrid/DataGridProvider/DataResolver.tsx +281 -0
- package/src/datagrid/DataGridProvider/index.tsx +134 -0
- package/src/datagrid/DataGridProvider/transformViewColumns.ts +54 -0
- package/src/datagrid/DataGridProvider/utils.ts +89 -0
- package/src/datagrid/column-filter/constants.ts +493 -0
- package/src/datagrid/column-filter/index.ts +3 -0
- package/src/datagrid/column-filter/types.ts +68 -0
- package/src/datagrid/column-filter/utils.ts +19 -0
- package/src/datagrid/context.ts +66 -0
- package/src/datagrid/hooks/index.ts +19 -0
- package/src/datagrid/hooks/useChangeView.ts +18 -0
- package/src/datagrid/hooks/useGridColumnFilter.ts +28 -0
- package/src/datagrid/hooks/useGridColumns.ts +13 -0
- package/src/datagrid/hooks/useGridCommands.ts +21 -0
- package/src/datagrid/hooks/useGridData.ts +8 -0
- package/src/datagrid/hooks/useGridDataState.ts +8 -0
- package/src/datagrid/hooks/useGridExtraFilter.ts +6 -0
- package/src/datagrid/hooks/useGridOptions.ts +3 -0
- package/src/datagrid/hooks/useGridPagination.ts +3 -0
- package/src/datagrid/hooks/useGridRefresh.ts +19 -0
- package/src/datagrid/hooks/useGridSchema.ts +13 -0
- package/src/datagrid/hooks/useGridSelection.ts +28 -0
- package/src/datagrid/hooks/useGridSorting.ts +23 -0
- package/src/datagrid/hooks/useGridViewLookupData.ts +10 -0
- package/src/datagrid/hooks/useLoadMainGridPage.ts +90 -0
- package/src/datagrid/hooks/useMainGridCommands.ts +255 -0
- package/src/datagrid/hooks/useMaxRecords.ts +6 -0
- package/src/datagrid/hooks/useSearchText.ts +22 -0
- package/src/datagrid/hooks/useSelectedView.ts +14 -0
- package/src/datagrid/hooks/useSubGridCommands.ts +104 -0
- package/src/dialog/DialogProvider.tsx +20 -0
- package/src/dialog/context.ts +14 -0
- package/src/dialog/hooks/index.ts +8 -0
- package/src/dialog/hooks/useCloseDialog.ts +36 -0
- package/src/dialog/hooks/useDialogItem.ts +8 -0
- package/src/dialog/hooks/useDialogItems.ts +6 -0
- package/src/dialog/hooks/useOpenAlertDialog.ts +30 -0
- package/src/dialog/hooks/useOpenConfirmDialog.ts +45 -0
- package/src/dialog/hooks/useOpenDialog.ts +39 -0
- package/src/dialog/hooks/useOpenErrorDialog.ts +26 -0
- package/src/dialog/hooks/useOpenPromptDialog.ts +46 -0
- package/src/dialog/index.ts +7 -0
- package/src/form/FormValidationStringContext.ts +30 -0
- package/src/hooks/index.ts +5 -0
- package/src/hooks/useDebouncedValue.ts +38 -0
- package/src/hooks/useElementLayout.ts +49 -0
- package/src/hooks/useIsMobile.ts +21 -0
- package/src/hooks/useStorageState.ts +36 -0
- package/src/hooks/useSystemColorScheme.ts +38 -0
- package/src/index.css +4 -0
- package/src/insights/context.ts +5 -0
- package/src/locale/context.ts +7 -0
- package/src/locale/index.ts +3 -0
- package/src/locale/types.ts +3 -0
- package/src/locale/useLocale.ts +13 -0
- package/src/metadata/MetadataProvider.tsx +51 -0
- package/src/metadata/context.ts +15 -0
- package/src/metadata/hooks/index.ts +8 -0
- package/src/metadata/hooks/useAppStore.ts +6 -0
- package/src/metadata/hooks/useExperienceStore.ts +6 -0
- package/src/metadata/hooks/useExperienceView.ts +36 -0
- package/src/metadata/hooks/useExperienceViewCommands.ts +20 -0
- package/src/metadata/hooks/useExperienceViewLookup.ts +33 -0
- package/src/metadata/hooks/useExperienceViewSubgridCommands.ts +20 -0
- package/src/metadata/hooks/useMetadata.ts +44 -0
- package/src/metadata/hooks/useSchema.ts +11 -0
- package/src/metadata/index.ts +3 -0
- package/src/mutable/context.ts +71 -0
- package/src/mutable/index.ts +9 -0
- package/src/mutable/state.ts +13 -0
- package/src/mutable/type.ts +9 -0
- package/src/mutable/utils.ts +80 -0
- package/src/navigation/hooks/useOpenForm.ts +34 -0
- package/src/progress-indicator/ProgressIndicatorProvider.tsx +77 -0
- package/src/progress-indicator/context.ts +12 -0
- package/src/progress-indicator/hooks/index.ts +1 -0
- package/src/progress-indicator/hooks/useProgressIndicator.ts +15 -0
- package/src/progress-indicator/index.ts +6 -0
- package/src/providers/PageEntityFormProvider/index.tsx +34 -0
- package/src/providers/PageEntityViewProvider/index.tsx +39 -0
- package/src/recordset/RecordSetProvider.tsx +55 -0
- package/src/recordset/context.ts +12 -0
- package/src/recordset/hooks/index.ts +3 -0
- package/src/recordset/hooks/useRecordSetResult.ts +94 -0
- package/src/recordset/hooks/useRecordSetSetter.ts +21 -0
- package/src/recordset/hooks/useRecordSetVisibility.ts +24 -0
- package/src/recordset/index.ts +3 -0
- package/src/route/RouteProvider.tsx +76 -0
- package/src/route/context.ts +39 -0
- package/src/route/hooks/index.ts +4 -0
- package/src/route/hooks/useBasePath.ts +7 -0
- package/src/route/hooks/usePathname.ts +7 -0
- package/src/route/hooks/useRouteResolver.ts +7 -0
- package/src/route/hooks/useRouter.ts +7 -0
- package/src/route/hooks/useSearchParams.ts +7 -0
- package/src/route/index.ts +2 -0
- package/src/route/types.ts +1 -0
- package/src/store/ClientAppStore.ts +20 -0
- package/src/store/ComponentStore.tsx +22 -0
- package/src/store/EventManager.ts +33 -0
- package/src/store/SchemaExperienceStore.ts +374 -0
- package/src/store/index.ts +4 -0
- package/src/toast-notification/ToastNotificationProvider.tsx +23 -0
- package/src/toast-notification/context.ts +17 -0
- package/src/toast-notification/hooks/index.ts +3 -0
- package/src/toast-notification/hooks/useCloseToastNotification.ts +36 -0
- package/src/toast-notification/hooks/useOpenToastNotification.ts +38 -0
- package/src/toast-notification/hooks/useToastNotificationItems.ts +6 -0
- package/src/toast-notification/index.ts +7 -0
- package/src/transport/InMemoryDataService/index.ts +157 -0
- package/src/transport/RestDataService/index.ts +151 -0
- package/src/transport/context.ts +6 -0
- package/src/transport/hooks/index.ts +1 -0
- package/src/transport/hooks/useDataService.ts +13 -0
- package/src/transport/index.ts +2 -0
- package/src/utils/calculateColumnWidths.ts +72 -0
- package/src/utils/index.ts +1 -0
- package/src/widget/context.ts +5 -0
- package/src/widget/hooks/index.ts +11 -0
- package/src/widget/index.ts +1 -0
- package/tsconfig.json +9 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,582 @@
|
|
|
1
|
+
import type { Attribute } from '@headless-adminapp/core/attributes';
|
|
2
|
+
import {
|
|
3
|
+
Form,
|
|
4
|
+
SectionEditableGridControl,
|
|
5
|
+
} from '@headless-adminapp/core/experience/form';
|
|
6
|
+
import {
|
|
7
|
+
InferredSchemaType,
|
|
8
|
+
Schema,
|
|
9
|
+
SchemaAttributes,
|
|
10
|
+
} from '@headless-adminapp/core/schema';
|
|
11
|
+
import { IDataService } from '@headless-adminapp/core/transport';
|
|
12
|
+
import { Nullable } from '@headless-adminapp/core/types';
|
|
13
|
+
import { yupResolver } from '@hookform/resolvers/yup';
|
|
14
|
+
import { memoize } from 'lodash';
|
|
15
|
+
import * as yup from 'yup';
|
|
16
|
+
|
|
17
|
+
import { localizedLabel } from '../../builders/CommandBuilder';
|
|
18
|
+
import {
|
|
19
|
+
getColumns,
|
|
20
|
+
getControls,
|
|
21
|
+
} from '../../dataform/DataFormProvider/DataResolver';
|
|
22
|
+
import { FormValidationStringSet } from '../../form/FormValidationStringContext';
|
|
23
|
+
|
|
24
|
+
export function getModifiedValues(
|
|
25
|
+
initialValues: any,
|
|
26
|
+
values: any,
|
|
27
|
+
exclude?: string[]
|
|
28
|
+
) {
|
|
29
|
+
const keys = Object.keys(values);
|
|
30
|
+
|
|
31
|
+
return keys.reduce((p, c) => {
|
|
32
|
+
if (c === '_id') {
|
|
33
|
+
return p;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (exclude && exclude.includes(c)) {
|
|
37
|
+
return p;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (
|
|
41
|
+
JSON.stringify(values[c]) !== JSON.stringify((initialValues as any)[c])
|
|
42
|
+
) {
|
|
43
|
+
p[c] = values[c];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return p;
|
|
47
|
+
}, {} as Record<string, any>);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
type SaveRecordResult =
|
|
51
|
+
| {
|
|
52
|
+
success: true;
|
|
53
|
+
recordId: string;
|
|
54
|
+
}
|
|
55
|
+
| {
|
|
56
|
+
success: false;
|
|
57
|
+
title?: string;
|
|
58
|
+
message: string;
|
|
59
|
+
isError: boolean;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export async function saveRecord({
|
|
63
|
+
values,
|
|
64
|
+
form,
|
|
65
|
+
schema,
|
|
66
|
+
dataService,
|
|
67
|
+
initialValues,
|
|
68
|
+
record,
|
|
69
|
+
getSchema,
|
|
70
|
+
}: {
|
|
71
|
+
values: any;
|
|
72
|
+
form: Form<SchemaAttributes>;
|
|
73
|
+
record: InferredSchemaType<SchemaAttributes> | undefined;
|
|
74
|
+
initialValues: Nullable<InferredSchemaType<SchemaAttributes>>;
|
|
75
|
+
schema: Schema<SchemaAttributes>;
|
|
76
|
+
dataService: IDataService;
|
|
77
|
+
getSchema: (logicalName: string) => Schema<SchemaAttributes>;
|
|
78
|
+
}): Promise<SaveRecordResult> {
|
|
79
|
+
const controls = getControls(form);
|
|
80
|
+
|
|
81
|
+
const editableGridControls = controls.filter(
|
|
82
|
+
(control) => control.type === 'editablegrid'
|
|
83
|
+
) as SectionEditableGridControl[];
|
|
84
|
+
|
|
85
|
+
const modifiedValues = getModifiedValues(
|
|
86
|
+
initialValues,
|
|
87
|
+
values,
|
|
88
|
+
editableGridControls.map((x) => x.attributeName)
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
let recordId: string;
|
|
92
|
+
|
|
93
|
+
if (record) {
|
|
94
|
+
recordId = record[schema.idAttribute] as string;
|
|
95
|
+
interface Operation {
|
|
96
|
+
type: 'create' | 'update' | 'delete';
|
|
97
|
+
logicalName: string;
|
|
98
|
+
data?: any;
|
|
99
|
+
id?: string;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const operations: Operation[] = [];
|
|
103
|
+
|
|
104
|
+
if (Object.keys(modifiedValues).length) {
|
|
105
|
+
operations.push({
|
|
106
|
+
type: 'update',
|
|
107
|
+
logicalName: schema.logicalName,
|
|
108
|
+
data: modifiedValues,
|
|
109
|
+
id: recordId,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
for (const control of editableGridControls) {
|
|
114
|
+
const gridSchema = getSchema(control.logicalName);
|
|
115
|
+
const gridRows = values[control.attributeName] as any[];
|
|
116
|
+
const initialGridRows = (initialValues as any)[
|
|
117
|
+
control.attributeName
|
|
118
|
+
] as any[];
|
|
119
|
+
|
|
120
|
+
const newRows = gridRows.filter((x) => !x[gridSchema.idAttribute]);
|
|
121
|
+
const updatedRows = gridRows.filter((x) => x[gridSchema.idAttribute]);
|
|
122
|
+
const deletedIds = initialGridRows
|
|
123
|
+
?.map((x) => x[gridSchema.idAttribute])
|
|
124
|
+
.filter(
|
|
125
|
+
(id) => !gridRows.find((x) => x[gridSchema.idAttribute] === id)
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
for (const row of newRows) {
|
|
129
|
+
operations.push({
|
|
130
|
+
type: 'create',
|
|
131
|
+
logicalName: control.logicalName,
|
|
132
|
+
data: {
|
|
133
|
+
...row,
|
|
134
|
+
[control.referenceAttribute]: {
|
|
135
|
+
id: recordId,
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
for (const row of updatedRows) {
|
|
142
|
+
const initialRow = initialGridRows.find(
|
|
143
|
+
(x) => x[gridSchema.idAttribute] === row[gridSchema.idAttribute]
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
if (!initialRow) {
|
|
147
|
+
throw new Error('Initial row not found');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const modifiedRow = getModifiedValues(initialRow, row);
|
|
151
|
+
|
|
152
|
+
if (!Object.keys(modifiedRow).length) {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
operations.push({
|
|
157
|
+
type: 'update',
|
|
158
|
+
logicalName: control.logicalName,
|
|
159
|
+
data: modifiedRow,
|
|
160
|
+
id: row[gridSchema.idAttribute],
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
for (const id of deletedIds) {
|
|
165
|
+
operations.push({
|
|
166
|
+
type: 'delete',
|
|
167
|
+
logicalName: control.logicalName,
|
|
168
|
+
id,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (!operations.length) {
|
|
174
|
+
return {
|
|
175
|
+
success: false,
|
|
176
|
+
title: 'No changes',
|
|
177
|
+
message: 'No changes made to the record',
|
|
178
|
+
isError: false,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (operations.length > 0) {
|
|
183
|
+
console.log('operations', operations);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
for (const operation of operations) {
|
|
187
|
+
switch (operation.type) {
|
|
188
|
+
case 'create':
|
|
189
|
+
await dataService.createRecord(operation.logicalName, operation.data);
|
|
190
|
+
break;
|
|
191
|
+
case 'update':
|
|
192
|
+
await dataService.updateRecord(
|
|
193
|
+
operation.logicalName,
|
|
194
|
+
operation.id!,
|
|
195
|
+
operation.data
|
|
196
|
+
);
|
|
197
|
+
break;
|
|
198
|
+
case 'delete':
|
|
199
|
+
await dataService.deleteRecord(operation.logicalName, operation.id!);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
} else {
|
|
203
|
+
const result = await dataService.createRecord(schema.logicalName, values);
|
|
204
|
+
|
|
205
|
+
recordId = (result as any)[schema.idAttribute] as string;
|
|
206
|
+
|
|
207
|
+
for (const control of editableGridControls) {
|
|
208
|
+
const gridRows = values[control.attributeName] as any[];
|
|
209
|
+
|
|
210
|
+
for (const row of gridRows) {
|
|
211
|
+
await dataService.createRecord(control.logicalName, {
|
|
212
|
+
...row,
|
|
213
|
+
[control.referenceAttribute]: {
|
|
214
|
+
id: recordId,
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return {
|
|
222
|
+
success: true,
|
|
223
|
+
recordId,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export function getInitialValues({
|
|
228
|
+
cloneRecord,
|
|
229
|
+
form,
|
|
230
|
+
record,
|
|
231
|
+
recordId,
|
|
232
|
+
defaultParameters,
|
|
233
|
+
}: {
|
|
234
|
+
cloneRecord: InferredSchemaType<SchemaAttributes> | undefined;
|
|
235
|
+
form: Form<SchemaAttributes>;
|
|
236
|
+
record: InferredSchemaType<SchemaAttributes> | undefined;
|
|
237
|
+
recordId: string | undefined;
|
|
238
|
+
schema: Schema<SchemaAttributes>;
|
|
239
|
+
defaultParameters: Record<string, any>;
|
|
240
|
+
}) {
|
|
241
|
+
const formColumns = getColumns(form);
|
|
242
|
+
const editableGridControls = getControls(form).filter(
|
|
243
|
+
(control) => control.type === 'editablegrid'
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
const allColumns = [
|
|
247
|
+
...formColumns,
|
|
248
|
+
...editableGridControls.map((x) => x.attributeName),
|
|
249
|
+
];
|
|
250
|
+
|
|
251
|
+
if (!recordId && !record && form.experience.cloneAttributes && cloneRecord) {
|
|
252
|
+
const cloneAttributesObj = form.experience.cloneAttributes.reduce(
|
|
253
|
+
(acc, item) => {
|
|
254
|
+
if (typeof item === 'string') {
|
|
255
|
+
acc[item] = item;
|
|
256
|
+
}
|
|
257
|
+
// TODO:
|
|
258
|
+
// else if (isEditableGridCloneAttribute(item)) {
|
|
259
|
+
// acc[item.attributeName] = item;
|
|
260
|
+
// }
|
|
261
|
+
|
|
262
|
+
return acc;
|
|
263
|
+
},
|
|
264
|
+
{} as Record<string, any>
|
|
265
|
+
);
|
|
266
|
+
|
|
267
|
+
return allColumns.reduce((acc, column) => {
|
|
268
|
+
const cloneAttributeInfo = cloneAttributesObj[column] as string;
|
|
269
|
+
// | EditableGridCloneAttribute; // TODO:
|
|
270
|
+
|
|
271
|
+
let value: unknown = null;
|
|
272
|
+
|
|
273
|
+
if (cloneAttributeInfo) {
|
|
274
|
+
if (typeof cloneAttributeInfo === 'string') {
|
|
275
|
+
value = cloneRecord[cloneAttributeInfo];
|
|
276
|
+
}
|
|
277
|
+
// else {
|
|
278
|
+
// const rows = cloneRecord[cloneAttributeInfo.attributeName] as any[];
|
|
279
|
+
|
|
280
|
+
// if (!rows?.length) {
|
|
281
|
+
// value = [];
|
|
282
|
+
// } else {
|
|
283
|
+
// value = rows.map((row) => {
|
|
284
|
+
// return Object.keys(row).reduce((p, c) => {
|
|
285
|
+
// if (c === '_id') {
|
|
286
|
+
// return p;
|
|
287
|
+
// }
|
|
288
|
+
|
|
289
|
+
// if (cloneAttributeInfo.attributes.includes(c)) {
|
|
290
|
+
// p[c] = row[c];
|
|
291
|
+
// } else {
|
|
292
|
+
// p[c] = null;
|
|
293
|
+
// }
|
|
294
|
+
|
|
295
|
+
// return p;
|
|
296
|
+
// }, {} as Record<string, any>);
|
|
297
|
+
// });
|
|
298
|
+
// }
|
|
299
|
+
// }
|
|
300
|
+
} else {
|
|
301
|
+
value = defaultParameters[column] ?? null;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return {
|
|
305
|
+
...acc,
|
|
306
|
+
[column]: value,
|
|
307
|
+
};
|
|
308
|
+
}, {} as Nullable<InferredSchemaType<SchemaAttributes>>);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return allColumns.reduce((acc, column) => {
|
|
312
|
+
const value = record ? record[column] : defaultParameters[column] ?? null;
|
|
313
|
+
return {
|
|
314
|
+
...acc,
|
|
315
|
+
[column]: value,
|
|
316
|
+
};
|
|
317
|
+
}, {} as Nullable<InferredSchemaType<SchemaAttributes>>);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export const formValidator = memoize(
|
|
321
|
+
function formValidator<A extends SchemaAttributes = SchemaAttributes>({
|
|
322
|
+
form,
|
|
323
|
+
schema,
|
|
324
|
+
readonlyAttributes,
|
|
325
|
+
formReadOnly,
|
|
326
|
+
getSchema,
|
|
327
|
+
language,
|
|
328
|
+
strings,
|
|
329
|
+
}: {
|
|
330
|
+
schema: Schema<A>;
|
|
331
|
+
form: Form<A>;
|
|
332
|
+
language: string;
|
|
333
|
+
formReadOnly?: boolean;
|
|
334
|
+
readonlyAttributes?: string[];
|
|
335
|
+
strings: FormValidationStringSet;
|
|
336
|
+
getSchema: (logicalName: string) => Schema;
|
|
337
|
+
}) {
|
|
338
|
+
return async (values: Record<string, any>, context: any, options: any) => {
|
|
339
|
+
// console.log('formValidator', values);
|
|
340
|
+
let validator = yup.object().shape({});
|
|
341
|
+
|
|
342
|
+
if (!formReadOnly) {
|
|
343
|
+
const activeControls = form.experience.tabs
|
|
344
|
+
.flatMap((tab) => tab.tabColumns)
|
|
345
|
+
.flatMap((tabColumn) => tabColumn.sections)
|
|
346
|
+
.flatMap((section) => {
|
|
347
|
+
return section.controls;
|
|
348
|
+
})
|
|
349
|
+
.filter((control) => {
|
|
350
|
+
if (control.type === 'standard') {
|
|
351
|
+
const attribute = schema.attributes[control.attributeName];
|
|
352
|
+
if (attribute.readonly) {
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return true;
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
const editableGridControls = activeControls.filter(
|
|
360
|
+
(control) => control.type === 'editablegrid'
|
|
361
|
+
);
|
|
362
|
+
|
|
363
|
+
const columns = Array.from(
|
|
364
|
+
new Set([
|
|
365
|
+
schema.primaryAttribute,
|
|
366
|
+
...activeControls
|
|
367
|
+
.filter((control) => control.type === 'standard')
|
|
368
|
+
.map((control) => control.attributeName),
|
|
369
|
+
])
|
|
370
|
+
);
|
|
371
|
+
|
|
372
|
+
validator = generateValidationSchema({
|
|
373
|
+
editableGrids: editableGridControls.map((control) => {
|
|
374
|
+
if (control.type !== 'editablegrid') {
|
|
375
|
+
throw new Error('Invalid control type');
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const schema = getSchema(control.logicalName);
|
|
379
|
+
|
|
380
|
+
return {
|
|
381
|
+
columns: control.attributes,
|
|
382
|
+
schema: schema,
|
|
383
|
+
attributeName: control.attributeName,
|
|
384
|
+
required: control.required,
|
|
385
|
+
};
|
|
386
|
+
}),
|
|
387
|
+
schema,
|
|
388
|
+
columns: columns as string[],
|
|
389
|
+
language,
|
|
390
|
+
strings,
|
|
391
|
+
readonlyAttributes,
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
const resolver = yupResolver(validator);
|
|
396
|
+
|
|
397
|
+
const result = await resolver(values, context, options);
|
|
398
|
+
|
|
399
|
+
// console.log(result);
|
|
400
|
+
|
|
401
|
+
return result;
|
|
402
|
+
};
|
|
403
|
+
},
|
|
404
|
+
({ form, language, schema, strings, readonlyAttributes, formReadOnly }) =>
|
|
405
|
+
JSON.stringify({
|
|
406
|
+
schema,
|
|
407
|
+
form,
|
|
408
|
+
language,
|
|
409
|
+
strings,
|
|
410
|
+
readonlyAttributes,
|
|
411
|
+
formReadOnly,
|
|
412
|
+
})
|
|
413
|
+
);
|
|
414
|
+
|
|
415
|
+
export const generateValidationSchema = memoize(
|
|
416
|
+
function generateValidationSchema<
|
|
417
|
+
A extends SchemaAttributes = SchemaAttributes
|
|
418
|
+
>({
|
|
419
|
+
columns,
|
|
420
|
+
editableGrids,
|
|
421
|
+
language,
|
|
422
|
+
schema,
|
|
423
|
+
strings,
|
|
424
|
+
readonlyAttributes,
|
|
425
|
+
}: {
|
|
426
|
+
schema: Schema<A>;
|
|
427
|
+
columns: string[];
|
|
428
|
+
readonlyAttributes?: string[];
|
|
429
|
+
editableGrids:
|
|
430
|
+
| Array<{
|
|
431
|
+
schema: Schema;
|
|
432
|
+
columns: string[];
|
|
433
|
+
attributeName: string;
|
|
434
|
+
required?: boolean;
|
|
435
|
+
}>
|
|
436
|
+
| undefined;
|
|
437
|
+
language: string;
|
|
438
|
+
strings: FormValidationStringSet;
|
|
439
|
+
}) {
|
|
440
|
+
return yup.object().shape({
|
|
441
|
+
...(columns.reduce((acc, column) => {
|
|
442
|
+
if (readonlyAttributes?.includes(column)) {
|
|
443
|
+
return acc;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
const attribute = schema.attributes[column];
|
|
447
|
+
|
|
448
|
+
const validationSchema = generateAttributeValidationSchema(
|
|
449
|
+
attribute,
|
|
450
|
+
language,
|
|
451
|
+
strings
|
|
452
|
+
);
|
|
453
|
+
|
|
454
|
+
return {
|
|
455
|
+
...acc,
|
|
456
|
+
[column]: validationSchema,
|
|
457
|
+
};
|
|
458
|
+
}, {} as Record<string, yup.Schema<any>>) as any),
|
|
459
|
+
...editableGrids?.reduce((acc, grid) => {
|
|
460
|
+
let validationSchema = yup
|
|
461
|
+
.array()
|
|
462
|
+
.of(
|
|
463
|
+
yup.object().shape({
|
|
464
|
+
...grid.columns.reduce((acc, column) => {
|
|
465
|
+
const attribute = grid.schema.attributes[column];
|
|
466
|
+
|
|
467
|
+
const validationSchema = generateAttributeValidationSchema(
|
|
468
|
+
attribute,
|
|
469
|
+
language,
|
|
470
|
+
strings
|
|
471
|
+
);
|
|
472
|
+
|
|
473
|
+
return {
|
|
474
|
+
...acc,
|
|
475
|
+
[column]: validationSchema,
|
|
476
|
+
};
|
|
477
|
+
}, {} as Record<string, yup.Schema<any>>),
|
|
478
|
+
})
|
|
479
|
+
)
|
|
480
|
+
.nullable();
|
|
481
|
+
|
|
482
|
+
if (grid.required) {
|
|
483
|
+
validationSchema = validationSchema
|
|
484
|
+
.required(strings.atLeastOneRowRequired)
|
|
485
|
+
.min(1, strings.atLeastOneRowRequired);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
acc[grid.attributeName] = validationSchema;
|
|
489
|
+
|
|
490
|
+
return acc;
|
|
491
|
+
}, {} as Record<string, yup.Schema<any>>),
|
|
492
|
+
});
|
|
493
|
+
},
|
|
494
|
+
({ columns, editableGrids, language, schema, strings, readonlyAttributes }) =>
|
|
495
|
+
JSON.stringify({
|
|
496
|
+
schema,
|
|
497
|
+
columns,
|
|
498
|
+
editableGrids,
|
|
499
|
+
language,
|
|
500
|
+
strings,
|
|
501
|
+
readonlyAttributes,
|
|
502
|
+
})
|
|
503
|
+
);
|
|
504
|
+
|
|
505
|
+
export const generateAttributeValidationSchema = memoize(
|
|
506
|
+
function generateAttributeValidationSchema(
|
|
507
|
+
attribute: Attribute,
|
|
508
|
+
language: string,
|
|
509
|
+
strings: FormValidationStringSet
|
|
510
|
+
) {
|
|
511
|
+
let validationSchema: yup.Schema;
|
|
512
|
+
|
|
513
|
+
switch (attribute.type) {
|
|
514
|
+
case 'string':
|
|
515
|
+
validationSchema = yup.string().nullable();
|
|
516
|
+
break;
|
|
517
|
+
case 'number':
|
|
518
|
+
validationSchema = yup.number().nullable();
|
|
519
|
+
break;
|
|
520
|
+
default:
|
|
521
|
+
validationSchema = yup.mixed().nullable();
|
|
522
|
+
break;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
const label = localizedLabel(language, attribute);
|
|
526
|
+
|
|
527
|
+
if (attribute.required) {
|
|
528
|
+
validationSchema = validationSchema.required(
|
|
529
|
+
`${label}: ${strings.required}`
|
|
530
|
+
);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
switch (attribute.type) {
|
|
534
|
+
case 'string':
|
|
535
|
+
if (attribute.maxLength) {
|
|
536
|
+
validationSchema = (validationSchema as yup.StringSchema).max(
|
|
537
|
+
attribute.maxLength,
|
|
538
|
+
`${label}: ${strings.maxLength}`
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
if (attribute.minLength) {
|
|
543
|
+
validationSchema = (validationSchema as yup.StringSchema).min(
|
|
544
|
+
attribute.minLength,
|
|
545
|
+
`${label}: ${strings.minLength}`
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
if (attribute.pattern) {
|
|
550
|
+
validationSchema = (validationSchema as yup.StringSchema).matches(
|
|
551
|
+
new RegExp(attribute.pattern),
|
|
552
|
+
`${label}: ${strings.invalidFormat}`
|
|
553
|
+
);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
if (attribute.format === 'email') {
|
|
557
|
+
validationSchema = (validationSchema as yup.StringSchema).email(
|
|
558
|
+
`${label}: ${strings.invalidEmail}`
|
|
559
|
+
);
|
|
560
|
+
} else if (attribute.format === 'phone') {
|
|
561
|
+
validationSchema = (validationSchema as yup.StringSchema).matches(
|
|
562
|
+
/^(\+\d{1,2}\s?)?\d{10}$/,
|
|
563
|
+
`${label}: ${strings.invalidPhoneNumber}`
|
|
564
|
+
);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
break;
|
|
568
|
+
default:
|
|
569
|
+
break;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
validationSchema = validationSchema.transform((value) => {
|
|
573
|
+
if (value === '') {
|
|
574
|
+
return null;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
return value;
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
return validationSchema;
|
|
581
|
+
}
|
|
582
|
+
);
|