@firecms/core 3.0.0-beta.2-pre.2 → 3.0.0-beta.2-pre.3

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 (55) hide show
  1. package/dist/components/EntityCollectionTable/EntityCollectionTable.d.ts +0 -3
  2. package/dist/components/EntityCollectionTable/EntityCollectionTableProps.d.ts +1 -8
  3. package/dist/components/EntityCollectionTable/index.d.ts +2 -4
  4. package/dist/components/EntityCollectionTable/internal/popup_field/PopupFormField.d.ts +1 -1
  5. package/dist/components/{ReferenceSelectionInner.d.ts → ReferenceTable/ReferenceSelectionTable.d.ts} +2 -2
  6. package/dist/components/{EntityCollectionTable/SimpleTable.d.ts → SelectableTable/SelectableTable.d.ts} +3 -4
  7. package/dist/components/SelectableTable/SelectableTableContext.d.ts +4 -0
  8. package/dist/components/common/index.d.ts +5 -0
  9. package/dist/components/{EntityCollectionTable → common}/types.d.ts +7 -0
  10. package/dist/components/common/useTableSearchHelper.d.ts +12 -0
  11. package/dist/components/index.d.ts +5 -2
  12. package/dist/form/components/index.d.ts +0 -1
  13. package/dist/hooks/useSnackbarController.d.ts +1 -0
  14. package/dist/index.es.js +3705 -3683
  15. package/dist/index.es.js.map +1 -1
  16. package/dist/index.umd.js +5 -5
  17. package/dist/index.umd.js.map +1 -1
  18. package/package.json +3 -3
  19. package/src/components/ArrayContainer.tsx +10 -3
  20. package/src/components/EntityCollectionTable/EntityCollectionTable.tsx +16 -22
  21. package/src/components/EntityCollectionTable/EntityCollectionTableProps.tsx +1 -5
  22. package/src/components/EntityCollectionTable/PropertyTableCell.tsx +2 -2
  23. package/src/components/EntityCollectionTable/column_utils.tsx +1 -1
  24. package/src/components/EntityCollectionTable/index.tsx +1 -9
  25. package/src/components/EntityCollectionTable/internal/popup_field/PopupFormField.tsx +2 -1
  26. package/src/components/EntityCollectionView/EntityCollectionView.tsx +19 -40
  27. package/src/components/{ReferenceSelectionInner.tsx → ReferenceTable/ReferenceSelectionTable.tsx} +31 -15
  28. package/src/components/{EntityCollectionTable/SimpleTable.tsx → SelectableTable/SelectableTable.tsx} +8 -9
  29. package/src/components/SelectableTable/SelectableTableContext.tsx +6 -0
  30. package/src/components/common/index.ts +5 -0
  31. package/src/components/{EntityCollectionTable → common}/types.tsx +5 -0
  32. package/src/components/common/useTableSearchHelper.ts +47 -0
  33. package/src/components/index.tsx +6 -2
  34. package/src/core/EntitySidePanel.tsx +7 -5
  35. package/src/form/EntityForm.tsx +1 -1
  36. package/src/form/components/index.tsx +0 -1
  37. package/src/hooks/useFireCMSContext.tsx +51 -3
  38. package/src/hooks/useReferenceDialog.tsx +2 -2
  39. package/src/hooks/useSnackbarController.tsx +1 -2
  40. package/dist/form/components/SwitchControl.d.ts +0 -8
  41. package/src/form/components/SwitchControl.tsx +0 -39
  42. /package/dist/components/{EntityCollectionTable → SelectableTable}/filters/BooleanFilterField.d.ts +0 -0
  43. /package/dist/components/{EntityCollectionTable → SelectableTable}/filters/DateTimeFilterField.d.ts +0 -0
  44. /package/dist/components/{EntityCollectionTable → SelectableTable}/filters/ReferenceFilterField.d.ts +0 -0
  45. /package/dist/components/{EntityCollectionTable → SelectableTable}/filters/StringNumberFilterField.d.ts +0 -0
  46. /package/dist/components/{EntityCollectionView → common}/useColumnsIds.d.ts +0 -0
  47. /package/dist/components/{EntityCollectionTable → common}/useDataSourceEntityCollectionTableController.d.ts +0 -0
  48. /package/dist/components/{EntityCollectionTable → common}/useDebouncedData.d.ts +0 -0
  49. /package/src/components/{EntityCollectionTable → SelectableTable}/filters/BooleanFilterField.tsx +0 -0
  50. /package/src/components/{EntityCollectionTable → SelectableTable}/filters/DateTimeFilterField.tsx +0 -0
  51. /package/src/components/{EntityCollectionTable → SelectableTable}/filters/ReferenceFilterField.tsx +0 -0
  52. /package/src/components/{EntityCollectionTable → SelectableTable}/filters/StringNumberFilterField.tsx +0 -0
  53. /package/src/components/{EntityCollectionView → common}/useColumnsIds.tsx +0 -0
  54. /package/src/components/{EntityCollectionTable → common}/useDataSourceEntityCollectionTableController.tsx +0 -0
  55. /package/src/components/{EntityCollectionTable → common}/useDebouncedData.ts +0 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@firecms/core",
