@firecms/core 3.0.0-alpha.82 → 3.0.0-alpha.83

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@firecms/core",
3
3
  "type": "module",
4
- "version": "3.0.0-alpha.82",
4
+ "version": "3.0.0-alpha.83",
5
5
  "description": "Awesome Firebase/Firestore-based headless open-source CMS",
6
6
  "funding": {
7
7
  "url": "https://github.com/sponsors/firecmsco"
@@ -38,7 +38,7 @@
38
38
  "generateIcons": "ts-node --esm src/icons/generateIcons.ts"
39
39
  },
40
40
  "dependencies": {
41
- "@firecms/ui": "^3.0.0-alpha.82",
41
+ "@firecms/ui": "^3.0.0-alpha.83",
42
42
  "@fontsource/ibm-plex-mono": "^5.0.8",
43
43
  "@fontsource/roboto": "^5.0.8",
44
44
  "@hello-pangea/dnd": "^16.5.0",
@@ -107,7 +107,7 @@
107
107
  "dist",
108
108
  "src"
109
109
  ],
110
- "gitHead": "46f5a2edf8418d2c209af9e059617d39213decb8",
110
+ "gitHead": "96d21eb290969ee8e2cc56ca13a47834bae0ee57",
111
111
  "publishConfig": {
112
112
  "access": "public"
113
113
  }
@@ -36,7 +36,7 @@ export const EntityCollectionRowActions = React.memo(function EntityCollectionRo
36
36
  unhighlightEntity,
37
37
  actions = [],
38
38
  hideId,
39
- selectionController
39
+ selectionController,
40
40
  }:
