@maxal_studio/kratosjs-react 1.0.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/README.md +44 -0
- package/dist/FieldRenderer.d.ts +13 -0
- package/dist/FieldRenderer.js +62 -0
- package/dist/FormRenderer.d.ts +7 -0
- package/dist/FormRenderer.js +78 -0
- package/dist/TableRenderer.d.ts +2 -0
- package/dist/TableRenderer.js +1 -0
- package/dist/api/actionsApi.d.ts +23 -0
- package/dist/api/actionsApi.js +46 -0
- package/dist/api/authenticatedFetch.d.ts +8 -0
- package/dist/api/authenticatedFetch.js +31 -0
- package/dist/api/exportApi.d.ts +18 -0
- package/dist/api/exportApi.js +50 -0
- package/dist/api/http.d.ts +24 -0
- package/dist/api/http.js +52 -0
- package/dist/api/resourceApi.d.ts +37 -0
- package/dist/api/resourceApi.js +52 -0
- package/dist/api/tableApi.d.ts +83 -0
- package/dist/api/tableApi.js +51 -0
- package/dist/api/urls.d.ts +19 -0
- package/dist/api/urls.js +46 -0
- package/dist/app.d.ts +101 -0
- package/dist/app.js +89 -0
- package/dist/auth/AuthContext.d.ts +22 -0
- package/dist/auth/AuthContext.js +147 -0
- package/dist/auth/LoginPage.d.ts +10 -0
- package/dist/auth/LoginPage.js +179 -0
- package/dist/auth/ProtectedRoute.d.ts +12 -0
- package/dist/auth/ProtectedRoute.js +22 -0
- package/dist/auth/authApiClient.d.ts +24 -0
- package/dist/auth/authApiClient.js +95 -0
- package/dist/auth/types.d.ts +103 -0
- package/dist/auth/types.js +1 -0
- package/dist/components/ActionFormModal.d.ts +22 -0
- package/dist/components/ActionFormModal.js +8 -0
- package/dist/components/AdminPanel.d.ts +11 -0
- package/dist/components/AdminPanel.js +194 -0
- package/dist/components/Checkbox.d.ts +10 -0
- package/dist/components/Checkbox.js +8 -0
- package/dist/components/CheckboxField.d.ts +7 -0
- package/dist/components/CheckboxField.js +26 -0
- package/dist/components/ColorPickerField.d.ts +7 -0
- package/dist/components/ColorPickerField.js +26 -0
- package/dist/components/DateTimePickerField.d.ts +7 -0
- package/dist/components/DateTimePickerField.js +64 -0
- package/dist/components/FileUploadField.d.ts +9 -0
- package/dist/components/FileUploadField.js +478 -0
- package/dist/components/GlobalSearch.d.ts +22 -0
- package/dist/components/GlobalSearch.js +181 -0
- package/dist/components/GroupField.d.ts +7 -0
- package/dist/components/GroupField.js +23 -0
- package/dist/components/HiddenField.d.ts +3 -0
- package/dist/components/HiddenField.js +10 -0
- package/dist/components/ModalBreadcrumb.d.ts +5 -0
- package/dist/components/ModalBreadcrumb.js +33 -0
- package/dist/components/ModalDrawer.d.ts +15 -0
- package/dist/components/ModalDrawer.js +40 -0
- package/dist/components/RadioField.d.ts +7 -0
- package/dist/components/RadioField.js +26 -0
- package/dist/components/RepeaterField.d.ts +3 -0
- package/dist/components/RepeaterField.js +191 -0
- package/dist/components/ResourceModalRenderer.d.ts +10 -0
- package/dist/components/ResourceModalRenderer.js +80 -0
- package/dist/components/RichEditorField.d.ts +3 -0
- package/dist/components/RichEditorField.js +655 -0
- package/dist/components/SectionField.d.ts +9 -0
- package/dist/components/SectionField.js +111 -0
- package/dist/components/SelectField.d.ts +8 -0
- package/dist/components/SelectField.js +523 -0
- package/dist/components/TabsField.d.ts +10 -0
- package/dist/components/TabsField.js +214 -0
- package/dist/components/TagsInputField.d.ts +7 -0
- package/dist/components/TagsInputField.js +172 -0
- package/dist/components/TextInputField.d.ts +7 -0
- package/dist/components/TextInputField.js +44 -0
- package/dist/components/TextareaField.d.ts +7 -0
- package/dist/components/TextareaField.js +31 -0
- package/dist/components/ToggleField.d.ts +7 -0
- package/dist/components/ToggleField.js +57 -0
- package/dist/components/ViewModal.d.ts +25 -0
- package/dist/components/ViewModal.js +159 -0
- package/dist/components/blocks/BlockRenderer.d.ts +7 -0
- package/dist/components/blocks/BlockRenderer.js +36 -0
- package/dist/components/blocks/FormBlockRenderer.d.ts +6 -0
- package/dist/components/blocks/FormBlockRenderer.js +110 -0
- package/dist/components/blocks/TableBlockRenderer.d.ts +6 -0
- package/dist/components/blocks/TableBlockRenderer.js +12 -0
- package/dist/components/blocks/TabsBlockRenderer.d.ts +7 -0
- package/dist/components/blocks/TabsBlockRenderer.js +11 -0
- package/dist/components/blocks/WidgetBlockRenderer.d.ts +6 -0
- package/dist/components/blocks/WidgetBlockRenderer.js +11 -0
- package/dist/components/columns/CheckboxColumnComponent.d.ts +6 -0
- package/dist/components/columns/CheckboxColumnComponent.js +21 -0
- package/dist/components/columns/ColorColumnComponent.d.ts +3 -0
- package/dist/components/columns/ColorColumnComponent.js +11 -0
- package/dist/components/columns/DeeplinkWrapper.d.ts +15 -0
- package/dist/components/columns/DeeplinkWrapper.js +85 -0
- package/dist/components/columns/IconColumnComponent.d.ts +3 -0
- package/dist/components/columns/IconColumnComponent.js +52 -0
- package/dist/components/columns/ImageColumnComponent.d.ts +3 -0
- package/dist/components/columns/ImageColumnComponent.js +98 -0
- package/dist/components/columns/MediaColumnComponent.d.ts +3 -0
- package/dist/components/columns/MediaColumnComponent.js +160 -0
- package/dist/components/columns/SelectColumnComponent.d.ts +6 -0
- package/dist/components/columns/SelectColumnComponent.js +26 -0
- package/dist/components/columns/TagsColumnComponent.d.ts +3 -0
- package/dist/components/columns/TagsColumnComponent.js +18 -0
- package/dist/components/columns/TextColumnComponent.d.ts +11 -0
- package/dist/components/columns/TextColumnComponent.js +107 -0
- package/dist/components/columns/TextInputColumnComponent.d.ts +6 -0
- package/dist/components/columns/TextInputColumnComponent.js +18 -0
- package/dist/components/columns/ToggleColumnComponent.d.ts +6 -0
- package/dist/components/columns/ToggleColumnComponent.js +25 -0
- package/dist/components/columns/VideoColumnComponent.d.ts +3 -0
- package/dist/components/columns/VideoColumnComponent.js +125 -0
- package/dist/components/columns/ViewColumnComponent.d.ts +3 -0
- package/dist/components/columns/ViewColumnComponent.js +7 -0
- package/dist/components/errors/ErrorBoundary.d.ts +23 -0
- package/dist/components/errors/ErrorBoundary.js +33 -0
- package/dist/components/filters/CustomFilterComponent.d.ts +10 -0
- package/dist/components/filters/CustomFilterComponent.js +33 -0
- package/dist/components/filters/DateFilterComponent.d.ts +15 -0
- package/dist/components/filters/DateFilterComponent.js +132 -0
- package/dist/components/filters/QueryBuilderFilterComponent.d.ts +11 -0
- package/dist/components/filters/QueryBuilderFilterComponent.js +200 -0
- package/dist/components/layout/Header.d.ts +10 -0
- package/dist/components/layout/Header.js +70 -0
- package/dist/components/layout/PanelBrandMark.d.ts +8 -0
- package/dist/components/layout/PanelBrandMark.js +28 -0
- package/dist/components/layout/Sidebar.d.ts +35 -0
- package/dist/components/layout/Sidebar.js +125 -0
- package/dist/components/modals/RelationCreateModal.d.ts +19 -0
- package/dist/components/modals/RelationCreateModal.js +57 -0
- package/dist/components/modals/ResourceFormModal.d.ts +37 -0
- package/dist/components/modals/ResourceFormModal.js +44 -0
- package/dist/components/modals/useResourceForm.d.ts +40 -0
- package/dist/components/modals/useResourceForm.js +138 -0
- package/dist/components/modals/view/RecordActions.d.ts +17 -0
- package/dist/components/modals/view/RecordActions.js +16 -0
- package/dist/components/modals/view/RecordDetails.d.ts +13 -0
- package/dist/components/modals/view/RecordDetails.js +29 -0
- package/dist/components/modals/view/RelationPanel.d.ts +18 -0
- package/dist/components/modals/view/RelationPanel.js +16 -0
- package/dist/components/modals/view/RelationTabs.d.ts +32 -0
- package/dist/components/modals/view/RelationTabs.js +42 -0
- package/dist/components/modals/view/useRecordView.d.ts +18 -0
- package/dist/components/modals/view/useRecordView.js +114 -0
- package/dist/components/pages/PageRenderer.d.ts +6 -0
- package/dist/components/pages/PageRenderer.js +107 -0
- package/dist/components/table/ColumnTogglePopup.d.ts +11 -0
- package/dist/components/table/ColumnTogglePopup.js +16 -0
- package/dist/components/table/GridCard.d.ts +21 -0
- package/dist/components/table/GridCard.js +30 -0
- package/dist/components/table/GridView.d.ts +23 -0
- package/dist/components/table/GridView.js +49 -0
- package/dist/components/table/LayoutToggle.d.ts +7 -0
- package/dist/components/table/LayoutToggle.js +9 -0
- package/dist/components/table/TableActionsDropdown.d.ts +13 -0
- package/dist/components/table/TableActionsDropdown.js +46 -0
- package/dist/components/table/TableBulkActions.d.ts +11 -0
- package/dist/components/table/TableBulkActions.js +21 -0
- package/dist/components/table/TableHeader.d.ts +14 -0
- package/dist/components/table/TableHeader.js +23 -0
- package/dist/components/table/TablePagination.d.ts +13 -0
- package/dist/components/table/TablePagination.js +55 -0
- package/dist/components/table/TableRow.d.ts +21 -0
- package/dist/components/table/TableRow.js +32 -0
- package/dist/components/table/TableSearchBar.d.ts +11 -0
- package/dist/components/table/TableSearchBar.js +12 -0
- package/dist/components/table/TableTabs.d.ts +14 -0
- package/dist/components/table/TableTabs.js +8 -0
- package/dist/components/ui/Badge.d.ts +6 -0
- package/dist/components/ui/Badge.js +12 -0
- package/dist/components/ui/Button.d.ts +22 -0
- package/dist/components/ui/Button.js +22 -0
- package/dist/components/ui/Card.d.ts +7 -0
- package/dist/components/ui/Card.js +5 -0
- package/dist/components/ui/ConfirmDialog.d.ts +19 -0
- package/dist/components/ui/ConfirmDialog.js +45 -0
- package/dist/components/ui/EmptyState.d.ts +9 -0
- package/dist/components/ui/EmptyState.js +6 -0
- package/dist/components/ui/ErrorAlert.d.ts +7 -0
- package/dist/components/ui/ErrorAlert.js +9 -0
- package/dist/components/ui/Input.d.ts +11 -0
- package/dist/components/ui/Input.js +10 -0
- package/dist/components/ui/Label.d.ts +5 -0
- package/dist/components/ui/Label.js +5 -0
- package/dist/components/ui/PillButton.d.ts +14 -0
- package/dist/components/ui/PillButton.js +19 -0
- package/dist/components/ui/Select.d.ts +7 -0
- package/dist/components/ui/Select.js +7 -0
- package/dist/components/ui/Spinner.d.ts +8 -0
- package/dist/components/ui/Spinner.js +14 -0
- package/dist/components/ui/Toast.d.ts +21 -0
- package/dist/components/ui/Toast.js +47 -0
- package/dist/components/ui/index.d.ts +24 -0
- package/dist/components/ui/index.js +12 -0
- package/dist/components/utils/HintDisplay.d.ts +11 -0
- package/dist/components/utils/HintDisplay.js +12 -0
- package/dist/components/utils/Icon.d.ts +22 -0
- package/dist/components/utils/Icon.js +22 -0
- package/dist/components/utils/MediaPreviewModal.d.ts +14 -0
- package/dist/components/utils/MediaPreviewModal.js +32 -0
- package/dist/components/utils/ViewFieldWrapper.d.ts +11 -0
- package/dist/components/utils/ViewFieldWrapper.js +9 -0
- package/dist/components/utils/layoutHelpers.d.ts +19 -0
- package/dist/components/utils/layoutHelpers.js +257 -0
- package/dist/components/widgets/ChartWidget.d.ts +16 -0
- package/dist/components/widgets/ChartWidget.js +192 -0
- package/dist/components/widgets/StatsWidget.d.ts +16 -0
- package/dist/components/widgets/StatsWidget.js +39 -0
- package/dist/components/widgets/WidgetRenderer.d.ts +10 -0
- package/dist/components/widgets/WidgetRenderer.js +50 -0
- package/dist/components/widgets/WidgetShell.d.ts +9 -0
- package/dist/components/widgets/WidgetShell.js +7 -0
- package/dist/contexts/AuthChallengeRegistryContext.d.ts +15 -0
- package/dist/contexts/AuthChallengeRegistryContext.js +15 -0
- package/dist/contexts/BlockRegistryContext.d.ts +18 -0
- package/dist/contexts/BlockRegistryContext.js +8 -0
- package/dist/contexts/ColumnRegistryContext.d.ts +8 -0
- package/dist/contexts/ColumnRegistryContext.js +30 -0
- package/dist/contexts/FieldRegistryContext.d.ts +13 -0
- package/dist/contexts/FieldRegistryContext.js +46 -0
- package/dist/contexts/PanelMetadataContext.d.ts +26 -0
- package/dist/contexts/PanelMetadataContext.js +26 -0
- package/dist/contexts/PanelProviders.d.ts +27 -0
- package/dist/contexts/PanelProviders.js +24 -0
- package/dist/contexts/ResourceModalContext.d.ts +26 -0
- package/dist/contexts/ResourceModalContext.js +76 -0
- package/dist/contexts/SlotRegistryContext.d.ts +19 -0
- package/dist/contexts/SlotRegistryContext.js +24 -0
- package/dist/contexts/TableRefreshContext.d.ts +10 -0
- package/dist/contexts/TableRefreshContext.js +30 -0
- package/dist/contexts/WidgetRegistryContext.d.ts +17 -0
- package/dist/contexts/WidgetRegistryContext.js +14 -0
- package/dist/contexts/createRegistryContext.d.ts +19 -0
- package/dist/contexts/createRegistryContext.js +20 -0
- package/dist/hooks/useAfterStateUpdated.d.ts +6 -0
- package/dist/hooks/useAfterStateUpdated.js +62 -0
- package/dist/hooks/useValidation.d.ts +26 -0
- package/dist/hooks/useValidation.js +76 -0
- package/dist/i18n/I18nProvider.d.ts +27 -0
- package/dist/i18n/I18nProvider.js +101 -0
- package/dist/i18n/LocaleSwitcher.d.ts +10 -0
- package/dist/i18n/LocaleSwitcher.js +30 -0
- package/dist/i18n/activeLocale.d.ts +11 -0
- package/dist/i18n/activeLocale.js +34 -0
- package/dist/i18n/buildClientI18n.d.ts +28 -0
- package/dist/i18n/buildClientI18n.js +67 -0
- package/dist/i18n/index.d.ts +11 -0
- package/dist/i18n/index.js +9 -0
- package/dist/i18n/locales/core/en.d.ts +225 -0
- package/dist/i18n/locales/core/en.js +252 -0
- package/dist/i18n/locales/core/index.d.ts +2 -0
- package/dist/i18n/locales/core/index.js +4 -0
- package/dist/i18n/locales/core/sq.d.ts +253 -0
- package/dist/i18n/locales/core/sq.js +255 -0
- package/dist/i18n/useFormatter.d.ts +18 -0
- package/dist/i18n/useFormatter.js +37 -0
- package/dist/i18n/useLocale.d.ts +11 -0
- package/dist/i18n/useLocale.js +11 -0
- package/dist/i18n/useTranslation.d.ts +12 -0
- package/dist/i18n/useTranslation.js +12 -0
- package/dist/index.d.ts +106 -0
- package/dist/index.js +101 -0
- package/dist/pages/ResourceListPage.d.ts +8 -0
- package/dist/pages/ResourceListPage.js +139 -0
- package/dist/plugin.d.ts +79 -0
- package/dist/plugin.js +34 -0
- package/dist/runtime/conditions.d.ts +35 -0
- package/dist/runtime/conditions.js +97 -0
- package/dist/runtime/formTraversal.d.ts +25 -0
- package/dist/runtime/formTraversal.js +37 -0
- package/dist/runtime/serializedFunctions.d.ts +41 -0
- package/dist/runtime/serializedFunctions.js +264 -0
- package/dist/slots/Slot.d.ts +24 -0
- package/dist/slots/Slot.js +29 -0
- package/dist/slots/SlotCluster.d.ts +22 -0
- package/dist/slots/SlotCluster.js +49 -0
- package/dist/slots/index.d.ts +7 -0
- package/dist/slots/index.js +4 -0
- package/dist/slots/mergeSlots.d.ts +18 -0
- package/dist/slots/mergeSlots.js +35 -0
- package/dist/slots/types.d.ts +87 -0
- package/dist/slots/types.js +30 -0
- package/dist/styles.css +1 -0
- package/dist/table/TableContext.d.ts +36 -0
- package/dist/table/TableContext.js +13 -0
- package/dist/table/TableRenderer.d.ts +29 -0
- package/dist/table/TableRenderer.js +159 -0
- package/dist/table/components/FiltersPanel.d.ts +11 -0
- package/dist/table/components/FiltersPanel.js +52 -0
- package/dist/table/components/TableToolbar.d.ts +28 -0
- package/dist/table/components/TableToolbar.js +27 -0
- package/dist/table/components/TableToolbarButton.d.ts +6 -0
- package/dist/table/components/TableToolbarButton.js +9 -0
- package/dist/table/components/TableView.d.ts +12 -0
- package/dist/table/components/TableView.js +21 -0
- package/dist/table/defaultRowActions.d.ts +21 -0
- package/dist/table/defaultRowActions.js +37 -0
- package/dist/table/hooks/useColumnVisibility.d.ts +13 -0
- package/dist/table/hooks/useColumnVisibility.js +59 -0
- package/dist/table/hooks/useEditableRows.d.ts +22 -0
- package/dist/table/hooks/useEditableRows.js +63 -0
- package/dist/table/hooks/useTableActions.d.ts +54 -0
- package/dist/table/hooks/useTableActions.js +313 -0
- package/dist/table/hooks/useTableData.d.ts +28 -0
- package/dist/table/hooks/useTableData.js +63 -0
- package/dist/table/hooks/useTableLayout.d.ts +12 -0
- package/dist/table/hooks/useTableLayout.js +31 -0
- package/dist/table/hooks/useTableQuery.d.ts +29 -0
- package/dist/table/hooks/useTableQuery.js +135 -0
- package/dist/types/index.d.ts +224 -0
- package/dist/types/index.js +6 -0
- package/dist/utils/classNames.d.ts +7 -0
- package/dist/utils/classNames.js +9 -0
- package/dist/utils/columnMediaDimensions.d.ts +13 -0
- package/dist/utils/columnMediaDimensions.js +29 -0
- package/dist/utils/columnVisibilityStorage.d.ts +22 -0
- package/dist/utils/columnVisibilityStorage.js +56 -0
- package/dist/utils/fieldErrors.d.ts +13 -0
- package/dist/utils/fieldErrors.js +25 -0
- package/dist/utils/formatValue.d.ts +28 -0
- package/dist/utils/formatValue.js +109 -0
- package/dist/utils/layoutStorage.d.ts +23 -0
- package/dist/utils/layoutStorage.js +53 -0
- package/dist/utils/redirectHandler.d.ts +7 -0
- package/dist/utils/redirectHandler.js +25 -0
- package/dist/utils/tableFormatters.d.ts +14 -0
- package/dist/utils/tableFormatters.js +93 -0
- package/dist/utils/widgetVisibilityStorage.d.ts +11 -0
- package/dist/utils/widgetVisibilityStorage.js +39 -0
- package/package.json +101 -0
- package/src/FieldRenderer.test.tsx +44 -0
- package/src/FieldRenderer.tsx +104 -0
- package/src/FormRenderer.containers.test.tsx +121 -0
- package/src/FormRenderer.test.tsx +174 -0
- package/src/FormRenderer.tsx +140 -0
- package/src/TableRenderer.tsx +2 -0
- package/src/api/actionsApi.ts +76 -0
- package/src/api/authenticatedFetch.ts +40 -0
- package/src/api/exportApi.ts +66 -0
- package/src/api/http.test.ts +58 -0
- package/src/api/http.ts +68 -0
- package/src/api/resourceApi.ts +88 -0
- package/src/api/tableApi.test.ts +108 -0
- package/src/api/tableApi.ts +107 -0
- package/src/api/urls.ts +50 -0
- package/src/app.test.tsx +67 -0
- package/src/app.tsx +181 -0
- package/src/auth/AuthContext.tsx +188 -0
- package/src/auth/LoginPage.tsx +380 -0
- package/src/auth/ProtectedRoute.tsx +39 -0
- package/src/auth/authApiClient.ts +109 -0
- package/src/auth/authFlow.test.tsx +168 -0
- package/src/auth/types.ts +104 -0
- package/src/components/ActionFormModal.tsx +45 -0
- package/src/components/AdminPanel.tsx +368 -0
- package/src/components/Checkbox.tsx +59 -0
- package/src/components/CheckboxField.tsx +88 -0
- package/src/components/ColorPickerField.tsx +93 -0
- package/src/components/DateTimePickerField.tsx +112 -0
- package/src/components/FileUploadField.tsx +841 -0
- package/src/components/GlobalSearch.tsx +436 -0
- package/src/components/GroupField.tsx +85 -0
- package/src/components/HiddenField.tsx +14 -0
- package/src/components/ModalBreadcrumb.tsx +74 -0
- package/src/components/ModalDrawer.tsx +137 -0
- package/src/components/RadioField.tsx +80 -0
- package/src/components/RepeaterField.tsx +546 -0
- package/src/components/ResourceModalRenderer.tsx +144 -0
- package/src/components/RichEditorField.tsx +942 -0
- package/src/components/SectionField.tsx +242 -0
- package/src/components/SelectField.tsx +843 -0
- package/src/components/TabsField.test.tsx +151 -0
- package/src/components/TabsField.tsx +386 -0
- package/src/components/TagsInputField.tsx +411 -0
- package/src/components/TextInputField.tsx +91 -0
- package/src/components/TextareaField.tsx +110 -0
- package/src/components/ToggleField.tsx +126 -0
- package/src/components/ViewModal.tsx +353 -0
- package/src/components/blocks/BlockRenderer.tsx +56 -0
- package/src/components/blocks/FormBlockRenderer.tsx +160 -0
- package/src/components/blocks/TableBlockRenderer.tsx +33 -0
- package/src/components/blocks/TabsBlockRenderer.tsx +49 -0
- package/src/components/blocks/WidgetBlockRenderer.tsx +19 -0
- package/src/components/columns/CheckboxColumnComponent.tsx +38 -0
- package/src/components/columns/ColorColumnComponent.tsx +23 -0
- package/src/components/columns/CustomColumn.test.tsx +55 -0
- package/src/components/columns/DeeplinkWrapper.tsx +103 -0
- package/src/components/columns/IconColumnComponent.tsx +55 -0
- package/src/components/columns/ImageColumnComponent.tsx +220 -0
- package/src/components/columns/MediaColumnComponent.tsx +294 -0
- package/src/components/columns/SelectColumnComponent.tsx +49 -0
- package/src/components/columns/TagsColumnComponent.tsx +46 -0
- package/src/components/columns/TextColumnComponent.tsx +191 -0
- package/src/components/columns/TextInputColumnComponent.tsx +35 -0
- package/src/components/columns/ToggleColumnComponent.tsx +56 -0
- package/src/components/columns/VideoColumnComponent.tsx +236 -0
- package/src/components/columns/ViewColumnComponent.tsx +9 -0
- package/src/components/errors/ErrorBoundary.tsx +58 -0
- package/src/components/filters/CustomFilterComponent.tsx +130 -0
- package/src/components/filters/DateFilterComponent.tsx +272 -0
- package/src/components/filters/QueryBuilderFilterComponent.tsx +502 -0
- package/src/components/layout/Header.tsx +212 -0
- package/src/components/layout/PanelBrandMark.tsx +61 -0
- package/src/components/layout/Sidebar.tsx +283 -0
- package/src/components/modals/RelationCreateModal.tsx +107 -0
- package/src/components/modals/ResourceFormModal.test.tsx +119 -0
- package/src/components/modals/ResourceFormModal.tsx +128 -0
- package/src/components/modals/useResourceForm.ts +207 -0
- package/src/components/modals/view/RecordActions.tsx +69 -0
- package/src/components/modals/view/RecordDetails.tsx +60 -0
- package/src/components/modals/view/RelationPanel.tsx +76 -0
- package/src/components/modals/view/RelationTabs.tsx +145 -0
- package/src/components/modals/view/useRecordView.ts +134 -0
- package/src/components/pages/PageRenderer.tsx +173 -0
- package/src/components/table/ColumnTogglePopup.tsx +85 -0
- package/src/components/table/GridCard.tsx +155 -0
- package/src/components/table/GridView.tsx +138 -0
- package/src/components/table/LayoutToggle.tsx +24 -0
- package/src/components/table/TableActionsDropdown.tsx +114 -0
- package/src/components/table/TableBulkActions.tsx +65 -0
- package/src/components/table/TableHeader.tsx +96 -0
- package/src/components/table/TablePagination.tsx +169 -0
- package/src/components/table/TableRow.tsx +155 -0
- package/src/components/table/TableSearchBar.tsx +66 -0
- package/src/components/table/TableTabs.tsx +49 -0
- package/src/components/ui/Badge.tsx +30 -0
- package/src/components/ui/Button.test.tsx +78 -0
- package/src/components/ui/Button.tsx +102 -0
- package/src/components/ui/Card.tsx +23 -0
- package/src/components/ui/ConfirmDialog.tsx +112 -0
- package/src/components/ui/EmptyState.tsx +24 -0
- package/src/components/ui/ErrorAlert.tsx +37 -0
- package/src/components/ui/Input.tsx +48 -0
- package/src/components/ui/Label.tsx +15 -0
- package/src/components/ui/PillButton.tsx +72 -0
- package/src/components/ui/Select.tsx +33 -0
- package/src/components/ui/Spinner.tsx +39 -0
- package/src/components/ui/Toast.tsx +105 -0
- package/src/components/ui/index.ts +24 -0
- package/src/components/utils/HintDisplay.tsx +26 -0
- package/src/components/utils/Icon.tsx +36 -0
- package/src/components/utils/MediaPreviewModal.tsx +114 -0
- package/src/components/utils/ViewFieldWrapper.tsx +23 -0
- package/src/components/utils/layoutHelpers.ts +267 -0
- package/src/components/widgets/ChartWidget.tsx +247 -0
- package/src/components/widgets/StatsWidget.tsx +72 -0
- package/src/components/widgets/WidgetRenderer.tsx +108 -0
- package/src/components/widgets/WidgetShell.tsx +37 -0
- package/src/contexts/AuthChallengeRegistryContext.tsx +29 -0
- package/src/contexts/BlockRegistryContext.tsx +28 -0
- package/src/contexts/ColumnRegistryContext.tsx +38 -0
- package/src/contexts/FieldRegistryContext.tsx +56 -0
- package/src/contexts/PanelMetadataContext.tsx +60 -0
- package/src/contexts/PanelProviders.tsx +85 -0
- package/src/contexts/ResourceModalContext.tsx +137 -0
- package/src/contexts/SlotRegistryContext.tsx +35 -0
- package/src/contexts/TableRefreshContext.tsx +44 -0
- package/src/contexts/WidgetRegistryContext.tsx +34 -0
- package/src/contexts/createRegistryContext.tsx +29 -0
- package/src/hooks/useAfterStateUpdated.ts +70 -0
- package/src/hooks/useValidation.test.ts +59 -0
- package/src/hooks/useValidation.ts +95 -0
- package/src/i18n/I18nProvider.tsx +128 -0
- package/src/i18n/LocaleSwitcher.tsx +50 -0
- package/src/i18n/activeLocale.ts +39 -0
- package/src/i18n/buildClientI18n.ts +101 -0
- package/src/i18n/i18n.test.tsx +140 -0
- package/src/i18n/index.ts +12 -0
- package/src/i18n/locales/core/en.ts +274 -0
- package/src/i18n/locales/core/index.ts +5 -0
- package/src/i18n/locales/core/sq.ts +275 -0
- package/src/i18n/useFormatter.ts +42 -0
- package/src/i18n/useLocale.ts +16 -0
- package/src/i18n/useTranslation.ts +17 -0
- package/src/index.ts +244 -0
- package/src/pages/ResourceListPage.tsx +205 -0
- package/src/plugin.ts +110 -0
- package/src/runtime/conditions.test.ts +99 -0
- package/src/runtime/conditions.ts +148 -0
- package/src/runtime/formTraversal.ts +41 -0
- package/src/runtime/serializedFunctions.test.ts +59 -0
- package/src/runtime/serializedFunctions.ts +284 -0
- package/src/slots/Slot.test.tsx +89 -0
- package/src/slots/Slot.tsx +47 -0
- package/src/slots/SlotCluster.test.tsx +95 -0
- package/src/slots/SlotCluster.tsx +107 -0
- package/src/slots/index.ts +15 -0
- package/src/slots/mergeSlots.test.ts +71 -0
- package/src/slots/mergeSlots.ts +40 -0
- package/src/slots/slotNames.test.ts +21 -0
- package/src/slots/types.ts +119 -0
- package/src/styles.css +437 -0
- package/src/table/TableContext.tsx +41 -0
- package/src/table/TableRenderer.test.tsx +197 -0
- package/src/table/TableRenderer.tsx +390 -0
- package/src/table/components/FiltersPanel.tsx +193 -0
- package/src/table/components/TableToolbar.tsx +153 -0
- package/src/table/components/TableToolbarButton.tsx +14 -0
- package/src/table/components/TableView.tsx +106 -0
- package/src/table/defaultRowActions.ts +43 -0
- package/src/table/hooks/useColumnVisibility.test.ts +51 -0
- package/src/table/hooks/useColumnVisibility.ts +71 -0
- package/src/table/hooks/useEditableRows.test.ts +69 -0
- package/src/table/hooks/useEditableRows.ts +89 -0
- package/src/table/hooks/useTableActions.ts +393 -0
- package/src/table/hooks/useTableData.ts +89 -0
- package/src/table/hooks/useTableLayout.ts +45 -0
- package/src/table/hooks/useTableQuery.test.ts +116 -0
- package/src/table/hooks/useTableQuery.ts +172 -0
- package/src/test/mockFetch.ts +67 -0
- package/src/test/setup.ts +25 -0
- package/src/types/index.ts +228 -0
- package/src/utils/classNames.ts +10 -0
- package/src/utils/columnMediaDimensions.ts +45 -0
- package/src/utils/columnVisibilityStorage.ts +55 -0
- package/src/utils/fieldErrors.test.ts +35 -0
- package/src/utils/fieldErrors.ts +27 -0
- package/src/utils/formatValue.test.tsx +65 -0
- package/src/utils/formatValue.tsx +117 -0
- package/src/utils/layoutStorage.ts +52 -0
- package/src/utils/redirectHandler.ts +29 -0
- package/src/utils/tableFormatters.test.ts +54 -0
- package/src/utils/tableFormatters.ts +104 -0
- package/src/utils/widgetVisibilityStorage.ts +38 -0
- package/tailwind.config.js +9 -0
- package/vite.config.ts +17 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SerializedColumn, SerializedTable } from '@maxal_studio/kratosjs';
|
|
3
|
+
/**
|
|
4
|
+
* Shared table state and handlers for row-level components (TableRow,
|
|
5
|
+
* GridCard, TableView). Replaces the 15-prop drilling of v1.
|
|
6
|
+
*/
|
|
7
|
+
export interface TableContextValue {
|
|
8
|
+
schema: SerializedTable & {
|
|
9
|
+
canCreate?: boolean;
|
|
10
|
+
canEdit?: boolean;
|
|
11
|
+
canDelete?: boolean;
|
|
12
|
+
canView?: boolean;
|
|
13
|
+
};
|
|
14
|
+
visibleColumns: SerializedColumn[];
|
|
15
|
+
/** Actions filtered by the resource's can* capabilities */
|
|
16
|
+
visibleActions: any[];
|
|
17
|
+
data: any[];
|
|
18
|
+
isLoading: boolean;
|
|
19
|
+
error: string | null;
|
|
20
|
+
setError: (error: string | null) => void;
|
|
21
|
+
selectedRows: Set<any>;
|
|
22
|
+
changedRows: Map<any, any>;
|
|
23
|
+
openActionsRowId: any;
|
|
24
|
+
onToggleActions: (rowId: any) => void;
|
|
25
|
+
onRowSelect: (rowId: any) => void;
|
|
26
|
+
onSelectAll: () => void;
|
|
27
|
+
onCellChange: (rowId: any, columnName: string, value: any) => void;
|
|
28
|
+
onRowAction: (actionName: string, rowId: any) => void;
|
|
29
|
+
onSaveRow: (rowId: any) => void;
|
|
30
|
+
onResetRow: (rowId: any) => void;
|
|
31
|
+
}
|
|
32
|
+
export declare function TableProvider({ value, children }: {
|
|
33
|
+
value: TableContextValue;
|
|
34
|
+
children: React.ReactNode;
|
|
35
|
+
}): React.JSX.Element;
|
|
36
|
+
export declare function useTableContext(): TableContextValue;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext } from 'react';
|
|
3
|
+
const TableContext = createContext(null);
|
|
4
|
+
export function TableProvider({ value, children }) {
|
|
5
|
+
return _jsx(TableContext.Provider, { value: value, children: children });
|
|
6
|
+
}
|
|
7
|
+
export function useTableContext() {
|
|
8
|
+
const context = useContext(TableContext);
|
|
9
|
+
if (!context) {
|
|
10
|
+
throw new Error('useTableContext must be used within a TableRenderer');
|
|
11
|
+
}
|
|
12
|
+
return context;
|
|
13
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SerializedTable } from '@maxal_studio/kratosjs';
|
|
3
|
+
export interface TableRendererProps {
|
|
4
|
+
schema: SerializedTable & {
|
|
5
|
+
canCreate?: boolean;
|
|
6
|
+
canEdit?: boolean;
|
|
7
|
+
canDelete?: boolean;
|
|
8
|
+
canView?: boolean;
|
|
9
|
+
};
|
|
10
|
+
isResource: boolean;
|
|
11
|
+
apiUrl: string;
|
|
12
|
+
onBulkAction?: (action: string, selectedIds: any[]) => Promise<void> | void;
|
|
13
|
+
onRowAction?: (action: string, rowId: any) => Promise<void> | void;
|
|
14
|
+
className?: string;
|
|
15
|
+
relatedResourceSlug?: string;
|
|
16
|
+
relatedResourceApiUrl?: string;
|
|
17
|
+
apiBaseUrl?: string;
|
|
18
|
+
depth?: number;
|
|
19
|
+
onCloseAll?: () => void;
|
|
20
|
+
onCreateClick?: () => void;
|
|
21
|
+
onEditClick?: (rowId: any) => void;
|
|
22
|
+
onViewClick?: (rowId: any) => void;
|
|
23
|
+
canCreate?: boolean;
|
|
24
|
+
canEdit?: boolean;
|
|
25
|
+
canDelete?: boolean;
|
|
26
|
+
canView?: boolean;
|
|
27
|
+
refreshKey?: number;
|
|
28
|
+
}
|
|
29
|
+
export declare function TableRenderer({ schema, isResource, apiUrl, onBulkAction, onRowAction, className, relatedResourceSlug, relatedResourceApiUrl, apiBaseUrl, depth, onCloseAll, onCreateClick, onEditClick, onViewClick, canCreate, canEdit, canDelete, canView, refreshKey, }: TableRendererProps): React.JSX.Element;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React, { useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { cn } from '../utils/classNames';
|
|
4
|
+
import { TableApiClient } from '../api/tableApi';
|
|
5
|
+
import { getFormSchema } from '../api/resourceApi';
|
|
6
|
+
import { deriveApiBaseUrl, resourceSlugFromUrl, resourceStorageKey } from '../api/urls';
|
|
7
|
+
import { useResourceModal } from '../contexts/ResourceModalContext';
|
|
8
|
+
import { WidgetRenderer } from '../components/widgets/WidgetRenderer';
|
|
9
|
+
import { TableTabs } from '../components/table/TableTabs';
|
|
10
|
+
import { TableBulkActions } from '../components/table/TableBulkActions';
|
|
11
|
+
import { TablePagination } from '../components/table/TablePagination';
|
|
12
|
+
import { GridView } from '../components/table/GridView';
|
|
13
|
+
import { ResourceFormModal } from '../components/modals/ResourceFormModal';
|
|
14
|
+
import { ActionFormModal } from '../components/ActionFormModal';
|
|
15
|
+
import { useTableQuery } from './hooks/useTableQuery';
|
|
16
|
+
import { useTableData } from './hooks/useTableData';
|
|
17
|
+
import { useEditableRows } from './hooks/useEditableRows';
|
|
18
|
+
import { useColumnVisibility } from './hooks/useColumnVisibility';
|
|
19
|
+
import { useTableLayout } from './hooks/useTableLayout';
|
|
20
|
+
import { useTableActions } from './hooks/useTableActions';
|
|
21
|
+
import { buildRowActions } from './defaultRowActions';
|
|
22
|
+
import { TableProvider } from './TableContext';
|
|
23
|
+
import { TableToolbar } from './components/TableToolbar';
|
|
24
|
+
import { Slot } from '../slots/Slot';
|
|
25
|
+
import { TableView } from './components/TableView';
|
|
26
|
+
import { FiltersPanel } from './components/FiltersPanel';
|
|
27
|
+
export function TableRenderer({ schema, isResource = true, apiUrl, onBulkAction, onRowAction, className, relatedResourceSlug, relatedResourceApiUrl, apiBaseUrl, depth = 0, onCloseAll, onCreateClick, onEditClick, onViewClick, canCreate = true, canEdit = true, canDelete = true, canView = true, refreshKey, }) {
|
|
28
|
+
const { openModal, closeModal } = useResourceModal();
|
|
29
|
+
// Derived identifiers
|
|
30
|
+
const computedApiBaseUrl = apiBaseUrl || deriveApiBaseUrl(apiUrl);
|
|
31
|
+
const resourceSlug = relatedResourceSlug || resourceSlugFromUrl(apiUrl);
|
|
32
|
+
const resourceKey = useMemo(() => resourceStorageKey(apiUrl, isResource, relatedResourceSlug), [apiUrl, isResource, relatedResourceSlug]);
|
|
33
|
+
const apiClient = useMemo(() => new TableApiClient(computedApiBaseUrl, apiUrl, isResource ? '/list' : ''), [computedApiBaseUrl, apiUrl, isResource]);
|
|
34
|
+
// Query + data + change tracking
|
|
35
|
+
const query = useTableQuery(schema);
|
|
36
|
+
const editableRef = useRef(() => { });
|
|
37
|
+
const table = useTableData({
|
|
38
|
+
apiClient,
|
|
39
|
+
queryParams: query.queryParams,
|
|
40
|
+
refreshKey,
|
|
41
|
+
onLoaded: rows => editableRef.current(rows),
|
|
42
|
+
});
|
|
43
|
+
const editable = useEditableRows({
|
|
44
|
+
data: table.data,
|
|
45
|
+
setData: table.setData,
|
|
46
|
+
saveRecord: async (rowId, changes) => {
|
|
47
|
+
// Relation tables save through the related resource's own endpoint
|
|
48
|
+
if (relatedResourceSlug) {
|
|
49
|
+
const relatedApiUrl = relatedResourceApiUrl || `${computedApiBaseUrl}/${relatedResourceSlug}`;
|
|
50
|
+
const relatedClient = new TableApiClient(computedApiBaseUrl, relatedApiUrl, '/list');
|
|
51
|
+
await relatedClient.updateRecord(rowId, changes);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
await apiClient.updateRecord(rowId, changes);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
onSaveError: () => table.setError('Failed to save changes. Please try again.'),
|
|
58
|
+
});
|
|
59
|
+
editableRef.current = editable.resetTracking;
|
|
60
|
+
// Presentation state
|
|
61
|
+
const columns = useColumnVisibility(schema.columns, resourceKey);
|
|
62
|
+
const layoutState = useTableLayout(schema, resourceSlug);
|
|
63
|
+
const [openActionsRowId, setOpenActionsRowId] = useState(null);
|
|
64
|
+
// Row + bulk actions
|
|
65
|
+
const actions = useTableActions({
|
|
66
|
+
schema,
|
|
67
|
+
apiClient,
|
|
68
|
+
apiBaseUrl: computedApiBaseUrl,
|
|
69
|
+
resourceSlug,
|
|
70
|
+
relatedResourceSlug,
|
|
71
|
+
relatedResourceApiUrl,
|
|
72
|
+
apiUrl,
|
|
73
|
+
canEdit,
|
|
74
|
+
canDelete,
|
|
75
|
+
canView,
|
|
76
|
+
data: table.data,
|
|
77
|
+
reload: table.reload,
|
|
78
|
+
setError: table.setError,
|
|
79
|
+
setIsLoading: table.setIsLoading,
|
|
80
|
+
getQueryParams: () => query.queryParams,
|
|
81
|
+
onRowAction,
|
|
82
|
+
onBulkAction,
|
|
83
|
+
onEditClick,
|
|
84
|
+
onViewClick,
|
|
85
|
+
});
|
|
86
|
+
// Create modal
|
|
87
|
+
const [createModalOpen, setCreateModalOpen] = useState(false);
|
|
88
|
+
const [createFormSchema, setCreateFormSchema] = useState(null);
|
|
89
|
+
const handleCreateModalOpen = async () => {
|
|
90
|
+
if (!createFormSchema) {
|
|
91
|
+
try {
|
|
92
|
+
setCreateFormSchema(await getFormSchema(computedApiBaseUrl, resourceSlug));
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
console.error('Error loading form schema:', err);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
openModal(resourceSlug, 'create');
|
|
99
|
+
setCreateModalOpen(true);
|
|
100
|
+
};
|
|
101
|
+
// Reset the cached create schema when the resource changes
|
|
102
|
+
React.useEffect(() => {
|
|
103
|
+
setCreateFormSchema(null);
|
|
104
|
+
}, [apiUrl]);
|
|
105
|
+
const handleCloseAll = () => {
|
|
106
|
+
setCreateModalOpen(false);
|
|
107
|
+
onCloseAll?.();
|
|
108
|
+
};
|
|
109
|
+
// Built-in view/edit/delete row actions are derived from capability flags;
|
|
110
|
+
// custom actions from the schema are merged in (delete stays last).
|
|
111
|
+
const visibleActions = useMemo(() => buildRowActions(schema.actions, { canView, canEdit, canDelete }), [schema.actions, canEdit, canDelete, canView]);
|
|
112
|
+
const filtersLayout = schema.filtersLayout || 'inline';
|
|
113
|
+
const hasWidgets = !relatedResourceSlug && schema.widgets && Array.isArray(schema.widgets) && schema.widgets.length > 0;
|
|
114
|
+
const tableContext = {
|
|
115
|
+
schema,
|
|
116
|
+
visibleColumns: columns.visibleColumns,
|
|
117
|
+
visibleActions,
|
|
118
|
+
data: table.data,
|
|
119
|
+
isLoading: table.isLoading,
|
|
120
|
+
error: table.error,
|
|
121
|
+
setError: table.setError,
|
|
122
|
+
selectedRows: actions.selectedRows,
|
|
123
|
+
changedRows: editable.changedRows,
|
|
124
|
+
openActionsRowId,
|
|
125
|
+
onToggleActions: id => setOpenActionsRowId(openActionsRowId === id ? null : id),
|
|
126
|
+
onRowSelect: actions.handleRowSelect,
|
|
127
|
+
onSelectAll: actions.handleSelectAll,
|
|
128
|
+
onCellChange: editable.handleCellChange,
|
|
129
|
+
onRowAction: actions.handleRowAction,
|
|
130
|
+
onSaveRow: editable.handleSaveRow,
|
|
131
|
+
onResetRow: editable.handleResetRow,
|
|
132
|
+
};
|
|
133
|
+
return (_jsx(TableProvider, { value: tableContext, children: _jsxs("div", { className: cn('w-full', className), children: [hasWidgets && (_jsx(WidgetRenderer, { widgets: schema.widgets, widgetData: table.widgetData, className: cn(layoutState.widgetsExpanded ? 'mb-4' : 'mb-0'), expanded: layoutState.widgetsExpanded, onExpandedChange: layoutState.setWidgetsExpanded })), _jsxs("div", { className: "mb-4 space-y-4 p-1 sm:p-0", children: [schema.tabs && Array.isArray(schema.tabs) && schema.tabs.length > 0 && (_jsx(TableTabs, { tabs: schema.tabs, activeTab: query.activeTab, onTabChange: query.handleTabClick })), _jsx(TableToolbar, { schema: schema, query: query, layout: layoutState.layout, onLayoutChange: layoutState.setLayout, visibleColumnNames: columns.visibleColumnNames, onColumnToggle: columns.handleColumnToggle, showCreateButton: canCreate, onCreateClick: onCreateClick, onCreateModalOpen: handleCreateModalOpen, onHeaderAction: actions.handleHeaderAction, showWidgetsToggle: hasWidgets, widgetsExpanded: layoutState.widgetsExpanded, onWidgetsToggle: () => layoutState.setWidgetsExpanded(!layoutState.widgetsExpanded) }), schema.filters && schema.filters.length > 0 && filtersLayout === 'inline' && (_jsx(FiltersPanel, { filters: schema.filters, values: query.filters, queryBuilderValues: query.queryBuilders, onChange: query.handleFilterChange, onClear: query.handleClearFilters, layout: "inline" }))] }), _jsx(TableBulkActions, { schema: schema, selectedCount: actions.selectedRows.size, onBulkAction: actionName => actions.handleBulkAction(actionName, Array.from(actions.selectedRows)), onClearSelection: actions.clearSelection, canDelete: canDelete }), actions.selectedRows.size > 0 && (_jsx(Slot, { name: "table.bulkActions", context: {
|
|
134
|
+
schema,
|
|
135
|
+
resourceSlug: resourceSlugFromUrl(apiUrl),
|
|
136
|
+
data: {
|
|
137
|
+
selectedCount: actions.selectedRows.size,
|
|
138
|
+
selectedIds: Array.from(actions.selectedRows),
|
|
139
|
+
},
|
|
140
|
+
}, as: "div", className: "mb-4 flex flex-wrap items-center gap-2 empty:hidden" })), _jsx(Slot, { name: "table.aboveTable", context: { schema, resourceSlug: resourceSlugFromUrl(apiUrl) }, as: "div", className: "mb-3 space-y-3 empty:hidden" }), _jsxs("div", { className: "overflow-hidden rounded-xl border border-border bg-surface", children: [layoutState.layout === 'table' ? (_jsx(TableView, { query: query, embedded: true })) : (_jsx(GridView, { schema: schema, data: table.data, visibleColumns: columns.visibleColumns, selectedRows: actions.selectedRows, changedRows: editable.changedRows, openActionsRowId: openActionsRowId, onRowSelect: actions.handleRowSelect, onCellChange: editable.handleCellChange, onRowAction: actions.handleRowAction, onSaveRow: editable.handleSaveRow, onResetRow: editable.handleResetRow, onToggleActions: id => setOpenActionsRowId(openActionsRowId === id ? null : id), isLoading: table.isLoading, error: table.error, visibleActions: visibleActions, embedded: true })), _jsx(TablePagination, { schema: schema, currentPage: query.currentPage, perPage: query.perPage, totalRecords: table.totalRecords, onPageChange: query.handlePageChange, onPageSizeChange: query.handlePageSizeChange, className: "border-t border-border/60" })] }), _jsx(Slot, { name: "table.belowTable", context: { schema, resourceSlug: resourceSlugFromUrl(apiUrl) }, as: "div", className: "mt-3 space-y-3 empty:hidden" }), createModalOpen && createFormSchema && (_jsx(ResourceFormModal, { isOpen: createModalOpen, onClose: () => {
|
|
141
|
+
setCreateModalOpen(false);
|
|
142
|
+
closeModal();
|
|
143
|
+
}, mode: "create", resourceSlug: resourceSlugFromUrl(apiUrl), resourceName: schema.resource || resourceSlugFromUrl(apiUrl), apiBaseUrl: computedApiBaseUrl, formSchema: createFormSchema, onSuccess: () => {
|
|
144
|
+
table.reload();
|
|
145
|
+
closeModal();
|
|
146
|
+
}, depth: depth, onCloseAll: handleCloseAll })), actions.actionFormModal && (_jsx(ActionFormModal, { isOpen: !!actions.actionFormModal, onClose: () => {
|
|
147
|
+
actions.setActionFormModal(null);
|
|
148
|
+
closeModal();
|
|
149
|
+
}, actionName: actions.actionFormModal.actionName, actionLabel: (actions.actionFormModal.isBulk
|
|
150
|
+
? schema.bulkActions?.find(a => a.name === actions.actionFormModal.actionName)?.label
|
|
151
|
+
: schema.actions?.find(a => a.name === actions.actionFormModal.actionName)?.label) ||
|
|
152
|
+
actions.actionFormModal.actionName, formSchema: actions.actionFormModal.formSchema, recordIds: actions.actionFormModal.recordIds, isBulk: actions.actionFormModal.isBulk, requiresConfirmation: actions.actionFormModal.requiresConfirmation, modalDescription: actions.actionFormModal.modalDescription, apiBaseUrl: computedApiBaseUrl, resourceSlug: resourceSlug, onSuccess: () => {
|
|
153
|
+
if (actions.actionFormModal?.isBulk) {
|
|
154
|
+
actions.clearSelection();
|
|
155
|
+
}
|
|
156
|
+
table.reload();
|
|
157
|
+
closeModal();
|
|
158
|
+
}, depth: depth, onCloseAll: handleCloseAll }))] }) }));
|
|
159
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SerializedFilter } from '@maxal_studio/kratosjs';
|
|
3
|
+
export interface FiltersPanelProps {
|
|
4
|
+
filters: SerializedFilter[];
|
|
5
|
+
values: Record<string, any>;
|
|
6
|
+
queryBuilderValues: Record<string, any[]>;
|
|
7
|
+
onChange: (name: string, value: any, isQueryBuilder?: boolean) => void;
|
|
8
|
+
onClear: () => void;
|
|
9
|
+
layout: 'inline' | 'dropdown' | 'sidebar';
|
|
10
|
+
}
|
|
11
|
+
export declare function FiltersPanel({ filters, values, queryBuilderValues, onChange, onClear, layout }: FiltersPanelProps): React.JSX.Element;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { Filter, ChevronDown, X } from 'lucide-react';
|
|
4
|
+
import { cn } from '../../utils/classNames';
|
|
5
|
+
import { Select } from '../../components/ui/Select';
|
|
6
|
+
import { Label } from '../../components/ui/Label';
|
|
7
|
+
import { PillButton, PillIconButton } from '../../components/ui/PillButton';
|
|
8
|
+
import { QueryBuilderFilterComponent } from '../../components/filters/QueryBuilderFilterComponent';
|
|
9
|
+
import { CustomFilterComponent } from '../../components/filters/CustomFilterComponent';
|
|
10
|
+
import { DateFilterComponent } from '../../components/filters/DateFilterComponent';
|
|
11
|
+
import { TableToolbarButton } from './TableToolbarButton';
|
|
12
|
+
import { translate } from '../../i18n/activeLocale';
|
|
13
|
+
function FilterField({ filter, value, onChange, embedded }) {
|
|
14
|
+
const hasValue = value !== undefined && value !== '' && value !== null;
|
|
15
|
+
if (filter.type === 'select') {
|
|
16
|
+
return (_jsxs("div", { className: "space-y-1.5", children: [_jsx(Label, { children: filter.label || filter.name }), _jsxs(Select, { value: value || '', onChange: e => onChange(e.target.value || undefined), active: hasValue, children: [_jsx("option", { value: "", children: filter.placeholder || `All ${filter.label || filter.name}` }), filter.options &&
|
|
17
|
+
Object.entries(filter.options).map(([val, label]) => (_jsx("option", { value: val, children: label }, val)))] })] }));
|
|
18
|
+
}
|
|
19
|
+
if (filter.type === 'ternary') {
|
|
20
|
+
return (_jsxs("div", { className: "space-y-1.5", children: [_jsx(Label, { children: filter.label || filter.name }), _jsxs(Select, { value: value !== undefined ? String(value) : '', onChange: e => onChange(e.target.value === '' ? undefined : e.target.value === 'true'), active: hasValue, children: [_jsx("option", { value: "", children: filter.placeholder || translate('core:common.all') }), _jsx("option", { value: "true", children: filter.trueLabel || translate('core:common.yes') }), _jsx("option", { value: "false", children: filter.falseLabel || translate('core:common.no') })] })] }));
|
|
21
|
+
}
|
|
22
|
+
if (filter.type === 'date') {
|
|
23
|
+
return _jsx(DateFilterComponent, { filter: filter, value: value, onChange: onChange, embedded: embedded });
|
|
24
|
+
}
|
|
25
|
+
if (filter.type === 'queryBuilder') {
|
|
26
|
+
return (_jsxs("div", { className: "space-y-1.5", children: [_jsx(Label, { children: filter.label || translate('core:filters.advanced_search') }), _jsx(QueryBuilderFilterComponent, { filter: filter, value: value, onChange: value => onChange(value, true), embedded: embedded })] }));
|
|
27
|
+
}
|
|
28
|
+
if (filter.type === 'custom') {
|
|
29
|
+
return (_jsxs("div", { className: "space-y-1.5", children: [_jsx(Label, { children: filter.label || filter.name }), _jsx(CustomFilterComponent, { filter: filter, value: value, onChange: onChange, embedded: embedded })] }));
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
export function FiltersPanel({ filters, values, queryBuilderValues, onChange, onClear, layout }) {
|
|
34
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
35
|
+
const regularCount = Object.keys(values).filter(key => values[key] !== undefined).length;
|
|
36
|
+
const queryBuilderCount = Object.keys(queryBuilderValues).filter(key => queryBuilderValues[key] && queryBuilderValues[key].length > 0).length;
|
|
37
|
+
const activeCount = regularCount + queryBuilderCount;
|
|
38
|
+
const fields = filters.map(filter => {
|
|
39
|
+
const isQueryBuilder = filter.type === 'queryBuilder';
|
|
40
|
+
const value = isQueryBuilder ? queryBuilderValues[filter.name] : values[filter.name];
|
|
41
|
+
return (_jsx(FilterField, { filter: filter, value: value, onChange: (value, isQB) => onChange(filter.name, value, isQB), embedded: layout === 'dropdown' }, filter.name));
|
|
42
|
+
});
|
|
43
|
+
// Inline layout — all filters visible in a card
|
|
44
|
+
if (layout === 'inline') {
|
|
45
|
+
return (_jsxs("div", { className: "rounded-xl border border-border bg-surface p-4", children: [_jsx("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4", children: fields }), activeCount > 0 && (_jsx("div", { className: "mt-4 flex justify-end border-t border-border/60 pt-4", children: _jsx("button", { type: "button", onClick: onClear, className: "text-sm font-medium text-accent transition-colors hover:text-accent-hover", children: translate('core:filters.clear_all_filters') }) }))] }));
|
|
46
|
+
}
|
|
47
|
+
// Dropdown layout — filters behind a trigger button
|
|
48
|
+
return (_jsxs("div", { className: "relative", children: [_jsxs(TableToolbarButton, { onClick: () => setIsOpen(!isOpen), icon: _jsx(Filter, { className: "h-4 w-4" }), className: cn(activeCount > 0 && 'ring-2 ring-ring border-accent'), "aria-expanded": isOpen, children: [_jsx("span", { children: translate('core:table.filters') }), activeCount > 0 && (_jsx("span", { className: "inline-flex h-5 min-w-[20px] items-center justify-center rounded-full bg-accent px-1.5 text-xs font-bold text-accent-fg", children: activeCount })), _jsx(ChevronDown, { className: cn('h-4 w-4 transition-transform', isOpen && 'rotate-180') })] }), isOpen && (_jsxs(_Fragment, { children: [_jsx("div", { className: "fixed inset-0 z-40", onClick: () => setIsOpen(false) }), _jsxs("div", { className: "fixed inset-x-4 top-1/2 z-50 flex max-h-[80vh] w-auto -translate-y-1/2 flex-col overflow-hidden rounded-lg border border-border bg-raised p-4 shadow-soft-lg sm:absolute sm:inset-auto sm:right-0 sm:top-full sm:left-auto sm:mt-2 sm:w-[min(480px,calc(100vw-2rem))] sm:translate-y-0", children: [_jsxs("div", { className: "mb-4 flex shrink-0 items-center justify-between", children: [_jsx("h3", { className: "text-base font-semibold text-fg", children: translate('core:table.filters') }), _jsx(PillIconButton, { "aria-label": translate('core:table.close_filters'), onClick: () => setIsOpen(false), children: _jsx(X, { className: "h-4 w-4" }) })] }), _jsx("div", { className: "flex-1 space-y-4 overflow-y-auto pr-2", children: fields }), _jsxs("div", { className: "mt-4 flex shrink-0 items-center justify-between border-t border-border pt-4", children: [_jsx("button", { type: "button", onClick: () => {
|
|
49
|
+
onClear();
|
|
50
|
+
setIsOpen(false);
|
|
51
|
+
}, disabled: activeCount === 0, className: "text-sm font-medium text-fg-secondary transition-colors hover:text-fg disabled:opacity-50", children: translate('core:common.clear_all') }), _jsx(PillButton, { variant: "primary", onClick: () => setIsOpen(false), children: translate('core:common.done') })] })] })] }))] }));
|
|
52
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SerializedTable } from '@maxal_studio/kratosjs';
|
|
3
|
+
import { TableQueryApi } from '../hooks/useTableQuery';
|
|
4
|
+
export interface TableToolbarProps {
|
|
5
|
+
schema: SerializedTable;
|
|
6
|
+
query: TableQueryApi;
|
|
7
|
+
/** Layout switching (undefined hides the toggle) */
|
|
8
|
+
layout?: 'table' | 'grid';
|
|
9
|
+
onLayoutChange?: (layout: 'table' | 'grid') => void;
|
|
10
|
+
/** Column visibility */
|
|
11
|
+
visibleColumnNames: Set<string>;
|
|
12
|
+
onColumnToggle: (columnName: string, visible: boolean) => void;
|
|
13
|
+
/** Create button */
|
|
14
|
+
showCreateButton: boolean;
|
|
15
|
+
onCreateClick?: () => void;
|
|
16
|
+
onCreateModalOpen?: () => void;
|
|
17
|
+
/** Header actions (e.g. Export), rendered as buttons in the toolbar */
|
|
18
|
+
onHeaderAction?: (actionName: string) => void;
|
|
19
|
+
/** Widgets panel toggle (icon-only, sits with other toolbar controls) */
|
|
20
|
+
showWidgetsToggle?: boolean;
|
|
21
|
+
widgetsExpanded?: boolean;
|
|
22
|
+
onWidgetsToggle?: () => void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The row of list controls above the table: search + create, filter
|
|
26
|
+
* trigger (dropdown layout), layout switch and column settings.
|
|
27
|
+
*/
|
|
28
|
+
export declare function TableToolbar({ schema, query, layout, onLayoutChange, visibleColumnNames, onColumnToggle, showCreateButton, onCreateClick, onCreateModalOpen, onHeaderAction, showWidgetsToggle, widgetsExpanded, onWidgetsToggle, }: TableToolbarProps): React.JSX.Element;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { Columns3Cog, LayoutDashboard } from 'lucide-react';
|
|
4
|
+
import { TableSearchBar } from '../../components/table/TableSearchBar';
|
|
5
|
+
import { LayoutToggle } from '../../components/table/LayoutToggle';
|
|
6
|
+
import { ColumnTogglePopup } from '../../components/table/ColumnTogglePopup';
|
|
7
|
+
import { Icon } from '../../components/utils/Icon';
|
|
8
|
+
import { FiltersPanel } from './FiltersPanel';
|
|
9
|
+
import { cn } from '../../utils/classNames';
|
|
10
|
+
import { TableToolbarButton, TableToolbarIconButton } from './TableToolbarButton';
|
|
11
|
+
import { translate } from '../../i18n/activeLocale';
|
|
12
|
+
import { SlotCluster } from '../../slots/SlotCluster';
|
|
13
|
+
/**
|
|
14
|
+
* The row of list controls above the table: search + create, filter
|
|
15
|
+
* trigger (dropdown layout), layout switch and column settings.
|
|
16
|
+
*/
|
|
17
|
+
export function TableToolbar({ schema, query, layout, onLayoutChange, visibleColumnNames, onColumnToggle, showCreateButton, onCreateClick, onCreateModalOpen, onHeaderAction, showWidgetsToggle, widgetsExpanded, onWidgetsToggle, }) {
|
|
18
|
+
const [isColumnToggleOpen, setIsColumnToggleOpen] = useState(false);
|
|
19
|
+
const filtersLayout = schema.filtersLayout || 'inline';
|
|
20
|
+
const hasFilters = !!schema.filters && schema.filters.length > 0;
|
|
21
|
+
const headerActions = schema.headerActions || [];
|
|
22
|
+
return (_jsxs("div", { className: "flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-end sm:gap-3", children: [_jsx("div", { className: "w-full min-w-0 sm:flex-1", children: _jsx(TableSearchBar, { searchable: schema.searchable || false, searchQuery: query.searchQuery, onSearchChange: query.handleSearch, onCreateClick: onCreateClick, onCreateModalOpen: onCreateModalOpen, showCreateButton: showCreateButton }) }), _jsxs("div", { className: "flex flex-wrap items-center justify-end gap-1 sm:gap-1.5", children: [_jsx(SlotCluster, { name: "table.toolbar", context: { schema } }), headerActions.map(action => (_jsx(TableToolbarButton, { onClick: () => onHeaderAction?.(action.name), icon: action.icon ? _jsx(Icon, { name: action.icon, size: 16 }) : undefined, children: action.label || action.name }, action.name))), hasFilters && filtersLayout === 'dropdown' && (_jsx(FiltersPanel, { filters: schema.filters, values: query.filters, queryBuilderValues: query.queryBuilders, onChange: query.handleFilterChange, onClear: query.handleClearFilters, layout: "dropdown" })), showWidgetsToggle && onWidgetsToggle && (_jsxs(TableToolbarIconButton, { id: "widgets-toggle", className: cn('relative', widgetsExpanded && 'bg-raised text-accent shadow-soft-sm ring-1 ring-accent/30'), onClick: onWidgetsToggle, "aria-expanded": widgetsExpanded, "aria-pressed": widgetsExpanded, "aria-controls": "widgets-content", title: widgetsExpanded
|
|
23
|
+
? translate('core:table.hide_widgets')
|
|
24
|
+
: translate('core:table.show_widgets'), "aria-label": widgetsExpanded
|
|
25
|
+
? translate('core:table.hide_widgets')
|
|
26
|
+
: translate('core:table.show_widgets'), children: [_jsx(LayoutDashboard, { className: "h-4 w-4" }), widgetsExpanded && (_jsx("span", { className: "absolute right-1 top-1 h-1.5 w-1.5 rounded-full bg-accent ring-2 ring-base", "aria-hidden": true }))] })), schema.allowLayoutSwitch && layout && onLayoutChange && (_jsx(LayoutToggle, { layout: layout, onLayoutChange: onLayoutChange })), schema.showColumnSettings !== false && (_jsxs("div", { className: "relative", children: [_jsx(TableToolbarIconButton, { className: cn(isColumnToggleOpen && 'bg-raised text-fg shadow-soft-sm'), "aria-label": translate('core:table.column_settings'), title: translate('core:table.column_settings'), "aria-expanded": isColumnToggleOpen, onClick: () => setIsColumnToggleOpen(!isColumnToggleOpen), children: _jsx(Columns3Cog, { className: "h-4 w-4" }) }), _jsx(ColumnTogglePopup, { columns: schema.columns, visibleColumnNames: visibleColumnNames, onToggle: onColumnToggle, isOpen: isColumnToggleOpen, onClose: () => setIsColumnToggleOpen(false) })] }))] })] }));
|
|
27
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { PillButton, PillIconButton } from '../../components/ui/PillButton';
|
|
3
|
+
export type TableToolbarButtonProps = React.ComponentProps<typeof PillButton>;
|
|
4
|
+
export type TableToolbarIconButtonProps = React.ComponentProps<typeof PillIconButton>;
|
|
5
|
+
export declare function TableToolbarButton(props: TableToolbarButtonProps): React.JSX.Element;
|
|
6
|
+
export declare function TableToolbarIconButton({ className, ...props }: TableToolbarIconButtonProps): React.JSX.Element;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cn } from '../../utils/classNames';
|
|
3
|
+
import { PillButton, PillIconButton } from '../../components/ui/PillButton';
|
|
4
|
+
export function TableToolbarButton(props) {
|
|
5
|
+
return _jsx(PillButton, { ...props });
|
|
6
|
+
}
|
|
7
|
+
export function TableToolbarIconButton({ className, ...props }) {
|
|
8
|
+
return _jsx(PillIconButton, { className: cn('text-fg-secondary hover:text-fg', className), ...props });
|
|
9
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { TableQueryApi } from '../hooks/useTableQuery';
|
|
3
|
+
export interface TableViewProps {
|
|
4
|
+
query: TableQueryApi;
|
|
5
|
+
/** When true, outer card wrapper is omitted (parent provides the surface). */
|
|
6
|
+
embedded?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The classic table layout: header, rows, loading/empty states.
|
|
10
|
+
* All row state and handlers come from TableContext.
|
|
11
|
+
*/
|
|
12
|
+
export declare function TableView({ query, embedded }: TableViewProps): React.JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { TableHeader } from '../../components/table/TableHeader';
|
|
3
|
+
import { TableRow } from '../../components/table/TableRow';
|
|
4
|
+
import { Spinner } from '../../components/ui/Spinner';
|
|
5
|
+
import { EmptyState } from '../../components/ui/EmptyState';
|
|
6
|
+
import { ErrorAlert } from '../../components/ui/ErrorAlert';
|
|
7
|
+
import { useTableContext } from '../TableContext';
|
|
8
|
+
import { cn } from '../../utils/classNames';
|
|
9
|
+
import { translate } from '../../i18n/activeLocale';
|
|
10
|
+
/**
|
|
11
|
+
* The classic table layout: header, rows, loading/empty states.
|
|
12
|
+
* All row state and handlers come from TableContext.
|
|
13
|
+
*/
|
|
14
|
+
export function TableView({ query, embedded = false }) {
|
|
15
|
+
const { schema, visibleColumns, visibleActions, data, isLoading, error, setError, selectedRows, changedRows, openActionsRowId, onToggleActions, onRowSelect, onSelectAll, onCellChange, onRowAction, onSaveRow, onResetRow, } = useTableContext();
|
|
16
|
+
const colSpan = visibleColumns.length + (schema.bulkActions?.length ? 1 : 0) + 1;
|
|
17
|
+
return (_jsx("div", { className: cn(!embedded && 'overflow-hidden rounded-xl border border-border bg-surface'), children: _jsxs("div", { className: "w-full overflow-x-auto", children: [error ? _jsx(ErrorAlert, { className: "m-4", message: error, onDismiss: () => setError(null) }) : null, _jsxs("table", { className: "w-full min-w-full", style: { tableLayout: 'auto' }, children: [_jsx(TableHeader, { schema: schema, visibleColumns: visibleColumns, sortColumn: query.sortColumn, sortDirection: query.sortDirection, onSort: query.handleSort, selectedRowsCount: selectedRows.size, totalRows: data.length, onSelectAll: onSelectAll }), _jsx("tbody", { children: isLoading ? (_jsx("tr", { children: _jsx("td", { colSpan: colSpan, className: "px-4 py-12 text-center", children: _jsx(Spinner, { label: translate('core:common.loading_ellipsis') }) }) })) : data.length === 0 ? (_jsx("tr", { children: _jsx("td", { colSpan: colSpan, children: _jsx(EmptyState, { title: translate('core:table.no_records'), description: translate('core:table.no_records_hint') }) }) })) : (data.map((row, rowIndex) => {
|
|
18
|
+
const rowId = row.id || row._id || rowIndex;
|
|
19
|
+
return (_jsx(TableRow, { schema: { ...schema, actions: visibleActions }, row: row, rowIndex: rowIndex, totalRows: data.length, rowId: rowId, visibleColumns: visibleColumns, isSelected: selectedRows.has(rowId), hasChanges: changedRows.has(rowId), openActionsRowId: openActionsRowId, onRowSelect: onRowSelect, onCellChange: onCellChange, onRowAction: onRowAction, onSaveRow: onSaveRow, onResetRow: onResetRow, onToggleActions: onToggleActions }, rowId));
|
|
20
|
+
})) })] })] }) }));
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SerializedAction } from '@maxal_studio/kratosjs';
|
|
2
|
+
/**
|
|
3
|
+
* Built-in row actions are derived from the resource capability flags
|
|
4
|
+
* (canView / canEdit / canDelete). The `view` / `edit` / `delete` names are
|
|
5
|
+
* handled by name in useTableActions (delete shows its own confirmation), so
|
|
6
|
+
* these descriptors only carry the label/icon/color used to render the buttons.
|
|
7
|
+
*/
|
|
8
|
+
export declare const BUILT_IN_ACTION_NAMES: string[];
|
|
9
|
+
/**
|
|
10
|
+
* Build the effective row actions for a table: built-in view/edit (from
|
|
11
|
+
* capabilities), then custom actions, then delete last. Any custom action that
|
|
12
|
+
* reuses a built-in name is dropped to avoid duplicates.
|
|
13
|
+
*
|
|
14
|
+
* Built-in labels are translated here (per call, at render time) so they follow
|
|
15
|
+
* the active locale instead of freezing at module load.
|
|
16
|
+
*/
|
|
17
|
+
export declare function buildRowActions(customActions: SerializedAction[] | undefined, caps: {
|
|
18
|
+
canView: boolean;
|
|
19
|
+
canEdit: boolean;
|
|
20
|
+
canDelete: boolean;
|
|
21
|
+
}): SerializedAction[];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { translate } from '../i18n/activeLocale';
|
|
2
|
+
/**
|
|
3
|
+
* Built-in row actions are derived from the resource capability flags
|
|
4
|
+
* (canView / canEdit / canDelete). The `view` / `edit` / `delete` names are
|
|
5
|
+
* handled by name in useTableActions (delete shows its own confirmation), so
|
|
6
|
+
* these descriptors only carry the label/icon/color used to render the buttons.
|
|
7
|
+
*/
|
|
8
|
+
export const BUILT_IN_ACTION_NAMES = ['view', 'edit', 'delete'];
|
|
9
|
+
/**
|
|
10
|
+
* Build the effective row actions for a table: built-in view/edit (from
|
|
11
|
+
* capabilities), then custom actions, then delete last. Any custom action that
|
|
12
|
+
* reuses a built-in name is dropped to avoid duplicates.
|
|
13
|
+
*
|
|
14
|
+
* Built-in labels are translated here (per call, at render time) so they follow
|
|
15
|
+
* the active locale instead of freezing at module load.
|
|
16
|
+
*/
|
|
17
|
+
export function buildRowActions(customActions, caps) {
|
|
18
|
+
const custom = (customActions || []).filter(action => !BUILT_IN_ACTION_NAMES.includes(action.name));
|
|
19
|
+
const result = [];
|
|
20
|
+
if (caps.canView) {
|
|
21
|
+
result.push({ type: 'action', name: 'view', label: translate('core:common.view'), icon: 'Eye' });
|
|
22
|
+
}
|
|
23
|
+
if (caps.canEdit) {
|
|
24
|
+
result.push({ type: 'action', name: 'edit', label: translate('core:common.edit'), icon: 'Pencil' });
|
|
25
|
+
}
|
|
26
|
+
result.push(...custom);
|
|
27
|
+
if (caps.canDelete) {
|
|
28
|
+
result.push({
|
|
29
|
+
type: 'action',
|
|
30
|
+
name: 'delete',
|
|
31
|
+
label: translate('core:common.delete'),
|
|
32
|
+
icon: 'Trash2',
|
|
33
|
+
color: 'text-red-600',
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SerializedColumn } from '@maxal_studio/kratosjs';
|
|
2
|
+
export interface ColumnVisibilityApi {
|
|
3
|
+
/** Names of toggleable columns currently visible */
|
|
4
|
+
visibleColumnNames: Set<string>;
|
|
5
|
+
/** Columns to actually render (respects hidden/toggleable/user prefs) */
|
|
6
|
+
visibleColumns: SerializedColumn[];
|
|
7
|
+
handleColumnToggle: (columnName: string, visible: boolean) => void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* localStorage-backed column visibility, keyed per resource.
|
|
11
|
+
* On first visit, columns flagged toggledHiddenByDefault are persisted as hidden.
|
|
12
|
+
*/
|
|
13
|
+
export declare function useColumnVisibility(columns: SerializedColumn[] | undefined, resourceKey: string): ColumnVisibilityApi;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { columnVisibilityStorage } from '../../utils/columnVisibilityStorage';
|
|
3
|
+
function toggleableOf(columns) {
|
|
4
|
+
return (columns || []).filter(col => col.hidden !== true && col.toggleable !== false);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* localStorage-backed column visibility, keyed per resource.
|
|
8
|
+
* On first visit, columns flagged toggledHiddenByDefault are persisted as hidden.
|
|
9
|
+
*/
|
|
10
|
+
export function useColumnVisibility(columns, resourceKey) {
|
|
11
|
+
const [hiddenColumns, setHiddenColumns] = useState(() => {
|
|
12
|
+
const stored = columnVisibilityStorage.getHiddenColumns(resourceKey);
|
|
13
|
+
if (stored !== null) {
|
|
14
|
+
return stored;
|
|
15
|
+
}
|
|
16
|
+
// First visit: apply schema defaults
|
|
17
|
+
return toggleableOf(columns)
|
|
18
|
+
.filter(col => col.toggledHiddenByDefault === true)
|
|
19
|
+
.map(col => col.name);
|
|
20
|
+
});
|
|
21
|
+
// Persist defaults on first visit, and re-sync when the resource changes
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!columns || columns.length === 0)
|
|
24
|
+
return;
|
|
25
|
+
const stored = columnVisibilityStorage.getHiddenColumns(resourceKey);
|
|
26
|
+
if (stored === null) {
|
|
27
|
+
const defaults = toggleableOf(columns)
|
|
28
|
+
.filter(col => col.toggledHiddenByDefault === true)
|
|
29
|
+
.map(col => col.name);
|
|
30
|
+
columnVisibilityStorage.setHiddenColumns(resourceKey, defaults);
|
|
31
|
+
setHiddenColumns(defaults);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
setHiddenColumns(stored);
|
|
35
|
+
}
|
|
36
|
+
}, [columns, resourceKey]);
|
|
37
|
+
const visibleColumnNames = useMemo(() => {
|
|
38
|
+
const visible = new Set(toggleableOf(columns).map(col => col.name));
|
|
39
|
+
hiddenColumns.forEach(name => visible.delete(name));
|
|
40
|
+
return visible;
|
|
41
|
+
}, [columns, hiddenColumns]);
|
|
42
|
+
const visibleColumns = useMemo(() => {
|
|
43
|
+
return (columns || []).filter(col => {
|
|
44
|
+
if (col.hidden)
|
|
45
|
+
return false;
|
|
46
|
+
if (col.toggleable === false)
|
|
47
|
+
return true;
|
|
48
|
+
return visibleColumnNames.has(col.name);
|
|
49
|
+
});
|
|
50
|
+
}, [columns, visibleColumnNames]);
|
|
51
|
+
const handleColumnToggle = (columnName, visible) => {
|
|
52
|
+
setHiddenColumns(prev => {
|
|
53
|
+
const next = visible ? prev.filter(name => name !== columnName) : [...new Set([...prev, columnName])];
|
|
54
|
+
columnVisibilityStorage.setHiddenColumns(resourceKey, next);
|
|
55
|
+
return next;
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
return { visibleColumnNames, visibleColumns, handleColumnToggle };
|
|
59
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface EditableRowsApi {
|
|
3
|
+
changedRows: Map<any, any>;
|
|
4
|
+
handleCellChange: (rowId: any, columnName: string, newValue: any) => void;
|
|
5
|
+
handleSaveRow: (rowId: any) => Promise<void>;
|
|
6
|
+
handleResetRow: (rowId: any) => void;
|
|
7
|
+
/** Reset change tracking after a (re)load */
|
|
8
|
+
resetTracking: (rows: any[]) => void;
|
|
9
|
+
}
|
|
10
|
+
export interface UseEditableRowsOptions {
|
|
11
|
+
data: any[];
|
|
12
|
+
setData: React.Dispatch<React.SetStateAction<any[]>>;
|
|
13
|
+
/** Persists the changed cells of one row */
|
|
14
|
+
saveRecord: (rowId: any, changes: any) => Promise<void>;
|
|
15
|
+
/** Notified when a save fails (e.g. show a toast) */
|
|
16
|
+
onSaveError?: (error: Error) => void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Change tracking for inline-editable columns: per-row dirty state,
|
|
20
|
+
* optimistic cell updates, save and reset.
|
|
21
|
+
*/
|
|
22
|
+
export declare function useEditableRows({ data, setData, saveRecord, onSaveError }: UseEditableRowsOptions): EditableRowsApi;
|