@firecms/core 3.0.0-alpha.47 → 3.0.0-alpha.49

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.
@@ -2,8 +2,8 @@ import { EntityCollection, ModifyCollectionProps } from "../types";
2
2
  /**
3
3
  *
4
4
  */
5
- export declare function joinCollectionLists(targetCollections: EntityCollection[], sourceCollections: EntityCollection[] | undefined, parentPaths?: string[], modifyCollection?: (props: ModifyCollectionProps) => EntityCollection | undefined): EntityCollection[];
5
+ export declare function joinCollectionLists(targetCollections: EntityCollection[], sourceCollections: EntityCollection[] | undefined, parentPaths?: string[], modifyCollection?: (props: ModifyCollectionProps) => EntityCollection | void): EntityCollection[];
6
6
  /**
7
7
  *
8
8
  */
9
- export declare function mergeCollection(target: EntityCollection, source: EntityCollection, parentPaths?: string[], modifyCollection?: (props: ModifyCollectionProps) => EntityCollection | undefined): EntityCollection;
9
+ export declare function mergeCollection(target: EntityCollection, source: EntityCollection, parentPaths?: string[], modifyCollection?: (props: ModifyCollectionProps) => EntityCollection | void): EntityCollection;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firecms/core",
3
- "version": "3.0.0-alpha.47",
3
+ "version": "3.0.0-alpha.49",
4
4
  "description": "Awesome Firebase/Firestore-based headless open-source CMS",
5
5
  "funding": {
6
6
  "url": "https://github.com/sponsors/firecmsco"
@@ -133,7 +133,7 @@
133
133
  "dist",
134
134
  "src"
135
135
  ],
136
- "gitHead": "1c2310776f2da9bba46ba352e9a5244118dcdc3f",
136
+ "gitHead": "c9502da4e2caa2c3c896fbae55a7fe788cd0b840",
137
137
  "publishConfig": {
138
138
  "access": "public"
139
139
  }