41
41
  {
42
42
  entity: Entity<any>,
@@ -64,6 +64,7 @@ export const useEntityCollectionTableController = () => useContext<EntityCollect
64
64
  export const EntityCollectionTable = React.memo<EntityCollectionTableProps<any>>(
65
65
  function EntityCollectionTable<M extends Record<string, any>, UserType extends User>
66
66
  ({
67
+ debugKey,
67
68
  forceFilter,
68
69
  actionsStart,
69
70
  actions,
@@ -150,10 +151,9 @@ export const EntityCollectionTable = React.memo<EntityCollectionTableProps<any>>
150
151
  setItemCount?.(pageSize);
151
152
  }, [pageSize]);
152
153
 
153
- const onRowClick = useCallback(({ rowData }: {
154
+ const onRowClickCallback = useCallback(({ rowData }: {
154
155
  rowData: Entity<M>
155
156
  }) => {
156
- console.debug("EntityCollectionTable click");
157
157
  if (inlineEditing)
158
158
  return;
159
159
  return onEntityClick && onEntityClick(rowData);
@@ -388,6 +388,8 @@ export const EntityCollectionTable = React.memo<EntityCollectionTableProps<any>>
388
388
  // createFilterField,
389
389
  // });
390
390
 
391
+ const onRowClick = inlineEditing ? undefined : (onEntityClick ? onRowClickCallback : undefined);
392
+
391
393
  return (
392
394
 
393
395
  <EntityCollectionTableContext.Provider
@@ -421,7 +423,7 @@ export const EntityCollectionTable = React.memo<EntityCollectionTableProps<any>>
421
423
  data={data}
422
424
  columns={columns}
423
425
  cellRenderer={cellRenderer}
424
- onRowClick={inlineEditing ? undefined : (onEntityClick ? onRowClick : undefined)}
426
+ onRowClick={onRowClick}
425
427
  onEndReached={loadNextPage}
426
428
  onResetPagination={resetPagination}
427
429
  error={dataLoadingError}
@@ -23,6 +23,7 @@ export type OnColumnResizeParams = { width: number, key: string };
23
23
  export type EntityCollectionTableProps<M extends Record<string, any>,
24
24
  UserType extends User = User> = {
25
25
 
26
+ debugKey?: string;
26
27
  /**
27
28
  * Display these entities as selected
28
29
  */
@@ -387,7 +387,7 @@ export const PropertyTableCell = React.memo<PropertyTableCellProps<any, any>>(
387
387
  multiselect={true}
388
388
  path={arrayProperty.of.path}
389
389
  previewProperties={arrayProperty.of.previewProperties}
390
- title={arrayProperty.of.name}
390
+ title={arrayProperty.name}
391
391
  forceFilter={arrayProperty.of.forceFilter}
392
392
  />;
393
393
  }
@@ -196,7 +196,6 @@ export const SimpleEntityCollectionTable = React.memo<SimpleEntityCollectionTabl
196
196
  const onRowClick = useCallback(({ rowData }: {
197
197
  rowData: Entity<M>
198
198
  }) => {
199
- console.debug("EntityCollectionTable click");
200
199
  if (inlineEditing)
201
200
  return;
202
201
  return onEntityClick && onEntityClick(rowData);
@@ -231,7 +230,6 @@ export const SimpleEntityCollectionTable = React.memo<SimpleEntityCollectionTabl
231
230
  setSelectedCell(undefined);
232
231
  }, []);
233
232
 
234
-
235
233
  const onFilterUpdate = useCallback((updatedFilterValues?: FilterValues<any>) => {
236
234
  setFilterValues?.({ ...updatedFilterValues, ...forceFilter } as FilterValues<any>);
237
235
  }, [forceFilter]);
@@ -39,7 +39,8 @@ import {
39
39
  saveEntityWithCallbacks,
40
40
  useAuthController,
41
41
  useCustomizationController,
42
- useDataSource, useFireCMSContext,
42
+ useDataSource,
43
+ useFireCMSContext,
43
44
  useLargeLayout,
44
45
  useNavigationController,
45
46
  useSideEntityController
@@ -701,15 +702,19 @@ export const EntityCollectionView = React.memo(
701
702
  equal(a.forceFilter, b.forceFilter);
702
703
  }) as React.FunctionComponent<EntityCollectionViewProps<any>>
703
704
 
704
- export function useSelectionController<M extends Record<string, any> = any>(): SelectionController<M> {
705
+ export function useSelectionController<M extends Record<string, any> = any>(
706
+ onSelectionChange?: (entity: Entity<M>, selected: boolean) => void
707
+ ): SelectionController<M> {
705
708
 
706
709
  const [selectedEntities, setSelectedEntities] = useState<Entity<M>[]>([]);
707
710
 
708
711
  const toggleEntitySelection = useCallback((entity: Entity<M>) => {
709
712
  let newValue;
710
713
  if (selectedEntities.map(e => e.id).includes(entity.id)) {
714
+ onSelectionChange?.(entity, false);
711
715
  newValue = selectedEntities.filter((item: Entity<M>) => item.id !== entity.id);
712
716
  } else {
717
+ onSelectionChange?.(entity, true);
713
718
  newValue = [...selectedEntities, entity];
714
719
  }
715
720
  setSelectedEntities(newValue);
@@ -25,7 +25,7 @@ export function EntityPreview<M extends Record<string, any>>(
25
25
  className
26
26
  }: EntityPreviewProps<M>) {
27
27
 
28
- const context = useFireCMSContext();
28
+ const customizationController: CustomizationController = useCustomizationController();
29
29
  const resolvedCollection: ResolvedEntityCollection<M> = useMemo(() => resolveCollection<M>({
30
30
  collection,
31
31
  path,
@@ -34,8 +34,6 @@ export function EntityPreview<M extends Record<string, any>>(
34
34
  fields: customizationController.propertyConfigs
35
35
  }), [collection, path, entity]);
36
36
 
37
- const customizationController: CustomizationController = useCustomizationController();
38
-
39
37
  const properties: ResolvedProperties = resolvedCollection.properties;
40
38
 
41
39
  return (
@@ -113,7 +113,31 @@ export function ReferenceSelectionInner<M extends Record<string, any>>(
113
113
 
114
114
  const [entitiesDisplayedFirst, setEntitiesDisplayedFirst] = useState<Entity<any>[]>([]);
115
115
 
116
- const selectionController = useSelectionController();
116
+ const toggleEntitySelection = (entity: Entity<any>) => {
117
+ let newValue;
118
+ const selectedEntities = selectionController.selectedEntities;
119
+
120
+ analyticsController.onAnalyticsEvent?.("reference_selection_toggle", {
121
+ path: fullPath,
122
+ entityId: entity.id
123
+ });
124
+ if (selectedEntities) {
125
+
126
+ if (selectedEntities.map((e) => e.id).indexOf(entity.id) > -1) {
127
+ newValue = selectedEntities.filter((item: Entity<any>) => item.id !== entity.id);
128
+ } else {
129
+ if (maxSelection && selectedEntities.length >= maxSelection)
130
+ return;
131
+ newValue = [...selectedEntities, entity];
132
+ }
133
+ selectionController.setSelectedEntities(newValue);
134
+
135
+ if (onMultipleEntitiesSelected)
136
+ onMultipleEntitiesSelected(newValue);
137
+ }
138
+ };
139
+
140
+ const selectionController = useSelectionController(toggleEntitySelection);
117
141
 
118
142
  /**
119
143
  * Fetch initially selected ids
@@ -157,34 +181,7 @@ export function ReferenceSelectionInner<M extends Record<string, any>>(
157
181
  }
158
182
  };
159
183
 
160
- const toggleEntitySelection = (entity: Entity<any>) => {
161
- console.debug("ReferenceSelectionInner toggleEntitySelection", entity);
162
- let newValue;
163
- const selectedEntities = selectionController.selectedEntities;
164
-
165
- analyticsController.onAnalyticsEvent?.("reference_selection_toggle", {
166
- path: fullPath,
167
- entityId: entity.id
168
- });
169
- if (selectedEntities) {
170
-
171
- if (selectedEntities.map((e) => e.id).indexOf(entity.id) > -1) {
172
- newValue = selectedEntities.filter((item: Entity<any>) => item.id !== entity.id);
173
- } else {
174
- if (maxSelection && selectedEntities.length >= maxSelection)
175
- return;
176
- newValue = [...selectedEntities, entity];
177
- }
178
- selectionController.setSelectedEntities(newValue);
179
-
180
- if (onMultipleEntitiesSelected)
181
- onMultipleEntitiesSelected(newValue);
182
- }
183
- };
184
-
185
184
  const onEntityClick = (entity: Entity<any>) => {
186
- console.debug("ReferenceSelectionInner onEntityClick", entity);
187
-
188
185
  if (!multiselect && onSingleEntitySelected) {
189
186
  analyticsController.onAnalyticsEvent?.("reference_selected_single", {
190
187
  path: fullPath,
@@ -276,6 +273,7 @@ export function ReferenceSelectionInner<M extends Record<string, any>>(
276
273
  <div className="flex-grow">
277
274
  {entitiesDisplayedFirst &&
278
275
  <EntityCollectionTable
276
+ debugKey={"reference_selection_table"}
279
277
  displayedColumnIds={displayedColumnIds}
280
278
  onEntityClick={onEntityClick}
281
279
  tableController={tableController}
@@ -211,7 +211,9 @@ export const PropertyPreview = React.memo(function PropertyPreview<T extends CMS
211
211
  content = JSON.stringify(value);
212
212
  }
213
213
 
214
- return content === undefined || content === null ? <EmptyValue/> : content;
214
+ return content === undefined || content === null || (Array.isArray(content) && content.length === 0)
215
+ ? <EmptyValue/>
216
+ : content;
215
217
  }, equal);
216
218
 
217
219
  function buildWrongValueType(name: string | undefined, dataType: string, value: any) {