@firecms/collection_editor 3.0.0-alpha.9 → 3.0.0-beta.10

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.
Files changed (149) hide show
  1. package/LICENSE +114 -21
  2. package/dist/ConfigControllerProvider.d.ts +13 -3
  3. package/dist/index.d.ts +4 -2
  4. package/dist/index.es.js +5587 -4976
  5. package/dist/index.es.js.map +1 -1
  6. package/dist/index.umd.js +6829 -1
  7. package/dist/index.umd.js.map +1 -1
  8. package/dist/types/collection_editor_controller.d.ts +36 -8
  9. package/dist/types/collection_inference.d.ts +1 -1
  10. package/dist/types/config_controller.d.ts +33 -6
  11. package/dist/types/persisted_collection.d.ts +4 -2
  12. package/dist/ui/CollectionViewHeaderAction.d.ts +11 -0
  13. package/dist/{components → ui}/EditorCollectionAction.d.ts +1 -1
  14. package/dist/ui/EditorCollectionActionStart.d.ts +2 -0
  15. package/dist/ui/MissingReferenceWidget.d.ts +3 -0
  16. package/dist/ui/NewCollectionButton.d.ts +1 -0
  17. package/dist/ui/PropertyAddColumnComponent.d.ts +8 -0
  18. package/dist/{components → ui}/collection_editor/CollectionDetailsForm.d.ts +3 -2
  19. package/dist/{components → ui}/collection_editor/CollectionEditorDialog.d.ts +15 -11
  20. package/dist/{components → ui}/collection_editor/CollectionEditorWelcomeView.d.ts +3 -3
  21. package/dist/{components → ui}/collection_editor/CollectionPropertiesEditorForm.d.ts +8 -6
  22. package/dist/{components → ui}/collection_editor/CollectionYupValidation.d.ts +3 -0
  23. package/dist/ui/collection_editor/EntityCustomViewsSelectDialog.d.ts +4 -0
  24. package/dist/{components → ui}/collection_editor/EnumForm.d.ts +1 -2
  25. package/dist/ui/collection_editor/GetCodeDialog.d.ts +5 -0
  26. package/dist/{components → ui}/collection_editor/PropertyEditView.d.ts +21 -11
  27. package/dist/{components → ui}/collection_editor/PropertyFieldPreview.d.ts +4 -3
  28. package/dist/{components → ui}/collection_editor/PropertyTree.d.ts +11 -7
  29. package/dist/{components → ui}/collection_editor/SubcollectionsEditTab.d.ts +3 -3
  30. package/dist/ui/collection_editor/SwitchControl.d.ts +8 -0
  31. package/dist/{components → ui}/collection_editor/import/CollectionEditorImportDataPreview.d.ts +1 -1
  32. package/dist/ui/collection_editor/import/CollectionEditorImportMapping.d.ts +14 -0
  33. package/dist/{components → ui}/collection_editor/import/clean_import_data.d.ts +1 -1
  34. package/dist/{components → ui}/collection_editor/properties/BlockPropertyField.d.ts +4 -1
  35. package/dist/{components → ui}/collection_editor/properties/CommonPropertyFields.d.ts +1 -1
  36. package/dist/{components → ui}/collection_editor/properties/MapPropertyField.d.ts +4 -1
  37. package/dist/ui/collection_editor/properties/MarkdownPropertyField.d.ts +4 -0
  38. package/dist/{components → ui}/collection_editor/properties/RepeatPropertyField.d.ts +4 -1
  39. package/dist/{components → ui}/collection_editor/properties/StringPropertyField.d.ts +1 -1
  40. package/dist/ui/collection_editor/properties/UrlPropertyField.d.ts +4 -0
  41. package/dist/ui/collection_editor/templates/blog_template.d.ts +2 -0
  42. package/dist/ui/collection_editor/templates/pages_template.d.ts +2 -0
  43. package/dist/ui/collection_editor/templates/products_template.d.ts +2 -0
  44. package/dist/ui/collection_editor/templates/users_template.d.ts +2 -0
  45. package/dist/{components → ui}/collection_editor/util.d.ts +1 -0
  46. package/dist/ui/collection_editor/utils/strings.d.ts +1 -0
  47. package/dist/ui/collection_editor/utils/supported_fields.d.ts +3 -0
  48. package/dist/ui/collection_editor/utils/update_property_for_widget.d.ts +2 -0
  49. package/dist/useCollectionEditorPlugin.d.ts +17 -6
  50. package/dist/utils/collections.d.ts +6 -0
  51. package/dist/utils/entities.d.ts +3 -4
  52. package/package.json +35 -37
  53. package/src/ConfigControllerProvider.tsx +350 -0
  54. package/src/index.ts +36 -0
  55. package/src/types/collection_editor_controller.tsx +53 -0
  56. package/src/types/collection_inference.ts +3 -0
  57. package/src/types/config_controller.tsx +60 -0
  58. package/src/types/config_permissions.ts +20 -0
  59. package/src/types/persisted_collection.ts +9 -0
  60. package/src/ui/CollectionViewHeaderAction.tsx +48 -0
  61. package/src/ui/EditorCollectionAction.tsx +56 -0
  62. package/src/ui/EditorCollectionActionStart.tsx +88 -0
  63. package/src/ui/HomePageEditorCollectionAction.tsx +89 -0
  64. package/src/ui/MissingReferenceWidget.tsx +37 -0
  65. package/src/ui/NewCollectionButton.tsx +18 -0
  66. package/src/ui/NewCollectionCard.tsx +48 -0
  67. package/src/ui/PropertyAddColumnComponent.tsx +47 -0
  68. package/src/ui/collection_editor/CollectionDetailsForm.tsx +426 -0
  69. package/src/ui/collection_editor/CollectionEditorDialog.tsx +826 -0
  70. package/src/ui/collection_editor/CollectionEditorWelcomeView.tsx +214 -0
  71. package/src/ui/collection_editor/CollectionPropertiesEditorForm.tsx +513 -0
  72. package/src/ui/collection_editor/CollectionYupValidation.tsx +7 -0
  73. package/src/ui/collection_editor/EntityCustomViewsSelectDialog.tsx +37 -0
  74. package/src/ui/collection_editor/EnumForm.tsx +357 -0
  75. package/src/ui/collection_editor/GetCodeDialog.tsx +122 -0
  76. package/src/ui/collection_editor/PropertyEditView.tsx +789 -0
  77. package/src/ui/collection_editor/PropertyFieldPreview.tsx +204 -0
  78. package/src/ui/collection_editor/PropertyTree.tsx +254 -0
  79. package/src/ui/collection_editor/SubcollectionsEditTab.tsx +269 -0
  80. package/src/ui/collection_editor/SwitchControl.tsx +39 -0
  81. package/src/ui/collection_editor/UnsavedChangesDialog.tsx +47 -0
  82. package/src/ui/collection_editor/import/CollectionEditorImportDataPreview.tsx +53 -0
  83. package/src/ui/collection_editor/import/CollectionEditorImportMapping.tsx +299 -0
  84. package/src/ui/collection_editor/import/clean_import_data.ts +53 -0
  85. package/src/ui/collection_editor/properties/BlockPropertyField.tsx +144 -0
  86. package/src/ui/collection_editor/properties/BooleanPropertyField.tsx +40 -0
  87. package/src/ui/collection_editor/properties/CommonPropertyFields.tsx +110 -0
  88. package/src/ui/collection_editor/properties/DateTimePropertyField.tsx +89 -0
  89. package/src/ui/collection_editor/properties/EnumPropertyField.tsx +114 -0
  90. package/src/ui/collection_editor/properties/KeyValuePropertyField.tsx +20 -0
  91. package/src/ui/collection_editor/properties/MapPropertyField.tsx +150 -0
  92. package/src/ui/collection_editor/properties/MarkdownPropertyField.tsx +139 -0
  93. package/src/ui/collection_editor/properties/NumberPropertyField.tsx +38 -0
  94. package/src/ui/collection_editor/properties/ReferencePropertyField.tsx +160 -0
  95. package/src/ui/collection_editor/properties/RepeatPropertyField.tsx +108 -0
  96. package/src/ui/collection_editor/properties/StoragePropertyField.tsx +215 -0
  97. package/src/ui/collection_editor/properties/StringPropertyField.tsx +70 -0
  98. package/src/ui/collection_editor/properties/UrlPropertyField.tsx +89 -0
  99. package/src/ui/collection_editor/properties/advanced/AdvancedPropertyValidation.tsx +45 -0
  100. package/src/ui/collection_editor/properties/validation/ArrayPropertyValidation.tsx +50 -0
  101. package/src/ui/collection_editor/properties/validation/GeneralPropertyValidation.tsx +61 -0
  102. package/src/ui/collection_editor/properties/validation/NumberPropertyValidation.tsx +115 -0
  103. package/src/ui/collection_editor/properties/validation/StringPropertyValidation.tsx +150 -0
  104. package/src/ui/collection_editor/properties/validation/ValidationPanel.tsx +28 -0
  105. package/src/ui/collection_editor/templates/blog_template.ts +115 -0
  106. package/src/ui/collection_editor/templates/pages_template.ts +183 -0
  107. package/src/ui/collection_editor/templates/products_template.ts +88 -0
  108. package/src/ui/collection_editor/templates/users_template.ts +42 -0
  109. package/src/ui/collection_editor/util.ts +28 -0
  110. package/src/ui/collection_editor/utils/strings.ts +9 -0
  111. package/src/ui/collection_editor/utils/supported_fields.tsx +29 -0
  112. package/src/ui/collection_editor/utils/update_property_for_widget.ts +271 -0
  113. package/src/ui/collection_editor/utils/useTraceUpdate.tsx +23 -0
  114. package/src/useCollectionEditorController.tsx +9 -0
  115. package/src/useCollectionEditorPlugin.tsx +164 -0
  116. package/src/useCollectionsConfigController.tsx +9 -0
  117. package/src/utils/arrays.ts +3 -0
  118. package/src/utils/collections.ts +30 -0
  119. package/src/utils/entities.ts +38 -0
  120. package/src/vite-env.d.ts +1 -0
  121. package/dist/components/collection_editor/PropertySelectItem.d.ts +0 -8
  122. package/dist/components/collection_editor/SelectIcons.d.ts +0 -6
  123. package/dist/components/collection_editor/import/CollectionEditorImportMapping.d.ts +0 -4
  124. package/dist/components/collection_editor/properties/FieldHelperView.d.ts +0 -4
  125. package/dist/components/collection_editor/templates/blog_template.d.ts +0 -10
  126. package/dist/components/collection_editor/templates/products_template.d.ts +0 -12
  127. package/dist/components/collection_editor/templates/users_template.d.ts +0 -7
  128. package/dist/components/collection_editor/utils/supported_fields.d.ts +0 -3
  129. package/dist/components/collection_editor/utils/update_property_for_widget.d.ts +0 -3
  130. package/dist/types/editable_properties.d.ts +0 -10
  131. package/dist/utils/icons.d.ts +0 -2
  132. package/dist/utils/synonyms.d.ts +0 -1951
  133. /package/dist/{components → ui}/HomePageEditorCollectionAction.d.ts +0 -0
  134. /package/dist/{components → ui}/NewCollectionCard.d.ts +0 -0
  135. /package/dist/{components → ui}/collection_editor/UnsavedChangesDialog.d.ts +0 -0
  136. /package/dist/{components → ui}/collection_editor/properties/BooleanPropertyField.d.ts +0 -0
  137. /package/dist/{components → ui}/collection_editor/properties/DateTimePropertyField.d.ts +0 -0
  138. /package/dist/{components → ui}/collection_editor/properties/EnumPropertyField.d.ts +0 -0
  139. /package/dist/{components → ui}/collection_editor/properties/KeyValuePropertyField.d.ts +0 -0
  140. /package/dist/{components → ui}/collection_editor/properties/NumberPropertyField.d.ts +0 -0
  141. /package/dist/{components → ui}/collection_editor/properties/ReferencePropertyField.d.ts +0 -0
  142. /package/dist/{components → ui}/collection_editor/properties/StoragePropertyField.d.ts +0 -0
  143. /package/dist/{components → ui}/collection_editor/properties/advanced/AdvancedPropertyValidation.d.ts +0 -0
  144. /package/dist/{components → ui}/collection_editor/properties/validation/ArrayPropertyValidation.d.ts +0 -0
  145. /package/dist/{components → ui}/collection_editor/properties/validation/GeneralPropertyValidation.d.ts +0 -0
  146. /package/dist/{components → ui}/collection_editor/properties/validation/NumberPropertyValidation.d.ts +0 -0
  147. /package/dist/{components → ui}/collection_editor/properties/validation/StringPropertyValidation.d.ts +0 -0
  148. /package/dist/{components → ui}/collection_editor/properties/validation/ValidationPanel.d.ts +0 -0
  149. /package/dist/{components → ui}/collection_editor/utils/useTraceUpdate.d.ts +0 -0