3
3
  "type": "module",
4
- "version": "3.0.0-beta.2-pre.2",
4
+ "version": "3.0.0-beta.2-pre.3",
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-beta.2-pre.2",
41
+ "@firecms/ui": "^3.0.0-beta.2-pre.3",
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": "f3f62fc3cbc4f0d9d1a26817a14cff06393b7c2b",
110
+ "gitHead": "c78c58643c73ba776dfbcb8315d1a99160bb607a",
111
111
  "publishConfig": {
112
112
  "access": "public"
113
113
  }
@@ -274,7 +274,7 @@ export function ArrayItemOptions({
274
274
  const iconRef = React.useRef<HTMLDivElement>(null);
275
275
  useOutsideAlerter(iconRef, () => setMenuOpen(false));
276
276
 
277
- return <div className={`ml-2 flex ${direction === "row" ? "flex-row-reverse" : "flex-col"} items-center`}
277
+ return <div className={`pl-2 pt-1 pb-4 flex ${direction === "row" ? "flex-row-reverse" : "flex-col"} items-center`}
278
278
  ref={iconRef}
279
279
  {...provided.dragHandleProps}>
280
280
  <Tooltip
@@ -302,14 +302,21 @@ export function ArrayItemOptions({
302
302
  </IconButton>
303
303
 
304
304
  <Menu
305
+ portalContainer={iconRef.current}
305
306
  open={menuOpen}
306
307
  trigger={<div/>}>
307
308
 
308
- <MenuItem dense onClick={() => remove(index)}>
309
+ <MenuItem dense onClick={(e) => {
310
+ setMenuOpen(false);
311
+ remove(index);
312
+ }}>
309
313
  <RemoveIcon size={"small"}/>
310
314
  Remove
311
315
  </MenuItem>
312
- <MenuItem dense onClick={() => copy(index)}>
316
+ <MenuItem dense onClick={() => {
317
+ setMenuOpen(false);
318
+ copy(index);
319
+ }}>
313
320
  <ContentCopyIcon size={"small"}/>
314
321
  Copy
315
322
  </MenuItem>
@@ -8,7 +8,7 @@ import { CellRendererParams, VirtualTableColumn } from "../VirtualTable";
8
8
  import { getValueInPath } from "../../util";
9
9
  import { getRowHeight } from "../VirtualTable/common";
10
10
  import { EntityCollectionRowActions } from "./EntityCollectionRowActions";
11
- import { EntityCollectionTableController } from "./types";
11
+ import { EntityCollectionTableController } from "../common/types";
12
12
  import { CollectionTableToolbar } from "./internal/CollectionTableToolbar";
13
13
  import { EntityCollectionTableProps } from "./EntityCollectionTableProps";
14
14
  import { EntityTableCell } from "./internal/EntityTableCell";
@@ -16,13 +16,8 @@ import { CustomFieldValidator } from "../../form/validation";
16
16
  import { renderSkeletonText } from "../../preview";
17
17
  import { propertiesToColumns } from "./column_utils";
18
18
  import { ErrorView } from "../ErrorView";
19
- import { SimpleTable } from "./SimpleTable";
19
+ import { SelectableTable } from "../SelectableTable/SelectableTable";
20
20
 
21
- const DEFAULT_STATE = {} as any;
22
-
23
- export const EntityCollectionTableContext = React.createContext<EntityCollectionTableController<any>>(DEFAULT_STATE);
24
-
25
- export const useEntityCollectionTableController = () => useContext<EntityCollectionTableController<any>>(EntityCollectionTableContext);
26
21
 
27
22
  /**
28
23
  * This component is in charge of rendering a collection table with a high
@@ -313,21 +308,20 @@ export const EntityCollectionTable = React.memo<EntityCollectionTableProps<any>>
313
308
  actions={actions}
314
309
  loading={tableController.dataLoading}/>
315
310
 
316
- <SimpleTable columns={columns}
317
- size={size}
318
- inlineEditing={inlineEditing}
319
- cellRenderer={cellRenderer}
320
- onEntityClick={onEntityClick}
321
- highlightedRow={useCallback((entity: Entity<M>) => selectedEntityIds?.includes(entity.id) ?? false, [selectedEntityIds])}
322
- tableController={tableController}
323
- onValueChange={onValueChange}
324
- onColumnResize={onColumnResize}
325
- hoverRow={hoverRow}
326
- filterable={filterable}
327
- emptyComponent={emptyComponent}
328
- endAdornment={endAdornment}
329
- AddColumnComponent={AddColumnComponent}/>
330
-
311
+ <SelectableTable columns={columns}
312
+ size={size}
313
+ inlineEditing={inlineEditing}
314
+ cellRenderer={cellRenderer}
315
+ onEntityClick={onEntityClick}
316
+ highlightedRow={useCallback((entity: Entity<M>) => selectedEntityIds?.includes(entity.id) ?? false, [selectedEntityIds])}
317
+ tableController={tableController}
318
+ onValueChange={onValueChange}
319
+ onColumnResize={onColumnResize}
320
+ hoverRow={hoverRow}
321
+ filterable={filterable}
322
+ emptyComponent={emptyComponent}
323
+ endAdornment={endAdornment}
324
+ AddColumnComponent={AddColumnComponent}/>
331
325
 
332
326
  </div>
333
327
  );
@@ -10,12 +10,8 @@ import {
10
10
  SelectionController,
11
11
  User
12
12
  } from "../../types";
13
- import { OnCellValueChange, UniqueFieldValidator } from "./types";
13
+ import { OnCellValueChange, OnColumnResizeParams, UniqueFieldValidator } from "../common/types";
14
14
 
15
- /**
16
- * @group Collection components
17
- */
18
- export type OnColumnResizeParams = { width: number, key: string };
19
15
 
20
16
  /**
21
17
  * @group Collection components
@@ -24,13 +24,13 @@ import { getPreviewSizeFrom } from "../../preview/util";
24
24
  import { isReadOnly } from "../../util";
25
25
 
26
26
  import { CustomFieldValidator, mapPropertyToYup } from "../../form/validation";
27
- import { useEntityCollectionTableController } from "./EntityCollectionTable";
28
27
  import { useClearRestoreValue, useFireCMSContext } from "../../hooks";
29
28
 
30
29
  import { EntityTableCell } from "./internal/EntityTableCell";
31
30
  import { EntityTableCellActions } from "./internal/EntityTableCellActions";
32
31
 
33
32
  import { getRowHeight } from "../VirtualTable/common";
33
+ import { useSelectableTableController } from "../SelectableTable/SelectableTableContext";
34
34
 
35
35
  export interface PropertyTableCellProps<T extends CMSType, M extends Record<string, any>> {
36
36
  propertyKey: string;
@@ -84,7 +84,7 @@ export const PropertyTableCell = React.memo<PropertyTableCellProps<any, any>>(
84
84
  selectedCell,
85
85
  select,
86
86
  setPopupCell
87
- } = useEntityCollectionTableController();
87
+ } = useSelectableTableController();
88
88
 
89
89
  const selected = selectedCell?.propertyKey === propertyKey &&
90
90
  selectedCell?.entity.path === entity.path &&
@@ -3,7 +3,7 @@ import { getTableCellAlignment, getTablePropertyColumnWidth } from "./internal/c
3
3
  import { FilterValues, ResolvedProperties, ResolvedProperty } from "../../types";
4
4
  import { VirtualTableColumn } from "../VirtualTable";
5
5
  import { getIconForProperty, getResolvedPropertyInPath } from "../../util";
6
- import { getColumnKeysForProperty } from "../EntityCollectionView/useColumnsIds";
6
+ import { getColumnKeysForProperty } from "../common/useColumnsIds";
7
7
 
8
8
  export function buildIdColumn(largeLayout?: boolean): VirtualTableColumn {
9
9
  return {
@@ -4,17 +4,9 @@ export {
4
4
 
5
5
  export type {
6
6
  EntityCollectionTableProps,
7
- OnColumnResizeParams
8
7
  } from "./EntityCollectionTableProps";
9
8
 
10
- export type {
11
- UniqueFieldValidator,
12
- OnCellValueChange,
13
- OnCellValueChangeParams
14
- } from "./types";
15
-
16
9
  export * from "./PropertyTableCell";
17
- export * from "./SimpleTable";
18
10
  export * from "./EntityCollectionRowActions";
19
- export * from "./useDataSourceEntityCollectionTableController";
11
+ export * from "../common/useDataSourceEntityCollectionTableController";
20
12
  export * from "./column_utils";
@@ -19,11 +19,12 @@ import { useDraggable } from "./useDraggable";
19
19
  import { CustomFieldValidator, getYupEntitySchema } from "../../../../form/validation";
20
20
  import { useWindowSize } from "./useWindowSize";
21
21
  import { ElementResizeListener } from "./ElementResizeListener";
22
- import { ErrorView, OnCellValueChangeParams } from "../../../../components";
22
+ import { ErrorView } from "../../../ErrorView";
23
23
  import { getPropertyInPath, isReadOnly, resolveCollection } from "../../../../util";
24
24
  import { Button, ClearIcon, DialogActions, IconButton, Typography } from "@firecms/ui";
25
25
  import { PropertyFieldBinding } from "../../../../form";
26
26
  import { useCustomizationController, useFireCMSContext } from "../../../../hooks";
27
+ import { OnCellValueChangeParams } from "../../../common";
27
28
 
28
29
  interface PopupFormFieldProps<M extends Record<string, any>> {
29
30
  entity?: Entity<M>;
@@ -16,14 +16,11 @@ import {
16
16
  SelectionController
17
17
  } from "../../types";
18
18
  import {
19
+ EntityCollectionRowActions,
19
20
  EntityCollectionTable,
20
- OnCellValueChange,
21
- OnColumnResizeParams,
22
- UniqueFieldValidator
21
+ useDataSourceEntityCollectionTableController
23
22
  } from "../EntityCollectionTable";
24
23
 
25
- import { EntityCollectionRowActions } from "../EntityCollectionTable/EntityCollectionRowActions";
26
-
27
24
  import {
28
25
  canCreateEntity,
29
26
  canDeleteEntity,
@@ -40,16 +37,12 @@ import {
40
37
  useAuthController,
41
38
  useCustomizationController,
42
39
  useDataSource,
43
- useFireCMSContext,
44
40
  useLargeLayout,
45
41
  useNavigationController,
46
42
  useSideEntityController
47
43
  } from "../../hooks";
48
44
  import { useUserConfigurationPersistence } from "../../hooks/useUserConfigurationPersistence";
49
45
  import { EntityCollectionViewActions } from "./EntityCollectionViewActions";
50
- import {
51
- useDataSourceEntityCollectionTableController
52
- } from "../EntityCollectionTable/useDataSourceEntityCollectionTableController";
53
46
  import {
54
47
  AddIcon,
55
48
  Button,
@@ -66,7 +59,13 @@ import {
66
59
  } from "@firecms/ui";
67
60
  import { setIn } from "formik";
68
61
  import { getSubcollectionColumnId } from "../EntityCollectionTable/internal/common";
69
- import { useColumnIds } from "./useColumnsIds";
62
+ import {
63
+ OnCellValueChange,
64
+ OnColumnResizeParams,
65
+ UniqueFieldValidator,
66
+ useColumnIds,
67
+ useTableSearchHelper
68
+ } from "../common";
70
69
  import { PopupFormField } from "../EntityCollectionTable/internal/popup_field/PopupFormField";
71
70
  import { GetPropertyForProps } from "../EntityCollectionTable/EntityCollectionTableProps";
72
71
  import {
@@ -130,7 +129,6 @@ export const EntityCollectionView = React.memo(
130
129
  const userConfigPersistence = useUserConfigurationPersistence();
131
130
  const analyticsController = useAnalyticsController();
132
131
  const customizationController = useCustomizationController();
133
- const context = useFireCMSContext();
134
132
 
135
133
  const containerRef = React.useRef<HTMLDivElement>(null);
136
134
 
@@ -148,7 +146,6 @@ export const EntityCollectionView = React.memo(
148
146
  const [selectedNavigationEntity, setSelectedNavigationEntity] = useState<Entity<M> | undefined>(undefined);
149
147
  const [deleteEntityClicked, setDeleteEntityClicked] = React.useState<Entity<M> | Entity<M>[] | undefined>(undefined);
150
148
 
151
- const [textSearchLoading, setTextSearchLoading] = useState<boolean>(false);
152
149
  const [lastDeleteTimestamp, setLastDeleteTimestamp] = React.useState<number>(0);
153
150
 
154
151
  // number of entities in the collection
@@ -569,34 +566,16 @@ export const EntityCollectionView = React.memo(
569
566
  }
570
567
  : undefined;
571
568
 
572
- const [textSearchInitialised, setTextSearchInitialised] = useState<boolean>(false);
573
- let onTextSearchClick: (() => void) | undefined;
574
- let textSearchEnabled = Boolean(collection.textSearchEnabled);
575
- if (customizationController?.plugins) {
576
- const addTextSearchClickListener = customizationController.plugins?.find(p => Boolean(p.collectionView?.onTextSearchClick));
577
-
578
- onTextSearchClick = addTextSearchClickListener
579
- ? () => {
580
- setTextSearchLoading(true);
581
- Promise.all(customizationController.plugins?.map(p => {
582
- if (p.collectionView?.onTextSearchClick)
583
- return p.collectionView.onTextSearchClick({ context, path: resolvedFullPath, collection, parentCollectionIds });
584
- return Promise.resolve(true);
585
- }) as Promise<boolean>[])
586
- .then((res) => {
587
- if (res.every(Boolean)) setTextSearchInitialised(true);
588
- })
589
- .finally(() => setTextSearchLoading(false));
590
- }
591
- : undefined;
592
-
593
- customizationController.plugins?.forEach(p => {
594
- if (!textSearchEnabled)
595
- if (p.collectionView?.showTextSearchBar) {
596
- textSearchEnabled = p.collectionView.showTextSearchBar({ context, path: resolvedFullPath, collection, parentCollectionIds });
597
- }
598
- })
599
- }
569
+ const {
570
+ textSearchLoading,
571
+ textSearchInitialised,
572
+ onTextSearchClick,
573
+ textSearchEnabled
574
+ } = useTableSearchHelper({
575
+ collection,
576
+ fullPath: resolvedFullPath,
577
+ parentCollectionIds
578
+ });
600
579
 
601
580
  return (
602
581
  <div className={cn("overflow-hidden h-full w-full", className)}
@@ -1,8 +1,11 @@
1
1
  import React, { MouseEventHandler, useCallback, useEffect, useMemo, useState } from "react";
2
- import { CollectionSize, Entity, EntityCollection, FilterValues } from "../types";
2
+ import { CollectionSize, Entity, EntityCollection, FilterValues } from "../../types";
3
3
 
4
- import { EntityCollectionTable } from "./EntityCollectionTable";
5
- import { EntityCollectionRowActions } from "./EntityCollectionTable/EntityCollectionRowActions";
4
+ import {
5
+ EntityCollectionRowActions,
6
+ EntityCollectionTable,
7
+ useDataSourceEntityCollectionTableController
8
+ } from "../EntityCollectionTable";
6
9
  import {
7
10
  useAuthController,
8
11
  useCustomizationController,
@@ -10,17 +13,14 @@ import {
10
13
  useLargeLayout,
11
14
  useNavigationController,
12
15
  useSideEntityController
13
- } from "../hooks";
14
- import { ErrorView } from "./ErrorView";
16
+ } from "../../hooks";
17
+ import { ErrorView } from "../ErrorView";
15
18
  import { AddIcon, Button, DialogActions, Typography } from "@firecms/ui";
16
- import { canCreateEntity, fullPathToCollectionSegments, resolveCollection } from "../util";
17
- import { useSelectionController } from "./EntityCollectionView/EntityCollectionView";
18
- import {
19
- useDataSourceEntityCollectionTableController
20
- } from "./EntityCollectionTable/useDataSourceEntityCollectionTableController";
21
- import { useColumnIds } from "./EntityCollectionView/useColumnsIds";
22
- import { useSideDialogContext } from "../core";
23
- import { useAnalyticsController } from "../hooks/useAnalyticsController";
19
+ import { canCreateEntity, fullPathToCollectionSegments, resolveCollection } from "../../util";
20
+ import { useSelectionController } from "../EntityCollectionView/EntityCollectionView";
21
+ import { useColumnIds, useTableSearchHelper } from "../common";
22
+ import { useSideDialogContext } from "../../core";
23
+ import { useAnalyticsController } from "../../hooks/useAnalyticsController";
24
24
 
25
25
  /**
26
26
  * @group Components
@@ -88,7 +88,7 @@ export interface ReferenceSelectionInnerProps<M extends Record<string, any>> {
88
88
  * You probably want to open this dialog as a side view using {@link useReferenceDialog}
89
89
  * @group Components
90
90
  */
91
- export function ReferenceSelectionInner<M extends Record<string, any>>(
91
+ export function ReferenceSelectionTable<M extends Record<string, any>>(
92
92
  {
93
93
  onSingleEntitySelected,
94
94
  onMultipleEntitiesSelected,
@@ -98,7 +98,7 @@ export function ReferenceSelectionInner<M extends Record<string, any>>(
98
98
  selectedEntityIds: selectedEntityIdsProp,
99
99
  description,
100
100
  forceFilter,
101
- maxSelection
101
+ maxSelection,
102
102
  }: ReferenceSelectionInnerProps<M>) {
103
103
 
104
104
  const sideDialogContext = useSideDialogContext();
@@ -266,6 +266,19 @@ export function ReferenceSelectionInner<M extends Record<string, any>>(
266
266
  forceFilter
267
267
  });
268
268
 
269
+
270
+ const {
271
+ textSearchLoading,
272
+ textSearchInitialised,
273
+ onTextSearchClick,
274
+ textSearchEnabled
275
+ } =
276
+ // eslint-disable-next-line react-hooks/rules-of-hooks
277
+ useTableSearchHelper({
278
+ collection,
279
+ fullPath,
280
+ });
281
+
269
282
  return (
270
283
 
271
284
  <div className="flex flex-col h-full">
@@ -273,6 +286,9 @@ export function ReferenceSelectionInner<M extends Record<string, any>>(
273
286
  <div className="flex-grow">
274
287
  {entitiesDisplayedFirst &&
275
288
  <EntityCollectionTable
289
+ textSearchLoading={textSearchLoading}
290
+ onTextSearchClick={textSearchInitialised ? undefined : onTextSearchClick}
291
+ textSearchEnabled={textSearchEnabled}
276
292
  displayedColumnIds={displayedColumnIds}
277
293
  onEntityClick={onEntityClick}
278
294
  tableController={tableController}
@@ -10,17 +10,16 @@ import {
10
10
  } from "../../types";
11
11
  import { CellRendererParams, VirtualTable, VirtualTableColumn } from "../VirtualTable";
12
12
  import { enumToObjectEntries } from "../../util";
13
- import { OnCellValueChange } from "./types";
14
- import { OnColumnResizeParams } from "./EntityCollectionTableProps";
13
+ import { OnCellValueChange, OnColumnResizeParams } from "../common/types";
15
14
  import { FilterFormFieldProps } from "../VirtualTable/VirtualTableHeader";
16
15
  import { ReferenceFilterField } from "./filters/ReferenceFilterField";
17
16
  import { StringNumberFilterField } from "./filters/StringNumberFilterField";
18
17
  import { BooleanFilterField } from "./filters/BooleanFilterField";
19
18
  import { DateTimeFilterField } from "./filters/DateTimeFilterField";
20
- import { EntityCollectionTableContext } from "./EntityCollectionTable";
21
19
  import { useOutsideAlerter } from "@firecms/ui";
20
+ import { SelectableTableContext } from "./SelectableTableContext";
22
21
 
23
- export type SimpleTableProps<M extends Record<string, any>> = {
22
+ export type SelectableTableProps<M extends Record<string, any>> = {
24
23
 
25
24
  /**
26
25
  * Callback when a cell value changes.
@@ -108,8 +107,8 @@ export type SimpleTableProps<M extends Record<string, any>> = {
108
107
  * @see VirtualTable
109
108
  * @group Components
110
109
  */
111
- export const SimpleTable = React.memo<SimpleTableProps<any>>(
112
- function SimpleTable<M extends Record<string, any>>
110
+ export const SelectableTable = React.memo<SelectableTableProps<any>>(
111
+ function SelectableTable<M extends Record<string, any>>
113
112
  ({
114
113
  onValueChange,
115
114
  cellRenderer,
@@ -143,7 +142,7 @@ export const SimpleTable = React.memo<SimpleTableProps<any>>(
143
142
  highlightedRow,
144
143
  endAdornment,
145
144
  AddColumnComponent
146
- }: SimpleTableProps<M>) {
145
+ }: SelectableTableProps<M>) {
147
146
 
148
147
  const ref = useRef<HTMLDivElement>(null);
149
148
  const [size, setSize] = React.useState<CollectionSize>("m");
@@ -203,7 +202,7 @@ export const SimpleTable = React.memo<SimpleTableProps<any>>(
203
202
  }, [forceFilter]);
204
203
 
205
204
  return (
206
- <EntityCollectionTableContext.Provider
205
+ <SelectableTableContext.Provider
207
206
  value={{
208
207
  setPopupCell: setPopupCell as ((cell?: SelectedCellProps<M>) => void),
209
208
  select,
@@ -244,7 +243,7 @@ export const SimpleTable = React.memo<SimpleTableProps<any>>(
244
243
  />
245
244
 
246
245
  </div>
247
- </EntityCollectionTableContext.Provider>
246
+ </SelectableTableContext.Provider>
248
247
  );
249
248
 
250
249
  },
@@ -0,0 +1,6 @@
1
+ import React, { useContext } from "react";
2
+ import { EntityCollectionTableController } from "../common/types";
3
+
4
+ export const SelectableTableContext = React.createContext<EntityCollectionTableController<any>>({} as any);
5
+
6
+ export const useSelectableTableController = () => useContext<EntityCollectionTableController<any>>(SelectableTableContext);
@@ -0,0 +1,5 @@
1
+ export * from "./types";
2
+ export * from "./useDebouncedData";
3
+ export * from "./useColumnsIds";
4
+ export * from "./useDataSourceEntityCollectionTableController";
5
+ export * from "./useTableSearchHelper";
@@ -56,3 +56,8 @@ export type UniqueFieldValidator = (props: {
56
56
  * @group Collection components
57
57
  */
58
58
  export type OnCellValueChange<T, M extends Record<string, any>> = (params: OnCellValueChangeParams<T, M>) => Promise<void> | void;
59
+
60
+ /**
61
+ * @group Collection components
62
+ */
63
+ export type OnColumnResizeParams = { width: number, key: string };
@@ -0,0 +1,47 @@
1
+ import { useState } from "react";
2
+
3
+ import { EntityCollection } from "../../types";
4
+ import { useCustomizationController, useFireCMSContext } from "../../hooks";
5
+
6
+ export interface UseTableSearchHelperParams<M extends Record<string, any>> {
7
+ collection: EntityCollection<M>;
8
+ fullPath: string;
9
+ parentCollectionIds?: string[];
10
+ }
11
+
12
+ export function useTableSearchHelper<M extends Record<string, any>>({ collection, fullPath, parentCollectionIds }: UseTableSearchHelperParams<M>) {
13
+
14
+ const context = useFireCMSContext();
15
+ const customizationController = useCustomizationController();
16
+
17
+ const [textSearchLoading, setTextSearchLoading] = useState<boolean>(false);
18
+ const [textSearchInitialised, setTextSearchInitialised] = useState<boolean>(false);
19
+ let onTextSearchClick: (() => void) | undefined;
20
+ let textSearchEnabled = Boolean(collection.textSearchEnabled);
21
+ if (customizationController?.plugins) {
22
+ const addTextSearchClickListener = customizationController.plugins?.find(p => Boolean(p.collectionView?.onTextSearchClick));
23
+
24
+ onTextSearchClick = addTextSearchClickListener
25
+ ? () => {
26
+ setTextSearchLoading(true);
27
+ Promise.all(customizationController.plugins?.map(p => {
28
+ if (p.collectionView?.onTextSearchClick)
29
+ return p.collectionView.onTextSearchClick({ context, path: fullPath, collection, parentCollectionIds });
30
+ return Promise.resolve(true);
31
+ }) as Promise<boolean>[])
32
+ .then((res) => {
33
+ if (res.every(Boolean)) setTextSearchInitialised(true);
34
+ })
35
+ .finally(() => setTextSearchLoading(false));
36
+ }
37
+ : undefined;
38
+
39
+ customizationController.plugins?.forEach(p => {
40
+ if (!textSearchEnabled)
41
+ if (p.collectionView?.showTextSearchBar) {
42
+ textSearchEnabled = p.collectionView.showTextSearchBar({ context, path: fullPath, collection, parentCollectionIds });
43
+ }
44
+ })
45
+ }
46
+ return { textSearchLoading, textSearchInitialised, onTextSearchClick, textSearchEnabled };
47
+ }
@@ -4,13 +4,17 @@ export { ErrorView } from "./ErrorView";
4
4
  export type { EntityPreviewProps } from "./EntityPreview";
5
5
  export { EntityPreview } from "./EntityPreview";
6
6
 
7
- export type { ReferenceSelectionInnerProps } from "./ReferenceSelectionInner";
8
- export { ReferenceSelectionInner } from "./ReferenceSelectionInner";
7
+ export type { ReferenceSelectionInnerProps } from "./ReferenceTable/ReferenceSelectionTable";
8
+ export { ReferenceSelectionTable } from "./ReferenceTable/ReferenceSelectionTable";
9
9
 
10
10
  export { CircularProgressCenter } from "./CircularProgressCenter";
11
11
 
12
+ export * from "./common";
13
+
12
14
  export * from "./HomePage";
15
+ export * from "./SelectableTable/SelectableTable";
13
16
  export * from "./EntityCollectionView/EntityCollectionView";
17
+ export * from "./EntityCollectionView/EntityCollectionViewActions";
14
18
 
15
19
  export * from "./PropertyConfigBadge";
16
20
 
@@ -33,13 +33,15 @@ export function EntitySidePanel(props: EntitySidePanelProps) {
33
33
  if (!props) return undefined;
34
34
  let usedCollection = props.collection;
35
35
 
36
+ const registryCollection = navigationController.getCollection(props.path, props.entityId);
37
+ if (registryCollection) {
38
+ usedCollection = registryCollection;
39
+ }
36
40
  if (!usedCollection) {
37
- usedCollection = navigationController.getCollection(props.path, props.entityId);
38
- if (!usedCollection) {
39
- console.error("ERROR: No collection found in path `", props.path, "`. Entity id: ", props.entityId);
40
- throw Error("ERROR: No collection found in path `" + props.path + "`. Make sure you have defined a collection for this path in the root navigation.");
41
- }
41
+ console.error("ERROR: No collection found in path `", props.path, "`. Entity id: ", props.entityId);
42
+ throw Error("ERROR: No collection found in path `" + props.path + "`. Make sure you have defined a collection for this path in the root navigation.");
42
43
  }
44
+
43
45
  return usedCollection;
44
46
  }, [navigationController, props]);
45
47
 
@@ -427,7 +427,7 @@ function EntityFormInternal<M extends Record<string, any>>({
427
427
  {pluginActions}
428
428
  </div>}
429
429
 
430
- <div className="pl-4 pr-4 pt-12 pb-16 md:pl-8">
430
+ <div className="pt-12 pb-16 pl-8 pr-8">
431
431
  <div
432
432
  className={`w-full py-2 flex flex-col items-start mt-${4 + (pluginActions ? 8 : 0)} lg:mt-${8 + (pluginActions ? 8 : 0)} mb-8`}>
433
433
 
@@ -1,3 +1,2 @@
1
1
  export * from "./FormikArrayContainer";
2
- export * from "./SwitchControl";
3
2
  export * from "./FieldHelperText";