@firecms/collection_editor 3.0.0-canary.40 → 3.0.0-canary.42

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 (30) hide show
  1. package/LICENSE +113 -21
  2. package/dist/ConfigControllerProvider.d.ts +2 -2
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.es.js +1680 -1684
  5. package/dist/index.es.js.map +1 -1
  6. package/dist/index.umd.js +2 -2
  7. package/dist/index.umd.js.map +1 -1
  8. package/dist/types/collection_editor_controller.d.ts +1 -1
  9. package/dist/ui/collection_editor/CollectionEditorDialog.d.ts +1 -1
  10. package/dist/ui/collection_editor/CollectionEditorWelcomeView.d.ts +1 -1
  11. package/dist/ui/collection_editor/CollectionPropertiesEditorForm.d.ts +1 -1
  12. package/dist/ui/collection_editor/PropertyTree.d.ts +9 -9
  13. package/dist/ui/collection_editor/SubcollectionsEditTab.d.ts +1 -1
  14. package/dist/useCollectionEditorPlugin.d.ts +6 -7
  15. package/dist/utils/collections.d.ts +6 -0
  16. package/package.json +6 -6
  17. package/src/ConfigControllerProvider.tsx +28 -34
  18. package/src/index.ts +1 -0
  19. package/src/types/collection_editor_controller.tsx +1 -1
  20. package/src/ui/collection_editor/CollectionDetailsForm.tsx +1 -1
  21. package/src/ui/collection_editor/CollectionEditorDialog.tsx +26 -11
  22. package/src/ui/collection_editor/CollectionEditorWelcomeView.tsx +2 -2
  23. package/src/ui/collection_editor/CollectionPropertiesEditorForm.tsx +2 -2
  24. package/src/ui/collection_editor/SubcollectionsEditTab.tsx +1 -1
  25. package/src/ui/collection_editor/import/CollectionEditorImportDataPreview.tsx +20 -5
  26. package/src/ui/collection_editor/import/CollectionEditorImportMapping.tsx +9 -3
  27. package/src/useCollectionEditorPlugin.tsx +24 -23
  28. package/src/utils/collections.ts +30 -0
  29. package/dist/ui/RootCollectionSuggestions.d.ts +0 -3
  30. package/src/ui/RootCollectionSuggestions.tsx +0 -63
@@ -4,17 +4,16 @@ import { ConfigControllerProvider } from "./ConfigControllerProvider";
4
4
  import { CollectionEditorPermissionsBuilder } from "./types/config_permissions";
5
5
  import { EditorCollectionAction } from "./ui/EditorCollectionAction";
6
6
  import { HomePageEditorCollectionAction } from "./ui/HomePageEditorCollectionAction";
7
- import { NewCollectionCard } from "./ui/NewCollectionCard";
8
7
  import { PersistedCollection } from "./types/persisted_collection";
9
8
  import { CollectionInference } from "./types/collection_inference";
10
9
  import { CollectionsConfigController } from "./types/config_controller";
11
- import { RootCollectionSuggestions } from "./ui/RootCollectionSuggestions";
12
10
  import { CollectionViewHeaderAction } from "./ui/CollectionViewHeaderAction";
13
11
  import { PropertyAddColumnComponent } from "./ui/PropertyAddColumnComponent";
14
12
  import { NewCollectionButton } from "./ui/NewCollectionButton";
15
- import { AddIcon, Button, Typography } from "@firecms/ui";
13
+ import { AddIcon, Button, Paper, Typography } from "@firecms/ui";
16
14
  import { useCollectionEditorController } from "./useCollectionEditorController";
17
15
  import { EditorCollectionActionStart } from "./ui/EditorCollectionActionStart";
16
+ import { NewCollectionCard } from "./ui/NewCollectionCard";
18
17
 
