@firecms/collection_editor 3.0.0-canary.26 → 3.0.0-canary.261

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 (88) hide show
  1. package/LICENSE +114 -21
  2. package/README.md +165 -1
  3. package/dist/ConfigControllerProvider.d.ts +1 -2
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.es.js +10742 -4787
  6. package/dist/index.es.js.map +1 -1
  7. package/dist/index.umd.js +11412 -3
  8. package/dist/index.umd.js.map +1 -1
  9. package/dist/types/collection_editor_controller.d.ts +3 -2
  10. package/dist/types/collection_inference.d.ts +4 -1
  11. package/dist/types/config_controller.d.ts +3 -1
  12. package/dist/types/config_permissions.d.ts +2 -2
  13. package/dist/types/persisted_collection.d.ts +1 -1
  14. package/dist/ui/CollectionViewHeaderAction.d.ts +3 -2
  15. package/dist/ui/EditorCollectionActionStart.d.ts +2 -0
  16. package/dist/ui/EditorEntityAction.d.ts +2 -0
  17. package/dist/ui/PropertyAddColumnComponent.d.ts +3 -1
  18. package/dist/ui/collection_editor/CollectionDetailsForm.d.ts +3 -1
  19. package/dist/ui/collection_editor/CollectionEditorDialog.d.ts +3 -2
  20. package/dist/ui/collection_editor/CollectionEditorWelcomeView.d.ts +2 -2
  21. package/dist/ui/collection_editor/CollectionPropertiesEditorForm.d.ts +2 -2
  22. package/dist/ui/collection_editor/EntityActionsEditTab.d.ts +4 -0
  23. package/dist/ui/collection_editor/EntityActionsSelectDialog.d.ts +4 -0
  24. package/dist/ui/collection_editor/LayoutModeSwitch.d.ts +5 -0
  25. package/dist/ui/collection_editor/PropertyEditView.d.ts +8 -0
  26. package/dist/ui/collection_editor/PropertyTree.d.ts +11 -12
  27. package/dist/ui/collection_editor/SubcollectionsEditTab.d.ts +1 -1
  28. package/dist/ui/collection_editor/import/CollectionEditorImportMapping.d.ts +7 -0
  29. package/dist/ui/collection_editor/properties/MarkdownPropertyField.d.ts +4 -0
  30. package/dist/ui/collection_editor/properties/ReferencePropertyField.d.ts +2 -1
  31. package/dist/ui/collection_editor/properties/StringPropertyField.d.ts +1 -1
  32. package/dist/useCollectionEditorPlugin.d.ts +8 -11
  33. package/dist/utils/collections.d.ts +6 -0
  34. package/package.json +23 -35
  35. package/src/ConfigControllerProvider.tsx +64 -66
  36. package/src/index.ts +1 -0
  37. package/src/types/collection_editor_controller.tsx +6 -5
  38. package/src/types/collection_inference.ts +4 -1
  39. package/src/types/config_controller.tsx +4 -1
  40. package/src/types/config_permissions.ts +1 -1
  41. package/src/types/persisted_collection.ts +2 -3
  42. package/src/ui/CollectionViewHeaderAction.tsx +10 -5
  43. package/src/ui/EditorCollectionAction.tsx +12 -70
  44. package/src/ui/EditorCollectionActionStart.tsx +87 -0
  45. package/src/ui/EditorEntityAction.tsx +51 -0
  46. package/src/ui/HomePageEditorCollectionAction.tsx +21 -14
  47. package/src/ui/NewCollectionButton.tsx +1 -1
  48. package/src/ui/NewCollectionCard.tsx +3 -3
  49. package/src/ui/PropertyAddColumnComponent.tsx +11 -6
  50. package/src/ui/collection_editor/CollectionDetailsForm.tsx +157 -50
  51. package/src/ui/collection_editor/CollectionEditorDialog.tsx +117 -37
  52. package/src/ui/collection_editor/CollectionEditorWelcomeView.tsx +23 -32
  53. package/src/ui/collection_editor/CollectionPropertiesEditorForm.tsx +46 -41
  54. package/src/ui/collection_editor/EntityActionsEditTab.tsx +163 -0
  55. package/src/ui/collection_editor/EntityActionsSelectDialog.tsx +41 -0
  56. package/src/ui/collection_editor/EntityCustomViewsSelectDialog.tsx +11 -7
  57. package/src/ui/collection_editor/EnumForm.tsx +11 -7
  58. package/src/ui/collection_editor/GetCodeDialog.tsx +60 -28
  59. package/src/ui/collection_editor/LayoutModeSwitch.tsx +54 -0
  60. package/src/ui/collection_editor/PropertyEditView.tsx +264 -78
  61. package/src/ui/collection_editor/PropertyFieldPreview.tsx +8 -10
  62. package/src/ui/collection_editor/PropertyTree.tsx +184 -138
  63. package/src/ui/collection_editor/SubcollectionsEditTab.tsx +26 -19
  64. package/src/ui/collection_editor/UnsavedChangesDialog.tsx +9 -7
  65. package/src/ui/collection_editor/import/CollectionEditorImportDataPreview.tsx +33 -9
  66. package/src/ui/collection_editor/import/CollectionEditorImportMapping.tsx +42 -9
  67. package/src/ui/collection_editor/properties/BlockPropertyField.tsx +32 -20
  68. package/src/ui/collection_editor/properties/DateTimePropertyField.tsx +54 -47
  69. package/src/ui/collection_editor/properties/EnumPropertyField.tsx +3 -1
  70. package/src/ui/collection_editor/properties/MapPropertyField.tsx +8 -7
  71. package/src/ui/collection_editor/properties/MarkdownPropertyField.tsx +139 -0
  72. package/src/ui/collection_editor/properties/ReferencePropertyField.tsx +7 -3
  73. package/src/ui/collection_editor/properties/RepeatPropertyField.tsx +0 -1
  74. package/src/ui/collection_editor/properties/StoragePropertyField.tsx +34 -19
  75. package/src/ui/collection_editor/properties/StringPropertyField.tsx +1 -10
  76. package/src/ui/collection_editor/properties/UrlPropertyField.tsx +1 -0
  77. package/src/ui/collection_editor/properties/advanced/AdvancedPropertyValidation.tsx +2 -0
  78. package/src/ui/collection_editor/properties/validation/ValidationPanel.tsx +2 -2
  79. package/src/ui/collection_editor/templates/pages_template.ts +1 -6
  80. package/src/ui/collection_editor/utils/strings.ts +13 -6
  81. package/src/ui/collection_editor/utils/supported_fields.tsx +1 -0
  82. package/src/ui/collection_editor/utils/update_property_for_widget.ts +9 -0
  83. package/src/useCollectionEditorPlugin.tsx +38 -32
  84. package/src/utils/collections.ts +46 -0
  85. package/dist/ui/RootCollectionSuggestions.d.ts +0 -3
  86. package/dist/ui/collection_editor/PropertySelectItem.d.ts +0 -8
  87. package/src/ui/RootCollectionSuggestions.tsx +0 -63
  88. package/src/ui/collection_editor/PropertySelectItem.tsx +0 -32
