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

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.
@@ -25,7 +25,7 @@ export interface CollectionEditorDialogProps {
25
25
  icon: React.ReactNode;
26
26
  };
27
27
  pathSuggestions?: (path?: string) => Promise<string[]>;
28
- getUser: (uid: string) => User | null;
28
+ getUser?: (uid: string) => User | null;
29
29
  getData?: (path: string, parentPaths: string[]) => Promise<object[]>;
30
30
  parentCollection?: PersistedCollection;
31
31
  }
@@ -9,7 +9,7 @@ type CollectionEditorFormProps = {
9
9
  setDirty?: (dirty: boolean) => void;
10
10
  reservedGroups?: string[];
11
11
  extraIcon: React.ReactNode;
12
- getUser: (uid: string) => User | null;
12
+ getUser?: (uid: string) => User | null;
13
13
  getData?: () => Promise<object[]>;
14
14
  doCollectionInference: (collection: PersistedCollection) => Promise<Partial<EntityCollection> | null> | undefined;
15
15
  propertyConfigs: Record<string, PropertyConfig>;
@@ -4,17 +4,17 @@ import { DraggableProvided } from "@hello-pangea/dnd";
4
4
  export declare const PropertyTree: React.MemoExoticComponent<(<M extends {
5
5
  [Key: string]: CMSType;
6
6
  }>({ namespace, selectedPropertyKey, onPropertyClick, properties, propertiesOrder: propertiesOrderProp, additionalFields, errors, onPropertyMove, onPropertyRemove, className, inferredPropertyKeys, collectionEditable }: {
7
- namespace?: string | undefined;
8
- selectedPropertyKey?: string | undefined;
9
- onPropertyClick?: ((propertyKey: string, namespace?: string) => void) | undefined;
7
+ namespace?: string;
8
+ selectedPropertyKey?: string;
9
+ onPropertyClick?: (propertyKey: string, namespace?: string) => void;
10
10
  properties: PropertiesOrBuilders<M>;
11
- propertiesOrder?: string[] | undefined;
12
- additionalFields?: AdditionalFieldDelegate<M, import("@firecms/core").User>[] | undefined;
11
+ propertiesOrder?: string[];
12
+ additionalFields?: AdditionalFieldDelegate<M>[];
13
13
  errors: Record<string, any>;
14
- onPropertyMove?: ((propertiesOrder: string[], namespace?: string) => void) | undefined;
15
- onPropertyRemove?: ((propertyKey: string, namespace?: string) => void) | undefined;
16
- className?: string | undefined;
17
- inferredPropertyKeys?: string[] | undefined;
14
+ onPropertyMove?: (propertiesOrder: string[], namespace?: string) => void;
15
+ onPropertyRemove?: (propertyKey: string, namespace?: string) => void;
16
+ className?: string;
17
+ inferredPropertyKeys?: string[];
18
18
  collectionEditable: boolean;
19
19
  }) => import("react/jsx-runtime").JSX.Element)>;
20
20
  export declare function PropertyTreeEntry({ propertyKey, namespace, propertyOrBuilder, additionalField, provided, selectedPropertyKey, errors, onPropertyClick, onPropertyMove, onPropertyRemove, inferredPropertyKeys, collectionEditable }: {
@@ -7,6 +7,6 @@ export declare function SubcollectionsEditTab({ collection, parentCollection, co
7
7
  parentCollection?: EntityCollection;
8
8
  configController: CollectionsConfigController;
9
9
  collectionInference?: CollectionInference;
10
- getUser: (uid: string) => User | null;
10
+ getUser?: (uid: string) => User | null;
11
11
  parentCollectionIds?: string[];
12
12
  }): import("react/jsx-runtime").JSX.Element;
@@ -18,7 +18,7 @@ export interface CollectionConfigControllerProps<EC extends PersistedCollection
18
18
  * names when creating collections.
19
19
  * e.g. ["admin"]
20
20
  */
21
- reservedGroups: string[];
21
+ reservedGroups?: string[];
22
22
  extraView?: {
23
23
  View: React.ComponentType<{
24
24
  path: string;
@@ -28,7 +28,7 @@ export interface CollectionConfigControllerProps<EC extends PersistedCollection
28
28
  pathSuggestions?: (path: string) => Promise<string[]>;
29
29
  collectionInference?: CollectionInference;
30
30
  getData?: (path: string, parentPaths: string[]) => Promise<object[]>;
31
- getUser: (uid: string) => UserType | null;
31
+ getUser?: (uid: string) => UserType | null;
32
32
  onAnalyticsEvent?: (event: string, params?: object) => void;
33
33
  introMode?: "new_project" | "existing_project";
34
34
  }
@@ -0,0 +1,6 @@
1
+ import { EntityCollection, ModifyCollectionProps } from "@firecms/core";
2
+ import { PersistedCollection } from "../types/persisted_collection";
3
+ /**
4
+ * Function in charge of merging collections defined in code with those stored in the backend.
5
+ */
6
+ export declare const mergeCollections: (baseCollections: EntityCollection[], backendCollections: PersistedCollection[], modifyCollection?: (props: ModifyCollectionProps) => EntityCollection | void) => EntityCollection<any, any>[];
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-canary.40",
4
+ "version": "3.0.0-canary.41",
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-canary.40",
11
- "@firecms/formex": "^3.0.0-canary.40",
12
- "@firecms/schema_inference": "^3.0.0-canary.40",
13
- "@firecms/ui": "^3.0.0-canary.40",
10
+ "@firecms/data_import_export": "^3.0.0-canary.41",
11
+ "@firecms/formex": "^3.0.0-canary.41",
12
+ "@firecms/schema_inference": "^3.0.0-canary.41",
13
+ "@firecms/ui": "^3.0.0-canary.41",
14
14
  "json5": "^2.2.3",
15
15
  "prism-react-renderer": "^2.3.1"
16
16
  },
@@ -81,5 +81,5 @@
81
81
  "publishConfig": {
82
82
  "access": "public"
83
83
  },
84
- "gitHead": "40b01721ac260b6cce7f5d8a3a1d768410e7f20d"
84
+ "gitHead": "d1ffa185f8930bab4e7b9941ba551c53f947aa1f"
85
85
  }
@@ -50,7 +50,7 @@ export interface ConfigControllerProviderProps {
50
50
 
51
51
  pathSuggestions?: (path?: string) => Promise<string[]>;
52
52
 
53
- getUser: (uid: string) => User | null
53
+ getUser?: (uid: string) => User | null
54
54
 
55
55
  getData?: (path: string, parentPaths: string[]) => Promise<object[]>;
56
56
 
package/src/index.ts CHANGED
@@ -12,6 +12,7 @@ export {
12
12
  export {
13
13
  editableProperty, removeNonEditableProperties
14
14
  } from "./utils/entities";
15
+ export * from "./utils/collections";
15
16
 
16
17
  export type {
17
18
  CollectionsConfigController, DeleteCollectionParams, SaveCollectionParams, UpdateCollectionParams
@@ -76,7 +76,7 @@ export interface CollectionEditorDialogProps {
76
76
  icon: React.ReactNode
77
77
  };
78
78
  pathSuggestions?: (path?: string) => Promise<string[]>;
79
- getUser: (uid: string) => User | null;
79
+ getUser?: (uid: string) => User | null;
80
80
  getData?: (path: string, parentPaths: string[]) => Promise<object[]>;
81
81
  parentCollection?: PersistedCollection;
82
82
  }
@@ -170,7 +170,8 @@ export function CollectionEditor(props: CollectionEditorDialogProps & {
170
170
  } catch (e) {
171
171
  console.error(e);
172
172
  }
173
- }, [navigation.getCollectionFromPaths, props.editedCollectionId, props.parentCollectionIds, navigation.initialised]);
173
+ }, [props.editedCollectionId, props.parentCollectionIds, navigation]);
174
+
174
175
  if (!topLevelNavigation) {
175
176
  throw Error("Internal: Navigation not ready in collection editor");
176
177
  }
@@ -733,7 +734,10 @@ function CollectionEditorInternal<M extends Record<string, any>>({
733
734
  }
734
735
 
735
736
  function applyPropertyConfigs<M extends Record<string, any> = any>(collection: PersistedCollection<M>, propertyConfigs: Record<string, PropertyConfig<any>>): PersistedCollection<M> {
736
- const { properties, ...rest } = collection;
737
+ const {
738
+ properties,
739
+ ...rest
740
+ } = collection;
737
741
  const propertiesResult: PropertiesOrBuilders<any> = {};
738
742
  if (properties) {
739
743
  Object.keys(properties).forEach((key) => {
@@ -741,7 +745,10 @@ function applyPropertyConfigs<M extends Record<string, any> = any>(collection: P
741
745
  });
742
746
  }
743
747
 
744
- return { ...rest, properties: propertiesResult };
748
+ return {
749
+ ...rest,
750
+ properties: propertiesResult
751
+ };
745
752
  }
746
753
 
747
754
  function applyPropertiesConfig(property: PropertyOrBuilder, propertyConfigs: Record<string, PropertyConfig<any>>) {
@@ -761,7 +768,10 @@ function applyPropertiesConfig(property: PropertyOrBuilder, propertyConfigs: Rec
761
768
  Object.keys(internalProperty.properties).forEach((key) => {
762
769
  properties[key] = applyPropertiesConfig(((internalProperty as MapProperty).properties as Properties)[key] as Property, propertyConfigs);
763
770
  });
764
- internalProperty = { ...internalProperty, properties };
771
+ internalProperty = {
772
+ ...internalProperty,
773
+ properties
774
+ };
765
775
  }
766
776
 
767
777
  }
@@ -43,7 +43,7 @@ type CollectionEditorFormProps = {
43
43
  setDirty?: (dirty: boolean) => void;
44
44
  reservedGroups?: string[];
45
45
  extraIcon: React.ReactNode;
46
- getUser: (uid: string) => User | null;
46
+ getUser?: (uid: string) => User | null;
47
47
  getData?: () => Promise<object[]>;
48
48
  doCollectionInference: (collection: PersistedCollection) => Promise<Partial<EntityCollection> | null> | undefined;
49
49
  propertyConfigs: Record<string, PropertyConfig>;
@@ -301,7 +301,7 @@ export function CollectionPropertiesEditorForm({
301
301
  ? values.propertiesOrder
302
302
  : Object.keys(values.properties)) as string[];
303
303
 
304
- const owner = useMemo(() => values.ownerId ? getUser(values.ownerId) : null, [getUser, values.ownerId]);
304
+ const owner = useMemo(() => values.ownerId && getUser ? getUser(values.ownerId) : null, [getUser, values.ownerId]);
305
305
 
306
306
  const onPropertyClick = useCallback((propertyKey: string, namespace?: string) => {
307
307
  console.debug("CollectionEditor: onPropertyClick", {
@@ -41,7 +41,7 @@ export function SubcollectionsEditTab({
41
41
  parentCollection?: EntityCollection,
42
42
  configController: CollectionsConfigController;
43
43
  collectionInference?: CollectionInference;
44
- getUser: (uid: string) => User | null;
44
+ getUser?: (uid: string) => User | null;
45
45
  parentCollectionIds?: string[];
46
46
  }) {
47
47
 
@@ -33,7 +33,7 @@ export interface CollectionConfigControllerProps<EC extends PersistedCollection
33
33
  * names when creating collections.
34
34
  * e.g. ["admin"]
35
35
  */
36
- reservedGroups: string[];
36
+ reservedGroups?: string[];
37
37
 
38
38
  extraView?: {
39
39
  View: React.ComponentType<{
@@ -48,7 +48,7 @@ export interface CollectionConfigControllerProps<EC extends PersistedCollection
48
48
 
49
49
  getData?: (path: string, parentPaths: string[]) => Promise<object[]>;
50
50
 
51
- getUser: (uid: string) => UserType | null;
51
+ getUser?: (uid: string) => UserType | null;
52
52
 
53
53
  onAnalyticsEvent?: (event: string, params?: object) => void;
54
54
 
@@ -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
+ }