@firecms/collection_editor 3.0.0-alpha.21 → 3.0.0-alpha.25

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 (92) hide show
  1. package/dist/ConfigControllerProvider.d.ts +36 -0
  2. package/dist/components/CollectionViewHeaderAction.d.ts +8 -0
  3. package/dist/components/EditorCollectionAction.d.ts +2 -0
  4. package/dist/components/HomePageEditorCollectionAction.d.ts +2 -0
  5. package/dist/components/MissingReferenceWidget.d.ts +3 -0
  6. package/dist/components/NewCollectionCard.d.ts +2 -0
  7. package/dist/components/PropertyAddColumnComponent.d.ts +6 -0
  8. package/dist/components/RootCollectionSuggestions.d.ts +1 -0
  9. package/dist/components/collection_editor/CollectionDetailsForm.d.ts +9 -0
  10. package/dist/components/collection_editor/CollectionEditorDialog.d.ts +37 -0
  11. package/dist/components/collection_editor/CollectionEditorWelcomeView.d.ts +15 -0
  12. package/dist/components/collection_editor/CollectionPropertiesEditorForm.d.ts +19 -0
  13. package/dist/components/collection_editor/CollectionYupValidation.d.ts +11 -0
  14. package/dist/components/collection_editor/EntityCustomViewsSelectDialog.d.ts +4 -0
  15. package/dist/components/collection_editor/EnumForm.d.ts +13 -0
  16. package/dist/components/collection_editor/PropertyEditView.d.ts +39 -0
  17. package/dist/components/collection_editor/PropertyFieldPreview.d.ts +15 -0
  18. package/dist/components/collection_editor/PropertySelectItem.d.ts +8 -0
  19. package/dist/components/collection_editor/PropertyTree.d.ts +30 -0
  20. package/dist/components/collection_editor/SelectIcons.d.ts +6 -0
  21. package/dist/components/collection_editor/SubcollectionsEditTab.d.ts +12 -0
  22. package/dist/components/collection_editor/UnsavedChangesDialog.d.ts +9 -0
  23. package/dist/components/collection_editor/import/CollectionEditorImportDataPreview.d.ts +7 -0
  24. package/dist/components/collection_editor/import/CollectionEditorImportMapping.d.ts +6 -0
  25. package/dist/components/collection_editor/import/clean_import_data.d.ts +7 -0
  26. package/dist/components/collection_editor/properties/BlockPropertyField.d.ts +7 -0
  27. package/dist/components/collection_editor/properties/BooleanPropertyField.d.ts +3 -0
  28. package/dist/components/collection_editor/properties/CommonPropertyFields.d.ts +10 -0
  29. package/dist/components/collection_editor/properties/DateTimePropertyField.d.ts +3 -0
  30. package/dist/components/collection_editor/properties/EnumPropertyField.d.ts +8 -0
  31. package/dist/components/collection_editor/properties/FieldHelperView.d.ts +4 -0
  32. package/dist/components/collection_editor/properties/KeyValuePropertyField.d.ts +3 -0
  33. package/dist/components/collection_editor/properties/MapPropertyField.d.ts +7 -0
  34. package/dist/components/collection_editor/properties/NumberPropertyField.d.ts +3 -0
  35. package/dist/components/collection_editor/properties/ReferencePropertyField.d.ts +13 -0
  36. package/dist/components/collection_editor/properties/RepeatPropertyField.d.ts +9 -0
  37. package/dist/components/collection_editor/properties/StoragePropertyField.d.ts +5 -0
  38. package/dist/components/collection_editor/properties/StringPropertyField.d.ts +5 -0
  39. package/dist/components/collection_editor/properties/advanced/AdvancedPropertyValidation.d.ts +3 -0
  40. package/dist/components/collection_editor/properties/validation/ArrayPropertyValidation.d.ts +5 -0
  41. package/dist/components/collection_editor/properties/validation/GeneralPropertyValidation.d.ts +4 -0
  42. package/dist/components/collection_editor/properties/validation/NumberPropertyValidation.d.ts +3 -0
  43. package/dist/components/collection_editor/properties/validation/StringPropertyValidation.d.ts +11 -0
  44. package/dist/components/collection_editor/properties/validation/ValidationPanel.d.ts +2 -0
  45. package/dist/components/collection_editor/templates/blog_template.d.ts +10 -0
  46. package/dist/components/collection_editor/templates/products_template.d.ts +12 -0
  47. package/dist/components/collection_editor/templates/users_template.d.ts +7 -0
  48. package/dist/components/collection_editor/util.d.ts +4 -0
  49. package/dist/components/collection_editor/utils/supported_fields.d.ts +3 -0
  50. package/dist/components/collection_editor/utils/update_property_for_widget.d.ts +2 -0
  51. package/dist/components/collection_editor/utils/useTraceUpdate.d.ts +1 -0
  52. package/dist/index.d.ts +11 -0
  53. package/dist/index.es.js +6754 -0
  54. package/dist/index.es.js.map +1 -0
  55. package/dist/index.umd.js +2 -0
  56. package/dist/index.umd.js.map +1 -0
  57. package/dist/types/collection_editor_controller.d.ts +33 -0
  58. package/dist/types/collection_inference.d.ts +2 -0
  59. package/dist/types/config_controller.d.ts +33 -0
  60. package/dist/types/config_permissions.d.ts +19 -0
  61. package/dist/types/persisted_collection.d.ts +6 -0
  62. package/dist/useCollectionEditorController.d.ts +6 -0
  63. package/dist/useCollectionEditorPlugin.d.ts +44 -0
  64. package/dist/useCollectionsConfigController.d.ts +6 -0
  65. package/dist/utils/arrays.d.ts +1 -0
  66. package/dist/utils/entities.d.ts +3 -0
  67. package/dist/utils/icons.d.ts +1 -0
  68. package/dist/utils/join_collections.d.ts +13 -0
  69. package/dist/utils/synonyms.d.ts +1951 -0
  70. package/package.json +6 -5
  71. package/src/ConfigControllerProvider.tsx +131 -8
  72. package/src/components/CollectionViewHeaderAction.tsx +38 -0
  73. package/src/components/MissingReferenceWidget.tsx +2 -1
  74. package/src/components/NewCollectionCard.tsx +2 -1
  75. package/src/components/PropertyAddColumnComponent.tsx +39 -0
  76. package/src/components/RootCollectionSuggestions.tsx +2 -1
  77. package/src/components/collection_editor/CollectionDetailsForm.tsx +1 -0
  78. package/src/components/collection_editor/CollectionEditorDialog.tsx +1 -1
  79. package/src/components/collection_editor/CollectionPropertiesEditorForm.tsx +3 -3
  80. package/src/components/collection_editor/PropertyEditView.tsx +112 -97
  81. package/src/components/collection_editor/SubcollectionsEditTab.tsx +14 -3
  82. package/src/components/collection_editor/import/CollectionEditorImportMapping.tsx +1 -1
  83. package/src/components/collection_editor/properties/BlockPropertyField.tsx +1 -1
  84. package/src/components/collection_editor/properties/CommonPropertyFields.tsx +0 -1
  85. package/src/components/collection_editor/properties/MapPropertyField.tsx +1 -1
  86. package/src/components/collection_editor/properties/RepeatPropertyField.tsx +1 -1
  87. package/src/index.ts +1 -0
  88. package/src/types/collection_editor_controller.tsx +11 -2
  89. package/src/types/config_controller.tsx +13 -2
  90. package/src/types/persisted_collection.ts +2 -1
  91. package/src/useCollectionEditorPlugin.tsx +22 -2
  92. package/src/utils/join_collections.ts +11 -48
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firecms/collection_editor",
3
- "version": "3.0.0-alpha.21",
3
+ "version": "3.0.0-alpha.25",
4
4
  "main": "./dist/index.umd.js",
