@rebasepro/cms 0.28.2 → 0.29.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 +3 -3
- package/dist/collection_editor/_cms_internals.d.ts +0 -1
- package/dist/collection_editor/ui/EditorCollectionAction.d.ts +2 -2
- package/dist/collection_editor/ui/EditorCollectionAction.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportDataPreview.js +2 -2
- package/dist/collection_editor/ui/collection_editor/import/CollectionEditorImportDataPreview.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/MarkdownPropertyField.js +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/MarkdownPropertyField.js.map +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/StoragePropertyField.js +1 -1
- package/dist/collection_editor/ui/collection_editor/properties/StoragePropertyField.js.map +1 -1
- package/dist/components/AdditionalFieldValue.d.ts +9 -3
- package/dist/components/AdditionalFieldValue.js +7 -4
- package/dist/components/AdditionalFieldValue.js.map +1 -1
- package/dist/components/CollectionPanel.d.ts +117 -18
- package/dist/components/CollectionPanel.js +115 -37
- package/dist/components/CollectionPanel.js.map +1 -1
- package/dist/components/CollectionTableBinding/CollectionRowActions.d.ts +5 -5
- package/dist/components/CollectionTableBinding/CollectionRowActions.js +16 -12
- package/dist/components/CollectionTableBinding/CollectionRowActions.js.map +1 -1
- package/dist/components/CollectionTableBinding/CollectionTableBinding.js +33 -8
- package/dist/components/CollectionTableBinding/CollectionTableBinding.js.map +1 -1
- package/dist/components/CollectionTableBinding/CollectionTableBindingProps.d.ts +8 -3
- package/dist/components/CollectionTableBinding/PropertyTableCell.js +2 -2
- package/dist/components/CollectionTableBinding/PropertyTableCell.js.map +1 -1
- package/dist/components/CollectionTableBinding/column_utils.d.ts +9 -1
- package/dist/components/CollectionTableBinding/column_utils.js +6 -3
- package/dist/components/CollectionTableBinding/column_utils.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.js +2 -2
- package/dist/components/CollectionTableBinding/fields/TableMultipleRelationField.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableReferenceField.js +2 -2
- package/dist/components/CollectionTableBinding/fields/TableReferenceField.js.map +1 -1
- package/dist/components/CollectionTableBinding/fields/TableRelationField.js +2 -2
- package/dist/components/CollectionTableBinding/fields/TableRelationField.js.map +1 -1
- package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.d.ts +3 -2
- package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.js +9 -7
- package/dist/components/CollectionTableBinding/internal/CollectionTableToolbar.js.map +1 -1
- package/dist/components/CollectionTableBinding/internal/common.d.ts +26 -2
- package/dist/components/CollectionTableBinding/internal/common.js +88 -4
- package/dist/components/CollectionTableBinding/internal/common.js.map +1 -1
- package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.js +4 -3
- package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.js.map +1 -1
- package/dist/components/CollectionViewBinding/BoardCardBinding.d.ts +7 -1
- package/dist/components/CollectionViewBinding/BoardCardBinding.js +19 -14
- package/dist/components/CollectionViewBinding/BoardCardBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionAddButton.d.ts +28 -0
- package/dist/components/CollectionViewBinding/CollectionAddButton.js +50 -0
- package/dist/components/CollectionViewBinding/CollectionAddButton.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.d.ts +11 -3
- package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.js +9 -4
- package/dist/components/CollectionViewBinding/CollectionBoardViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionCardViewBinding.d.ts +5 -3
- package/dist/components/CollectionViewBinding/CollectionCardViewBinding.js +5 -3
- package/dist/components/CollectionViewBinding/CollectionCardViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionEntityActions.d.ts +29 -0
- package/dist/components/CollectionViewBinding/CollectionEntityActions.js +112 -0
- package/dist/components/CollectionViewBinding/CollectionEntityActions.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionListViewBinding.d.ts +2 -2
- package/dist/components/CollectionViewBinding/CollectionListViewBinding.js +58 -16
- package/dist/components/CollectionViewBinding/CollectionListViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionToolbar.d.ts +57 -0
- package/dist/components/CollectionViewBinding/CollectionToolbar.js +146 -0
- package/dist/components/CollectionViewBinding/CollectionToolbar.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionViewActions.d.ts +2 -2
- package/dist/components/CollectionViewBinding/CollectionViewActions.js +22 -26
- package/dist/components/CollectionViewBinding/CollectionViewActions.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewBinding.d.ts +58 -22
- package/dist/components/CollectionViewBinding/CollectionViewBinding.js +81 -1089
- package/dist/components/CollectionViewBinding/CollectionViewBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/CollectionViewContent.d.ts +9 -0
- package/dist/components/CollectionViewBinding/CollectionViewContent.js +152 -0
- package/dist/components/CollectionViewBinding/CollectionViewContent.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionViewDialogs.d.ts +9 -0
- package/dist/components/CollectionViewBinding/CollectionViewDialogs.js +38 -0
- package/dist/components/CollectionViewBinding/CollectionViewDialogs.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionViewFrame.d.ts +13 -0
- package/dist/components/CollectionViewBinding/CollectionViewFrame.js +32 -0
- package/dist/components/CollectionViewBinding/CollectionViewFrame.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionViewScope.d.ts +14 -0
- package/dist/components/CollectionViewBinding/CollectionViewScope.js +22 -0
- package/dist/components/CollectionViewBinding/CollectionViewScope.js.map +1 -0
- package/dist/components/CollectionViewBinding/CollectionViewStartActions.d.ts +2 -2
- package/dist/components/CollectionViewBinding/CollectionViewStartActions.js +39 -67
- package/dist/components/CollectionViewBinding/CollectionViewStartActions.js.map +1 -1
- package/dist/components/CollectionViewBinding/CustomViewHost.d.ts +28 -0
- package/dist/components/CollectionViewBinding/CustomViewHost.js +54 -0
- package/dist/components/CollectionViewBinding/CustomViewHost.js.map +1 -0
- package/dist/components/CollectionViewBinding/EntitiesCount.d.ts +24 -0
- package/dist/components/CollectionViewBinding/EntitiesCount.js +69 -0
- package/dist/components/CollectionViewBinding/EntitiesCount.js.map +1 -0
- package/dist/components/CollectionViewBinding/EntityCardBinding.d.ts +7 -1
- package/dist/components/CollectionViewBinding/EntityCardBinding.js +34 -23
- package/dist/components/CollectionViewBinding/EntityCardBinding.js.map +1 -1
- package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.d.ts +17 -0
- package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.js +107 -0
- package/dist/components/CollectionViewBinding/EntityIdHeaderWidget.js.map +1 -0
- package/dist/components/CollectionViewBinding/FiltersButton.d.ts +15 -0
- package/dist/components/CollectionViewBinding/FiltersButton.js +49 -0
- package/dist/components/CollectionViewBinding/FiltersButton.js.map +1 -0
- package/dist/components/CollectionViewBinding/PluginColumnSlots.d.ts +35 -0
- package/dist/components/CollectionViewBinding/PluginColumnSlots.js +45 -0
- package/dist/components/CollectionViewBinding/PluginColumnSlots.js.map +1 -0
- package/dist/components/CollectionViewBinding/RowActions.d.ts +40 -0
- package/dist/components/CollectionViewBinding/RowActions.js +60 -0
- package/dist/components/CollectionViewBinding/RowActions.js.map +1 -0
- package/dist/components/CollectionViewBinding/SplitListView.d.ts +7 -4
- package/dist/components/CollectionViewBinding/SplitListView.js +20 -21
- package/dist/components/CollectionViewBinding/SplitListView.js.map +1 -1
- package/dist/components/CollectionViewBinding/builtin_action_props.d.ts +13 -0
- package/dist/components/CollectionViewBinding/fields.d.ts +22 -0
- package/dist/components/CollectionViewBinding/fields.js +47 -0
- package/dist/components/CollectionViewBinding/fields.js.map +1 -0
- package/dist/components/CollectionViewBinding/useBoardDataController.js +6 -7
- package/dist/components/CollectionViewBinding/useBoardDataController.js.map +1 -1
- package/dist/components/CollectionViewBinding/useCollectionLargeLayout.d.ts +19 -0
- package/dist/components/CollectionViewBinding/useCollectionLargeLayout.js +28 -0
- package/dist/components/CollectionViewBinding/useCollectionLargeLayout.js.map +1 -0
- package/dist/components/CollectionViewBinding/useCollectionViewState.d.ts +125 -0
- package/dist/components/CollectionViewBinding/useCollectionViewState.js +844 -0
- package/dist/components/CollectionViewBinding/useCollectionViewState.js.map +1 -0
- package/dist/components/CollectionViewBinding/usePreviewSlots.d.ts +20 -0
- package/dist/components/CollectionViewBinding/usePreviewSlots.js +23 -2
- package/dist/components/CollectionViewBinding/usePreviewSlots.js.map +1 -1
- package/dist/components/CollectionViewBinding/useSelectionController.d.ts +21 -3
- package/dist/components/CollectionViewBinding/useSelectionController.js +37 -6
- package/dist/components/CollectionViewBinding/useSelectionController.js.map +1 -1
- package/dist/components/CollectionsProvider.d.ts +3 -3
- package/dist/components/CollectionsProvider.js +4 -4
- package/dist/components/CollectionsProvider.js.map +1 -1
- package/dist/components/CollectionsScopeContext.d.ts +1 -1
- package/dist/components/CollectionsScopeContext.js +1 -1
- package/dist/components/CollectionsScopeContext.js.map +1 -1
- package/dist/components/DeleteEntityDialog.d.ts +1 -1
- package/dist/components/DeleteEntityDialog.js +2 -2
- package/dist/components/DeleteEntityDialog.js.map +1 -1
- package/dist/components/DetailViewBinding.js +32 -68
- package/dist/components/DetailViewBinding.js.map +1 -1
- package/dist/components/EditFormActions.js +5 -4
- package/dist/components/EditFormActions.js.map +1 -1
- package/dist/components/EditViewBinding.d.ts +2 -2
- package/dist/components/EditViewBinding.js +25 -15
- package/dist/components/EditViewBinding.js.map +1 -1
- package/dist/components/EntityDisplayHeader.js +8 -5
- package/dist/components/EntityDisplayHeader.js.map +1 -1
- package/dist/components/EntityPreviewBinding.js +1 -1
- package/dist/components/EntityPreviewBinding.js.map +1 -1
- package/dist/components/EntityViewBinding.d.ts +8 -1
- package/dist/components/EntityViewBinding.js +43 -14
- package/dist/components/EntityViewBinding.js.map +1 -1
- package/dist/components/EntityViewBody.d.ts +40 -0
- package/dist/components/EntityViewBody.js +90 -0
- package/dist/components/EntityViewBody.js.map +1 -0
- package/dist/components/FieldValue.d.ts +50 -0
- package/dist/components/FieldValue.js +81 -0
- package/dist/components/FieldValue.js.map +1 -0
- package/dist/components/InlineEntityPreview.js +1 -1
- package/dist/components/InlineEntityPreview.js.map +1 -1
- package/dist/components/PanelNotFound.d.ts +5 -0
- package/dist/components/PanelNotFound.js +21 -0
- package/dist/components/PanelNotFound.js.map +1 -0
- package/dist/components/RebaseCMS.d.ts +1 -1
- package/dist/components/RebaseCMS.js +11 -3
- package/dist/components/RebaseCMS.js.map +1 -1
- package/dist/components/RebaseNavigation.js +9 -3
- package/dist/components/RebaseNavigation.js.map +1 -1
- package/dist/components/RebaseShell.js +10 -5
- package/dist/components/RebaseShell.js.map +1 -1
- package/dist/components/RecordDetail.d.ts +61 -0
- package/dist/components/RecordDetail.js +123 -0
- package/dist/components/RecordDetail.js.map +1 -0
- package/dist/components/RecordForm.d.ts +126 -0
- package/dist/components/{EntityFormPanel.js → RecordForm.js} +64 -36
- package/dist/components/RecordForm.js.map +1 -0
- package/dist/components/ReferenceTable/SelectionTableBinding.d.ts +47 -17
- package/dist/components/ReferenceTable/SelectionTableBinding.js +89 -53
- package/dist/components/ReferenceTable/SelectionTableBinding.js.map +1 -1
- package/dist/components/ReferenceWidget.d.ts +5 -3
- package/dist/components/ReferenceWidget.js +10 -7
- package/dist/components/ReferenceWidget.js.map +1 -1
- package/dist/components/RelationSelector.js +4 -4
- package/dist/components/RelationSelector.js.map +1 -1
- package/dist/components/SelectableTable/SelectableTable.js +2 -3
- package/dist/components/SelectableTable/SelectableTable.js.map +1 -1
- package/dist/components/SelectableTable/SelectionStore.d.ts +1 -1
- package/dist/components/SelectableTable/SelectionStore.js +1 -1
- package/dist/components/SelectableTable/SelectionStore.js.map +1 -1
- package/dist/components/SelectableTable/filters/ReferenceFilterField.js +2 -2
- package/dist/components/SelectableTable/filters/ReferenceFilterField.js.map +1 -1
- package/dist/components/SidePanelBinding.js +13 -12
- package/dist/components/SidePanelBinding.js.map +1 -1
- package/dist/components/collection_prop.d.ts +18 -0
- package/dist/components/collection_prop.js +23 -0
- package/dist/components/collection_prop.js.map +1 -0
- package/dist/components/common/default_entity_actions.js +54 -54
- package/dist/components/common/default_entity_actions.js.map +1 -1
- package/dist/components/history/EntityHistoryView.d.ts +4 -1
- package/dist/components/history/EntityHistoryView.js +1 -1
- package/dist/components/history/EntityHistoryView.js.map +1 -1
- package/dist/components/history/LastEditedByFormAction.d.ts +1 -1
- package/dist/components/index.d.ts +4 -2
- package/dist/data_export/export/ExportCollectionAction.d.ts +3 -2
- package/dist/data_export/export/ExportCollectionAction.js +4 -3
- package/dist/data_export/export/ExportCollectionAction.js.map +1 -1
- package/dist/data_export/export/additional_fields.d.ts +6 -3
- package/dist/data_export/export/additional_fields.js +8 -4
- package/dist/data_export/export/additional_fields.js.map +1 -1
- package/dist/data_import/import/ImportCollectionAction.js +2 -2
- package/dist/data_import/import/ImportCollectionAction.js.map +1 -1
- package/dist/form/EntityForm.d.ts +1 -1
- package/dist/form/EntityForm.js +255 -150
- package/dist/form/EntityForm.js.map +1 -1
- package/dist/form/EntityFormActions.js +3 -2
- package/dist/form/EntityFormActions.js.map +1 -1
- package/dist/form/EntityFormBinding.d.ts +1 -1
- package/dist/form/EntityFormBinding.js +22 -11
- package/dist/form/EntityFormBinding.js.map +1 -1
- package/dist/form/FormField.d.ts +36 -0
- package/dist/form/FormField.js +41 -0
- package/dist/form/FormField.js.map +1 -0
- package/dist/form/FormFieldsContext.d.ts +69 -0
- package/dist/form/FormFieldsContext.js +143 -0
- package/dist/form/FormFieldsContext.js.map +1 -0
- package/dist/form/PropertyFieldBinding.js +4 -4
- package/dist/form/PropertyFieldBinding.js.map +1 -1
- package/dist/form/collection_showing.d.ts +8 -0
- package/dist/form/collection_showing.js +29 -0
- package/dist/form/collection_showing.js.map +1 -0
- package/dist/form/components/ErrorFocus.js +2 -1
- package/dist/form/components/ErrorFocus.js.map +1 -1
- package/dist/form/components/FieldBlock.js +3 -1
- package/dist/form/components/FieldBlock.js.map +1 -1
- package/dist/form/components/FormRail.d.ts +5 -1
- package/dist/form/components/FormRail.js +5 -1
- package/dist/form/components/FormRail.js.map +1 -1
- package/dist/form/components/FormSections.d.ts +5 -1
- package/dist/form/components/FormSections.js +11 -4
- package/dist/form/components/FormSections.js.map +1 -1
- package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.js +2 -2
- package/dist/form/field_bindings/ArrayOfReferencesFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/MarkdownEditorFieldBinding.js +1 -1
- package/dist/form/field_bindings/MarkdownEditorFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/MultipleRelationFieldBinding.js +2 -2
- package/dist/form/field_bindings/MultipleRelationFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/ReadOnlyFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/ReferenceFieldBinding.js +2 -2
- package/dist/form/field_bindings/ReferenceFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/RelationFieldBinding.js +2 -2
- package/dist/form/field_bindings/RelationFieldBinding.js.map +1 -1
- package/dist/form/field_bindings/StorageUploadFieldBinding.js +1 -1
- package/dist/form/field_bindings/StorageUploadFieldBinding.js.map +1 -1
- package/dist/form/form_dom_ids.d.ts +25 -0
- package/dist/form/form_dom_ids.js +42 -0
- package/dist/form/form_dom_ids.js.map +1 -0
- package/dist/form/index.d.ts +3 -1
- package/dist/form/resolve_cell_property.d.ts +5 -0
- package/dist/form/resolve_cell_property.js +22 -1
- package/dist/form/resolve_cell_property.js.map +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/navigation/useBuildNavigationStateController.d.ts +2 -2
- package/dist/hooks/navigation/useBuildNavigationStateController.js.map +1 -1
- package/dist/hooks/navigation/useNavigationResolution.d.ts +3 -3
- package/dist/hooks/navigation/useNavigationResolution.js.map +1 -1
- package/dist/hooks/navigation/useResolvedCollections.d.ts +2 -2
- package/dist/hooks/navigation/useResolvedCollections.js.map +1 -1
- package/dist/hooks/navigation/useResolvedViews.d.ts +2 -2
- package/dist/hooks/navigation/useResolvedViews.js.map +1 -1
- package/dist/hooks/useBuildSidePanel.js +9 -9
- package/dist/hooks/useBuildSidePanel.js.map +1 -1
- package/dist/hooks/useEntityDisplay.js +6 -4
- package/dist/hooks/useEntityDisplay.js.map +1 -1
- package/dist/hooks/useRecordActions.js +2 -2
- package/dist/hooks/useRecordActions.js.map +1 -1
- package/dist/hooks/useSelectionDialog.d.ts +20 -7
- package/dist/hooks/useSelectionDialog.js +29 -8
- package/dist/hooks/useSelectionDialog.js.map +1 -1
- package/dist/index.d.ts +8 -3
- package/dist/index.js +15 -9
- package/dist/mcp-view.d.ts +9 -0
- package/dist/mcp-view.js +2 -0
- package/dist/mcp_view/app_modules.d.ts +29 -0
- package/dist/mcp_view/app_modules.js +163 -0
- package/dist/mcp_view/app_modules.js.map +1 -0
- package/dist/mcp_view/bridge.d.ts +90 -0
- package/dist/mcp_view/bridge.js +205 -0
- package/dist/mcp_view/bridge.js.map +1 -0
- package/dist/mcp_view/code_app.d.ts +65 -0
- package/dist/mcp_view/code_app.js +139 -0
- package/dist/mcp_view/code_app.js.map +1 -0
- package/dist/mcp_view/index.d.ts +54 -0
- package/dist/mcp_view/index.js +262 -0
- package/dist/mcp_view/index.js.map +1 -0
- package/dist/mcp_view/payload.d.ts +78 -0
- package/dist/mcp_view/payload.js +155 -0
- package/dist/mcp_view/payload.js.map +1 -0
- package/dist/mcp_view/screen.d.ts +30 -0
- package/dist/mcp_view/screen.js +245 -0
- package/dist/mcp_view/screen.js.map +1 -0
- package/dist/mcp_view/storage_source.d.ts +14 -0
- package/dist/mcp_view/storage_source.js +29 -0
- package/dist/mcp_view/storage_source.js.map +1 -0
- package/dist/mcp_view/store.d.ts +9 -0
- package/dist/mcp_view/store.js +27 -0
- package/dist/mcp_view/store.js.map +1 -0
- package/dist/mcp_view/tool_driver.d.ts +160 -0
- package/dist/mcp_view/tool_driver.js +575 -0
- package/dist/mcp_view/tool_driver.js.map +1 -0
- package/dist/preview/components/DatePreview.d.ts +34 -1
- package/dist/preview/components/DatePreview.js +72 -37
- package/dist/preview/components/DatePreview.js.map +1 -1
- package/dist/routes/RebaseRoute.js +1 -1
- package/dist/routes/RebaseRoute.js.map +1 -1
- package/dist/selection/SelectionMenu.d.ts +5 -3
- package/dist/selection/SelectionMenu.js +16 -9
- package/dist/selection/SelectionMenu.js.map +1 -1
- package/dist/selection/index.d.ts +2 -1
- package/dist/selection/resolve_selection.d.ts +61 -7
- package/dist/selection/resolve_selection.js +93 -11
- package/dist/selection/resolve_selection.js.map +1 -1
- package/dist/types/components/EntityFormProps.d.ts +60 -10
- package/dist/types/fields.d.ts +2 -65
- package/dist/util/dataControllerAdapter.d.ts +8 -0
- package/dist/util/dataControllerAdapter.js +11 -0
- package/dist/util/dataControllerAdapter.js.map +1 -1
- package/dist/util/navigation_utils.d.ts +5 -4
- package/dist/util/navigation_utils.js +6 -6
- package/dist/util/navigation_utils.js.map +1 -1
- package/dist/util/propertyConfigMapper.d.ts +8 -0
- package/dist/util/propertyConfigMapper.js +16 -2
- package/dist/util/propertyConfigMapper.js.map +1 -1
- package/package.json +15 -9
- package/recipes/README.md +79 -26
- package/recipes/approval-queue.tsx +79 -0
- package/recipes/bulk-set-status.tsx +23 -17
- package/recipes/calendar-view.tsx +28 -23
- package/recipes/master-detail.tsx +75 -0
- package/recipes/my-preferences.tsx +3 -3
- package/recipes/orders-dashboard.tsx +58 -84
- package/recipes/site-settings.tsx +4 -4
- package/dist/components/EntityFormPanel.d.ts +0 -63
- package/dist/components/EntityFormPanel.js.map +0 -1
|
@@ -34,7 +34,7 @@ var NO_VIEWS = [];
|
|
|
34
34
|
* path; a data router is not required. No CMS route serves the page, so a
|
|
35
35
|
* record opens in a side panel or a dialog over it, never by URL.
|
|
36
36
|
*
|
|
37
|
-
* `CollectionPanel` and `
|
|
37
|
+
* `CollectionPanel` and `RecordForm` given a `collection` bring one of
|
|
38
38
|
* these themselves when none is above; mount it yourself to share one between
|
|
39
39
|
* several of them, or to use the lower-level pieces (`CollectionViewBinding`,
|
|
40
40
|
* `useSidePanel`) directly.
|
|
@@ -44,8 +44,8 @@ var NO_VIEWS = [];
|
|
|
44
44
|
* <Rebase client={client} authController={authController}>
|
|
45
45
|
* <BrowserRouter>
|
|
46
46
|
* <CollectionsProvider collections={[postsCollection, authorsCollection]}>
|
|
47
|
-
* <CollectionPanel
|
|
48
|
-
* <CollectionPanel
|
|
47
|
+
* <CollectionPanel collection="posts"/>
|
|
48
|
+
* <CollectionPanel collection="authors"/>
|
|
49
49
|
* </CollectionsProvider>
|
|
50
50
|
* </BrowserRouter>
|
|
51
51
|
* </Rebase>
|
|
@@ -106,7 +106,7 @@ function CollectionsProvider({ collections, children }) {
|
|
|
106
106
|
collections: resolvedCollections,
|
|
107
107
|
views: NO_VIEWS,
|
|
108
108
|
authController: context.authController,
|
|
109
|
-
data:
|
|
109
|
+
data: context.data,
|
|
110
110
|
collectionRegistryController,
|
|
111
111
|
urlController,
|
|
112
112
|
adminMode: adminModeController?.mode
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CollectionsProvider.js","names":[],"sources":["../../src/components/CollectionsProvider.tsx"],"sourcesContent":["import React, { useCallback, useContext, useEffect, useId, useMemo, useRef } from \"react\";\nimport {\n CollectionResolverRegistrationContext,\n RebaseDataContext,\n StudioBridgeRegistryContext,\n useAdminModeController,\n useCustomizationController,\n useData,\n useDataSources,\n useRebaseContext,\n useUserConfigurationPersistence\n} from \"@rebasepro/app\";\nimport { buildRoutedRebaseData, CollectionRegistry, resolveDataSource } from \"@rebasepro/common\";\nimport { resolveAdminCollection } from \"@rebasepro/cms-types\";\nimport type { AdminCollection, AppView, RebasePlugin, UrlController } from \"@rebasepro/cms-types\";\n\nimport { useBuildCollectionRegistryController } from \"../hooks/navigation/useBuildCollectionRegistryController\";\nimport { useBuildUrlController } from \"../hooks/navigation/useBuildUrlController\";\nimport { useBuildNavigationStateController } from \"../hooks/navigation/useBuildNavigationStateController\";\nimport { CollectionRegistryContext } from \"../hooks/navigation/contexts/CollectionRegistryContext\";\nimport { UrlContext } from \"../hooks/navigation/contexts/UrlContext\";\nimport { NavigationStateContext } from \"../hooks/navigation/contexts/NavigationStateContext\";\nimport { SidePanelProvider } from \"./SidePanelProvider\";\nimport { SideDialogs } from \"./SideDialogs\";\nimport { CollectionsScopeContext } from \"./CollectionsScopeContext\";\n\nconst EMPTY_PLUGINS: RebasePlugin[] = [];\n\n/**\n * Whether `path` starts with a collection this registry holds — the longest\n * leading run of whole segments, since a slug may contain slashes.\n */\nfunction holdsLeadingCollection(registry: CollectionRegistry, path: string): boolean {\n const segments = path.split(\"/\").filter(Boolean);\n for (let length = segments.length; length > 0; length--) {\n if (registry.get(segments.slice(0, length).join(\"/\"))) return true;\n }\n return false;\n}\nconst NO_VIEWS: AppView[] = [];\n\n/**\n * @group Components\n */\nexport interface CollectionsProviderProps {\n /**\n * The collections this scope can show and edit — `defineCollection`\n * configs or resolved collections. Keep the array stable (a module\n * constant, or `useMemo`): a new array is a new set of collections.\n */\n collections: AdminCollection[];\n children: React.ReactNode;\n}\n\n/**\n * Everything a collection view or a record form needs to work in a page of\n * your own app, without `<RebaseCMS>`, `<RebaseNavigation>` or\n * `<RebaseShell>`: a registry of the collections you hand it, the record side\n * panel and dialogs (rendered here), and the navigation guard.\n *\n * It needs `<Rebase>` above it and a React Router router — any router, at any\n * path; a data router is not required. No CMS route serves the page, so a\n * record opens in a side panel or a dialog over it, never by URL.\n *\n * `CollectionPanel` and `EntityFormPanel` given a `collection` bring one of\n * these themselves when none is above; mount it yourself to share one between\n * several of them, or to use the lower-level pieces (`CollectionViewBinding`,\n * `useSidePanel`) directly.\n *\n * @example\n * ```tsx\n * <Rebase client={client} authController={authController}>\n * <BrowserRouter>\n * <CollectionsProvider collections={[postsCollection, authorsCollection]}>\n * <CollectionPanel path=\"posts\"/>\n * <CollectionPanel path=\"authors\"/>\n * </CollectionsProvider>\n * </BrowserRouter>\n * </Rebase>\n * ```\n *\n * @group Components\n */\nexport function CollectionsProvider({ collections, children }: CollectionsProviderProps) {\n const context = useRebaseContext();\n const adminModeController = useAdminModeController();\n const userConfigPersistence = useUserConfigurationPersistence();\n const customizationController = useCustomizationController();\n const dataSources = useDataSources();\n const collectionRegistryController = useBuildCollectionRegistryController({ userConfigPersistence, dataSources: dataSources.registry });\n\n // The data layer gives a row its address from its collection's primary\n // key, and these collections are known only here. Registered under this\n // scope's own owner, so several scopes on one page — and the full CMS\n // beside them — do not overwrite each other. During render for the reason\n // `RebaseNavigation` gives (the views that fetch rows are below), and again\n // on mount, since a strict-mode remount runs the cleanup in between.\n const registerCollectionResolver = useContext(CollectionResolverRegistrationContext);\n const owner = useId();\n const getCollectionRef = useRef(collectionRegistryController.getCollection);\n getCollectionRef.current = collectionRegistryController.getCollection;\n const registryRef = collectionRegistryController.collectionRegistryRef;\n // Asked about every collection any owner has, so a path this scope does\n // not hold is answered quietly rather than by the registry's warning.\n const resolveCollection = useCallback((slug: string) =>\n holdsLeadingCollection(registryRef.current, slug) ? getCollectionRef.current(slug) : undefined, [registryRef]);\n const resolveDataPath = collectionRegistryController.resolveDataPath;\n registerCollectionResolver(resolveCollection, resolveDataPath, owner);\n useEffect(() => {\n registerCollectionResolver(resolveCollection, resolveDataPath, owner);\n return () => registerCollectionResolver(undefined, undefined, owner);\n }, [registerCollectionResolver, resolveCollection, resolveDataPath, owner]);\n\n // Each collection routed to the data source it declares, as in the CMS.\n const defaultData = useData();\n const routedData = useMemo(() => buildRoutedRebaseData({\n defaultData,\n sources: dataSources.sources,\n resolveKey: (slugOrPath) => resolveDataSource(resolveCollection(slugOrPath), dataSources.registry).key\n }), [defaultData, dataSources, resolveCollection]);\n\n // Paths are still built — a panel keys its records by them — but nothing\n // navigates to one, and no URL is read as a record to open.\n const builtUrlController = useBuildUrlController({\n basePath: \"/\",\n baseCollectionPath: \"/c\",\n collectionRegistryController\n });\n const urlController = useMemo<UrlController>(() => ({\n ...builtUrlController,\n isUrlCollectionPath: () => false,\n routesMounted: false\n }), [builtUrlController]);\n\n const resolvedCollections = useMemo(() => collections.map(collection => resolveAdminCollection(collection)), [collections]);\n const navigationStateController = useBuildNavigationStateController({\n plugins: customizationController.plugins ?? EMPTY_PLUGINS,\n collections: resolvedCollections,\n views: NO_VIEWS,\n authController: context.authController!,\n data: routedData,\n collectionRegistryController,\n urlController,\n adminMode: adminModeController?.mode\n });\n\n // The Studio bridge describes the CMS's own controllers. A scope embedded\n // in the shell must not replace them there, so its registrations go nowhere.\n return (\n <CollectionsScopeContext.Provider value={true}>\n <StudioBridgeRegistryContext.Provider value={null}>\n <RebaseDataContext.Provider value={routedData}>\n <CollectionRegistryContext.Provider value={collectionRegistryController}>\n <UrlContext.Provider value={urlController}>\n <NavigationStateContext.Provider value={navigationStateController}>\n <SidePanelProvider>\n {children}\n <SideDialogs/>\n </SidePanelProvider>\n </NavigationStateContext.Provider>\n </UrlContext.Provider>\n </CollectionRegistryContext.Provider>\n </RebaseDataContext.Provider>\n </StudioBridgeRegistryContext.Provider>\n </CollectionsScopeContext.Provider>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AA0BA,IAAM,gBAAgC,CAAC;;;;;AAMvC,SAAS,uBAAuB,UAA8B,MAAuB;CACjF,MAAM,WAAW,KAAK,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO;CAC/C,KAAK,IAAI,SAAS,SAAS,QAAQ,SAAS,GAAG,UAC3C,IAAI,SAAS,IAAI,SAAS,MAAM,GAAG,MAAM,CAAC,CAAC,KAAK,GAAG,CAAC,GAAG,OAAO;CAElE,OAAO;AACX;AACA,IAAM,WAAsB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4C7B,SAAgB,oBAAoB,EAAE,aAAa,YAAsC;CACrF,MAAM,UAAU,iBA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;EACP,gBAAgB,QAAQ;EACxB,MAAM;EACN;EACA;EACA,WAAW,qBAAqB;CACpC,CAAC;CAID,OACI,oBAAC,wBAAwB,UAAzB;EAAkC,OAAO;YACrC,oBAAC,4BAA4B,UAA7B;GAAsC,OAAO;aACzC,oBAAC,kBAAkB,UAAnB;IAA4B,OAAO;cAC/B,oBAAC,0BAA0B,UAA3B;KAAoC,OAAO;eACvC,oBAAC,WAAW,UAAZ;MAAqB,OAAO;gBACxB,oBAAC,uBAAuB,UAAxB;OAAiC,OAAO;iBACpC,qBAAC,mBAAD,EAAA,UAAA,CACK,UACD,oBAAC,aAAD,CAAa,CAAA,CACE,EAAA,CAAA;MACU,CAAA;KAChB,CAAA;IACW,CAAA;GACZ,CAAA;EACM,CAAA;CACR,CAAA;AAE1C"}
|
|
1
|
+
{"version":3,"file":"CollectionsProvider.js","names":[],"sources":["../../src/components/CollectionsProvider.tsx"],"sourcesContent":["import React, { useCallback, useContext, useEffect, useId, useMemo, useRef } from \"react\";\nimport {\n CollectionResolverRegistrationContext,\n RebaseDataContext,\n StudioBridgeRegistryContext,\n useAdminModeController,\n useCustomizationController,\n useData,\n useDataSources,\n useRebaseContext,\n useUserConfigurationPersistence\n} from \"@rebasepro/app\";\nimport { buildRoutedRebaseData, CollectionRegistry, resolveDataSource } from \"@rebasepro/common\";\nimport { resolveAdminCollection } from \"@rebasepro/cms-types\";\nimport type { AdminCollection, AppView, RebasePlugin, UrlController } from \"@rebasepro/cms-types\";\n\nimport { useBuildCollectionRegistryController } from \"../hooks/navigation/useBuildCollectionRegistryController\";\nimport { useBuildUrlController } from \"../hooks/navigation/useBuildUrlController\";\nimport { useBuildNavigationStateController } from \"../hooks/navigation/useBuildNavigationStateController\";\nimport { CollectionRegistryContext } from \"../hooks/navigation/contexts/CollectionRegistryContext\";\nimport { UrlContext } from \"../hooks/navigation/contexts/UrlContext\";\nimport { NavigationStateContext } from \"../hooks/navigation/contexts/NavigationStateContext\";\nimport { SidePanelProvider } from \"./SidePanelProvider\";\nimport { SideDialogs } from \"./SideDialogs\";\nimport { CollectionsScopeContext } from \"./CollectionsScopeContext\";\n\nconst EMPTY_PLUGINS: RebasePlugin[] = [];\n\n/**\n * Whether `path` starts with a collection this registry holds — the longest\n * leading run of whole segments, since a slug may contain slashes.\n */\nfunction holdsLeadingCollection(registry: CollectionRegistry, path: string): boolean {\n const segments = path.split(\"/\").filter(Boolean);\n for (let length = segments.length; length > 0; length--) {\n if (registry.get(segments.slice(0, length).join(\"/\"))) return true;\n }\n return false;\n}\nconst NO_VIEWS: AppView[] = [];\n\n/**\n * @group Components\n */\nexport interface CollectionsProviderProps {\n /**\n * The collections this scope can show and edit — `defineCollection`\n * configs or resolved collections. Keep the array stable (a module\n * constant, or `useMemo`): a new array is a new set of collections.\n */\n collections: AdminCollection[];\n children: React.ReactNode;\n}\n\n/**\n * Everything a collection view or a record form needs to work in a page of\n * your own app, without `<RebaseCMS>`, `<RebaseNavigation>` or\n * `<RebaseShell>`: a registry of the collections you hand it, the record side\n * panel and dialogs (rendered here), and the navigation guard.\n *\n * It needs `<Rebase>` above it and a React Router router — any router, at any\n * path; a data router is not required. No CMS route serves the page, so a\n * record opens in a side panel or a dialog over it, never by URL.\n *\n * `CollectionPanel` and `RecordForm` given a `collection` bring one of\n * these themselves when none is above; mount it yourself to share one between\n * several of them, or to use the lower-level pieces (`CollectionViewBinding`,\n * `useSidePanel`) directly.\n *\n * @example\n * ```tsx\n * <Rebase client={client} authController={authController}>\n * <BrowserRouter>\n * <CollectionsProvider collections={[postsCollection, authorsCollection]}>\n * <CollectionPanel collection=\"posts\"/>\n * <CollectionPanel collection=\"authors\"/>\n * </CollectionsProvider>\n * </BrowserRouter>\n * </Rebase>\n * ```\n *\n * @group Components\n */\nexport function CollectionsProvider({ collections, children }: CollectionsProviderProps) {\n const context = useRebaseContext();\n const adminModeController = useAdminModeController();\n const userConfigPersistence = useUserConfigurationPersistence();\n const customizationController = useCustomizationController();\n const dataSources = useDataSources();\n const collectionRegistryController = useBuildCollectionRegistryController({ userConfigPersistence, dataSources: dataSources.registry });\n\n // The data layer gives a row its address from its collection's primary\n // key, and these collections are known only here. Registered under this\n // scope's own owner, so several scopes on one page — and the full CMS\n // beside them — do not overwrite each other. During render for the reason\n // `RebaseNavigation` gives (the views that fetch rows are below), and again\n // on mount, since a strict-mode remount runs the cleanup in between.\n const registerCollectionResolver = useContext(CollectionResolverRegistrationContext);\n const owner = useId();\n const getCollectionRef = useRef(collectionRegistryController.getCollection);\n getCollectionRef.current = collectionRegistryController.getCollection;\n const registryRef = collectionRegistryController.collectionRegistryRef;\n // Asked about every collection any owner has, so a path this scope does\n // not hold is answered quietly rather than by the registry's warning.\n const resolveCollection = useCallback((slug: string) =>\n holdsLeadingCollection(registryRef.current, slug) ? getCollectionRef.current(slug) : undefined, [registryRef]);\n const resolveDataPath = collectionRegistryController.resolveDataPath;\n registerCollectionResolver(resolveCollection, resolveDataPath, owner);\n useEffect(() => {\n registerCollectionResolver(resolveCollection, resolveDataPath, owner);\n return () => registerCollectionResolver(undefined, undefined, owner);\n }, [registerCollectionResolver, resolveCollection, resolveDataPath, owner]);\n\n // Each collection routed to the data source it declares, as in the CMS.\n const defaultData = useData();\n const routedData = useMemo(() => buildRoutedRebaseData({\n defaultData,\n sources: dataSources.sources,\n resolveKey: (slugOrPath) => resolveDataSource(resolveCollection(slugOrPath), dataSources.registry).key\n }), [defaultData, dataSources, resolveCollection]);\n\n // Paths are still built — a panel keys its records by them — but nothing\n // navigates to one, and no URL is read as a record to open.\n const builtUrlController = useBuildUrlController({\n basePath: \"/\",\n baseCollectionPath: \"/c\",\n collectionRegistryController\n });\n const urlController = useMemo<UrlController>(() => ({\n ...builtUrlController,\n isUrlCollectionPath: () => false,\n routesMounted: false\n }), [builtUrlController]);\n\n const resolvedCollections = useMemo(() => collections.map(collection => resolveAdminCollection(collection)), [collections]);\n const navigationStateController = useBuildNavigationStateController({\n plugins: customizationController.plugins ?? EMPTY_PLUGINS,\n collections: resolvedCollections,\n views: NO_VIEWS,\n authController: context.authController!,\n // The collection and view builders get the rows the server sends.\n data: context.data,\n collectionRegistryController,\n urlController,\n adminMode: adminModeController?.mode\n });\n\n // The Studio bridge describes the CMS's own controllers. A scope embedded\n // in the shell must not replace them there, so its registrations go nowhere.\n return (\n <CollectionsScopeContext.Provider value={true}>\n <StudioBridgeRegistryContext.Provider value={null}>\n <RebaseDataContext.Provider value={routedData}>\n <CollectionRegistryContext.Provider value={collectionRegistryController}>\n <UrlContext.Provider value={urlController}>\n <NavigationStateContext.Provider value={navigationStateController}>\n <SidePanelProvider>\n {children}\n <SideDialogs/>\n </SidePanelProvider>\n </NavigationStateContext.Provider>\n </UrlContext.Provider>\n </CollectionRegistryContext.Provider>\n </RebaseDataContext.Provider>\n </StudioBridgeRegistryContext.Provider>\n </CollectionsScopeContext.Provider>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AA0BA,IAAM,gBAAgC,CAAC;;;;;AAMvC,SAAS,uBAAuB,UAA8B,MAAuB;CACjF,MAAM,WAAW,KAAK,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO;CAC/C,KAAK,IAAI,SAAS,SAAS,QAAQ,SAAS,GAAG,UAC3C,IAAI,SAAS,IAAI,SAAS,MAAM,GAAG,MAAM,CAAC,CAAC,KAAK,GAAG,CAAC,GAAG,OAAO;CAElE,OAAO;AACX;AACA,IAAM,WAAsB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4C7B,SAAgB,oBAAoB,EAAE,aAAa,YAAsC;CACrF,MAAM,UAAU,iBAAiB;CACjC,MAAM,sBAAsB,uBAAuB;CACnD,MAAM,wBAAwB,gCAAgC;CAC9D,MAAM,0BAA0B,2BAA2B;CAC3D,MAAM,cAAc,eAAe;CACnC,MAAM,+BAA+B,qCAAqC;EAAE;EAAuB,aAAa,YAAY;CAAS,CAAC;CAQtI,MAAM,6BAA6B,WAAW,qCAAqC;CACnF,MAAM,QAAQ,MAAM;CACpB,MAAM,mBA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oBAAC,WAAW,UAAZ;MAAqB,OAAO;gBACxB,oBAAC,uBAAuB,UAAxB;OAAiC,OAAO;iBACpC,qBAAC,mBAAD,EAAA,UAAA,CACK,UACD,oBAAC,aAAD,CAAa,CAAA,CACE,EAAA,CAAA;MACU,CAAA;KAChB,CAAA;IACW,CAAA;GACZ,CAAA;EACM,CAAA;CACR,CAAA;AAE1C"}
|
|
@@ -3,7 +3,7 @@ import type { AdminCollection } from "@rebasepro/cms-types";
|
|
|
3
3
|
* Whether a collections scope — the registry, URL controller, navigation state
|
|
4
4
|
* and record panels — is mounted above: `<RebaseNavigation>` (the full CMS) or
|
|
5
5
|
* a `<CollectionsProvider>`. The components that can stand on their own
|
|
6
|
-
* (`CollectionPanel`, `
|
|
6
|
+
* (`CollectionPanel`, `RecordForm`) read it to decide whether to bring
|
|
7
7
|
* their own.
|
|
8
8
|
*
|
|
9
9
|
* @internal
|
|
@@ -4,7 +4,7 @@ import { createContext } from "react";
|
|
|
4
4
|
* Whether a collections scope — the registry, URL controller, navigation state
|
|
5
5
|
* and record panels — is mounted above: `<RebaseNavigation>` (the full CMS) or
|
|
6
6
|
* a `<CollectionsProvider>`. The components that can stand on their own
|
|
7
|
-
* (`CollectionPanel`, `
|
|
7
|
+
* (`CollectionPanel`, `RecordForm`) read it to decide whether to bring
|
|
8
8
|
* their own.
|
|
9
9
|
*
|
|
10
10
|
* @internal
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CollectionsScopeContext.js","names":[],"sources":["../../src/components/CollectionsScopeContext.ts"],"sourcesContent":["import { createContext } from \"react\";\nimport type { AdminCollection } from \"@rebasepro/cms-types\";\n\n/**\n * Whether a collections scope — the registry, URL controller, navigation state\n * and record panels — is mounted above: `<RebaseNavigation>` (the full CMS) or\n * a `<CollectionsProvider>`. The components that can stand on their own\n * (`CollectionPanel`, `
|
|
1
|
+
{"version":3,"file":"CollectionsScopeContext.js","names":[],"sources":["../../src/components/CollectionsScopeContext.ts"],"sourcesContent":["import { createContext } from \"react\";\nimport type { AdminCollection } from \"@rebasepro/cms-types\";\n\n/**\n * Whether a collections scope — the registry, URL controller, navigation state\n * and record panels — is mounted above: `<RebaseNavigation>` (the full CMS) or\n * a `<CollectionsProvider>`. The components that can stand on their own\n * (`CollectionPanel`, `RecordForm`) read it to decide whether to bring\n * their own.\n *\n * @internal\n */\nexport const CollectionsScopeContext = createContext<boolean>(false);\n\n/**\n * Whether a scope's top-level collections hold the one at `path` — asked\n * quietly, unlike a registry lookup, which warns about a path it cannot place.\n *\n * A subcollection's path (`posts/p1/comments`) is held by the scope that holds\n * its root, so the path's leading segments are matched, longest run first,\n * since a slug may itself contain slashes (`content/de-DE/podcasts`).\n *\n * @internal\n */\nexport function isRegistered(collections: AdminCollection[] | undefined, path: string): boolean {\n if (!collections?.length) return false;\n const slugs = new Set(collections.map(collection => collection.slug));\n const segments = path.split(\"/\").filter(Boolean);\n for (let length = segments.length; length > 0; length--) {\n if (slugs.has(segments.slice(0, length).join(\"/\"))) return true;\n }\n return false;\n}\n"],"mappings":";;;;;;;;;;;AAYA,IAAa,0BAA0B,cAAuB,KAAK;;;;;;;;;;;AAYnE,SAAgB,aAAa,aAA4C,MAAuB;CAC5F,IAAI,CAAC,aAAa,QAAQ,OAAO;CACjC,MAAM,QAAQ,IAAI,IAAI,YAAY,KAAI,eAAc,WAAW,IAAI,CAAC;CACpE,MAAM,WAAW,KAAK,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO;CAC/C,KAAK,IAAI,SAAS,SAAS,QAAQ,SAAS,GAAG,UAC3C,IAAI,MAAM,IAAI,SAAS,MAAM,GAAG,MAAM,CAAC,CAAC,KAAK,GAAG,CAAC,GAAG,OAAO;CAE/D,OAAO;AACX"}
|
|
@@ -7,7 +7,7 @@ export interface DeleteEntityDialogProps<M extends Record<string, unknown>> {
|
|
|
7
7
|
*
|
|
8
8
|
* A selection may be a *query* — every row matching a filter, most of them
|
|
9
9
|
* never read. That is why this is not an `Entity[]`: the rows do not exist
|
|
10
|
-
* until {@link
|
|
10
|
+
* until {@link resolveEntitySelection} reads them, and it only does that once the
|
|
11
11
|
* user has confirmed.
|
|
12
12
|
*/
|
|
13
13
|
target?: Entity<M> | EntitySelection<M>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useAdminContext } from "../hooks/useAdminContext.js";
|
|
2
2
|
import { EntityViewBinding } from "./EntityViewBinding.js";
|
|
3
|
-
import {
|
|
3
|
+
import { resolveEntitySelection } from "../selection/resolve_selection.js";
|
|
4
4
|
import { mapWithConcurrency } from "../util/map_with_concurrency.js";
|
|
5
5
|
import { useCallback, useMemo, useRef, useState } from "react";
|
|
6
6
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -96,7 +96,7 @@ function DeleteEntityDialog({ target, collection, onClose, open, onEntityDelete,
|
|
|
96
96
|
cancelledRef.current = { aborted: false };
|
|
97
97
|
let entities;
|
|
98
98
|
try {
|
|
99
|
-
entities = await
|
|
99
|
+
entities = await resolveEntitySelection({
|
|
100
100
|
selection,
|
|
101
101
|
accessor: dataClient.collection(path),
|
|
102
102
|
signal: cancelledRef.current,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeleteEntityDialog.js","names":[],"sources":["../../src/components/DeleteEntityDialog.tsx"],"sourcesContent":["import { Entity } from \"@rebasepro/types\";\nimport React, { useCallback, useMemo, useRef, useState } from \"react\";\nimport { Button, CircularProgress, Dialog, DialogActions, DialogContent, DialogTitle, Typography } from \"@rebasepro/ui\";\nimport {\n deleteEntityWithCallbacks,\n useData,\n useSnackbarController,\n useTranslation\n} from \"@rebasepro/app\";\nimport { useAdminContext } from \"../hooks\";\nimport { EntityViewBinding } from \"./EntityViewBinding\";\nimport type { AdminCollection, EntitySelection } from \"@rebasepro/cms-types\";\nimport { resolveSelection } from \"../selection\";\nimport { mapWithConcurrency } from \"../util/map_with_concurrency\";\n\n/**\n * Deletes in flight at once.\n *\n * The bulk delete used to be `Promise.all(entities.map(performDelete))`, which\n * is unremarkable for the handful of rows anyone could tick by hand and\n * untenable the moment \"select all 12,480 matching\" can reach it.\n */\nconst DELETE_CONCURRENCY = 8;\n\nexport interface DeleteEntityDialogProps<M extends Record<string, unknown>> {\n /**\n * What to delete: one row, or a whole selection.\n *\n * A selection may be a *query* — every row matching a filter, most of them\n * never read. That is why this is not an `Entity[]`: the rows do not exist\n * until {@link resolveSelection} reads them, and it only does that once the\n * user has confirmed.\n */\n target?: Entity<M> | EntitySelection<M>,\n path: string,\n collection: AdminCollection<M>\n open: boolean;\n onClose: () => void;\n\n onEntityDelete?(path: string, entity: Entity<M>): void;\n\n onMultipleEntitiesDelete?(path: string, entities: Entity<M>[]): void;\n\n /**\n * What the DELETE at this path actually does.\n *\n * `\"unlink\"` when the rows are shared through a junction: the server removes\n * the link and leaves the row alone, so a dialog promising deletion would be\n * describing something else.\n */\n variant?: \"delete\" | \"unlink\";\n}\n\nfunction isSelection<M extends Record<string, unknown>>(\n target: Entity<M> | EntitySelection<M>\n): target is EntitySelection<M> {\n return (target as EntitySelection<M>).type === \"entities\" || (target as EntitySelection<M>).type === \"query\";\n}\n\nexport function DeleteEntityDialog<M extends Record<string, unknown>>({\n target,\n collection,\n onClose,\n open,\n onEntityDelete,\n onMultipleEntitiesDelete,\n path,\n variant = \"delete\"\n}: DeleteEntityDialogProps<M>) {\n const dataClient = useData();\n const snackbarController = useSnackbarController();\n const { t } = useTranslation();\n const [loading, setLoading] = useState(false);\n const [progress, setProgress] = useState<string | undefined>(undefined);\n const cancelledRef = useRef({ aborted: false });\n\n const context = useAdminContext();\n\n // A one-row selection is a single delete: the dialog shows that row rather\n // than the anonymous \"these entities\" copy, which is what anyone ticking\n // exactly one checkbox expects to see.\n const { singleEntity, selection } = useMemo(() => {\n if (!target)\n return { singleEntity: undefined,\n selection: undefined };\n if (!isSelection(target))\n return { singleEntity: target,\n selection: undefined };\n if (target.type === \"entities\" && target.entities.length === 1)\n return { singleEntity: target.entities[0],\n selection: undefined };\n return { singleEntity: undefined,\n selection: target };\n }, [target]);\n\n /** How many rows this will delete; `undefined` when only the server knows. */\n const selectionCount = selection === undefined\n ? 1\n : selection.type === \"entities\"\n ? selection.entities.length\n : selection.count === undefined\n ? undefined\n : Math.max(0, selection.count - selection.excluded.length);\n\n const handleCancel = useCallback(() => {\n cancelledRef.current.aborted = true;\n onClose();\n }, [onClose]);\n\n const onDeleteSuccess = useCallback((entity: Entity<any>) => {\n console.debug(\"Deleted\", entity);\n }, []);\n\n const onDeleteFailure = useCallback((entity: Entity<any>, e: Error) => {\n snackbarController.open({\n type: \"error\",\n title: t(\"error_deleting\"),\n message: e?.message\n });\n\n console.error(\"Error deleting entity\");\n console.error(e);\n }, [collection.name]);\n\n const performDelete = useCallback((entity: Entity<M>, onFailure: (entity: Entity<any>, e: Error) => void = onDeleteFailure): Promise<boolean> =>\n deleteEntityWithCallbacks({\n data: dataClient,\n entity,\n collection: collection,\n onDeleteSuccess,\n onDeleteFailure: onFailure,\n context\n }), [dataClient, collection, onDeleteSuccess, onDeleteFailure, context]);\n\n const handleOk = useCallback(async () => {\n\n if (singleEntity) {\n setLoading(true);\n const success = await performDelete(singleEntity);\n setLoading(false);\n if (success) {\n onEntityDelete?.(path, singleEntity);\n snackbarController.open({\n type: \"success\",\n message: variant === \"unlink\"\n ? t(\"removed_from_record\")\n : t(\"deleted\", { name: collection.singularName ?? collection.name })\n });\n onClose();\n }\n return;\n }\n\n if (!selection) return;\n\n setLoading(true);\n cancelledRef.current = { aborted: false };\n\n let entities: Entity<M>[];\n try {\n // Reading happens *after* the confirmation, not before it: a query\n // selection over a large collection is tens of requests, and doing\n // them up front would make clicking the bin — an action the user has\n // not yet agreed to — the expensive part.\n entities = await resolveSelection<M>({\n selection,\n accessor: dataClient.collection<M>(path),\n signal: cancelledRef.current,\n onProgress: (loaded, total) => setProgress(\n total === undefined\n ? t(\"selection_reading_rows_unknown\", { loaded: loaded.toLocaleString() })\n : t(\"selection_reading_rows\", {\n loaded: loaded.toLocaleString(),\n total: total.toLocaleString()\n })\n )\n });\n } catch (e) {\n setLoading(false);\n setProgress(undefined);\n snackbarController.open({\n type: \"error\",\n title: t(\"error_deleting_entities\", { collection: collection.name }),\n message: (e as Error)?.message\n });\n return;\n }\n\n if (cancelledRef.current.aborted) {\n setLoading(false);\n setProgress(undefined);\n return;\n }\n\n // Collected, not one snackbar per row: a mass refusal (a foreign key\n // every row trips) queued a toast per row of a delete that can walk\n // 20,000 of them. The summary below names how many, and the first cause.\n const failures: Error[] = [];\n const recordFailure = (_entity: Entity<any>, e: Error) => {\n failures.push(e);\n console.error(\"Error deleting entity\", e);\n };\n\n let results: boolean[] = [];\n try {\n results = await mapWithConcurrency(\n entities,\n DELETE_CONCURRENCY,\n // Cancel has to reach the deletes too, not just the read that\n // precedes them. It cannot recall the ones already in flight,\n // but it stops the queue — otherwise closing the dialog on a\n // 12,000-row delete would leave it running with nothing on\n // screen saying so.\n (entity) => cancelledRef.current.aborted\n ? Promise.resolve(false)\n : performDelete(entity, recordFailure),\n (completed, total) => setProgress(t(\"selection_deleting_progress\", {\n completed: completed.toLocaleString(),\n total: total.toLocaleString()\n }))\n );\n } catch (e) {\n // `mapWithConcurrency` runs every task before it rethrows, so the\n // rows that could be deleted have been. The per-row failure handler\n // has already reported the cause.\n console.error(\"Error deleting entities\", e);\n }\n\n setLoading(false);\n setProgress(undefined);\n\n onMultipleEntitiesDelete?.(path, entities.filter((_, i) => results[i]));\n\n const deleted = results.filter(Boolean).length;\n const failedSummary = failures.length > 0\n ? t(\"delete_rows_failed\", {\n failed: failures.length.toLocaleString(),\n total: entities.length.toLocaleString(),\n reason: failures[0]?.message ?? \"\"\n })\n : undefined;\n if (deleted === entities.length && entities.length > 0) {\n snackbarController.open({\n type: \"success\",\n message: variant === \"unlink\"\n ? t(\"removed_from_record\")\n : t(\"multiple_deleted\", { collection: collection.name })\n });\n } else if (deleted > 0) {\n snackbarController.open({\n type: \"warning\",\n title: failedSummary ? t(\"some_entities_deleted\", { collection: collection.name }) : undefined,\n message: failedSummary ?? t(\"some_entities_deleted\", { collection: collection.name })\n });\n } else {\n snackbarController.open({\n type: \"error\",\n title: failedSummary ? t(\"error_deleting_entities\", { collection: collection.name }) : undefined,\n message: failedSummary ?? t(\"error_deleting_entities\", { collection: collection.name })\n });\n }\n onClose();\n }, [singleEntity, selection, performDelete, dataClient, path, onEntityDelete, onMultipleEntitiesDelete, onClose, snackbarController, collection.name, collection.singularName, t, variant]);\n\n const entityName = collection.singularName ?? collection.name;\n\n let dialogTitle: React.ReactNode;\n if (singleEntity) {\n dialogTitle = variant === \"unlink\"\n ? t(\"unlink_entity_confirm_title\", { entityName })\n : t(\"delete_entity_confirm_title\", { entityName });\n } else if (variant === \"unlink\") {\n dialogTitle = <><b>{collection.name}</b>: {t(\"confirm_multiple_unlink\")}</>;\n } else if (selectionCount === undefined) {\n // \"Every matching row, and the server has not said how many.\" Naming a\n // number here would be inventing one for an irreversible action.\n dialogTitle = t(\"confirm_delete_selection_unknown\");\n } else {\n dialogTitle = t(\"confirm_delete_selection\", {\n total: selectionCount.toLocaleString(),\n collection: collection.name\n });\n }\n\n return (\n <Dialog\n maxWidth={singleEntity ? \"2xl\" : \"lg\"}\n aria-labelledby=\"delete-dialog\"\n open={open}\n // Escape and a click outside are a cancel, not just a close: the\n // abort flag is what stops a bulk delete's queue, and a dialog that\n // only closed left it deleting with nothing on screen.\n onOpenChange={(open) => {\n if (!open) handleCancel();\n }}\n >\n <DialogTitle id=\"delete-dialog-title\">\n {dialogTitle}\n </DialogTitle>\n <DialogContent fullHeight={true}>\n {variant === \"unlink\" && <div className={\"px-4 pt-4\"}>\n <Typography variant={\"body2\"} color={\"secondary\"}>\n {t(\"unlink_entity_confirm_body\", { collectionName: collection.name })}\n </Typography>\n </div>}\n {singleEntity && <div className={\"p-4\"}>\n <EntityViewBinding\n entity={singleEntity}\n collection={collection}\n path={path}/>\n </div>}\n {!singleEntity && variant === \"delete\" && <div className={\"px-4 pt-4\"}>\n <Typography variant={\"body2\"} color={\"secondary\"}>\n {t(\"confirm_delete_selection_body\")}\n </Typography>\n </div>}\n </DialogContent>\n <DialogActions>\n\n {loading && <CircularProgress size={\"smallest\"}/>}\n {progress && <Typography variant={\"caption\"} color={\"secondary\"}>{progress}</Typography>}\n\n <Button onClick={handleCancel}\n variant=\"text\">\n {t(\"cancel\")}\n </Button>\n <Button\n autoFocus\n disabled={loading}\n onClick={handleOk}\n variant=\"filled\">\n {t(\"ok\")}\n </Button>\n </DialogActions>\n\n </Dialog>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAsBA,IAAM,qBAAqB;AA+B3B,SAAS,YACL,QAC4B;CAC5B,OAAQ,OAA8B,SAAS,cAAe,OAA8B,SAAS;AACzG;AAEA,SAAgB,mBAAsD,EAClE,QACA,YACA,SACA,MACA,gBACA,0BACA,MACA,UAAU,YACiB;CAC3B,MAAM,aAAa,QAAQ;CAC3B,MAAM,qBAAqB,sBAAsB;CACjD,MAAM,EAAE,MAAM,eAAe;CAC7B,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAC5C,MAAM,CAAC,UAAU,eAAe,SAA6B,KAAA,CAAS;CACtE,MAAM,eAAe,OAAO,EAAE,SAAS,MAAM,CAAC;CAE9C,MAAM,UAAU,gBAAgB;CAKhC,MAAM,EAAE,cAAc,cAAc,cAAc;EAC9C,IAAI,CAAC,QACD,OAAO;GAAE,cAAc,KAAA;GACnB,WAAW,KAAA;EAAU;EAC7B,IAAI,CAAC,YAAY,MAAM,GACnB,OAAO;GAAE,cAAc;GACnB,WAAW,KAAA;EAAU;EAC7B,IAAI,OAAO,SAAS,cAAc,OAAO,SAAS,WAAW,GACzD,OAAO;GAAE,cAAc,OAAO,SAAS;GACnC,WAAW,KAAA;EAAU;EAC7B,OAAO;GAAE,cAAc,KAAA;GACnB,WAAW;EAAO;CAC1B,GAAG,CAAC,MAAM,CAAC;;CAGX,MAAM,iBAAiB,cAAc,KAAA,IAC/B,IACA,UAAU,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M,aAAa;EAC5B;YATJ;GAWI,oBAAC,aAAD;IAAa,IAAG;cACX;GACQ,CAAA;GACb,qBAAC,eAAD;IAAe,YAAY;cAA3B;KACK,YAAY,YAAY,oBAAC,OAAD;MAAK,WAAW;gBACrC,oBAAC,YAAD;OAAY,SAAS;OAAS,OAAO;iBAChC,EAAE,8BAA8B,EAAE,gBAAgB,WAAW,KAAK,CAAC;MAC5D,CAAA;KACX,CAAA;KACJ,gBAAgB,oBAAC,OAAD;MAAK,WAAW;gBAC7B,oBAAC,mBAAD;OACI,QAAQ;OACI;OACN;MAAM,CAAA;KACf,CAAA;KACJ,CAAC,gBAAgB,YAAY,YAAY,oBAAC,OAAD;MAAK,WAAW;gBACtD,oBAAC,YAAD;OAAY,SAAS;OAAS,OAAO;iBAChC,EAAE,+BAA+B;MAC1B,CAAA;KACX,CAAA;IACM;;GACf,qBAAC,eAAD,EAAA,UAAA;IAEK,WAAW,oBAAC,kBAAD,EAAkB,MAAM,WAAY,CAAA;IAC/C,YAAY,oBAAC,YAAD;KAAY,SAAS;KAAW,OAAO;eAAc;IAAqB,CAAA;IAEvF,oBAAC,QAAD;KAAQ,SAAS;KACb,SAAQ;eACP,EAAE,QAAQ;IACP,CAAA;IACR,oBAAC,QAAD;KACI,WAAA;KACA,UAAU;KACV,SAAS;KACT,SAAQ;eACP,EAAE,IAAI;IACH,CAAA;GACG,EAAA,CAAA;EAEX;;AAEhB"}
|
|
1
|
+
{"version":3,"file":"DeleteEntityDialog.js","names":[],"sources":["../../src/components/DeleteEntityDialog.tsx"],"sourcesContent":["import { Entity } from \"@rebasepro/types\";\nimport React, { useCallback, useMemo, useRef, useState } from \"react\";\nimport { Button, CircularProgress, Dialog, DialogActions, DialogContent, DialogTitle, Typography } from \"@rebasepro/ui\";\nimport {\n deleteEntityWithCallbacks,\n useData,\n useSnackbarController,\n useTranslation\n} from \"@rebasepro/app\";\nimport { useAdminContext } from \"../hooks\";\nimport { EntityViewBinding } from \"./EntityViewBinding\";\nimport type { AdminCollection, EntitySelection } from \"@rebasepro/cms-types\";\nimport { resolveEntitySelection } from \"../selection/resolve_selection\";\nimport { mapWithConcurrency } from \"../util/map_with_concurrency\";\n\n/**\n * Deletes in flight at once.\n *\n * The bulk delete used to be `Promise.all(entities.map(performDelete))`, which\n * is unremarkable for the handful of rows anyone could tick by hand and\n * untenable the moment \"select all 12,480 matching\" can reach it.\n */\nconst DELETE_CONCURRENCY = 8;\n\nexport interface DeleteEntityDialogProps<M extends Record<string, unknown>> {\n /**\n * What to delete: one row, or a whole selection.\n *\n * A selection may be a *query* — every row matching a filter, most of them\n * never read. That is why this is not an `Entity[]`: the rows do not exist\n * until {@link resolveEntitySelection} reads them, and it only does that once the\n * user has confirmed.\n */\n target?: Entity<M> | EntitySelection<M>,\n path: string,\n collection: AdminCollection<M>\n open: boolean;\n onClose: () => void;\n\n onEntityDelete?(path: string, entity: Entity<M>): void;\n\n onMultipleEntitiesDelete?(path: string, entities: Entity<M>[]): void;\n\n /**\n * What the DELETE at this path actually does.\n *\n * `\"unlink\"` when the rows are shared through a junction: the server removes\n * the link and leaves the row alone, so a dialog promising deletion would be\n * describing something else.\n */\n variant?: \"delete\" | \"unlink\";\n}\n\nfunction isSelection<M extends Record<string, unknown>>(\n target: Entity<M> | EntitySelection<M>\n): target is EntitySelection<M> {\n return (target as EntitySelection<M>).type === \"entities\" || (target as EntitySelection<M>).type === \"query\";\n}\n\nexport function DeleteEntityDialog<M extends Record<string, unknown>>({\n target,\n collection,\n onClose,\n open,\n onEntityDelete,\n onMultipleEntitiesDelete,\n path,\n variant = \"delete\"\n}: DeleteEntityDialogProps<M>) {\n const dataClient = useData();\n const snackbarController = useSnackbarController();\n const { t } = useTranslation();\n const [loading, setLoading] = useState(false);\n const [progress, setProgress] = useState<string | undefined>(undefined);\n const cancelledRef = useRef({ aborted: false });\n\n const context = useAdminContext();\n\n // A one-row selection is a single delete: the dialog shows that row rather\n // than the anonymous \"these entities\" copy, which is what anyone ticking\n // exactly one checkbox expects to see.\n const { singleEntity, selection } = useMemo(() => {\n if (!target)\n return { singleEntity: undefined,\n selection: undefined };\n if (!isSelection(target))\n return { singleEntity: target,\n selection: undefined };\n if (target.type === \"entities\" && target.entities.length === 1)\n return { singleEntity: target.entities[0],\n selection: undefined };\n return { singleEntity: undefined,\n selection: target };\n }, [target]);\n\n /** How many rows this will delete; `undefined` when only the server knows. */\n const selectionCount = selection === undefined\n ? 1\n : selection.type === \"entities\"\n ? selection.entities.length\n : selection.count === undefined\n ? undefined\n : Math.max(0, selection.count - selection.excluded.length);\n\n const handleCancel = useCallback(() => {\n cancelledRef.current.aborted = true;\n onClose();\n }, [onClose]);\n\n const onDeleteSuccess = useCallback((entity: Entity<any>) => {\n console.debug(\"Deleted\", entity);\n }, []);\n\n const onDeleteFailure = useCallback((entity: Entity<any>, e: Error) => {\n snackbarController.open({\n type: \"error\",\n title: t(\"error_deleting\"),\n message: e?.message\n });\n\n console.error(\"Error deleting entity\");\n console.error(e);\n }, [collection.name]);\n\n const performDelete = useCallback((entity: Entity<M>, onFailure: (entity: Entity<any>, e: Error) => void = onDeleteFailure): Promise<boolean> =>\n deleteEntityWithCallbacks({\n data: dataClient,\n entity,\n collection: collection,\n onDeleteSuccess,\n onDeleteFailure: onFailure,\n context\n }), [dataClient, collection, onDeleteSuccess, onDeleteFailure, context]);\n\n const handleOk = useCallback(async () => {\n\n if (singleEntity) {\n setLoading(true);\n const success = await performDelete(singleEntity);\n setLoading(false);\n if (success) {\n onEntityDelete?.(path, singleEntity);\n snackbarController.open({\n type: \"success\",\n message: variant === \"unlink\"\n ? t(\"removed_from_record\")\n : t(\"deleted\", { name: collection.singularName ?? collection.name })\n });\n onClose();\n }\n return;\n }\n\n if (!selection) return;\n\n setLoading(true);\n cancelledRef.current = { aborted: false };\n\n let entities: Entity<M>[];\n try {\n // Reading happens *after* the confirmation, not before it: a query\n // selection over a large collection is tens of requests, and doing\n // them up front would make clicking the bin — an action the user has\n // not yet agreed to — the expensive part.\n entities = await resolveEntitySelection<M>({\n selection,\n accessor: dataClient.collection<M>(path),\n signal: cancelledRef.current,\n onProgress: (loaded, total) => setProgress(\n total === undefined\n ? t(\"selection_reading_rows_unknown\", { loaded: loaded.toLocaleString() })\n : t(\"selection_reading_rows\", {\n loaded: loaded.toLocaleString(),\n total: total.toLocaleString()\n })\n )\n });\n } catch (e) {\n setLoading(false);\n setProgress(undefined);\n snackbarController.open({\n type: \"error\",\n title: t(\"error_deleting_entities\", { collection: collection.name }),\n message: (e as Error)?.message\n });\n return;\n }\n\n if (cancelledRef.current.aborted) {\n setLoading(false);\n setProgress(undefined);\n return;\n }\n\n // Collected, not one snackbar per row: a mass refusal (a foreign key\n // every row trips) queued a toast per row of a delete that can walk\n // 20,000 of them. The summary below names how many, and the first cause.\n const failures: Error[] = [];\n const recordFailure = (_entity: Entity<any>, e: Error) => {\n failures.push(e);\n console.error(\"Error deleting entity\", e);\n };\n\n let results: boolean[] = [];\n try {\n results = await mapWithConcurrency(\n entities,\n DELETE_CONCURRENCY,\n // Cancel has to reach the deletes too, not just the read that\n // precedes them. It cannot recall the ones already in flight,\n // but it stops the queue — otherwise closing the dialog on a\n // 12,000-row delete would leave it running with nothing on\n // screen saying so.\n (entity) => cancelledRef.current.aborted\n ? Promise.resolve(false)\n : performDelete(entity, recordFailure),\n (completed, total) => setProgress(t(\"selection_deleting_progress\", {\n completed: completed.toLocaleString(),\n total: total.toLocaleString()\n }))\n );\n } catch (e) {\n // `mapWithConcurrency` runs every task before it rethrows, so the\n // rows that could be deleted have been. The per-row failure handler\n // has already reported the cause.\n console.error(\"Error deleting entities\", e);\n }\n\n setLoading(false);\n setProgress(undefined);\n\n onMultipleEntitiesDelete?.(path, entities.filter((_, i) => results[i]));\n\n const deleted = results.filter(Boolean).length;\n const failedSummary = failures.length > 0\n ? t(\"delete_rows_failed\", {\n failed: failures.length.toLocaleString(),\n total: entities.length.toLocaleString(),\n reason: failures[0]?.message ?? \"\"\n })\n : undefined;\n if (deleted === entities.length && entities.length > 0) {\n snackbarController.open({\n type: \"success\",\n message: variant === \"unlink\"\n ? t(\"removed_from_record\")\n : t(\"multiple_deleted\", { collection: collection.name })\n });\n } else if (deleted > 0) {\n snackbarController.open({\n type: \"warning\",\n title: failedSummary ? t(\"some_entities_deleted\", { collection: collection.name }) : undefined,\n message: failedSummary ?? t(\"some_entities_deleted\", { collection: collection.name })\n });\n } else {\n snackbarController.open({\n type: \"error\",\n title: failedSummary ? t(\"error_deleting_entities\", { collection: collection.name }) : undefined,\n message: failedSummary ?? t(\"error_deleting_entities\", { collection: collection.name })\n });\n }\n onClose();\n }, [singleEntity, selection, performDelete, dataClient, path, onEntityDelete, onMultipleEntitiesDelete, onClose, snackbarController, collection.name, collection.singularName, t, variant]);\n\n const entityName = collection.singularName ?? collection.name;\n\n let dialogTitle: React.ReactNode;\n if (singleEntity) {\n dialogTitle = variant === \"unlink\"\n ? t(\"unlink_entity_confirm_title\", { entityName })\n : t(\"delete_entity_confirm_title\", { entityName });\n } else if (variant === \"unlink\") {\n dialogTitle = <><b>{collection.name}</b>: {t(\"confirm_multiple_unlink\")}</>;\n } else if (selectionCount === undefined) {\n // \"Every matching row, and the server has not said how many.\" Naming a\n // number here would be inventing one for an irreversible action.\n dialogTitle = t(\"confirm_delete_selection_unknown\");\n } else {\n dialogTitle = t(\"confirm_delete_selection\", {\n total: selectionCount.toLocaleString(),\n collection: collection.name\n });\n }\n\n return (\n <Dialog\n maxWidth={singleEntity ? \"2xl\" : \"lg\"}\n aria-labelledby=\"delete-dialog\"\n open={open}\n // Escape and a click outside are a cancel, not just a close: the\n // abort flag is what stops a bulk delete's queue, and a dialog that\n // only closed left it deleting with nothing on screen.\n onOpenChange={(open) => {\n if (!open) handleCancel();\n }}\n >\n <DialogTitle id=\"delete-dialog-title\">\n {dialogTitle}\n </DialogTitle>\n <DialogContent fullHeight={true}>\n {variant === \"unlink\" && <div className={\"px-4 pt-4\"}>\n <Typography variant={\"body2\"} color={\"secondary\"}>\n {t(\"unlink_entity_confirm_body\", { collectionName: collection.name })}\n </Typography>\n </div>}\n {singleEntity && <div className={\"p-4\"}>\n <EntityViewBinding\n entity={singleEntity}\n collection={collection}\n path={path}/>\n </div>}\n {!singleEntity && variant === \"delete\" && <div className={\"px-4 pt-4\"}>\n <Typography variant={\"body2\"} color={\"secondary\"}>\n {t(\"confirm_delete_selection_body\")}\n </Typography>\n </div>}\n </DialogContent>\n <DialogActions>\n\n {loading && <CircularProgress size={\"smallest\"}/>}\n {progress && <Typography variant={\"caption\"} color={\"secondary\"}>{progress}</Typography>}\n\n <Button onClick={handleCancel}\n variant=\"text\">\n {t(\"cancel\")}\n </Button>\n <Button\n autoFocus\n disabled={loading}\n onClick={handleOk}\n variant=\"filled\">\n {t(\"ok\")}\n </Button>\n </DialogActions>\n\n </Dialog>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAsBA,IAAM,qBAAqB;AA+B3B,SAAS,YACL,QAC4B;CAC5B,OAAQ,OAA8B,SAAS,cAAe,OAA8B,SAAS;AACzG;AAEA,SAAgB,mBAAsD,EAClE,QACA,YACA,SACA,MACA,gBACA,0BACA,MACA,UAAU,YACiB;CAC3B,MAAM,aAAa,QAAQ;CAC3B,MAAM,qBAAqB,sBAAsB;CACjD,MAAM,EAAE,MAAM,eAAe;CAC7B,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAC5C,MAAM,CAAC,UAAU,eAAe,SAA6B,KAAA,CAAS;CACtE,MAAM,eAAe,OAAO,EAAE,SAAS,MAAM,CAAC;CAE9C,MAAM,UAAU,gBAAgB;CAKhC,MAAM,EAAE,cAAc,cAAc,cAAc;EAC9C,IAAI,CAAC,QACD,OAAO;GAAE,cAAc,KAAA;GACnB,WAAW,KAAA;EAAU;EAC7B,IAAI,CAAC,YAAY,MAAM,GACnB,OAAO;GAAE,cAAc;GACnB,WAAW,KAAA;EAAU;EAC7B,IAAI,OAAO,SAAS,cAAc,OAAO,SAAS,WAAW,GACzD,OAAO;GAAE,cA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,4BAA4B;EACxC,OAAO,eAAe,eAAe;EACrC,YAAY,WAAW;CAC3B,CAAC;CAGL,OACI,qBAAC,QAAD;EACI,UAAU,eAAe,QAAQ;EACjC,mBAAgB;EACV;EAIN,eAAe,SAAS;GACpB,IAAI,CAAC,MAAM,aAAa;EAC5B;YATJ;GAWI,oBAAC,aAAD;IAAa,IAAG;cACX;GACQ,CAAA;GACb,qBAAC,eAAD;IAAe,YAAY;cAA3B;KACK,YAAY,YAAY,oBAAC,OAAD;MAAK,WAAW;gBACrC,oBAAC,YAAD;OAAY,SAAS;OAAS,OAAO;iBAChC,EAAE,8BAA8B,EAAE,gBAAgB,WAAW,KAAK,CAAC;MAC5D,CAAA;KACX,CAAA;KACJ,gBAAgB,oBAAC,OAAD;MAAK,WAAW;gBAC7B,oBAAC,mBAAD;OACI,QAAQ;OACI;OACN;MAAM,CAAA;KACf,CAAA;KACJ,CAAC,gBAAgB,YAAY,YAAY,oBAAC,OAAD;MAAK,WAAW;gBACtD,oBAAC,YAAD;OAAY,SAAS;OAAS,OAAO;iBAChC,EAAE,+BAA+B;MAC1B,CAAA;KACX,CAAA;IACM;;GACf,qBAAC,eAAD,EAAA,UAAA;IAEK,WAAW,oBAAC,kBAAD,EAAkB,MAAM,WAAY,CAAA;IAC/C,YAAY,oBAAC,YAAD;KAAY,SAAS;KAAW,OAAO;eAAc;IAAqB,CAAA;IAEvF,oBAAC,QAAD;KAAQ,SAAS;KACb,SAAQ;eACP,EAAE,QAAQ;IACP,CAAA;IACR,oBAAC,QAAD;KACI,WAAA;KACA,UAAU;KACV,SAAS;KACT,SAAQ;eACP,EAAE,IAAI;IACH,CAAA;GACG,EAAA,CAAA;EAEX;;AAEhB"}
|
|
@@ -3,7 +3,6 @@ import { useUrlController } from "../hooks/navigation/contexts/UrlContext.js";
|
|
|
3
3
|
import { useAdminContext } from "../hooks/useAdminContext.js";
|
|
4
4
|
import { withListState } from "../util/view_mode.js";
|
|
5
5
|
import { resolvedSelectedEntityView } from "../util/resolutions.js";
|
|
6
|
-
import { EntityViewBinding } from "./EntityViewBinding.js";
|
|
7
6
|
import { EntityIdentityBar } from "./EntityIdentityBar.js";
|
|
8
7
|
import { SplitListCloseButton } from "./CollectionViewBinding/SplitListCloseButton.js";
|
|
9
8
|
import { SplitListShowButton } from "./CollectionViewBinding/SplitListShowButton.js";
|
|
@@ -12,14 +11,16 @@ import { EntityInspector } from "./EntityInspector.js";
|
|
|
12
11
|
import { useEntityDisplayTitle } from "../hooks/useEntityDisplayTitle.js";
|
|
13
12
|
import { ENTITY_VIEW_TAB_CLASS, MAIN_TAB_VALUE } from "../util/view_constants.js";
|
|
14
13
|
import { CollectionViewBinding } from "./CollectionViewBinding/CollectionViewBinding.js";
|
|
14
|
+
import { EntityViewBody, useReadOnlyFormContext } from "./EntityViewBody.js";
|
|
15
15
|
import { Suspense, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
16
16
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
17
17
|
import { Button, CenteredView, CircularProgressCenter, ErrorBoundary, IconButton, Maximize2Icon, PencilIcon, Skeleton, Tab, Tabs, Tooltip, Typography, cls, defaultBorderMixin, iconSize } from "@rebasepro/ui";
|
|
18
18
|
import { hasEntityId } from "@rebasepro/common";
|
|
19
|
-
import { CollectionScopeProvider, ErrorView, PluginProviderStack,
|
|
19
|
+
import { CollectionScopeProvider, ErrorView, PluginProviderStack, getAdminEntityChildViews, getIcon, removeInitialAndTrailingSlashes, resolveComponentRef, resolveDefaultSelectedView, rowOfEntity, useComponentOverride, useCustomizationController, useFetch, usePermissions, useRebaseContext, useSlot, useTranslation } from "@rebasepro/app";
|
|
20
20
|
import { useNavigate } from "react-router";
|
|
21
21
|
//#region src/components/DetailViewBinding.tsx
|
|
22
22
|
function DetailViewBinding({ entityId, ...props }) {
|
|
23
|
+
const { t } = useTranslation();
|
|
23
24
|
const { entity, dataLoading, dataLoadingError } = useFetch({
|
|
24
25
|
path: props.path,
|
|
25
26
|
entityId,
|
|
@@ -30,7 +31,7 @@ function DetailViewBinding({ entityId, ...props }) {
|
|
|
30
31
|
if (!dataLoading && dataLoadingError) return /* @__PURE__ */ jsx(CenteredView, { children: /* @__PURE__ */ jsx(ErrorView, { error: dataLoadingError }) });
|
|
31
32
|
if (!dataLoading && !entity) return /* @__PURE__ */ jsx(CenteredView, { children: /* @__PURE__ */ jsx(Typography, {
|
|
32
33
|
variant: "label",
|
|
33
|
-
children: "
|
|
34
|
+
children: t("entity_not_found")
|
|
34
35
|
}) });
|
|
35
36
|
const content = /* @__PURE__ */ jsx(DetailViewBindingInner, {
|
|
36
37
|
...props,
|
|
@@ -54,7 +55,7 @@ function DetailViewBindingInner({ path, entityId, selectedTab: selectedTabProp,
|
|
|
54
55
|
useCollectionRegistryController();
|
|
55
56
|
const { canEdit: canEditHook } = usePermissions();
|
|
56
57
|
const canEdit = useMemo(() => {
|
|
57
|
-
return entity ? canEditHook(collection, path, entity) : false;
|
|
58
|
+
return entity ? canEditHook(collection, path, entity.values) : false;
|
|
58
59
|
}, [
|
|
59
60
|
canEditHook,
|
|
60
61
|
entity,
|
|
@@ -65,9 +66,10 @@ function DetailViewBindingInner({ path, entityId, selectedTab: selectedTabProp,
|
|
|
65
66
|
useEffect(() => {
|
|
66
67
|
if (entity) setUsedEntity(entity);
|
|
67
68
|
}, [entity]);
|
|
69
|
+
const usedRow = usedEntity ? rowOfEntity(usedEntity, collection) : void 0;
|
|
68
70
|
const defaultSelectedView = useMemo(() => resolveDefaultSelectedView(collection.defaultSelectedView, {
|
|
69
71
|
status: "existing",
|
|
70
|
-
entityId
|
|
72
|
+
id: entityId
|
|
71
73
|
}), [collection, entityId]);
|
|
72
74
|
const userHasChangedTab = useRef(false);
|
|
73
75
|
const [selectedTab, setSelectedTab] = useState(() => {
|
|
@@ -104,40 +106,15 @@ function DetailViewBindingInner({ path, entityId, selectedTab: selectedTabProp,
|
|
|
104
106
|
const mainViewVisible = activeTab === MAIN_TAB_VALUE;
|
|
105
107
|
const mountedTabsRef = useRef(/* @__PURE__ */ new Set());
|
|
106
108
|
if (activeTab) mountedTabsRef.current.add(activeTab);
|
|
107
|
-
const readOnlyFormContext =
|
|
108
|
-
if (!hasEntityId(entityId)) return void 0;
|
|
109
|
-
const formexStub = createFormexStub(usedEntity?.values ?? {});
|
|
110
|
-
return {
|
|
111
|
-
entityId,
|
|
112
|
-
disabled: true,
|
|
113
|
-
readOnly: true,
|
|
114
|
-
openEntityMode: layout,
|
|
115
|
-
status: "existing",
|
|
116
|
-
values: usedEntity?.values ?? {},
|
|
117
|
-
setFieldValue: () => {
|
|
118
|
-
throw new Error("Cannot update values in read-only detail view");
|
|
119
|
-
},
|
|
120
|
-
save: () => {
|
|
121
|
-
throw new Error("Cannot save in read-only detail view");
|
|
122
|
-
},
|
|
123
|
-
submit: () => {
|
|
124
|
-
throw new Error("Cannot submit in read-only detail view");
|
|
125
|
-
},
|
|
126
|
-
collection,
|
|
127
|
-
path,
|
|
128
|
-
entity: usedEntity,
|
|
129
|
-
savingError: void 0,
|
|
130
|
-
formex: formexStub
|
|
131
|
-
};
|
|
132
|
-
}, [
|
|
109
|
+
const readOnlyFormContext = useReadOnlyFormContext({
|
|
133
110
|
entityId,
|
|
134
|
-
|
|
135
|
-
usedEntity,
|
|
111
|
+
entity: usedEntity,
|
|
136
112
|
collection,
|
|
137
|
-
path
|
|
138
|
-
|
|
113
|
+
path,
|
|
114
|
+
openEntityMode: layout
|
|
115
|
+
});
|
|
139
116
|
const pluginActionsTop = useSlot("form.actions.top", useMemo(() => ({
|
|
140
|
-
entityId,
|
|
117
|
+
id: entityId,
|
|
141
118
|
parentCollectionSlugs,
|
|
142
119
|
parentEntityIds,
|
|
143
120
|
path,
|
|
@@ -169,7 +146,8 @@ function DetailViewBindingInner({ path, entityId, selectedTab: selectedTabProp,
|
|
|
169
146
|
entity: usedEntity,
|
|
170
147
|
clickProps: useMemo(() => usedEntity ? {
|
|
171
148
|
view: "form",
|
|
172
|
-
|
|
149
|
+
row: usedRow,
|
|
150
|
+
id: String(usedEntity.id),
|
|
173
151
|
path,
|
|
174
152
|
collection,
|
|
175
153
|
context,
|
|
@@ -178,6 +156,7 @@ function DetailViewBindingInner({ path, entityId, selectedTab: selectedTabProp,
|
|
|
178
156
|
navigateBack: leaveRecord
|
|
179
157
|
} : void 0, [
|
|
180
158
|
usedEntity,
|
|
159
|
+
usedRow,
|
|
181
160
|
path,
|
|
182
161
|
collection,
|
|
183
162
|
context,
|
|
@@ -186,8 +165,6 @@ function DetailViewBindingInner({ path, entityId, selectedTab: selectedTabProp,
|
|
|
186
165
|
leaveRecord
|
|
187
166
|
])
|
|
188
167
|
});
|
|
189
|
-
const formViewConfig = collection.formView;
|
|
190
|
-
const FormViewBuilder = formViewConfig?.Builder ? resolveComponentRef(formViewConfig.Builder) : null;
|
|
191
168
|
const title = useEntityDisplayTitle({
|
|
192
169
|
collection,
|
|
193
170
|
entity: usedEntity,
|
|
@@ -211,7 +188,8 @@ function DetailViewBindingInner({ path, entityId, selectedTab: selectedTabProp,
|
|
|
211
188
|
collection,
|
|
212
189
|
parentCollectionSlugs,
|
|
213
190
|
parentEntityIds,
|
|
214
|
-
|
|
191
|
+
row: usedRow,
|
|
192
|
+
id: usedEntity ? String(usedEntity.id) : void 0,
|
|
215
193
|
modifiedValues: usedEntity?.values,
|
|
216
194
|
formContext: readOnlyFormContext
|
|
217
195
|
})
|
|
@@ -257,33 +235,15 @@ function DetailViewBindingInner({ path, entityId, selectedTab: selectedTabProp,
|
|
|
257
235
|
entityId,
|
|
258
236
|
collection
|
|
259
237
|
]);
|
|
260
|
-
const propertyDetailView = () => {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
parentCollectionSlugs,
|
|
270
|
-
parentEntityIds,
|
|
271
|
-
entity: usedEntity,
|
|
272
|
-
modifiedValues: usedEntity?.values,
|
|
273
|
-
formContext: readOnlyFormContext
|
|
274
|
-
})
|
|
275
|
-
}) })
|
|
276
|
-
})
|
|
277
|
-
});
|
|
278
|
-
return /* @__PURE__ */ jsx(Fragment, { children: usedEntity && /* @__PURE__ */ jsx(EntityViewBinding, {
|
|
279
|
-
entity: usedEntity,
|
|
280
|
-
collection,
|
|
281
|
-
path,
|
|
282
|
-
asPage: true,
|
|
283
|
-
openEntityMode: layout,
|
|
284
|
-
formContext: readOnlyFormContext
|
|
285
|
-
}) });
|
|
286
|
-
};
|
|
238
|
+
const propertyDetailView = () => usedEntity ? /* @__PURE__ */ jsx(EntityViewBody, {
|
|
239
|
+
entity: usedEntity,
|
|
240
|
+
collection,
|
|
241
|
+
path,
|
|
242
|
+
formContext: readOnlyFormContext,
|
|
243
|
+
openEntityMode: layout,
|
|
244
|
+
parentCollectionSlugs,
|
|
245
|
+
parentEntityIds
|
|
246
|
+
}) : null;
|
|
287
247
|
const subcollectionTabs = subcollections && subcollections.map((subcollection) => {
|
|
288
248
|
const icon = getIcon(subcollection.icon, void 0, void 0, "smallest");
|
|
289
249
|
return /* @__PURE__ */ jsx(Tab, {
|
|
@@ -358,7 +318,11 @@ function DetailViewBindingInner({ path, entityId, selectedTab: selectedTabProp,
|
|
|
358
318
|
onClose: onCloseRequest,
|
|
359
319
|
onInspect: includeJsonView ? () => setInspectorTab("json") : void 0,
|
|
360
320
|
onViewHistory: includeHistoryView ? () => setInspectorTab("history") : void 0,
|
|
361
|
-
externalLink: usedEntity ? customizationController?.entityLinkBuilder?.({
|
|
321
|
+
externalLink: usedEntity ? customizationController?.entityLinkBuilder?.({
|
|
322
|
+
row: rowOfEntity(usedEntity, collection),
|
|
323
|
+
id: String(usedEntity.id),
|
|
324
|
+
path: usedEntity.path
|
|
325
|
+
}) : void 0,
|
|
362
326
|
recordActions,
|
|
363
327
|
primaryAction: editButton,
|
|
364
328
|
leading: /* @__PURE__ */ jsxs(Fragment, { children: [
|