@@ -1,10 +1,9 @@
1
1
  import React from "react";
2
2
  import {
3
3
  Button,
4
- Checkbox,
4
+ CloudUploadIcon,
5
5
  DebouncedTextField,
6
6
  ExpandablePanel,
7
- FileUploadIcon,
8
7
  MultiSelect,
9
8
  MultiSelectItem,
10
9
  Typography
@@ -44,11 +43,13 @@ export function StoragePropertyField({
44
43
 
45
44
  const metadata = `${baseStoragePath}.metadata`;
46
45
  const fileName = `${baseStoragePath}.fileName`;
46
+ const maxSize = `${baseStoragePath}.maxSize`;
47
47
  const storagePath = `${baseStoragePath}.storagePath`;
48
48
  const storeUrl = `${baseStoragePath}.storeUrl`;
49
49
 
50
50
  const fileNameValue = getIn(values, fileName) ?? "{rand}_{file}";
51
51
  const storagePathValue = getIn(values, storagePath) ?? "/";
52
+ const maxSizeValue = getIn(values, maxSize);
52
53
 
53
54
  const storedValue = getIn(values, acceptedFiles);
54
55
  const fileTypesValue: string[] | undefined = Array.isArray(storedValue) ? storedValue : undefined;
@@ -56,10 +57,10 @@ export function StoragePropertyField({
56
57
 
57
58
  const handleTypesChange = (value: string[]) => {
58
59
  if (!value) setFieldValue(acceptedFiles, undefined);
59
- else if (value.includes("all")) setFieldValue(acceptedFiles, undefined);
60
- else if (value.length >= Object.keys(fileTypes).length) setFieldValue(acceptedFiles, undefined);
61
- else if (allFileTypesSelected)
62
- setFieldValue(acceptedFiles, Object.keys(fileTypes).filter((v) => !value.includes(v)));
60
+ // else if (value.includes("all")) setFieldValue(acceptedFiles, undefined);
61
+ // else if (value.length >= Object.keys(fileTypes).length) setFieldValue(acceptedFiles, undefined);
62
+ // else if (allFileTypesSelected)
63
+ // setFieldValue(acceptedFiles, Object.keys(fileTypes).filter((v) => !value.includes(v)));
63
64
  else setFieldValue(acceptedFiles, value);
64
65
  };
65
66
 
@@ -73,8 +74,8 @@ export function StoragePropertyField({
73
74
 
74
75
  <ExpandablePanel
75
76
  title={
76
- <div className="flex flex-row text-gray-500">
77
- <FileUploadIcon/>
77
+ <div className="flex flex-row text-surface-500">
78
+ <CloudUploadIcon/>
78
79
  <Typography variant={"subtitle2"}
79
80
  className="ml-2">
80
81
  File upload config
@@ -87,10 +88,12 @@ export function StoragePropertyField({
87
88
  <div className={"col-span-12"}>
88
89
 
89
90
  <MultiSelect
91
+ className={"w-full"}
92
+ placeholder={"All file types allowed"}
90
93
  disabled={disabled}
91
94
  name={acceptedFiles}
92
95
  value={fileTypesValue ?? []}
93
- onMultiValueChange={handleTypesChange}
96
+ onValueChange={handleTypesChange}
94
97
  label={allFileTypesSelected ? undefined : "Allowed file types"}
95
98
  renderValues={(selected) => {
96
99
  if (!selected || selected.length === 0) return "All file types allowed";
@@ -99,21 +102,15 @@ export function StoragePropertyField({
99
102
  .join(", ");
100
103
  }}>
101
104
 
102
- <MultiSelectItem key={"all"} value={"all"} className={"flex items-center gap-2"}>
103
- <Checkbox
104
- checked={!fileTypesValue}/>
105
- All
106
- </MultiSelectItem>
107
-
108
105
  {Object.entries(fileTypes).map(([value, label]) => (
109
106
  <MultiSelectItem key={value} value={value} className={"flex items-center gap-2"}>
110
- <Checkbox
111
- checked={allFileTypesSelected || fileTypesValue.indexOf(value) > -1}/>
107
+ {/*<Checkbox*/}
108
+ {/* checked={allFileTypesSelected || fileTypesValue.indexOf(value) > -1}/>*/}
112
109
  <div className={"flex-grow"}>
113
110
  {label}
114
111
  </div>
115
112
  <Button size={"small"}
116
- variant={"outlined"}
113
+ variant={"text"}
117
114
  onClick={(e) => {
118
115
  e.preventDefault();
119
116
  e.stopPropagation();
@@ -161,7 +158,10 @@ export function StoragePropertyField({
161
158
 
162
159
  <Field name={storeUrl}
163
160
  type="checkbox">
164
- {({ field, form }: FormexFieldProps) => {
161
+ {({
162
+ field,
163
+ form
164
+ }: FormexFieldProps) => {
165
165
  return <SwitchControl
166
166
  label={"Save URL instead of storage path"}
167
167
  disabled={existing || disabled}
@@ -178,6 +178,21 @@ export function StoragePropertyField({
178
178
  You can only change this prop upon creation.
179
179
  </Typography>
180
180
  </div>
181
+
182
+ <div className={"col-span-12"}>
183
+ <DebouncedTextField name={maxSize}
184
+ type={"number"}
185
+ label={"Max size (in bytes)"}
186
+ size={"small"}
187
+ value={maxSizeValue !== undefined && maxSizeValue !== null ? maxSizeValue.toString() : ""}
188
+ onChange={(e) => {
189
+ const value = e.target.value;
190
+ if (value === "") setFieldValue(maxSize, undefined);
191
+ else setFieldValue(maxSize, parseInt(value));
192
+ }}
193
+ />
194
+ </div>
195
+
181
196
  </div>
182
197
  </ExpandablePanel>
183
198
 
@@ -10,7 +10,7 @@ export function StringPropertyField({
10
10
  disabled,
11
11
  showErrors
12
12
  }: {
13
- widgetId: "text_field" | "multiline" | "markdown" | "email";
13
+ widgetId: "text_field" | "multiline" | "email";
14
14
  disabled: boolean;
15
15
  showErrors: boolean;
16
16
  }) {
@@ -42,15 +42,6 @@ export function StringPropertyField({
42
42
  trim={true}
43
43
  uppercase={true}
44
44
  showErrors={showErrors}/>}
45
- {widgetId === "markdown" &&
46
- <StringPropertyValidation disabled={disabled}
47
- length={true}
48
- lowercase={true}
49
- max={true}
50
- min={true}
51
- trim={true}
52
- uppercase={true}
53
- showErrors={showErrors}/>}
54
45
 
55
46
  {widgetId === "email" &&
56
47
  <StringPropertyValidation disabled={disabled}
@@ -24,6 +24,7 @@ export function UrlPropertyField({
24
24
  <Select
25
25
  disabled={disabled}
26
26
  position={"item-aligned"}
27
+ fullWidth={true}
27
28
  onValueChange={(value: string) => {
28
29
  if (value === "[NONE]")
29
30
  setFieldValue("url", true);
@@ -19,6 +19,7 @@ export function AdvancedPropertyValidation({ disabled }: {
19
19
  {({ field, form }: FormexFieldProps) => {
20
20
  return <SwitchControl
21
21
  label={"Hide from collection"}
22
+ size={"medium"}
22
23
  disabled={disabled}
23
24
  form={form}
24
25
  tooltip={"Hide this field from the collection view. It will still be visible in the form view"}
@@ -33,6 +34,7 @@ export function AdvancedPropertyValidation({ disabled }: {
33
34
  {({ field, form }: FormexFieldProps) => {
34
35
  return <SwitchControl
35
36
  label={"Read only"}
37
+ size={"medium"}
36
38
  disabled={disabled}
37
39
  tooltip={"Is this a read only field. Display only as a preview"}
38
40
  form={form}
@@ -10,9 +10,9 @@ export function ValidationPanel({
10
10
  <ExpandablePanel
11
11
  initiallyExpanded={false}
12
12
  asField={true}
13
- className="p-4"
13
+ innerClassName="p-4"
14
14
  title={
15
- <div className="flex flex-row text-gray-500">
15
+ <div className="flex flex-row text-surface-500">
16
16
  <RuleIcon/>
17
17
  <Typography variant={"subtitle2"}
18
18
  className="ml-2">
@@ -19,7 +19,7 @@ export const pagesCollectionTemplate: EntityCollection = {
19
19
  validation: {
20
20
  required: true,
21
21
  unique: true,
22
- matches: /^[a-z0-9]+(?:-[a-z0-9]+)*$/,
22
+ matches: "^[a-z0-9]+(?:-[a-z0-9]+)*$",
23
23
  matchesMessage: "Must be lowercase, alphanumeric, and hyphenated"
24
24
  }
25
25
  },
@@ -178,11 +178,6 @@ export const pagesCollectionTemplate: EntityCollection = {
178
178
  name: "Is Published",
179
179
  columnWidth: 100,
180
180
  description: "Should this page be live on the site?"
181
- },
182
- author_uid: {
183
- dataType: "reference",
184
- name: "Author",
185
- path: "users"
186
181
  }
187
182
  }
188
183
  };
@@ -1,9 +1,16 @@
1
1
  export function camelCase(str: string): string {
2
2
  if (!str) return "";
3
- return (str.slice(0, 1).toLowerCase() + str.slice(1))
4
- .replace(/([-_ ]){1,}/g, " ")
5
- .split(/[-_ ]/)
6
- .reduce((cur, acc) => {
7
- return cur + acc[0].toUpperCase() + acc.substring(1);
8
- }, "");
3
+ if (str.length === 1) return str.toLowerCase();
4
+
5
+ // Split by hyphens, underscores, or spaces and filter out empty strings
6
+ const parts = str.split(/[-_ ]+/).filter(Boolean);
7
+
8
+ if (parts.length === 0) return "";
9
+
10
+ // Start with first part in lowercase
11
+ return parts[0].toLowerCase() +
12
+ // Transform remaining parts to have first letter uppercase
13
+ parts.slice(1)
14
+ .map(part => part.charAt(0).toUpperCase() + part.substring(1).toLowerCase())
15
+ .join('');
9
16
  }
@@ -14,6 +14,7 @@ export const supportedFieldsIds: PropertyConfigId[] = [
14
14
  "file_upload",
15
15
  "multi_file_upload",
16
16
  "reference",
17
+ "reference_as_string",
17
18
  "multi_references",
18
19
  "switch",
19
20
  "date_time",
@@ -208,6 +208,15 @@ export function updatePropertyFromWidget(propertyData: any,
208
208
  editable: propertyData.editable !== undefined ? propertyData.editable : true
209
209
  } satisfies Property
210
210
  );
211
+ } else if (selectedWidgetId === "reference_as_string") {
212
+ updatedProperty = mergeDeep(
213
+ propertyData,
214
+ {
215
+ dataType: "string",
216
+ propertyConfig: "reference_as_string",
217
+ editable: propertyData.editable !== undefined ? propertyData.editable : true
218
+ } satisfies Property
219
+ );
211
220
  } else if (selectedWidgetId === "multi_references") {
212
221
  updatedProperty = mergeDeep(
213
222
  propertyData,
@@ -4,18 +4,19 @@ 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";
15
+ import { EditorCollectionActionStart } from "./ui/EditorCollectionActionStart";
16
+ import { NewCollectionCard } from "./ui/NewCollectionCard";
17
+ import { EditorEntityAction } from "./ui/EditorEntityAction";
17
18
 
18
- export interface CollectionConfigControllerProps<EC extends PersistedCollection = PersistedCollection, UserType extends User = User> {
19
+ export interface CollectionConfigControllerProps<EC extends PersistedCollection = PersistedCollection, USER extends User = User> {
19
20
 
20
21
  /**
21
22
  * Firebase app where the configuration is saved.
@@ -25,14 +26,14 @@ export interface CollectionConfigControllerProps<EC extends PersistedCollection
25
26
  /**
26
27
  * Define what actions can be performed on the configuration.
27
28
  */
28
- configPermissions?: CollectionEditorPermissionsBuilder<UserType, EC>;
29
+ configPermissions?: CollectionEditorPermissionsBuilder<USER, EC>;
29
30
 
30
31
  /**
31
32
  * The words you define here will not be allowed to be used as group
32
33
  * names when creating collections.
33
34
  * e.g. ["admin"]
34
35
  */
35
- reservedGroups: string[];
36
+ reservedGroups?: string[];
36
37
 
37
38
  extraView?: {
38
39
  View: React.ComponentType<{
@@ -41,17 +42,15 @@ export interface CollectionConfigControllerProps<EC extends PersistedCollection
41
42
  icon: React.ReactNode
42
43
  };
43
44
 
44
- pathSuggestions?: (path: string) => Promise<string[]>;
45
-
46
45
  collectionInference?: CollectionInference;
47
46
 
48
47
  getData?: (path: string, parentPaths: string[]) => Promise<object[]>;
49
48
 
50
- getUser: (uid: string) => UserType | null;
49
+ getUser?: (uid: string) => USER | null;
51
50
 
52
51
  onAnalyticsEvent?: (event: string, params?: object) => void;
53
52
 
54
- introMode?: "new_project" | "existing_project";
53
+ includeIntroView?: boolean;
55
54
 
56
55
  }
57
56
 
@@ -62,23 +61,22 @@ export interface CollectionConfigControllerProps<EC extends PersistedCollection
62
61
  * @param configPermissions
63
62
  * @param reservedGroups
64
63
  * @param extraView
65
- * @param pathSuggestions
64
+ * @param getData
66
65
  * @param getUser
67
66
  * @param collectionInference
68
67
  */
69
- export function useCollectionEditorPlugin<EC extends PersistedCollection = PersistedCollection, UserType extends User = User>
68
+ export function useCollectionEditorPlugin<EC extends PersistedCollection = PersistedCollection, USER extends User = User>
70
69
  ({
71
70
  collectionConfigController,
72
- introMode,
73
71
  configPermissions,
74
72
  reservedGroups,
75
73
  extraView,
76
- pathSuggestions,
77
74
  getUser,
78
75
  collectionInference,
79
76
  getData,
80
- onAnalyticsEvent
81
- }: CollectionConfigControllerProps<EC, UserType>): FireCMSPlugin<any, any, PersistedCollection> {
77
+ onAnalyticsEvent,
78
+ includeIntroView = true
79
+ }: CollectionConfigControllerProps<EC, USER>): FireCMSPlugin<any, any, PersistedCollection> {
82
80
 
83
81
  return {
84
82
  key: "collection_editor",
@@ -91,30 +89,33 @@ export function useCollectionEditorPlugin<EC extends PersistedCollection = Persi
91
89
  collectionInference,
92
90
  reservedGroups,
93
91
  extraView,
94
- pathSuggestions,
95
92
  getUser,
96
93
  getData,
97
- onAnalyticsEvent
94
+ onAnalyticsEvent,
98
95
  }
99
96
  },
100
97
  homePage: {
101
98
  additionalActions: <NewCollectionButton/>,
102
- additionalChildrenStart: introMode ? <IntroWidget introMode={introMode}/> : undefined,
103
- additionalChildrenEnd: <RootCollectionSuggestions introMode={introMode}/>,
99
+ additionalChildrenStart: includeIntroView ? <IntroWidget/> : undefined,
104
100
  CollectionActions: HomePageEditorCollectionAction,
105
- AdditionalCards: introMode ? undefined : NewCollectionCard,
101
+ AdditionalCards: NewCollectionCard,
102
+ allowDragAndDrop: true,
103
+ navigationEntries: collectionConfigController.navigationEntries,
104
+ onNavigationEntriesUpdate: collectionConfigController.saveNavigationEntries,
106
105
  },
107
106
  collectionView: {
107
+ CollectionActionsStart: EditorCollectionActionStart,
108
108
  CollectionActions: EditorCollectionAction,
109
109
  HeaderAction: CollectionViewHeaderAction,
110
110
  AddColumnComponent: PropertyAddColumnComponent
111
+ },
112
+ form: {
113
+ ActionsTop: EditorEntityAction,
111
114
  }
112
115
  };
113
116
  }
114
117
 
115
- export function IntroWidget({ introMode }: {
116
- introMode?: "new_project" | "existing_project";
117
- }) {
118
+ export function IntroWidget() {
118
119
 
119
120
  const navigation = useNavigationController();
120
121
  if (!navigation.topLevelNavigation)
@@ -129,17 +130,19 @@ export function IntroWidget({ introMode }: {
129
130
  }).createCollections
130
131
  : true;
131
132
 
133
+ if (!navigation.initialised || (navigation.collections ?? []).length > 0) {
134
+ return null;
135
+ }
136
+
132
137
  return (
133
- <div className={"mt-8 flex flex-col mt-8 p-2"}>
134
- <Typography variant={"h4"} className="mb-4">Welcome</Typography>
135
- <Typography paragraph={true}>Your admin panel is ready ✌️</Typography>
136
- <Typography paragraph={true}>
138
+ <Paper
139
+ className={"my-4 px-4 py-6 flex flex-col bg-white dark:bg-surface-accent-800 gap-2"}>
140
+ <Typography variant={"subtitle2"} className={"uppercase"}>No collections found</Typography>
141
+ <Typography>
137
142
  Start building collections in FireCMS easily. Map them to your existing
138
- database data, import from files, or use our templates. Simplify your data management process
139
- now.
143
+ database data, import from files, or use our templates.
140
144
  </Typography>
141
145
  {canCreateCollections && <Button
142
- className={"mt-4"}
143
146
  onClick={collectionEditorController && canCreateCollections
144
147
  ? () => collectionEditorController.createCollection({
145
148
  parentCollectionIds: [],
@@ -149,6 +152,9 @@ export function IntroWidget({ introMode }: {
149
152
  : undefined}>
150
153
  <AddIcon/>Create your first collection
151
154
  </Button>}
152
- </div>
155
+ <Typography color={"secondary"}>
156
+ You can also define collections programmatically.
157
+ </Typography>
158
+ </Paper>
153
159
  );
154
160
  }
@@ -0,0 +1,46 @@
1
+ import {
2
+ EntityCallbacks,
3
+ EntityCollection,
4
+ joinCollectionLists,
5
+ makePropertiesEditable,
6
+ ModifyCollectionProps,
7
+ Properties
8
+ } from "@firecms/core";
9
+ import { PersistedCollection } from "../types/persisted_collection";
10
+
11
+ /**
12
+ * Function in charge of merging collections defined in code with those stored in the backend.
13
+ */
14
+ export const mergeCollections = (baseCollections: EntityCollection[],
15
+ backendCollections: PersistedCollection[] = [],
16
+ modifyCollection?: (props: ModifyCollectionProps) => EntityCollection | void
17
+ ) => {
18
+
19
+ const markAsEditable = (c: PersistedCollection) => {
20
+ makePropertiesEditable(c.properties as Properties);
21
+ c.subcollections?.forEach(markAsEditable);
22
+ };
23
+
24
+ backendCollections.forEach(markAsEditable);
25
+
26
+ const result = joinCollectionLists(baseCollections, backendCollections, [], modifyCollection);
27
+
28
+ // sort the collections so they are in the same order as the base collections
29
+ result.sort((a, b) => {
30
+ const indexA = baseCollections.findIndex(c => c.id === a.id);
31
+ const indexB = baseCollections.findIndex(c => c.id === b.id);
32
+
33
+ if (indexA === -1 && indexB === -1) {
34
+ return 0; // Keep original order for items not in baseCollections
35
+ }
36
+ if (indexA === -1) {
37
+ return 1; // a is not in base, so it goes to the end
38
+ }
39
+ if (indexB === -1) {
40
+ return -1; // b is not in base, so it goes to the end
41
+ }
42
+ return indexA - indexB;
43
+ });
44
+
45
+ return result;
46
+ }
@@ -1,3 +0,0 @@
1
- export declare function RootCollectionSuggestions({ introMode }: {
2
- introMode?: "new_project" | "existing_project";
3
- }): import("react/jsx-runtime").JSX.Element;
@@ -1,8 +0,0 @@
1
- import { PropertyConfig } from "@firecms/core";
2
- export interface PropertySelectItemProps {
3
- value: string;
4
- optionDisabled: boolean;
5
- propertyConfig: PropertyConfig;
6
- existing: boolean;
7
- }
8
- export declare function PropertySelectItem({ value, optionDisabled, propertyConfig, existing }: PropertySelectItemProps): 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
- }
@@ -1,32 +0,0 @@
1
- import { PropertyConfigBadge, PropertyConfig } from "@firecms/core";
2
- import { cn, SelectItem, Typography } from "@firecms/ui";
3
-
4
- export interface PropertySelectItemProps {
5
- value: string;
6
- optionDisabled: boolean;
7
- propertyConfig: PropertyConfig;
8
- existing: boolean;
9
- }
10
-
11
- export function PropertySelectItem({ value, optionDisabled, propertyConfig, existing }: PropertySelectItemProps) {
12
- return <SelectItem value={value}
13
- disabled={optionDisabled}
14
- className={"flex flex-row items-center"}>
15
- <div
16
- className={cn(
17
- "flex flex-row items-center text-base min-h-[52px]",
18
- optionDisabled ? "w-full" : "")}>
19
- <div className={"mr-8"}>
20
- <PropertyConfigBadge propertyConfig={propertyConfig}/>
21
- </div>
22
- <div>
23
- <div>{propertyConfig.name}</div>
24
- <Typography variant={"caption"}
25
- color={"disabled"}
26
- className={"max-w-sm"}>
27
- {existing && optionDisabled ? "You can only switch to widgets that use the same data type" : propertyConfig.description}
28
- </Typography>
29
- </div>
30
- </div>
31
- </SelectItem>
32
- }