5
5
  "module": "./dist/index.es.js",
6
6
  "types": "dist/index.d.ts",
@@ -14,8 +14,8 @@
14
14
  "./package.json": "./package.json"
15
15
  },
16
16
  "dependencies": {
17
- "@firecms/data_import": "^3.0.0-alpha.21",
18
- "@firecms/schema_inference": "^3.0.0-alpha.21"
17
+ "@firecms/data_import": "^3.0.0-alpha.25",
18
+ "@firecms/schema_inference": "^3.0.0-alpha.25"
19
19
  },
20
20
  "peerDependencies": {
21
21
  "react": "^18.2.0",
@@ -26,7 +26,8 @@
26
26
  "scripts": {
27
27
  "dev": "vite",
28
28
  "test": "jest",
29
- "build": "vite build && tsc --emitDeclarationOnly -p tsconfig.prod.json"
29
+ "build": "vite build && tsc --emitDeclarationOnly -p tsconfig.prod.json",
30
+ "clean": "rm -rf dist && find ./src -name '*.js' -type f | xargs rm -f"
30
31
  },
31
32
  "eslintConfig": {
32
33
  "extends": [
@@ -75,5 +76,5 @@
75
76
  "publishConfig": {
76
77
  "access": "public"
77
78
  },
78
- "gitHead": "4a18047fa8fd4ddaa157ec2d415fcab89cf34d65"
79
+ "gitHead": "8bce80c65696930df7a8003b0b5d0310f595d46d"
79
80
  }
@@ -2,12 +2,20 @@ import React, { PropsWithChildren, useCallback, useEffect } from "react";
2
2
  import equal from "react-fast-compare"
3
3
 
4
4
  import { CollectionsConfigController } from "./types/config_controller";
5
- import { EntityCollection, useNavigationContext, User } from "@firecms/core";
5
+ import {
6
+ EntityCollection,
7
+ Property,
8
+ useFireCMSContext,
9
+ useNavigationContext,
10
+ User,
11
+ useSnackbarController
12
+ } from "@firecms/core";
6
13
  import { CollectionEditorDialog } from "./components/collection_editor/CollectionEditorDialog";
7
14
  import { useNavigate } from "react-router";
8
15
  import { CollectionEditorController } from "./types/collection_editor_controller";
9
16
  import { CollectionEditorPermissionsBuilder } from "./types/config_permissions";
10
17
  import { CollectionInference } from "./types/collection_inference";
18
+ import { PropertyFormDialog } from "./components/collection_editor/PropertyEditView";
11
19
 
12
20
  export const ConfigControllerContext = React.createContext<CollectionsConfigController>({} as any);
13
21
  export const CollectionEditorContext = React.createContext<CollectionEditorController>({} as any);
@@ -63,6 +71,8 @@ export const ConfigControllerProvider = React.memo(
63
71
 
64
72
  const navigation = useNavigationContext();
65
73
  const navigate = useNavigate();
74
+ const snackbarController = useSnackbarController();
75
+ const { fields: customFields } = useFireCMSContext();
66
76
 
67
77
  const {
68
78
  collections
@@ -89,6 +99,18 @@ export const ConfigControllerProvider = React.memo(
89
99
  group?: string,
90
100
  name?: string
91
101
  },
102
+ redirect: boolean
103
+ }>();
104
+
105
+ const [currentPropertyDialog, setCurrentPropertyDialog] = React.useState<{
106
+ propertyKey?: string,
107
+ property?: Property,
108
+ namespace?: string,
109
+ parentCollection?: EntityCollection,
110
+ currentPropertiesOrder?: string[],
111
+ editedCollectionPath: string,
112
+ fullPath?: string,
113
+ parentPathSegments: string[],
92
114
  }>();
93
115
 
94
116
  const defaultConfigPermissions: CollectionEditorPermissionsBuilder = useCallback(() => ({
@@ -97,7 +119,12 @@ export const ConfigControllerProvider = React.memo(
97
119
  deleteCollections: true
98
120
  }), []);
99
121
 
100
- const editCollection = useCallback(({ path, fullPath, parentPathSegments, parentCollection }: {
122
+ const editCollection = useCallback(({
123
+ path,
124
+ fullPath,
125
+ parentPathSegments,
126
+ parentCollection
127
+ }: {
101
128
  path?: string,
102
129
  fullPath?: string,
103
130
  parentPathSegments: string[],
@@ -108,24 +135,65 @@ export const ConfigControllerProvider = React.memo(
108
135
  fullPath,
109
136
  parentPathSegments,
110
137
  isNewCollection: false,
138
+ parentCollection,
139
+ redirect: false
140
+ });
141
+ }, []);
142
+
143
+ const editProperty = useCallback(({
144
+ propertyKey,
145
+ property,
146
+ editedCollectionPath,
147
+ currentPropertiesOrder,
148
+ parentPathSegments,
149
+ parentCollection
150
+ }: {
151
+ propertyKey?: string,
152
+ property?: Property,
153
+ currentPropertiesOrder?: string[],
154
+ editedCollectionPath: string,
155
+ parentPathSegments: string[],
156
+ parentCollection?: EntityCollection
157
+ }) => {
158
+ // namespace is all the path until the last dot
159
+ const namespace = propertyKey && propertyKey.includes(".")
160
+ ? propertyKey.substring(0, propertyKey.lastIndexOf("."))
161
+ : undefined;
162
+ const propertyKeyWithoutNamespace = propertyKey && propertyKey.includes(".")
163
+ ? propertyKey.substring(propertyKey.lastIndexOf(".") + 1)
164
+ : propertyKey;
165
+ setCurrentPropertyDialog({
166
+ propertyKey: propertyKeyWithoutNamespace,
167
+ property,
168
+ namespace,
169
+ currentPropertiesOrder,
170
+ editedCollectionPath,
171
+ parentPathSegments,
111
172
  parentCollection
112
173
  });
113
174
  }, []);
114
175
 
115
- const createCollection = React.useCallback(({ parentPathSegments, parentCollection, initialValues }: {
176
+ const createCollection = React.useCallback(({
177
+ parentPathSegments,
178
+ parentCollection,
179
+ initialValues,
180
+ redirect
181
+ }: {
116
182
  parentPathSegments: string[],
117
183
  parentCollection?: EntityCollection<any, any, any>
118
184
  initialValues?: {
119
185
  group?: string,
120
186
  path?: string,
121
187
  name?: string
122
- }
188
+ },
189
+ redirect: boolean
123
190
  }) => {
124
191
  setCurrentDialog({
125
192
  isNewCollection: true,
126
193
  parentPathSegments,
127
194
  parentCollection,
128
- initialValues
195
+ initialValues,
196
+ redirect
129
197
  });
130
198
  }, []);
131
199
 
@@ -145,6 +213,7 @@ export const ConfigControllerProvider = React.memo(
145
213
  value={{
146
214
  editCollection,
147
215
  createCollection,
216
+ editProperty,
148
217
  configPermissions: configPermissions ?? defaultConfigPermissions,
149
218
  rootPathSuggestions
150
219
  }}>
@@ -163,13 +232,67 @@ export const ConfigControllerProvider = React.memo(
163
232
  pathSuggestions={getPathSuggestions}
164
233
  getUser={getUser}
165
234
  handleClose={(collection) => {
166
- if (collection && currentDialog?.isNewCollection && !currentDialog.parentPathSegments.length) {
167
- const url = navigation.buildUrlCollectionPath(collection.alias ?? collection.path);
168
- navigate(url);
235
+ if (currentDialog?.redirect) {
236
+ if (collection && currentDialog?.isNewCollection && !currentDialog.parentPathSegments.length) {
237
+ const url = navigation.buildUrlCollectionPath(collection.alias ?? collection.path);
238
+ navigate(url);
239
+ }
169
240
  }
170
241
  setCurrentDialog(undefined);
171
242
  }}/>
172
243
 
244
+ {/* Used for editing properties*/}
245
+ <PropertyFormDialog
246
+ open={Boolean(currentPropertyDialog)}
247
+ includeIdAndName={true}
248
+ existingProperty={Boolean(currentPropertyDialog?.propertyKey)}
249
+ autoUpdateId={!currentPropertyDialog ? false : !currentPropertyDialog?.propertyKey}
250
+ autoOpenTypeSelect={!currentPropertyDialog ? false : !currentPropertyDialog?.propertyKey}
251
+ inArray={false}
252
+ getData={getData && currentDialog?.fullPath ? () => getData(currentDialog.fullPath!) : undefined}
253
+ onPropertyChanged={({
254
+ id,
255
+ property
256
+ }) => {
257
+ if (!currentPropertyDialog) return;
258
+ if (!id) return;
259
+ const newProperty = !(currentPropertyDialog.propertyKey);
260
+ return collectionConfigController.saveProperty({
261
+ path: currentPropertyDialog?.editedCollectionPath,
262
+ property,
263
+ propertyKey: id,
264
+ newPropertiesOrder: newProperty && currentPropertyDialog.currentPropertiesOrder ? [...currentPropertyDialog.currentPropertiesOrder, id] : undefined,
265
+ namespace: currentPropertyDialog.namespace,
266
+ parentPathSegments: currentPropertyDialog.parentPathSegments
267
+ })
268
+ .catch((e) => {
269
+ console.error(e);
270
+ snackbarController.open({
271
+ type: "error",
272
+ message: "Error persisting property: " + (e.message ?? "Details in the console")
273
+ });
274
+ return false;
275
+ });
276
+ }}
277
+ onPropertyChangedImmediate={false}
278
+ onDelete={() => {
279
+ }}
280
+ onError={() => {
281
+ }}
282
+ onOkClicked={() => {
283
+ setCurrentPropertyDialog(undefined);
284
+ }}
285
+ onCancel={() => {
286
+ setCurrentPropertyDialog(undefined);
287
+ }}
288
+ initialErrors={{}}
289
+ forceShowErrors={false}
290
+ existingPropertyKeys={[]}
291
+ allowDataInference={true}
292
+ customFields={customFields}
293
+ property={currentPropertyDialog?.property}
294
+ propertyKey={currentPropertyDialog?.propertyKey}/>
295
+
173
296
  </CollectionEditorContext.Provider>
174
297
 
175
298
  </ConfigControllerContext.Provider>
@@ -0,0 +1,38 @@
1
+ import { IconButton, ResolvedProperty, SettingsIcon, Tooltip } from "@firecms/core";
2
+ import React from "react";
3
+ import { useCollectionEditorController } from "../useCollectionEditorController";
4
+
5
+ export function CollectionViewHeaderAction({
6
+ propertyKey,
7
+ onHover,
8
+ property,
9
+ fullPath,
10
+ parentPathSegments
11
+ }: {
12
+ property: ResolvedProperty,
13
+ propertyKey: string,
14
+ onHover: boolean,
15
+ fullPath: string,
16
+ parentPathSegments: string[],
17
+ }) {
18
+
19
+ const collectionEditorController = useCollectionEditorController();
20
+
21
+ return (
22
+ <Tooltip title={"Edit"}>
23
+ <IconButton
24
+ className={onHover ? "bg-white dark:bg-gray-950" : "hidden"}
25
+ onClick={() => {
26
+ collectionEditorController.editProperty({
27
+ propertyKey,
28
+ property,
29
+ editedCollectionPath: fullPath,
30
+ parentPathSegments
31
+ });
32
+ }}
33
+ size={"small"}>
34
+ <SettingsIcon size={"small"}/>
35
+ </IconButton>
36
+ </Tooltip>
37
+ )
38
+ }
@@ -13,7 +13,8 @@ export function MissingReferenceWidget({ path: pathProp }: {
13
13
  onClick={() => {
14
14
  collectionEditor.createCollection({
15
15
  initialValues: { path, name: unslugify(path) },
16
- parentPathSegments
16
+ parentPathSegments,
17
+ redirect: false
17
18
  });
18
19
  }}>
19
20
  Create
@@ -23,7 +23,8 @@ export function NewCollectionCard({
23
23
  onClick={collectionEditorController && canCreateCollections
24
24
  ? () => collectionEditorController.createCollection({
25
25
  initialValues: group ? { group } : undefined,
26
- parentPathSegments: []
26
+ parentPathSegments: [],
27
+ redirect: true
27
28
  })
28
29
  : undefined}>
29
30
 
@@ -0,0 +1,39 @@
1
+ import { AddIcon, EntityCollection, getDefaultPropertiesOrder, Tooltip, useAuthController } from "@firecms/core";
2
+ import { useCollectionEditorController } from "../useCollectionEditorController";
3
+
4
+ export function PropertyAddColumnComponent({
5
+ fullPath,
6
+ parentPathSegments,
7
+ collection
8
+ }: {
9
+ fullPath: string,
10
+ parentPathSegments: string[],
11
+ collection: EntityCollection;
12
+ }) {
13
+
14
+ const authController = useAuthController();
15
+ const collectionEditorController = useCollectionEditorController();
16
+ const canEditCollection = collectionEditorController.configPermissions
17
+ ? collectionEditorController.configPermissions({
18
+ user: authController.user,
19
+ collection
20
+ }).editCollections
21
+ : true;
22
+
23
+ return (
24
+ <Tooltip title={canEditCollection ? "Add new property" : "You don't have permission to add new properties"}>
25
+ <div
26
+ className={"p-0.5 w-20 h-full flex items-center justify-center cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-950"}
27
+ // className={onHover ? "bg-white dark:bg-gray-950" : undefined}
28
+ onClick={() => {
29
+ collectionEditorController.editProperty({
30
+ editedCollectionPath: fullPath,
31
+ parentPathSegments,
32
+ currentPropertiesOrder: getDefaultPropertiesOrder(collection)
33
+ });
34
+ }}>
35
+ <AddIcon color={"inherit"}/>
36
+ </div>
37
+ </Tooltip>
38
+ )
39
+ }
@@ -38,7 +38,8 @@ export function RootCollectionSuggestions() {
38
38
  onClick={collectionEditorController && canCreateCollections
39
39
  ? () => collectionEditorController.createCollection({
40
40
  initialValues: { path, name: unslugify(path) },
41
- parentPathSegments: []
41
+ parentPathSegments: [],
42
+ redirect: true
42
43
  })
43
44
  : undefined}
44
45
  size="small">
@@ -242,6 +242,7 @@ export function CollectionDetailsForm({
242
242
  <div className={"col-span-12"}>
243
243
  <Field name={"alias"}
244
244
  as={DebouncedTextField}
245
+ disabled={!isNewCollection}
245
246
  label={"Alias"}
246
247
  validate={validateAlias}
247
248
  error={touched.alias && Boolean(errors.alias)}/>
@@ -308,7 +308,7 @@ export function CollectionEditorDialogInternal<M extends {
308
308
  if (!isNewCollection) {
309
309
  saveCollection(newCollectionState).then(() => {
310
310
  formikHelpers.resetForm({ values: initialValues });
311
- setNextMode();
311
+ // setNextMode();
312
312
  handleClose(newCollectionState);
313
313
  });
314
314
  return;
@@ -378,7 +378,7 @@ export function CollectionPropertiesEditorForm({
378
378
  <PropertyForm
379
379
  inArray={false}
380
380
  key={`edit_view_${selectedPropertyIndex}`}
381
- existing={!isNewCollection}
381
+ existingProperty={!isNewCollection}
382
382
  autoUpdateId={false}
383
383
  allowDataInference={!isNewCollection}
384
384
  autoOpenTypeSelect={false}
@@ -414,7 +414,7 @@ export function CollectionPropertiesEditorForm({
414
414
  key={`edit_view_${selectedPropertyIndex}`}
415
415
  autoUpdateId={isNewCollection}
416
416
  allowDataInference={!isNewCollection}
417
- existing={true}
417
+ existingProperty={true}
418
418
  autoOpenTypeSelect={false}
419
419
  propertyKey={selectedPropertyKey}
420
420
  propertyNamespace={selectedPropertyNamespace}
@@ -440,7 +440,7 @@ export function CollectionPropertiesEditorForm({
440
440
  {/* This is the dialog used for new properties*/}
441
441
  <PropertyFormDialog
442
442
  inArray={false}
443
- existing={false}
443
+ existingProperty={false}
444
444
  autoOpenTypeSelect={true}
445
445
  autoUpdateId={true}
446
446
  forceShowErrors={showErrors}