@@ -0,0 +1,20 @@
1
+ import { EntityCollection } from "@firecms/core";
2
+
3
+ export type CollectionEditorPermissionsBuilder<UserType = any, EC extends EntityCollection = EntityCollection> = (params: { user: UserType | null, collection?: EC }) => CollectionEditorPermissions;
4
+
5
+ export type CollectionEditorPermissions = {
6
+ /**
7
+ * Is the user allowed to create new collections.
8
+ */
9
+ createCollections: boolean;
10
+
11
+ /**
12
+ * Is the user allowed to modify this collection
13
+ */
14
+ editCollections: boolean;
15
+
16
+ /**
17
+ * Is the user allowed to delete this collection
18
+ */
19
+ deleteCollections: boolean;
20
+ }
@@ -0,0 +1,9 @@
1
+ import { EntityCollection, User } from "@firecms/core";
2
+
3
+ export type PersistedCollection<M extends Record<string, any> = any, UserType extends User = User>
4
+ = Omit<EntityCollection<M, UserType>, "subcollections"> & {
5
+ // properties: Properties<M>;
6
+ ownerId?: string;
7
+ subcollections?: PersistedCollection<any, any>[];
8
+ editable?: boolean;
9
+ }
@@ -0,0 +1,48 @@
1
+ import { EntityTableController, ResolvedProperty } from "@firecms/core";
2
+ import { IconButton, SettingsIcon, Tooltip } from "@firecms/ui";
3
+ import React from "react";
4
+ import { useCollectionEditorController } from "../useCollectionEditorController";
5
+ import { PersistedCollection } from "../types/persisted_collection";
6
+
7
+ export function CollectionViewHeaderAction({
8
+ propertyKey,
9
+ onHover,
10
+ property,
11
+ fullPath,
12
+ parentCollectionIds,
13
+ collection,
14
+ tableController
15
+ }: {
16
+ property: ResolvedProperty,
17
+ propertyKey: string,
18
+ onHover: boolean,
19
+ fullPath: string,
20
+ parentCollectionIds: string[],
21
+ collection: PersistedCollection;
22
+ tableController: EntityTableController;
23
+ }) {
24
+
25
+ const collectionEditorController = useCollectionEditorController();
26
+
27
+ return (
28
+ <Tooltip
29
+ asChild={true}
30
+ title={"Edit"}>
31
+ <IconButton
32
+ className={onHover ? "bg-white dark:bg-gray-950" : "hidden"}
33
+ onClick={() => {
34
+ collectionEditorController.editProperty({
35
+ propertyKey,
36
+ property,
37
+ editedCollectionId: collection.id,
38
+ parentCollectionIds,
39
+ collection,
40
+ existingEntities: tableController.data ?? []
41
+ });
42
+ }}
43
+ size={"small"}>
44
+ <SettingsIcon size={"small"}/>
45
+ </IconButton>
46
+ </Tooltip>
47
+ )
48
+ }
@@ -0,0 +1,56 @@
1
+ import { CollectionActionsProps, useAuthController, useNavigationController } from "@firecms/core";
2
+ import { IconButton, SettingsIcon, Tooltip, } from "@firecms/ui";
3
+
4
+ import { useCollectionEditorController } from "../useCollectionEditorController";
5
+ import { PersistedCollection } from "../types/persisted_collection";
6
+
7
+ export function EditorCollectionAction({
8
+ path: fullPath,
9
+ parentCollectionIds,
10
+ collection,
11
+ tableController
12
+ }: CollectionActionsProps) {
13
+
14
+ const authController = useAuthController();
15
+ const navigationController = useNavigationController();
16
+ const collectionEditorController = useCollectionEditorController();
17
+
18
+ const parentCollection = navigationController.getCollectionFromIds(parentCollectionIds);
19
+
20
+ const canEditCollection = collectionEditorController.configPermissions
21
+ ? collectionEditorController.configPermissions({
22
+ user: authController.user,
23
+ collection
24
+ }).editCollections
25
+ : true;
26
+
27
+ const editorButton = <Tooltip
28
+ asChild={true}
29
+ title={canEditCollection ? "Edit collection" : "You don't have permissions to edit this collection"}>
30
+ <IconButton
31
+ color={"primary"}
32
+ disabled={!canEditCollection}
33
+ onClick={canEditCollection
34
+ ? () => collectionEditorController?.editCollection({
35
+ id: collection.id,
36
+ fullPath,
37
+ parentCollectionIds,
38
+ parentCollection: parentCollection as PersistedCollection,
39
+ existingEntities: tableController?.data ?? []
40
+ })
41
+ : undefined}>
42
+ <SettingsIcon/>
43
+ </IconButton>
44
+ </Tooltip>;
45
+
46
+ return <>
47
+ {editorButton}
48
+ </>
49
+
50
+ }
51
+
52
+ function getObjectOrNull(o?: object): object | null {
53
+ if (o && Object.keys(o).length === 0)
54
+ return o
55
+ return o ?? null;
56
+ }
@@ -0,0 +1,88 @@
1
+ import equal from "react-fast-compare"
2
+
3
+ import { CollectionActionsProps, mergeDeep, useAuthController, useSnackbarController } from "@firecms/core";
4
+ import { Button, SaveIcon, Tooltip, UndoIcon, } from "@firecms/ui";
5
+
6
+ import { useCollectionEditorController } from "../useCollectionEditorController";
7
+ import { useCollectionsConfigController } from "../useCollectionsConfigController";
8
+ import { PersistedCollection } from "../types/persisted_collection";
9
+
10
+ export function EditorCollectionActionStart({
11
+ path: fullPath,
12
+ parentCollectionIds,
13
+ collection,
14
+ tableController
15
+ }: CollectionActionsProps) {
16
+
17
+ const authController = useAuthController();
18
+ const collectionEditorController = useCollectionEditorController();
19
+ const configController = useCollectionsConfigController();
20
+ const snackbarController = useSnackbarController();
21
+
22
+ const canEditCollection = collectionEditorController.configPermissions
23
+ ? collectionEditorController.configPermissions({
24
+ user: authController.user,
25
+ collection
26
+ }).editCollections
27
+ : true;
28
+
29
+ let saveDefaultFilterButton = null;
30
+ if (!equal(getObjectOrNull(tableController.filterValues), getObjectOrNull(collection.initialFilter)) ||
31
+ !equal(getObjectOrNull(tableController.sortBy), getObjectOrNull(collection.initialSort))) {
32
+ saveDefaultFilterButton = <>
33
+ <Tooltip
34
+ asChild={true}
35
+ title={tableController.sortBy || tableController.filterValues ? "Save default filter and sort" : "Clear default filter and sort"}>
36
+ <Button
37
+ color={"primary"}
38
+ size={"small"}
39
+ variant={"outlined"}
40
+ onClick={() => configController
41
+ ?.saveCollection({
42
+ id: collection.id,
43
+ parentCollectionIds,
44
+ collectionData: mergeDeep(collection as PersistedCollection,
45
+ {
46
+ initialFilter: tableController.filterValues ?? null,
47
+ initialSort: tableController.sortBy ?? null
48
+ })
49
+ }).then(() => {
50
+ snackbarController.open({
51
+ type: "success",
52
+ message: "Default config saved"
53
+ });
54
+ })}>
55
+ <SaveIcon/>
56
+ </Button>
57
+ </Tooltip>
58
+
59
+ {(collection.initialFilter || collection.initialSort) && <Tooltip
60
+ title={"Reset to default filter and sort"}>
61
+ <Button
62
+ color={"primary"}
63
+ size={"small"}
64
+ variant={"text"}
65
+ onClick={() => {
66
+ tableController.clearFilter?.();
67
+ if (collection?.initialFilter)
68
+ tableController.setFilterValues?.(collection?.initialFilter);
69
+ if (collection?.initialSort)
70
+ tableController.setSortBy?.(collection?.initialSort);
71
+ }}>
72
+ <UndoIcon/>
73
+ </Button>
74
+ </Tooltip>}
75
+ </>;
76
+ }
77
+
78
+ return <>
79
+ {canEditCollection && saveDefaultFilterButton}
80
+ </>
81
+
82
+ }
83
+
84
+ function getObjectOrNull(o?: object): object | null {
85
+ if (o && Object.keys(o).length === 0)
86
+ return o
87
+ return o ?? null;
88
+ }
@@ -0,0 +1,89 @@
1
+ import {
2
+ ConfirmationDialog,
3
+ PluginHomePageActionsProps,
4
+ useAuthController,
5
+ useSnackbarController
6
+ } from "@firecms/core";
7
+ import { DeleteIcon, IconButton, Menu, MenuItem, MoreVertIcon, SettingsIcon, } from "@firecms/ui";
8
+ import { useCollectionEditorController } from "../useCollectionEditorController";
9
+ import { useState } from "react";
10
+ import { useCollectionsConfigController } from "../useCollectionsConfigController";
11
+
12
+ export function HomePageEditorCollectionAction({
13
+ path,
14
+ collection
15
+ }: PluginHomePageActionsProps) {
16
+
17
+ const snackbarController = useSnackbarController();
18
+ const authController = useAuthController();
19
+ const configController = useCollectionsConfigController();
20
+ const collectionEditorController = useCollectionEditorController();
21
+
22
+ const permissions = collectionEditorController.configPermissions({
23
+ user: authController.user,
24
+ collection
25
+ });
26
+
27
+ const onEditCollectionClicked = () => {
28
+ collectionEditorController?.editCollection({
29
+ id: collection.id,
30
+ parentCollectionIds: []
31
+ });
32
+ };
33
+
34
+ const [deleteRequested, setDeleteRequested] = useState(false);
35
+
36
+ const deleteCollection = () => {
37
+ configController?.deleteCollection({ id: collection.id }).then(() => {
38
+ setDeleteRequested(false);
39
+ snackbarController.open({
40
+ message: "Collection deleted",
41
+ type: "success"
42
+ });
43
+ });
44
+ };
45
+
46
+ return <>
47
+
48
+ <div>
49
+ {permissions.deleteCollections &&
50
+ <Menu
51
+ trigger={<IconButton>
52
+ <MoreVertIcon size={"small"}/>
53
+ </IconButton>}
54
+ >
55
+ <MenuItem
56
+ dense={true}
57
+ onClick={(event) => {
58
+ event.preventDefault();
59
+ event.stopPropagation();
60
+ setDeleteRequested(true);
61
+ }}>
62
+ <DeleteIcon/>
63
+ Delete
64
+ </MenuItem>
65
+
66
+ </Menu>
67
+
68
+ }
69
+
70
+ {permissions.editCollections &&
71
+ <IconButton
72
+ onClick={(event) => {
73
+ onEditCollectionClicked();
74
+ }}>
75
+ <SettingsIcon size={"small"}/>
76
+ </IconButton>}
77
+ </div>
78
+
79
+ <ConfirmationDialog
80
+ open={deleteRequested}
81
+ onAccept={deleteCollection}
82
+ onCancel={() => setDeleteRequested(false)}
83
+ title={<>Delete this collection?</>}
84
+ body={<> This will <b>not
85
+ delete any data</b>, only
86
+ the collection in the CMS</>}/>
87
+ </>;
88
+
89
+ }
@@ -0,0 +1,37 @@
1
+ import { ErrorView, unslugify, useNavigationController } from "@firecms/core";
2
+ import { useCollectionEditorController } from "../useCollectionEditorController";
3
+ import { Button } from "@firecms/ui";
4
+
5
+ export function MissingReferenceWidget({ path: pathProp }: {
6
+ path: string
7
+ }) {
8
+ const navigation = useNavigationController();
9
+ const path = getLastSegment(pathProp);
10
+ const parentCollectionIds = navigation.getParentCollectionIds(pathProp);
11
+ const collectionEditor = useCollectionEditorController();
12
+ return <div className={"p-1 flex flex-col items-center"}>
13
+ <ErrorView error={"No collection for path: " + path}/>
14
+ <Button className={"mx-2"} variant={"outlined"}
15
+ size={"small"}
16
+ onClick={() => {
17
+ collectionEditor.createCollection({
18
+ initialValues: { path, name: unslugify(path) },
19
+ parentCollectionIds,
20
+ redirect: false,
21
+ sourceClick: "missing_reference"
22
+ });
23
+ }}>
24
+ Create
25
+ </Button>
26
+ </div>;
27
+ }
28
+
29
+ function getParentPathSegments(path: string): string[] {
30
+ const segments = path.split("/");
31
+ return segments.filter((segment, index) => index % 2 === 0 && index !== segments.length - 1);
32
+ }
33
+
34
+ function getLastSegment(path: string): string {
35
+ const segments = path.split("/");
36
+ return segments[segments.length - 1];
37
+ }
@@ -0,0 +1,18 @@
1
+ import { AddIcon, Button } from "@firecms/ui";
2
+ import { useCollectionEditorController } from "../useCollectionEditorController";
3
+
4
+ export function NewCollectionButton() {
5
+ const collectionEditorController = useCollectionEditorController();
6
+ return <div className={"bg-gray-50 dark:bg-gray-900 min-w-fit rounded"}>
7
+ <Button className={"min-w-fit"}
8
+ variant={"outlined"}
9
+ onClick={() => collectionEditorController.createCollection({
10
+ parentCollectionIds: [],
11
+ redirect: true,
12
+ sourceClick: "new_collection_button"
13
+ })}>
14
+ <AddIcon/>
15
+ New collection
16
+ </Button>
17
+ </div>
18
+ }
@@ -0,0 +1,48 @@
1
+ import { PluginHomePageAdditionalCardsProps, useAuthController } from "@firecms/core";
2
+ import { AddIcon, Card, cls, Typography } from "@firecms/ui";
3
+ import { useCollectionEditorController } from "../useCollectionEditorController";
4
+
5
+ export function NewCollectionCard({
6
+ group,
7
+ context
8
+ }: PluginHomePageAdditionalCardsProps) {
9
+
10
+ if (!context.navigation.topLevelNavigation)
11
+ throw Error("Navigation not ready in FireCMSHomePage");
12
+
13
+ const authController = useAuthController();
14
+
15
+ const collectionEditorController = useCollectionEditorController();
16
+ const canCreateCollections = collectionEditorController.configPermissions
17
+ ? collectionEditorController.configPermissions({
18
+ user: authController.user,
19
+ }).createCollections
20
+ : true;
21
+
22
+ return (
23
+ <Card className={cls("h-full p-4 min-h-[124px]")}
24
+ onClick={collectionEditorController && canCreateCollections
25
+ ? () => collectionEditorController.createCollection({
26
+ initialValues: group ? { group } : undefined,
27
+ parentCollectionIds: [],
28
+ redirect: true,
29
+ sourceClick: "new_collection_card"
30
+ })
31
+ : undefined}>
32
+
33
+ <div
34
+ className="flex items-center justify-center h-full w-full flex-grow flex-col">
35
+ <AddIcon color="primary" size={"large"}/>
36
+ <Typography color="primary"
37
+ variant={"caption"}
38
+ className={"font-medium"}>{"Add new collection".toUpperCase()}</Typography>
39
+
40
+ {!canCreateCollections &&
41
+ <Typography variant={"caption"}>You don&apos;t have permissions to create
42
+ collections</Typography>
43
+ }
44
+ </div>
45
+
46
+ </Card>
47
+ );
48
+ }
@@ -0,0 +1,47 @@
1
+ import { EntityTableController, getDefaultPropertiesOrder, useAuthController } from "@firecms/core";
2
+ import { AddIcon, Tooltip } from "@firecms/ui";
3
+ import { useCollectionEditorController } from "../useCollectionEditorController";
4
+ import { PersistedCollection } from "../types/persisted_collection";
5
+
6
+ export function PropertyAddColumnComponent({
7
+ fullPath,
8
+ parentCollectionIds,
9
+ collection,
10
+ tableController
11
+ }: {
12
+ fullPath: string,
13
+ parentCollectionIds: string[],
14
+ collection: PersistedCollection;
15
+ tableController: EntityTableController;
16
+ }) {
17
+
18
+ const authController = useAuthController();
19
+ const collectionEditorController = useCollectionEditorController();
20
+ const canEditCollection = collectionEditorController.configPermissions
21
+ ? collectionEditorController.configPermissions({
22
+ user: authController.user,
23
+ collection
24
+ }).editCollections
25
+ : true;
26
+
27
+ return (
28
+ <Tooltip
29
+ asChild={true}
30
+ title={canEditCollection ? "Add new property" : "You don't have permission to add new properties"}>
31
+ <div
32
+ className={"p-0.5 w-20 h-full flex items-center justify-center cursor-pointer bg-gray-100 bg-opacity-40 hover:bg-gray-100 dark:bg-gray-950 dark:bg-opacity-40 dark:hover:bg-gray-950"}
33
+ // className={onHover ? "bg-white dark:bg-gray-950" : undefined}
34
+ onClick={() => {
35
+ collectionEditorController.editProperty({
36
+ editedCollectionId: collection.id,
37
+ parentCollectionIds,
38
+ currentPropertiesOrder: getDefaultPropertiesOrder(collection),
39
+ collection,
40
+ existingEntities: tableController.data
41
+ });
42
+ }}>
43
+ <AddIcon color={"inherit"}/>
44
+ </div>
45
+ </Tooltip>
46
+ )
47
+ }