@@ -142,6 +142,7 @@ export const EntityCollectionTable = React.memo<EntityCollectionTableProps<any>>
142
142
  const onRowClick = useCallback(({ rowData }: {
143
143
  rowData: Entity<M>
144
144
  }) => {
145
+ console.debug("EntityCollectionTable click");
145
146
  if (inlineEditing)
146
147
  return;
147
148
  return onEntityClick && onEntityClick(rowData);
@@ -19,6 +19,7 @@ import { useEntityCollectionTableController } from "./EntityCollectionTable/useE
19
19
  import { AddIcon } from "../icons";
20
20
  import { useColumnIds } from "./EntityCollectionView/useColumnsIds";
21
21
  import { useSideDialogContext } from "../core";
22
+ import { useTraceUpdate } from "../util/useTraceUpdate";
22
23
 
23
24
  /**
24
25
  * @group Components
@@ -99,6 +100,8 @@ export function ReferenceSelectionInner<M extends Record<string, any>>(
99
100
  maxSelection
100
101
  }: ReferenceSelectionInnerProps<M>) {
101
102
 
103
+ console.log("ReferenceSelectionInner");
104
+
102
105
  const sideDialogContext = useSideDialogContext();
103
106
  const sideEntityController = useSideEntityController();
104
107
  const navigation = useNavigationController();
@@ -142,7 +145,7 @@ export function ReferenceSelectionInner<M extends Record<string, any>>(
142
145
  };
143
146
  }, [dataSource, fullPath, selectedEntityIdsProp, collection, selectionController.setSelectedEntities]);
144
147
 
145
- const onClear = useCallback(() => {
148
+ const onClear = () => {
146
149
  context.onAnalyticsEvent?.("reference_selection_clear", {
147
150
  path: fullPath
148
151
  });
@@ -152,9 +155,10 @@ export function ReferenceSelectionInner<M extends Record<string, any>>(
152
155
  } else if (onMultipleEntitiesSelected) {
153
156
  onMultipleEntitiesSelected([]);
154
157
  }
155
- }, [multiselect, onMultipleEntitiesSelected, onSingleEntitySelected]);
158
+ };
156
159
 
157
- const toggleEntitySelection = useCallback((entity: Entity<any>) => {
160
+ const toggleEntitySelection = (entity: Entity<any>) => {
161
+ console.debug("ReferenceSelectionInner toggleEntitySelection", entity);
158
162
  let newValue;
159
163
  const selectedEntities = selectionController.selectedEntities;
160
164
 
@@ -176,9 +180,10 @@ export function ReferenceSelectionInner<M extends Record<string, any>>(
176
180
  if (onMultipleEntitiesSelected)
177
181
  onMultipleEntitiesSelected(newValue);
178
182
  }
179
- }, [onMultipleEntitiesSelected, selectionController.selectedEntities]);
183
+ };
180
184
 
181
- const onEntityClick = useCallback((entity: Entity<any>) => {
185
+ const onEntityClick = (entity: Entity<any>) => {
186
+ console.debug("ReferenceSelectionInner onEntityClick", entity);
182
187
 
183
188
  if (!multiselect && onSingleEntitySelected) {
184
189
  context.onAnalyticsEvent?.("reference_selected_single", {
@@ -190,32 +195,31 @@ export function ReferenceSelectionInner<M extends Record<string, any>>(
190
195
  } else {
191
196
  toggleEntitySelection(entity);
192
197
  }
193
- }, [sideDialogContext, multiselect, onSingleEntitySelected, toggleEntitySelection]);
198
+ };
194
199
 
195
200
  // create a new entity from within the reference dialog
196
- const onNewClick = useCallback(() => {
197
- context.onAnalyticsEvent?.("reference_selection_new_entity", {
198
- path: fullPath
199
- });
200
- sideEntityController.open({
201
- path: fullPath,
202
- collection,
203
- updateUrl: true,
204
- onUpdate: ({ entity }) => {
205
- setEntitiesDisplayedFirst([entity, ...entitiesDisplayedFirst]);
206
- onEntityClick(entity);
207
- },
208
- closeOnSave: true
209
- });
210
- },
211
- [sideEntityController, fullPath, collection, entitiesDisplayedFirst, onEntityClick]);
212
-
213
- const tableRowActionsBuilder = useCallback(({
214
- entity,
215
- size,
216
- width,
217
- frozen
218
- }: {
201
+ const onNewClick = () => {
202
+ context.onAnalyticsEvent?.("reference_selection_new_entity", {
203
+ path: fullPath
204
+ });
205
+ sideEntityController.open({
206
+ path: fullPath,
207
+ collection,
208
+ updateUrl: true,
209
+ onUpdate: ({ entity }) => {
210
+ setEntitiesDisplayedFirst([entity, ...entitiesDisplayedFirst]);
211
+ onEntityClick(entity);
212
+ },
213
+ closeOnSave: true
214
+ });
215
+ };
216
+
217
+ const tableRowActionsBuilder = ({
218
+ entity,
219
+ size,
220
+ width,
221
+ frozen
222
+ }: {
219
223
  entity: Entity<any>,
220
224
  size: CollectionSize,
221
225
  width: number,
@@ -234,7 +238,7 @@ export function ReferenceSelectionInner<M extends Record<string, any>>(
234
238
  fullPath={fullPath}
235
239
  selectionController={selectionController}/>;
236
240
 
237
- }, [multiselect, selectionController.selectedEntities, toggleEntitySelection, collection?.hideIdFromCollection]);
241
+ };
238
242
 
239
243
  const onDone = useCallback((event: React.SyntheticEvent) => {
240
244
  event.stopPropagation();
@@ -15,16 +15,18 @@ export const VirtualTableRow = React.memo<VirtualTableRowProps<any>>(
15
15
  size,
16
16
  style,
17
17
  hoverRow,
18
- rowClassName,
18
+ rowClassName
19
19
  }: VirtualTableRowProps<T>) {
20
20
 
21
- const onClick = useCallback((event: React.SyntheticEvent) => onRowClick
22
- ? onRowClick({
23
- rowData,
24
- rowIndex,
25
- event
26
- })
27
- : undefined, [onRowClick, rowData, rowIndex]);
21
+ const onClick = useCallback((event: React.SyntheticEvent) => {
22
+ console.debug("VirtualTableRow click");
23
+ if (onRowClick)
24
+ onRowClick({
25
+ rowData,
26
+ rowIndex,
27
+ event
28
+ })
29
+ }, [onRowClick, rowData, rowIndex]);
28
30
 
29
31
  return (
30
32
  <div
@@ -10,25 +10,45 @@ import { mergeDeep } from "./objects";
10
10
  import { sortProperties } from "./collections";
11
11
  import { isPropertyBuilder } from "./entities";
12
12
 
13
+ function applyModifyFunction(modifyCollection: ((props: ModifyCollectionProps) => (EntityCollection | void)) | undefined,
14
+ collection: EntityCollection,
15
+ parentPaths: string[]) {
16
+ if (modifyCollection) {
17
+ const modified = modifyCollection({
18
+ collection,
19
+ parentPaths
20
+ });
21
+ const resCollection = modified ?? collection;
22
+ if (resCollection.subcollections) {
23
+ resCollection.subcollections = resCollection.subcollections.map((subcollection) => {
24
+ return applyModifyFunction(modifyCollection, subcollection, [...parentPaths, collection.path]);
25
+ });
26
+ }
27
+ return resCollection;
28
+ } else {
29
+ return collection;
30
+ }
31
+ }
32
+
13
33
  /**
14
34
  *
15
35
  */
16
36
  export function joinCollectionLists(targetCollections: EntityCollection[],
17
37
  sourceCollections: EntityCollection[] | undefined,
18
38
  parentPaths: string[] = [],
19
- modifyCollection?: (props: ModifyCollectionProps) => EntityCollection | undefined): EntityCollection[] {
39
+ modifyCollection?: (props: ModifyCollectionProps) => EntityCollection | void): EntityCollection[] {
20
40
 
21
41
  // merge collections that are in both lists
22
42
  const updatedCollections = (sourceCollections ?? [])
23
- .map((codedCollection) => {
24
- const storedCollection = targetCollections?.find((collection) => {
25
- return collection.id === codedCollection.id;
43
+ .map((sourceCol) => {
44
+ const targetCol = targetCollections?.find((collection) => {
45
+ return collection.id === sourceCol.id;
26
46
  // return collection.path === codedCollection.path || collection.id && codedCollection.id;
27
47
  });
28
- if (!storedCollection) {
29
- return codedCollection;
48
+ if (!targetCol) {
49
+ return applyModifyFunction(modifyCollection, sourceCol, parentPaths);
30
50
  } else {
31
- return mergeCollection(storedCollection, codedCollection, parentPaths, modifyCollection);
51
+ return mergeCollection(targetCol, sourceCol, parentPaths, modifyCollection);
32
52
  }
33
53
  });
34
54
 
@@ -37,8 +57,7 @@ export function joinCollectionLists(targetCollections: EntityCollection[],
37
57
  .filter((col) => !updatedCollections.map(c => c.id).includes(col.id))
38
58
  .map((col) => {
39
59
  if (modifyCollection) {
40
- const modified = modifyCollection({ collection: col, parentPaths });
41
- return modified ?? col;
60
+ return applyModifyFunction(modifyCollection, col, parentPaths);
42
61
  } else {
43
62
  return col;
44
63
  }
@@ -53,7 +72,7 @@ export function joinCollectionLists(targetCollections: EntityCollection[],
53
72
  export function mergeCollection(target: EntityCollection,
54
73
  source: EntityCollection,
55
74
  parentPaths: string[] = [],
56
- modifyCollection?: (props: ModifyCollectionProps) => EntityCollection | undefined
75
+ modifyCollection?: (props: ModifyCollectionProps) => EntityCollection | void
57
76
  ): EntityCollection {
58
77
 
59
78
  const subcollectionsMerged = joinCollectionLists(
@@ -86,7 +105,10 @@ export function mergeCollection(target: EntityCollection,
86
105
  entityViews: mergedEntityViews
87
106
  };
88
107
  if (modifyCollection) {
89
- const modifiedCollection = modifyCollection({ collection: resultCollection, parentPaths });
108
+ const modifiedCollection = modifyCollection({
109
+ collection: resultCollection,
110
+ parentPaths
111
+ });
90
112
  if (modifiedCollection)
91
113
  resultCollection = modifiedCollection;
92
114
  }
@@ -112,9 +134,17 @@ function mergePropertyOrBuilder(target: Property, source: PropertyOrBuilder): Pr
112
134
  if (property)
113
135
  mergedProperties[key] = mergePropertyOrBuilder(property, sourceProperties[key] as PropertyOrBuilder);
114
136
  });
115
- return { ...mergedProperty, editable: targetEditable && sourceEditable, properties: mergedProperties, propertiesOrder: mergedPropertiesOrder } as MapProperty;
137
+ return {
138
+ ...mergedProperty,
139
+ editable: targetEditable && sourceEditable,
140
+ properties: mergedProperties,
141
+ propertiesOrder: mergedPropertiesOrder
142
+ } as MapProperty;
116
143
  }
117
- return { ...mergedProperty, editable: targetEditable && sourceEditable };
144
+ return {
145
+ ...mergedProperty,
146
+ editable: targetEditable && sourceEditable
147
+ };
118
148
  }
119
149
  }
120
150