19
18
  export interface CollectionConfigControllerProps<EC extends PersistedCollection = PersistedCollection, UserType extends User = User> {
20
19
 
@@ -33,7 +32,7 @@ export interface CollectionConfigControllerProps<EC extends PersistedCollection
33
32
  * names when creating collections.
34
33
  * e.g. ["admin"]
35
34
  */
36
- reservedGroups: string[];
35
+ reservedGroups?: string[];
37
36
 
38
37
  extraView?: {
39
38
  View: React.ComponentType<{
@@ -42,18 +41,16 @@ export interface CollectionConfigControllerProps<EC extends PersistedCollection
42
41
  icon: React.ReactNode
43
42
  };
44
43
 
45
- pathSuggestions?: (path: string) => Promise<string[]>;
44
+ getPathSuggestions?: (path?: string) => Promise<string[]>;
46
45
 
47
46
  collectionInference?: CollectionInference;
48
47
 
49
48
  getData?: (path: string, parentPaths: string[]) => Promise<object[]>;
50
49
 
51
- getUser: (uid: string) => UserType | null;
50
+ getUser?: (uid: string) => UserType | null;
52
51
 
53
52
  onAnalyticsEvent?: (event: string, params?: object) => void;
54
53
 
55
- introMode?: "new_project" | "existing_project";
56
-
57
54
  }
58
55
 
59
56
  /**
@@ -63,18 +60,17 @@ export interface CollectionConfigControllerProps<EC extends PersistedCollection
63
60
  * @param configPermissions
64
61
  * @param reservedGroups
65
62
  * @param extraView
66
- * @param pathSuggestions
63
+ * @param getPathsSuggestions
67
64
  * @param getUser
68
65
  * @param collectionInference
69
66
  */
70
67
  export function useCollectionEditorPlugin<EC extends PersistedCollection = PersistedCollection, UserType extends User = User>
71
68
  ({
72
69
  collectionConfigController,
73
- introMode,
74
70
  configPermissions,
75
71
  reservedGroups,
76
72
  extraView,
77
- pathSuggestions,
73
+ getPathSuggestions,
78
74
  getUser,
79
75
  collectionInference,
80
76
  getData,
@@ -92,7 +88,7 @@ export function useCollectionEditorPlugin<EC extends PersistedCollection = Persi
92
88
  collectionInference,
93
89
  reservedGroups,
94
90
  extraView,
95
- pathSuggestions,
91
+ getPathSuggestions,
96
92
  getUser,
97
93
  getData,
98
94
  onAnalyticsEvent
@@ -100,10 +96,10 @@ export function useCollectionEditorPlugin<EC extends PersistedCollection = Persi
100
96
  },
101
97
  homePage: {
102
98
  additionalActions: <NewCollectionButton/>,
103
- additionalChildrenStart: introMode ? <IntroWidget introMode={introMode}/> : undefined,
104
- additionalChildrenEnd: <RootCollectionSuggestions introMode={introMode}/>,
99
+ additionalChildrenStart: <IntroWidget/>,
100
+ // additionalChildrenEnd: <RootCollectionSuggestions introMode={introMode}/>,
105
101
  CollectionActions: HomePageEditorCollectionAction,
106
- AdditionalCards: introMode ? undefined : NewCollectionCard,
102
+ AdditionalCards: NewCollectionCard,
107
103
  },
108
104
  collectionView: {
109
105
  CollectionActionsStart: EditorCollectionActionStart,
@@ -131,17 +127,19 @@ export function IntroWidget({ introMode }: {
131
127
  }).createCollections
132
128
  : true;
133
129
 
130
+ if ((navigation.collections ?? []).length > 0) {
131
+ return null;
132
+ }
133
+
134
134
  return (
135
- <div className={"mt-8 flex flex-col mt-8 p-2"}>
136
- <Typography variant={"h4"} className="mb-4">Welcome</Typography>
137
- <Typography paragraph={true}>Your admin panel is ready ✌️</Typography>
138
- <Typography paragraph={true}>
135
+ <Paper
136
+ className={"my-4 px-4 py-6 flex flex-col bg-white dark:bg-slate-800 gap-2"}>
137
+ <Typography variant={"subtitle2"} className={"uppercase"}>No collections found</Typography>
138
+ <Typography>
139
139
  Start building collections in FireCMS easily. Map them to your existing
140
- database data, import from files, or use our templates. Simplify your data management process
141
- now.
140
+ database data, import from files, or use our templates.
142
141
  </Typography>
143
142
  {canCreateCollections && <Button
144
- className={"mt-4"}
145
143
  onClick={collectionEditorController && canCreateCollections
146
144
  ? () => collectionEditorController.createCollection({
147
145
  parentCollectionIds: [],
@@ -151,6 +149,9 @@ export function IntroWidget({ introMode }: {
151
149
  : undefined}>
152
150
  <AddIcon/>Create your first collection
153
151
  </Button>}
154
- </div>
152
+ <Typography variant={"caption"} color={"secondary"}>
153
+ You can also define collections programmatically.
154
+ </Typography>
155
+ </Paper>
155
156
  );
156
157
  }
@@ -0,0 +1,30 @@
1
+ import {
2
+ EntityCollection,
3
+ joinCollectionLists,
4
+ makePropertiesEditable,
5
+ ModifyCollectionProps,
6
+ Properties
7
+ } from "@firecms/core";
8
+ import { PersistedCollection } from "../types/persisted_collection";
9
+
10
+ /**
11
+ * Function in charge of merging collections defined in code with those stored in the backend.
12
+ */
13
+ export const mergeCollections = (baseCollections: EntityCollection[],
14
+ backendCollections: PersistedCollection[],
15
+ modifyCollection?: (props: ModifyCollectionProps) => EntityCollection | void
16
+ ) => {
17
+
18
+ const markAsEditable = (c: PersistedCollection) => {
19
+ makePropertiesEditable(c.properties as Properties);
20
+ c.subcollections?.forEach(markAsEditable);
21
+ };
22
+ const storedCollections = backendCollections ?? [];
23
+ storedCollections.forEach(markAsEditable);
24
+
25
+ console.debug("Collections specified in code:", baseCollections);
26
+ console.debug("Collections stored in the backend", storedCollections);
27
+ const result = joinCollectionLists(baseCollections, storedCollections, [], modifyCollection);
28
+ console.debug("Collections after joining:", result);
29
+ return result;
30
+ }
@@ -1,3 +0,0 @@
1
- export declare function RootCollectionSuggestions({ introMode }: {
2
- introMode?: "new_project" | "existing_project";
3
- }): import("react/jsx-runtime").JSX.Element;
@@ -1,63 +0,0 @@
1
- import { unslugify, useAuthController, useNavigationController } from "@firecms/core";
2
- import { AddIcon, Chip, CircularProgress, Collapse, Typography, } from "@firecms/ui";
3
- import { useCollectionEditorController } from "../useCollectionEditorController";
4
- import React from "react";
5
-
6
- export function RootCollectionSuggestions({ introMode }: { introMode?: "new_project" | "existing_project" }) {
7
-
8
- const authController = useAuthController();
9
- const navigationController = useNavigationController();
10
-
11
- const collectionEditorController = useCollectionEditorController();
12
- const canCreateCollections = collectionEditorController.configPermissions
13
- ? collectionEditorController.configPermissions({
14
- user: authController.user
15
- }).createCollections
16
- : true;
17
-
18
- const rootPathSuggestions = collectionEditorController.rootPathSuggestions;
19
-
20
- const showSuggestions = (rootPathSuggestions ?? []).length > 3 || ((navigationController.collections ?? []).length === 0 && (rootPathSuggestions ?? []).length > 0);
21
- const forceShowSuggestions = introMode === "existing_project";
22
- return <Collapse
23
- in={forceShowSuggestions || showSuggestions}>
24
-
25
- <div
26
- className={"flex flex-col gap-1 p-2 my-4"}>
27
-
28
- {!introMode && <Typography variant={"body2"} color={"secondary"}>
29
- Create a collection <b>automatically</b> from your data:
30
- </Typography>}
31
-
32
- {introMode === "existing_project" && <Typography>
33
- You will see your <b>database collections</b> here, a few seconds after project creation
34
- </Typography>}
35
-
36
- <div
37
- className={"flex flex-row gap-1 overflow-scroll no-scrollbar "}>
38
- {(rootPathSuggestions ?? []).map((path) => {
39
- return (
40
- <div key={path}>
41
- <Chip
42
- icon={<AddIcon size={"small"}/>}
43
- colorScheme={"cyanLighter"}
44
- onClick={collectionEditorController && canCreateCollections
45
- ? () => collectionEditorController.createCollection({
46
- initialValues: { path, name: unslugify(path) },
47
- parentCollectionIds: [],
48
- redirect: true,
49
- sourceClick: "root_collection_suggestion"
50
- })
51
- : undefined}
52
- size="small">
53
- {path}
54
- </Chip>
55
- </div>
56
- );
57
- })}
58
- {rootPathSuggestions === undefined && <CircularProgress size={"small"}/>}
59
- {rootPathSuggestions?.length === 0 && <Typography variant={"caption"}>No suggestions</Typography>}
60
- </div>
61
- </div>
62
- </Collapse>
63
- }