@firecms/collection_editor 3.0.0-beta.7 → 3.0.0-beta.8

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.
@@ -1,5 +1,5 @@
1
1
  import { CollectionEditorPermissionsBuilder } from "./config_permissions";
2
- import { Property } from "@firecms/core";
2
+ import { Entity, Property } from "@firecms/core";
3
3
  import { PersistedCollection } from "./persisted_collection";
4
4
  /**
5
5
  * Controller to open the collection editor dialog.
@@ -11,6 +11,7 @@ export interface CollectionEditorController {
11
11
  fullPath?: string;
12
12
  parentCollectionIds: string[];
13
13
  parentCollection?: PersistedCollection;
14
+ existingEntities?: Entity<any>[];
14
15
  }) => void;
15
16
  createCollection: (props: {
16
17
  initialValues?: {
@@ -30,6 +31,7 @@ export interface CollectionEditorController {
30
31
  editedCollectionId: string;
31
32
  parentCollectionIds: string[];
32
33
  collection: PersistedCollection;
34
+ existingEntities: Entity<any>[];
33
35
  }) => void;
34
36
  configPermissions: CollectionEditorPermissionsBuilder;
35
37
  getPathSuggestions?: (path: string) => Promise<string[]>;
@@ -1,10 +1,11 @@
1
- import { ResolvedProperty } from "@firecms/core";
1
+ import { EntityTableController, ResolvedProperty } from "@firecms/core";
2
2
  import { PersistedCollection } from "../types/persisted_collection";
3
- export declare function CollectionViewHeaderAction({ propertyKey, onHover, property, fullPath, parentCollectionIds, collection }: {
3
+ export declare function CollectionViewHeaderAction({ propertyKey, onHover, property, fullPath, parentCollectionIds, collection, tableController }: {
4
4
  property: ResolvedProperty;
5
5
  propertyKey: string;
6
6
  onHover: boolean;
7
7
  fullPath: string;
8
8
  parentCollectionIds: string[];
9
9
  collection: PersistedCollection;
10
+ tableController: EntityTableController;
10
11
  }): import("react/jsx-runtime").JSX.Element;
@@ -1,6 +1,8 @@
1
+ import { EntityTableController } from "@firecms/core";
1
2
  import { PersistedCollection } from "../types/persisted_collection";
2
- export declare function PropertyAddColumnComponent({ fullPath, parentCollectionIds, collection }: {
3
+ export declare function PropertyAddColumnComponent({ fullPath, parentCollectionIds, collection, tableController }: {
3
4
  fullPath: string;
4
5
  parentCollectionIds: string[];
5
6
  collection: PersistedCollection;
7
+ tableController: EntityTableController;
6
8
  }): import("react/jsx-runtime").JSX.Element;
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import { EntityCollection, User } from "@firecms/core";
2
+ import { Entity, EntityCollection, User } from "@firecms/core";
3
3
  import { CollectionsConfigController } from "../../types/config_controller";
4
4
  import { CollectionInference } from "../../types/collection_inference";
5
5
  import { PersistedCollection } from "../../types/persisted_collection";
@@ -28,6 +28,7 @@ export interface CollectionEditorDialogProps {
28
28
  getUser?: (uid: string) => User | null;
29
29
  getData?: (path: string, parentPaths: string[]) => Promise<object[]>;
30
30
  parentCollection?: PersistedCollection;
31
+ existingEntities?: Entity<any>[];
31
32
  }
32
33
  export declare function CollectionEditorDialog(props: CollectionEditorDialogProps): import("react/jsx-runtime").JSX.Element;
33
34
  export declare function CollectionEditor(props: CollectionEditorDialogProps & {
@@ -38,7 +38,7 @@ export interface CollectionConfigControllerProps<EC extends PersistedCollection
38
38
  * @param configPermissions
39
39
  * @param reservedGroups
40
40
  * @param extraView
41
- * @param getPathsSuggestions
41
+ * @param getData
42
42
  * @param getUser
43
43
  * @param collectionInference
44
44
  */
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@firecms/collection_editor",
3
3
  "type": "module",
4
- "version": "3.0.0-beta.7",
4
+ "version": "3.0.0-beta.8",
5
5
  "main": "./dist/index.umd.js",
6
6
  "module": "./dist/index.es.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "source": "src/index.ts",
9
9
  "dependencies": {
10
- "@firecms/data_import_export": "^3.0.0-beta.7",
11
- "@firecms/formex": "^3.0.0-beta.7",
12
- "@firecms/schema_inference": "^3.0.0-beta.7",
13
- "@firecms/ui": "^3.0.0-beta.7",
10
+ "@firecms/data_import_export": "^3.0.0-beta.8",
11
+ "@firecms/formex": "^3.0.0-beta.8",
12
+ "@firecms/schema_inference": "^3.0.0-beta.8",
13
+ "@firecms/ui": "^3.0.0-beta.8",
14
14
  "json5": "^2.2.3",
15
15
  "prism-react-renderer": "^2.3.1"
16
16
  },
@@ -34,12 +34,6 @@
34
34
  "build": "vite build && tsc --emitDeclarationOnly -p tsconfig.prod.json",
35
35
  "clean": "rm -rf dist && find ./src -name '*.js' -type f | xargs rm -f"
36
36
  },
37
- "eslintConfig": {
38
- "extends": [
39
- "react-app",
40
- "react-app/jest"
41
- ]
42
- },
43
37
  "browserslist": {
44
38
  "production": [
45
39
  ">0.2%",
@@ -56,23 +50,13 @@
56
50
  "@jest/globals": "^29.7.0",
57
51
  "@types/react": "^18.3.3",
58
52
  "@types/react-dom": "^18.3.0",
59
- "@typescript-eslint/eslint-plugin": "^7.11.0",
60
- "@typescript-eslint/parser": "^7.11.0",
61
- "@vitejs/plugin-react": "^4.3.0",
62
- "eslint": "^8.57.0",
63
- "eslint-config-standard": "^17.1.0",
64
- "eslint-plugin-import": "^2.29.1",
65
- "eslint-plugin-n": "^16.6.2",
66
- "eslint-plugin-promise": "^6.2.0",
67
- "eslint-plugin-react": "^7.34.2",
68
- "eslint-plugin-react-hooks": "^4.6.2",
53
+ "@vitejs/plugin-react": "^4.3.1",
69
54
  "jest": "^29.7.0",
70
- "react-router": "^6.23.1",
71
- "react-router-dom": "^6.23.1",
72
- "ts-jest": "^29.1.4",
73
- "typescript": "^5.4.5",
74
- "vite": "^5.2.12",
75
- "vite-plugin-fonts": "^0.7.0"
55
+ "react-router": "^6.24.0",
56
+ "react-router-dom": "^6.24.0",
57
+ "ts-jest": "^29.1.5",
58
+ "typescript": "^5.5.3",
59
+ "vite": "^5.3.2"
76
60
  },
77
61
  "files": [
78
62
  "dist",
@@ -81,5 +65,5 @@
81
65
  "publishConfig": {
82
66
  "access": "public"
83
67
  },
84
- "gitHead": "b1f5dbd89d66bd75e8d214a4a6c40e07e371a1d1"
68
+ "gitHead": "4ef14d60f86cb2e581b908a1dc84ad6a87b14e2e"
85
69
  }
@@ -3,6 +3,7 @@ import equal from "react-fast-compare"
3
3
 
4
4
  import { CollectionsConfigController } from "./types/config_controller";
5
5
  import {
6
+ Entity,
6
7
  Property,
7
8
  useCustomizationController,
8
9
  useNavigationController,
@@ -88,7 +89,8 @@ export const ConfigControllerProvider = React.memo(
88
89
  group?: string,
89
90
  name?: string
90
91
  },
91
- redirect: boolean
92
+ redirect: boolean,
93
+ existingEntities?: Entity<any>[]
92
94
  }>();
93
95
 
94
96
  const [currentPropertyDialog, setCurrentPropertyDialog] = React.useState<{
@@ -101,6 +103,7 @@ export const ConfigControllerProvider = React.memo(
101
103
  fullPath?: string,
102
104
  parentCollectionIds: string[],
103
105
  collectionEditable: boolean;
106
+ existingEntities?: Entity<any>[]
104
107
  }>();
105
108
 
106
109
  const defaultConfigPermissions: CollectionEditorPermissionsBuilder = useCallback(() => ({
@@ -113,12 +116,14 @@ export const ConfigControllerProvider = React.memo(
113
116
  id,
114
117
  fullPath,
115
118
  parentCollectionIds,
116
- parentCollection
119
+ parentCollection,
120
+ existingEntities
117
121
  }: {
118
122
  id?: string,
119
123
  fullPath?: string,
120
124
  parentCollectionIds: string[],
121
- parentCollection?: PersistedCollection
125
+ parentCollection?: PersistedCollection,
126
+ existingEntities?: Entity<any>[]
122
127
  }) => {
123
128
  console.debug("Edit collection", id, fullPath, parentCollectionIds, parentCollection);
124
129
  onAnalyticsEvent?.("edit_collection", {
@@ -131,7 +136,8 @@ export const ConfigControllerProvider = React.memo(
131
136
  parentCollectionIds,
132
137
  isNewCollection: false,
133
138
  parentCollection,
134
- redirect: false
139
+ redirect: false,
140
+ existingEntities
135
141
  });
136
142
  };
137
143
 
@@ -141,7 +147,8 @@ export const ConfigControllerProvider = React.memo(
141
147
  editedCollectionId,
142
148
  currentPropertiesOrder,
143
149
  parentCollectionIds,
144
- collection
150
+ collection,
151
+ existingEntities
145
152
  }: {
146
153
  propertyKey?: string,
147
154
  property?: Property,
@@ -149,6 +156,7 @@ export const ConfigControllerProvider = React.memo(
149
156
  editedCollectionId: string,
150
157
  parentCollectionIds: string[],
151
158
  collection: PersistedCollection,
159
+ existingEntities?: Entity<any>[]
152
160
  }) => {
153
161
  console.debug("Edit property", propertyKey, property, editedCollectionId, currentPropertiesOrder, parentCollectionIds, collection);
154
162
  onAnalyticsEvent?.("edit_property", {
@@ -169,7 +177,8 @@ export const ConfigControllerProvider = React.memo(
169
177
  currentPropertiesOrder,
170
178
  editedCollectionId,
171
179
  parentCollectionIds,
172
- collectionEditable: collection?.editable ?? false
180
+ collectionEditable: collection?.editable ?? false,
181
+ existingEntities
173
182
  });
174
183
  };
175
184
 
@@ -1,5 +1,5 @@
1
1
  import { CollectionEditorPermissionsBuilder } from "./config_permissions";
2
- import { Property } from "@firecms/core";
2
+ import { Entity, Property } from "@firecms/core";
3
3
  import { PersistedCollection } from "./persisted_collection";
4
4
 
5
5
  /**
@@ -12,7 +12,8 @@ export interface CollectionEditorController {
12
12
  id?: string,
13
13
  fullPath?: string,
14
14
  parentCollectionIds: string[],
15
- parentCollection?: PersistedCollection
15
+ parentCollection?: PersistedCollection,
16
+ existingEntities?: Entity<any>[]
16
17
  }) => void;
17
18
 
18
19
  createCollection: (props: {
@@ -33,7 +34,8 @@ export interface CollectionEditorController {
33
34
  currentPropertiesOrder?: string[],
34
35
  editedCollectionId: string,
35
36
  parentCollectionIds: string[],
36
- collection: PersistedCollection
37
+ collection: PersistedCollection,
38
+ existingEntities: Entity<any>[]
37
39
  }) => void;
38
40
 
39
41
  configPermissions: CollectionEditorPermissionsBuilder;
@@ -1,4 +1,4 @@
1
- import { ResolvedProperty } from "@firecms/core";
1
+ import { EntityTableController, ResolvedProperty } from "@firecms/core";
2
2
  import { IconButton, SettingsIcon, Tooltip } from "@firecms/ui";
3
3
  import React from "react";
4
4
  import { useCollectionEditorController } from "../useCollectionEditorController";
@@ -10,7 +10,8 @@ export function CollectionViewHeaderAction({
10
10
  property,
11
11
  fullPath,
12
12
  parentCollectionIds,
13
- collection
13
+ collection,
14
+ tableController
14
15
  }: {
15
16
  property: ResolvedProperty,
16
17
  propertyKey: string,
@@ -18,6 +19,7 @@ export function CollectionViewHeaderAction({
18
19
  fullPath: string,
19
20
  parentCollectionIds: string[],
20
21
  collection: PersistedCollection;
22
+ tableController: EntityTableController;
21
23
  }) {
22
24
 
23
25
  const collectionEditorController = useCollectionEditorController();
@@ -32,7 +34,8 @@ export function CollectionViewHeaderAction({
32
34
  property,
33
35
  editedCollectionId: collection.id,
34
36
  parentCollectionIds,
35
- collection
37
+ collection,
38
+ existingEntities: tableController.data ?? []
36
39
  });
37
40
  }}
38
41
  size={"small"}>
@@ -1,16 +1,7 @@
1
- import equal from "react-fast-compare"
2
-
3
- import {
4
- CollectionActionsProps,
5
- mergeDeep,
6
- useAuthController,
7
- useNavigationController,
8
- useSnackbarController
9
- } from "@firecms/core";
10
- import { Button, IconButton, SaveIcon, SettingsIcon, Tooltip, UndoIcon, } from "@firecms/ui";
1
+ import { CollectionActionsProps, useAuthController, useNavigationController } from "@firecms/core";
2
+ import { IconButton, SettingsIcon, Tooltip, } from "@firecms/ui";
11
3
 
12
4
  import { useCollectionEditorController } from "../useCollectionEditorController";
13
- import { useCollectionsConfigController } from "../useCollectionsConfigController";
14
5
  import { PersistedCollection } from "../types/persisted_collection";
15
6
 
16
7
  export function EditorCollectionAction({
@@ -39,7 +30,13 @@ export function EditorCollectionAction({
39
30
  color={"primary"}
40
31
  disabled={!canEditCollection}
41
32
  onClick={canEditCollection
42
- ? () => collectionEditorController?.editCollection({ id: collection.id, fullPath, parentCollectionIds, parentCollection: parentCollection as PersistedCollection })
33
+ ? () => collectionEditorController?.editCollection({
34
+ id: collection.id,
35
+ fullPath,
36
+ parentCollectionIds,
37
+ parentCollection: parentCollection as PersistedCollection,
38
+ existingEntities: tableController?.data ?? []
39
+ })
43
40
  : undefined}>
44
41
  <SettingsIcon/>
45
42
  </IconButton>
@@ -25,7 +25,10 @@ export function HomePageEditorCollectionAction({
25
25
  });
26
26
 
27
27
  const onEditCollectionClicked = () => {
28
- collectionEditorController?.editCollection({ id: collection.id, parentCollectionIds: [] });
28
+ collectionEditorController?.editCollection({
29
+ id: collection.id,
30
+ parentCollectionIds: []
31
+ });
29
32
  };
30
33
 
31
34
  const [deleteRequested, setDeleteRequested] = useState(false);
@@ -49,11 +52,13 @@ export function HomePageEditorCollectionAction({
49
52
  <MoreVertIcon size={"small"}/>
50
53
  </IconButton>}
51
54
  >
52
- <MenuItem onClick={(event) => {
53
- event.preventDefault();
54
- event.stopPropagation();
55
- setDeleteRequested(true);
56
- }}>
55
+ <MenuItem
56
+ dense={true}
57
+ onClick={(event) => {
58
+ event.preventDefault();
59
+ event.stopPropagation();
60
+ setDeleteRequested(true);
61
+ }}>
57
62
  <DeleteIcon/>
58
63
  Delete
59
64
  </MenuItem>
@@ -1,4 +1,4 @@
1
- import { getDefaultPropertiesOrder, useAuthController } from "@firecms/core";
1
+ import { EntityTableController, getDefaultPropertiesOrder, useAuthController } from "@firecms/core";
2
2
  import { AddIcon, Tooltip } from "@firecms/ui";
3
3
  import { useCollectionEditorController } from "../useCollectionEditorController";
4
4
  import { PersistedCollection } from "../types/persisted_collection";
@@ -6,11 +6,13 @@ import { PersistedCollection } from "../types/persisted_collection";
6
6
  export function PropertyAddColumnComponent({
7
7
  fullPath,
8
8
  parentCollectionIds,
9
- collection
9
+ collection,
10
+ tableController
10
11
  }: {
11
12
  fullPath: string,
12
13
  parentCollectionIds: string[],
13
14
  collection: PersistedCollection;
15
+ tableController: EntityTableController;
14
16
  }) {
15
17
 
16
18
  const authController = useAuthController();
@@ -32,7 +34,8 @@ export function PropertyAddColumnComponent({
32
34
  editedCollectionId: collection.id,
33
35
  parentCollectionIds,
34
36
  currentPropertiesOrder: getDefaultPropertiesOrder(collection),
35
- collection
37
+ collection,
38
+ existingEntities: tableController.data
36
39
  });
37
40
  }}>
38
41
  <AddIcon color={"inherit"}/>
@@ -2,6 +2,7 @@ import * as React from "react";
2
2
  import { useEffect, useRef, useState } from "react";
3
3
  import {
4
4
  CircularProgressCenter,
5
+ Entity,
5
6
  EntityCollection,
6
7
  ErrorView,
7
8
  isPropertyBuilder,
@@ -79,6 +80,7 @@ export interface CollectionEditorDialogProps {
79
80
  getUser?: (uid: string) => User | null;
80
81
  getData?: (path: string, parentPaths: string[]) => Promise<object[]>;
81
82
  parentCollection?: PersistedCollection;
83
+ existingEntities?: Entity<any>[];
82
84
  }
83
85
 
84
86
  export function CollectionEditorDialog(props: CollectionEditorDialogProps) {
@@ -244,7 +246,8 @@ function CollectionEditorInternal<M extends Record<string, any>>({
244
246
  setCollection,
245
247
  initialValues,
246
248
  propertyConfigs,
247
- groups
249
+ groups,
250
+ existingEntities
248
251
  }: CollectionEditorDialogProps & {
249
252
  handleCancel: () => void,
250
253
  setFormDirty: (dirty: boolean) => void,
@@ -481,7 +484,14 @@ function CollectionEditorInternal<M extends Record<string, any>>({
481
484
 
482
485
  const parentPaths = !pathError && parentCollectionIds ? navigation.convertIdsToPaths(parentCollectionIds) : undefined;
483
486
  const resolvedPath = !pathError ? navigation.resolveAliasesFrom(updatedFullPath) : undefined;
484
- const getDataWithPath = resolvedPath && getData ? () => getData(resolvedPath, parentPaths ?? []) : undefined;
487
+ const getDataWithPath = resolvedPath && getData ? async () => {
488
+ const data = await getData(resolvedPath, parentPaths ?? []);
489
+ if (existingEntities) {
490
+ const existingData = existingEntities.map(e => e.values);
491
+ data.push(...existingData);
492
+ }
493
+ return data;
494
+ } : undefined;
485
495
 
486
496
  useEffect(() => {
487
497
  setFormDirty(dirty);
@@ -135,7 +135,7 @@ export function SubcollectionsEditTab({
135
135
  {totalEntityViews === 0 &&
136
136
  <Alert action={<Button variant="text"
137
137
  size={"small"}
138
- href={"https://firecms.co/docs/customization_quickstart"}
138
+ href={"https://firecms.co/docs/cloud/quickstart"}
139
139
  component={"a"}
140
140
  rel="noopener noreferrer"
141
141
  target="_blank">More info</Button>}>
@@ -71,7 +71,7 @@ export function EnumPropertyField({
71
71
  }}
72
72
  getData={getData
73
73
  ? () => getData()
74
- .then(res => res.map(d => values.id && getIn(d, values.id)).filter(Boolean))
74
+ .then(res => res.map(entry => values.id && getIn(entry, values.id)).filter(Boolean))
75
75
  : undefined}
76
76
  onValuesChanged={onValuesChanged}/>
77
77
  </div>
@@ -60,7 +60,7 @@ export interface CollectionConfigControllerProps<EC extends PersistedCollection
60
60
  * @param configPermissions
61
61
  * @param reservedGroups
62
62
  * @param extraView
63
- * @param getPathsSuggestions
63
+ * @param getData
64
64
  * @param getUser
65
65
  * @param collectionInference
66
66
  */