@databiosphere/findable-ui 20.0.0 → 21.0.0

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 (154) hide show
  1. package/.release-please-manifest.json +1 -1
  2. package/CHANGELOG.md +11 -0
  3. package/lib/components/Table/common/columnDef.js +18 -2
  4. package/lib/components/Table/common/columnIdentifier.d.ts +4 -0
  5. package/lib/components/Table/common/columnIdentifier.js +4 -0
  6. package/lib/components/Table/common/typeGuards.d.ts +11 -0
  7. package/lib/components/Table/common/typeGuards.js +8 -0
  8. package/lib/components/Table/common/utils.d.ts +1 -28
  9. package/lib/components/Table/common/utils.js +5 -88
  10. package/lib/components/Table/components/TableCell/common/utils.js +3 -3
  11. package/lib/components/Table/components/TableCell/components/RowSelectionCell/rowSelectionCell.d.ts +2 -5
  12. package/lib/components/Table/components/TableFeatures/ColumnVisibility/utils.d.ts +7 -18
  13. package/lib/components/Table/components/TableFeatures/ColumnVisibility/utils.js +20 -31
  14. package/lib/components/Table/components/TableHead/components/HeadSelectionCell/headSelectionCell.d.ts +2 -5
  15. package/lib/components/Table/components/TableHead/components/HeadSelectionCell/headSelectionCell.js +2 -2
  16. package/lib/components/Table/components/TableToolbar/components/ColumnGrouping/columnGrouping.js +5 -17
  17. package/lib/components/Table/components/TableToolbar/components/ColumnGrouping/components/MenuItems/constants.d.ts +3 -0
  18. package/lib/components/Table/components/TableToolbar/components/ColumnGrouping/components/MenuItems/constants.js +10 -0
  19. package/lib/components/Table/components/TableToolbar/components/ColumnGrouping/components/MenuItems/menuItems.d.ts +1 -1
  20. package/lib/components/Table/components/TableToolbar/components/ColumnGrouping/components/MenuItems/menuItems.js +22 -10
  21. package/lib/components/Table/components/TableToolbar/components/ColumnGrouping/components/MenuItems/types.d.ts +1 -2
  22. package/lib/components/Table/components/TableToolbar/components/ColumnGrouping/components/MenuItems/utils.d.ts +27 -0
  23. package/lib/components/Table/components/TableToolbar/components/ColumnGrouping/components/MenuItems/utils.js +45 -0
  24. package/lib/components/Table/components/TableToolbar/components/ColumnGrouping/constants.d.ts +1 -3
  25. package/lib/components/Table/components/TableToolbar/components/ColumnGrouping/constants.js +0 -10
  26. package/lib/components/Table/components/TableToolbar/components/ColumnGrouping/utils.d.ts +3 -13
  27. package/lib/components/Table/components/TableToolbar/components/ColumnGrouping/utils.js +22 -27
  28. package/lib/components/Table/components/TableToolbar/components/ColumnVisibility/columnVisibility.d.ts +3 -0
  29. package/lib/components/Table/components/TableToolbar/components/ColumnVisibility/columnVisibility.js +13 -0
  30. package/lib/components/Table/components/TableToolbar/components/ColumnVisibility/columnVisibility.styles.d.ts +3 -0
  31. package/lib/components/Table/components/TableToolbar/components/ColumnVisibility/columnVisibility.styles.js +11 -0
  32. package/lib/components/Table/components/TableToolbar/components/ColumnVisibility/components/MenuItems/constants.d.ts +2 -0
  33. package/lib/components/Table/components/TableToolbar/components/ColumnVisibility/components/MenuItems/constants.js +7 -0
  34. package/lib/components/Table/components/TableToolbar/components/ColumnVisibility/components/MenuItems/menuItems.d.ts +3 -0
  35. package/lib/components/Table/components/TableToolbar/components/ColumnVisibility/components/MenuItems/menuItems.js +22 -0
  36. package/lib/components/Table/components/TableToolbar/components/ColumnVisibility/components/MenuItems/menuItems.styles.d.ts +2 -0
  37. package/lib/components/Table/components/TableToolbar/components/ColumnVisibility/components/MenuItems/menuItems.styles.js +16 -0
  38. package/lib/components/Table/components/TableToolbar/components/ColumnVisibility/components/MenuItems/types.d.ts +4 -0
  39. package/lib/components/Table/components/TableToolbar/components/ColumnVisibility/components/MenuItems/types.js +1 -0
  40. package/lib/components/Table/components/TableToolbar/components/ColumnVisibility/components/MenuItems/utils.d.ts +26 -0
  41. package/lib/components/Table/components/TableToolbar/components/ColumnVisibility/components/MenuItems/utils.js +32 -0
  42. package/lib/components/Table/components/TableToolbar/components/ColumnVisibility/constants.d.ts +2 -0
  43. package/lib/components/Table/components/TableToolbar/components/ColumnVisibility/constants.js +3 -0
  44. package/lib/components/Table/components/TableToolbar/components/ColumnVisibility/types.d.ts +4 -0
  45. package/lib/components/Table/components/TableToolbar/components/ColumnVisibility/types.js +1 -0
  46. package/lib/components/Table/components/TableToolbar/tableToolbar.js +5 -12
  47. package/lib/components/Table/features/RowPosition/constants.js +5 -3
  48. package/lib/components/Table/features/RowPosition/types.d.ts +3 -0
  49. package/lib/components/Table/features/RowPosition/utils.d.ts +1 -7
  50. package/lib/components/Table/features/RowPosition/utils.js +0 -20
  51. package/lib/components/Table/features/RowPreview/constants.js +1 -1
  52. package/lib/components/Table/features/entities.d.ts +2 -2
  53. package/lib/components/Table/table.d.ts +2 -4
  54. package/lib/components/Table/table.js +9 -31
  55. package/lib/components/TableCreator/common/utils.js +1 -4
  56. package/lib/components/TableCreator/options/columnTrackSizing/typeGuards.d.ts +7 -0
  57. package/lib/components/TableCreator/options/columnTrackSizing/typeGuards.js +8 -0
  58. package/lib/components/TableCreator/options/columnTrackSizing/utils.d.ts +30 -0
  59. package/lib/components/TableCreator/options/columnTrackSizing/utils.js +83 -0
  60. package/lib/components/TableCreator/options/hook.js +8 -7
  61. package/lib/components/TableCreator/options/initialState/columnVisibility.d.ts +7 -0
  62. package/lib/components/TableCreator/options/initialState/columnVisibility.js +16 -0
  63. package/lib/components/TableCreator/options/initialState/hook.d.ts +2 -0
  64. package/lib/components/TableCreator/options/initialState/hook.js +10 -0
  65. package/lib/components/TableCreator/options/visibility/constants.d.ts +2 -0
  66. package/lib/components/TableCreator/options/visibility/constants.js +3 -0
  67. package/lib/components/TableCreator/options/visibility/hook.d.ts +2 -0
  68. package/lib/components/TableCreator/options/visibility/hook.js +11 -0
  69. package/lib/components/TableCreator/tableCreator.js +4 -18
  70. package/lib/config/entities.d.ts +0 -4
  71. package/lib/providers/exploreState/actions/updateVisibility/action.d.ts +10 -0
  72. package/lib/providers/exploreState/actions/updateVisibility/action.js +16 -0
  73. package/lib/providers/exploreState/actions/updateVisibility/dispatch.d.ts +7 -0
  74. package/lib/providers/exploreState/actions/updateVisibility/dispatch.js +12 -0
  75. package/lib/providers/exploreState/actions/updateVisibility/types.d.ts +9 -0
  76. package/lib/providers/exploreState/actions/updateVisibility/types.js +1 -0
  77. package/lib/providers/exploreState/actions/updateVisibility/utils.d.ts +10 -0
  78. package/lib/providers/exploreState/actions/updateVisibility/utils.js +21 -0
  79. package/lib/providers/exploreState/entities.d.ts +1 -1
  80. package/lib/providers/exploreState/initializer/utils.js +5 -13
  81. package/lib/providers/exploreState/payloads/entities.d.ts +1 -5
  82. package/lib/providers/exploreState/utils.d.ts +1 -1
  83. package/lib/providers/exploreState/utils.js +5 -5
  84. package/lib/providers/exploreState.d.ts +2 -8
  85. package/lib/providers/exploreState.js +2 -5
  86. package/package.json +1 -1
  87. package/src/components/Table/common/columnDef.ts +18 -2
  88. package/src/components/Table/common/columnIdentifier.ts +4 -0
  89. package/src/components/Table/common/typeGuards.ts +12 -0
  90. package/src/components/Table/common/utils.ts +5 -115
  91. package/src/components/Table/components/TableCell/common/utils.ts +3 -3
  92. package/src/components/Table/components/TableCell/components/RowSelectionCell/rowSelectionCell.tsx +3 -7
  93. package/src/components/Table/components/TableFeatures/ColumnVisibility/utils.ts +25 -44
  94. package/src/components/Table/components/TableHead/components/HeadSelectionCell/headSelectionCell.tsx +5 -9
  95. package/src/components/Table/components/TableToolbar/components/ColumnGrouping/columnGrouping.tsx +4 -22
  96. package/src/components/Table/components/TableToolbar/components/ColumnGrouping/components/MenuItems/constants.ts +13 -0
  97. package/src/components/Table/components/TableToolbar/components/ColumnGrouping/components/MenuItems/menuItems.tsx +47 -20
  98. package/src/components/Table/components/TableToolbar/components/ColumnGrouping/components/MenuItems/types.ts +1 -2
  99. package/src/components/Table/components/TableToolbar/components/ColumnGrouping/components/MenuItems/utils.ts +58 -0
  100. package/src/components/Table/components/TableToolbar/components/ColumnGrouping/constants.ts +1 -13
  101. package/src/components/Table/components/TableToolbar/components/ColumnGrouping/utils.ts +26 -33
  102. package/src/components/Table/components/TableToolbar/components/ColumnVisibility/columnVisibility.styles.ts +12 -0
  103. package/src/components/Table/components/TableToolbar/components/ColumnVisibility/columnVisibility.tsx +28 -0
  104. package/src/components/Table/components/TableToolbar/components/ColumnVisibility/components/MenuItems/constants.ts +9 -0
  105. package/src/components/Table/components/TableToolbar/components/ColumnVisibility/components/MenuItems/menuItems.styles.ts +17 -0
  106. package/src/components/Table/components/TableToolbar/components/ColumnVisibility/components/MenuItems/menuItems.tsx +53 -0
  107. package/src/components/Table/components/TableToolbar/components/ColumnVisibility/components/MenuItems/types.ts +5 -0
  108. package/src/components/Table/components/TableToolbar/components/ColumnVisibility/components/MenuItems/utils.ts +44 -0
  109. package/src/components/Table/components/TableToolbar/components/ColumnVisibility/constants.ts +5 -0
  110. package/src/components/Table/components/TableToolbar/components/ColumnVisibility/types.ts +5 -0
  111. package/src/components/Table/components/TableToolbar/tableToolbar.tsx +5 -19
  112. package/src/components/Table/features/RowPosition/constants.ts +8 -5
  113. package/src/components/Table/features/RowPosition/types.ts +4 -0
  114. package/src/components/Table/features/RowPosition/utils.ts +1 -30
  115. package/src/components/Table/features/RowPreview/constants.ts +1 -1
  116. package/src/components/Table/features/entities.ts +2 -2
  117. package/src/components/Table/table.tsx +8 -46
  118. package/src/components/TableCreator/common/utils.ts +0 -4
  119. package/src/components/TableCreator/options/columnTrackSizing/typeGuards.ts +12 -0
  120. package/src/components/TableCreator/options/columnTrackSizing/utils.ts +99 -0
  121. package/src/components/TableCreator/options/hook.ts +8 -11
  122. package/src/components/TableCreator/options/initialState/columnVisibility.ts +22 -0
  123. package/src/components/TableCreator/options/initialState/hook.ts +24 -0
  124. package/src/components/TableCreator/options/visibility/constants.ts +5 -0
  125. package/src/components/TableCreator/options/visibility/hook.ts +22 -0
  126. package/src/components/TableCreator/tableCreator.tsx +3 -27
  127. package/src/config/entities.ts +2 -4
  128. package/src/providers/exploreState/actions/updateVisibility/action.ts +29 -0
  129. package/src/providers/exploreState/actions/updateVisibility/dispatch.ts +19 -0
  130. package/src/providers/exploreState/actions/updateVisibility/types.ts +11 -0
  131. package/src/providers/exploreState/actions/updateVisibility/utils.ts +28 -0
  132. package/src/providers/exploreState/entities.ts +1 -1
  133. package/src/providers/exploreState/initializer/utils.ts +5 -21
  134. package/src/providers/exploreState/payloads/entities.ts +0 -6
  135. package/src/providers/exploreState/utils.ts +5 -5
  136. package/src/providers/exploreState.tsx +3 -18
  137. package/lib/components/Table/components/CheckboxMenu/checkboxMenu.d.ts +0 -16
  138. package/lib/components/Table/components/CheckboxMenu/checkboxMenu.js +0 -28
  139. package/lib/components/Table/components/CheckboxMenu/checkboxMenu.stories.d.ts +0 -5
  140. package/lib/components/Table/components/CheckboxMenu/checkboxMenu.stories.js +0 -46
  141. package/lib/components/Table/components/CheckboxMenu/checkboxMenu.styles.d.ts +0 -3
  142. package/lib/components/Table/components/CheckboxMenu/checkboxMenu.styles.js +0 -21
  143. package/lib/components/Table/features/constants.d.ts +0 -6
  144. package/lib/components/Table/features/constants.js +0 -8
  145. package/lib/components/TableCreator/common/constants.d.ts +0 -7
  146. package/lib/components/TableCreator/common/constants.js +0 -21
  147. package/src/components/Table/components/CheckboxMenu/checkboxMenu.stories.tsx +0 -54
  148. package/src/components/Table/components/CheckboxMenu/checkboxMenu.styles.ts +0 -22
  149. package/src/components/Table/components/CheckboxMenu/checkboxMenu.tsx +0 -87
  150. package/src/components/Table/features/constants.ts +0 -10
  151. package/src/components/TableCreator/common/constants.ts +0 -25
  152. /package/lib/components/Table/components/TableToolbar/components/ColumnGrouping/{columnGrouping.styles.d.ts → components/MenuItems/menuItems.styles.d.ts} +0 -0
  153. /package/lib/components/Table/components/TableToolbar/components/ColumnGrouping/{columnGrouping.styles.js → components/MenuItems/menuItems.styles.js} +0 -0
  154. /package/src/components/Table/components/TableToolbar/components/ColumnGrouping/{columnGrouping.styles.ts → components/MenuItems/menuItems.styles.ts} +0 -0
@@ -0,0 +1,83 @@
1
+ import { COLUMN_IDENTIFIER } from "../../../Table/common/columnIdentifier";
2
+ import { isGridTrackMinMax } from "./typeGuards";
3
+ /**
4
+ * Generates the grid track sizing for a table using a grid layout.
5
+ * Creates a string value for the `grid-template-columns` CSS property based on the visible columns.
6
+ * It ensures proper sizing for grouped, system, and non-system columns.
7
+ * - Grouped columns are excluded from grid sizing as they flex across the table.
8
+ * - System columns (e.g., "rowPosition" and "rowSelection") have pre-defined sizing.
9
+ * - Non-system columns collectively fill the table's width. If their total fractional sizing is less than `1fr`, the first non-system column is assigned `1fr` to ensure the table is filled.
10
+ * @param visibleColumns - Visible columns.
11
+ * @returns string defining the CSS `grid-template-columns` value for the table.
12
+ */
13
+ export function getColumnTrackSizing(visibleColumns) {
14
+ // Precompute track sizing.
15
+ const trackSizing = [];
16
+ let columnCount = 0; // Non-system column count.
17
+ let firstNonSystemColumnIndex = -1;
18
+ let totalFractionalSize = 0;
19
+ for (const [i, column] of visibleColumns.entries()) {
20
+ if (column.getIsGrouped())
21
+ continue;
22
+ // Get the column's track size.
23
+ const columnTrackSize = getColumnTrackSize(column);
24
+ trackSizing.push(columnTrackSize);
25
+ // Extract the fractional value (if it exists), and accumulate the total.
26
+ const frSize = extractFractionalValue(columnTrackSize);
27
+ if (frSize)
28
+ totalFractionalSize += frSize;
29
+ // Skip system columns; track the first non-system column index.
30
+ if (isSystemColumn(column))
31
+ continue;
32
+ if (firstNonSystemColumnIndex < 0)
33
+ firstNonSystemColumnIndex = i;
34
+ columnCount++;
35
+ }
36
+ // Adjust track sizing for the first non-system column when:
37
+ // - the table is a single-column table, or
38
+ // - the total `fr` value is less than 1.
39
+ if (firstNonSystemColumnIndex >= 0 &&
40
+ (columnCount === 1 || totalFractionalSize < 1)) {
41
+ trackSizing[firstNonSystemColumnIndex] = "1fr";
42
+ }
43
+ return trackSizing.join(" ");
44
+ }
45
+ /**
46
+ * Determines the CSS grid track size for a given column.
47
+ * Calculates the track size for a column based on its width configuration.
48
+ * If the column's width is defined as a min-max range, it returns a `minmax()` CSS function.
49
+ * Otherwise, it defaults to the column's width or `1fr` if no width is specified.
50
+ * @param column - Column.
51
+ * @returns A string representing the CSS track size for the column. This can be a `minmax()` function or a fixed/flexible value (e.g., `auto`, `1fr`, `200px`).
52
+ */
53
+ export function getColumnTrackSize(column) {
54
+ const width = column.columnDef.meta?.width || "1fr";
55
+ if (isGridTrackMinMax(width)) {
56
+ return `minmax(${width.min}, ${width.max})`;
57
+ }
58
+ return width;
59
+ }
60
+ /**
61
+ * Returns true if the column is a system column "rowPosition" or "rowSelection".
62
+ * @param column - Column.
63
+ * @returns true if the column is a system column.
64
+ */
65
+ function isSystemColumn(column) {
66
+ return (column.id === COLUMN_IDENTIFIER.ROW_POSITION ||
67
+ column.id === COLUMN_IDENTIFIER.ROW_SELECTION);
68
+ }
69
+ /**
70
+ * Extracts the fractional value (`fr`) from a CSS track size string.
71
+ * This function parses a CSS track size (e.g., `1fr`, `minmax(168px, 0.5fr)`)
72
+ * and extracts the numeric fractional value that appears before `fr`.
73
+ * If the input does not contain a valid fractional value, the function returns `0`.
74
+ * @param columnTrackSize - The CSS track size string e.g. `1fr`, `minmax(100px, 0.5fr)`, `200px`, or `auto`.
75
+ * @returns The fractional value as a number, or `0` if no fractional value is found.
76
+ */
77
+ export function extractFractionalValue(columnTrackSize) {
78
+ const match = columnTrackSize.match(/([\d.]+)fr/);
79
+ if (!match)
80
+ return 0;
81
+ const value = parseFloat(match[1]);
82
+ return Number.isNaN(value) ? 0 : value;
83
+ }
@@ -1,25 +1,26 @@
1
1
  import { useConfig } from "../../../hooks/useConfig";
2
2
  import { useExpandedOptions } from "./expanded/hook";
3
3
  import { useGroupingOptions } from "./grouping/hook";
4
+ import { useInitialState } from "./initialState/hook";
4
5
  import { useRowSelectionOptions } from "./rowSelection/hook";
5
6
  import { useSortingOptions } from "./sorting/hook";
7
+ import { useVisibilityOptions } from "./visibility/hook";
6
8
  export function useTableOptions() {
7
- const { entityConfig: { list: { defaultSort, tableOptions }, }, } = useConfig();
9
+ const { entityConfig } = useConfig();
10
+ const tableOptions = entityConfig.list.tableOptions;
8
11
  const expandedOptions = useExpandedOptions();
9
12
  const groupingOptions = useGroupingOptions();
10
13
  const rowSelectionOptions = useRowSelectionOptions();
11
14
  const sortingOptions = useSortingOptions();
15
+ const visibilityOptions = useVisibilityOptions();
16
+ const initialState = useInitialState(tableOptions);
12
17
  return {
13
18
  ...expandedOptions,
14
19
  ...groupingOptions,
15
20
  ...rowSelectionOptions,
16
21
  ...sortingOptions, // TODO(cc) merge of all sorting options.
22
+ ...visibilityOptions,
17
23
  ...tableOptions,
18
- initialState: {
19
- ...tableOptions?.initialState,
20
- sorting: defaultSort
21
- ? [defaultSort] // TODO(cc) deprecate `defaultSort` in favor of `initialState.sorting`.
22
- : tableOptions?.initialState?.sorting,
23
- },
24
+ initialState,
24
25
  };
25
26
  }
@@ -0,0 +1,7 @@
1
+ import { RowData, TableOptions, VisibilityState } from "@tanstack/react-table";
2
+ /**
3
+ * Returns initial column visibility state.
4
+ * @param tableOptions - Table options.
5
+ * @returns column visibility state.
6
+ */
7
+ export declare function getInitialColumnVisibilityState<T extends RowData>(tableOptions?: Partial<TableOptions<T>> | Partial<Omit<TableOptions<T>, "data" | "columns" | "getCoreRowModel">>): VisibilityState;
@@ -0,0 +1,16 @@
1
+ import { COLUMN_IDENTIFIER } from "../../../Table/common/columnIdentifier";
2
+ /**
3
+ * Returns initial column visibility state.
4
+ * @param tableOptions - Table options.
5
+ * @returns column visibility state.
6
+ */
7
+ export function getInitialColumnVisibilityState(tableOptions) {
8
+ const { initialState } = tableOptions || {};
9
+ const enableRowPosition = Boolean(tableOptions?.enableRowPosition);
10
+ const enableRowSelection = Boolean(tableOptions?.enableRowSelection);
11
+ return {
12
+ [COLUMN_IDENTIFIER.ROW_POSITION]: enableRowPosition,
13
+ [COLUMN_IDENTIFIER.ROW_SELECTION]: enableRowSelection,
14
+ ...initialState?.columnVisibility,
15
+ };
16
+ }
@@ -0,0 +1,2 @@
1
+ import { InitialTableState, RowData, TableOptions } from "@tanstack/react-table";
2
+ export declare function useInitialState<T extends RowData>(tableOptions?: Partial<TableOptions<T>> | Partial<Omit<TableOptions<T>, "data" | "columns" | "getCoreRowModel">>): InitialTableState;
@@ -0,0 +1,10 @@
1
+ import { useMemo } from "react";
2
+ import { getInitialColumnVisibilityState } from "./columnVisibility";
3
+ export function useInitialState(tableOptions) {
4
+ const { initialState } = tableOptions || {};
5
+ const columnVisibility = getInitialColumnVisibilityState(tableOptions);
6
+ return useMemo(() => ({
7
+ ...initialState,
8
+ columnVisibility,
9
+ }), [initialState, columnVisibility]);
10
+ }
@@ -0,0 +1,2 @@
1
+ import { VisibilityOptions } from "@tanstack/react-table";
2
+ export declare const VISIBILITY_OPTIONS: VisibilityOptions;
@@ -0,0 +1,3 @@
1
+ export const VISIBILITY_OPTIONS = {
2
+ enableHiding: true,
3
+ };
@@ -0,0 +1,2 @@
1
+ import { VisibilityOptions } from "@tanstack/react-table";
2
+ export declare function useVisibilityOptions(): VisibilityOptions;
@@ -0,0 +1,11 @@
1
+ import { useCallback } from "react";
2
+ import { useExploreState } from "../../../../hooks/useExploreState";
3
+ import { updateVisibility } from "../../../../providers/exploreState/actions/updateVisibility/dispatch";
4
+ import { VISIBILITY_OPTIONS } from "./constants";
5
+ export function useVisibilityOptions() {
6
+ const { exploreDispatch } = useExploreState();
7
+ const onColumnVisibilityChange = useCallback((updaterOrValue) => {
8
+ exploreDispatch(updateVisibility({ updaterOrValue }));
9
+ }, [exploreDispatch]);
10
+ return { ...VISIBILITY_OPTIONS, onColumnVisibilityChange };
11
+ }
@@ -3,23 +3,14 @@ import { PAPER_PANEL_STYLE } from "../common/Paper/paper";
3
3
  import { ComponentCreator } from "../ComponentCreator/ComponentCreator";
4
4
  import { Loading } from "../Loading/loading";
5
5
  import { COLUMN_DEF } from "../Table/common/columnDef";
6
- import { arrIncludesSome, getInitialState, sortingFn, } from "../Table/common/utils";
7
- import { RowSelectionCell } from "../Table/components/TableCell/components/RowSelectionCell/rowSelectionCell";
8
- import { HeadSelectionCell } from "../Table/components/TableHead/components/HeadSelectionCell/headSelectionCell";
6
+ import { arrIncludesSome, sortingFn } from "../Table/common/utils";
9
7
  import { Table } from "../Table/table";
10
- import { COLUMN_CONFIGS } from "./common/constants";
11
8
  import { buildBaseColumnDef } from "./common/utils";
12
9
  import { useTableOptions } from "./options/hook";
13
10
  import { TableCreator as TableCreatorContainer } from "./tableCreator.styles";
14
11
  const createCell = (config) => function CellCreator(cellContext) {
15
12
  return (React.createElement(ComponentCreator, { components: [config.componentConfig], response: cellContext.row.original, viewContext: { cellContext } }));
16
13
  };
17
- const createHeaderSelectionCell = () => function CellCreator({ table }) {
18
- return React.createElement(HeadSelectionCell, { tableInstance: table });
19
- };
20
- const createRowSelectionCell = () => function CellCreator({ row }) {
21
- return React.createElement(RowSelectionCell, { row: row });
22
- };
23
14
  export const TableCreator = ({ columns, getRowId, items, listView, loading, }) => {
24
15
  const tableOptions = useTableOptions();
25
16
  const columnDefs = useMemo(() => columns.reduce((acc, columnConfig) => {
@@ -33,15 +24,10 @@ export const TableCreator = ({ columns, getRowId, items, listView, loading, }) =
33
24
  }, [
34
25
  /* Initialize column definitions with the "row position" column */
35
26
  COLUMN_DEF.ROW_POSITION,
36
- /* Initialize column definitions with the "select" column */
37
- {
38
- ...buildBaseColumnDef(COLUMN_CONFIGS.SELECT),
39
- cell: createRowSelectionCell(),
40
- header: createHeaderSelectionCell(),
41
- },
27
+ /* Initialize column definitions with the "row selection" column */
28
+ COLUMN_DEF.ROW_SELECTION,
42
29
  ]), [columns]);
43
- const initialState = getInitialState(columns);
44
30
  return (React.createElement(TableCreatorContainer, null,
45
31
  React.createElement(Loading, { appear: false, loading: loading || false, panelStyle: PAPER_PANEL_STYLE.FLUID }),
46
- React.createElement(Table, { columns: columnDefs, getRowId: getRowId, initialState: initialState, items: items, listView: listView, loading: loading, tableOptions: tableOptions })));
32
+ React.createElement(Table, { columns: columnDefs, getRowId: getRowId, items: items, listView: listView, loading: loading, tableOptions: tableOptions })));
47
33
  };
@@ -81,9 +81,7 @@ export interface CategoryConfig {
81
81
  */
82
82
  export type ColumnConfig<T extends RowData, TValue = unknown, C extends keyof JSX.IntrinsicElements | JSXElementConstructor<any> = any> = Omit<ColumnDef<T, TValue>, "enableMultiSort"> & {
83
83
  columnPinned?: boolean;
84
- columnVisible?: boolean;
85
84
  componentConfig: ComponentConfig<C, T>;
86
- disableHiding?: boolean;
87
85
  header: string;
88
86
  id: string;
89
87
  meta?: ColumnMeta<T, unknown>;
@@ -201,7 +199,6 @@ export type GridTrackSize = GridTrackAuto | GridTrackLength | GridTrackFlex | Gr
201
199
  */
202
200
  export interface ListConfig<T extends RowData> {
203
201
  columns: ColumnConfig<T>[];
204
- defaultSort?: ColumnSort;
205
202
  tableOptions?: Omit<TableOptions<T>, "columns" | "data" | "getCoreRowModel">;
206
203
  }
207
204
  /**
@@ -210,7 +207,6 @@ export interface ListConfig<T extends RowData> {
210
207
  export interface ListViewConfig {
211
208
  disablePagination?: boolean;
212
209
  enableDownload?: boolean;
213
- enableRowPreview?: boolean;
214
210
  enableTab?: boolean;
215
211
  listHero?: ComponentsConfig;
216
212
  rowPreviewView?: ComponentsConfig;
@@ -0,0 +1,10 @@
1
+ import { ExploreState } from "../../../exploreState";
2
+ import { UpdateColumnVisibilityPayload } from "./types";
3
+ /**
4
+ * Reducer function to handle the "update column visibility" action.
5
+ * Updates the column visibility in the state for the current entity.
6
+ * @param state - Explore State.
7
+ * @param payload - Payload.
8
+ * @returns explore state.
9
+ */
10
+ export declare function updateColumnVisibilityAction(state: ExploreState, payload: UpdateColumnVisibilityPayload): ExploreState;
@@ -0,0 +1,16 @@
1
+ import { updateEntityPageState } from "../../utils";
2
+ import { buildNextColumnVisibility } from "./utils";
3
+ /**
4
+ * Reducer function to handle the "update column visibility" action.
5
+ * Updates the column visibility in the state for the current entity.
6
+ * @param state - Explore State.
7
+ * @param payload - Payload.
8
+ * @returns explore state.
9
+ */
10
+ export function updateColumnVisibilityAction(state, payload) {
11
+ const columnVisibility = buildNextColumnVisibility(state, payload.updaterOrValue);
12
+ return {
13
+ ...state,
14
+ entityPageState: updateEntityPageState(state.tabValue, state.entityPageState, { columnVisibility }),
15
+ };
16
+ }
@@ -0,0 +1,7 @@
1
+ import { UpdateColumnVisibilityAction, UpdateColumnVisibilityPayload } from "./types";
2
+ /**
3
+ * Action creator for updating column visibility in the state.
4
+ * @param payload - Payload.
5
+ * @returns Action with payload and action type.
6
+ */
7
+ export declare function updateVisibility(payload: UpdateColumnVisibilityPayload): UpdateColumnVisibilityAction;
@@ -0,0 +1,12 @@
1
+ import { ExploreActionKind } from "../../../exploreState";
2
+ /**
3
+ * Action creator for updating column visibility in the state.
4
+ * @param payload - Payload.
5
+ * @returns Action with payload and action type.
6
+ */
7
+ export function updateVisibility(payload) {
8
+ return {
9
+ payload,
10
+ type: ExploreActionKind.UpdateColumnVisibility,
11
+ };
12
+ }
@@ -0,0 +1,9 @@
1
+ import { Updater, VisibilityState } from "@tanstack/react-table";
2
+ import { ExploreActionKind } from "../../../exploreState";
3
+ export type UpdateColumnVisibilityAction = {
4
+ payload: UpdateColumnVisibilityPayload;
5
+ type: ExploreActionKind.UpdateColumnVisibility;
6
+ };
7
+ export type UpdateColumnVisibilityPayload = {
8
+ updaterOrValue: Updater<VisibilityState>;
9
+ };
@@ -0,0 +1,10 @@
1
+ import { Updater, VisibilityState } from "@tanstack/react-table";
2
+ import { ExploreState } from "../../../exploreState";
3
+ /**
4
+ * Builds the next column visibility state for the current entity type.
5
+ * Uses TanStack updater to update the column visibility state.
6
+ * @param state - Explore state.
7
+ * @param updaterOrValue - Updater or value to update the column visibility state.
8
+ * @returns column visibility state.
9
+ */
10
+ export declare function buildNextColumnVisibility(state: ExploreState, updaterOrValue: Updater<VisibilityState>): VisibilityState;
@@ -0,0 +1,21 @@
1
+ import { resolveUpdater } from "../../../../components/Table/options/updater";
2
+ /**
3
+ * Builds the next column visibility state for the current entity type.
4
+ * Uses TanStack updater to update the column visibility state.
5
+ * @param state - Explore state.
6
+ * @param updaterOrValue - Updater or value to update the column visibility state.
7
+ * @returns column visibility state.
8
+ */
9
+ export function buildNextColumnVisibility(state, updaterOrValue) {
10
+ return resolveUpdater(updaterOrValue, getOldColumnVisibility(state));
11
+ }
12
+ /**
13
+ * Retrieves the current "old" state from the explore state, for the current entity type.
14
+ * @param state - Explore state.
15
+ * @returns old column visibility state.
16
+ */
17
+ function getOldColumnVisibility(state) {
18
+ const { entityPageState, tabValue } = state;
19
+ const { columnVisibility = {} } = entityPageState[tabValue];
20
+ return columnVisibility;
21
+ }
@@ -4,7 +4,7 @@ import { RowPreviewState } from "../../components/Table/features/RowPreview/enti
4
4
  import { CategoryConfig, CategoryGroup, CategoryGroupConfig, EntityPath, SavedFilter } from "../../config/entities";
5
5
  export interface EntityPageState {
6
6
  categoryGroupConfigKey: CategoryGroupConfigKey;
7
- columnsVisibility: VisibilityState;
7
+ columnVisibility: VisibilityState;
8
8
  enableRowSelection: boolean;
9
9
  grouping: GroupingState;
10
10
  rowPreview: RowPreviewState;
@@ -1,5 +1,4 @@
1
- import { getInitialTableColumnVisibility } from "../../../components/Table/common/utils";
2
- import { ACCESSOR_KEYS } from "../../../components/TableCreator/common/constants";
1
+ import { getInitialColumnVisibilityState } from "../../../components/TableCreator/options/initialState/columnVisibility";
3
2
  import { SELECT_CATEGORY_KEY } from "../constants";
4
3
  import { getEntityCategoryGroupConfigKey, getFilterCount } from "../utils";
5
4
  import { DEFAULT_CATEGORY_GROUP_SAVED_FILTERS, DEFAULT_ENTITY_STATE, INITIAL_STATE, } from "./constants";
@@ -99,13 +98,8 @@ function initCategoryGroups(entityStateByCategoryGroupConfigKey, categoryGroupCo
99
98
  * @returns column visibility.
100
99
  */
101
100
  function initColumnVisibility(entityConfig) {
102
- const { list: { columns, tableOptions: { enableRowSelection, initialState: { columnVisibility = {} } = {}, } = {}, }, } = entityConfig;
103
- return {
104
- [ACCESSOR_KEYS.ROW_POSITION]: false, // Explicitly setting row position to false; required - currently `columnVisibility` is initialized from columns configuration.
105
- [ACCESSOR_KEYS.SELECT]: Boolean(enableRowSelection),
106
- ...getInitialTableColumnVisibility(columns),
107
- ...columnVisibility, // `columnVisibility` is managed by ExploreState; use table options to override this setting.
108
- };
101
+ const { list: { tableOptions = {} }, } = entityConfig;
102
+ return getInitialColumnVisibilityState(tableOptions);
109
103
  }
110
104
  /**
111
105
  * Returns the initial `enableRowSelection` option for the specified entity list configuration.
@@ -126,7 +120,7 @@ function initEntityPageState(config) {
126
120
  ...acc,
127
121
  [entity.route]: {
128
122
  categoryGroupConfigKey: initCategoryGroupConfigKey(config, entity),
129
- columnsVisibility: initColumnVisibility(entity),
123
+ columnVisibility: initColumnVisibility(entity),
130
124
  enableRowSelection: initEnableRowSelection(entity),
131
125
  grouping: initGrouping(entity),
132
126
  rowPreview: undefined,
@@ -197,9 +191,7 @@ function initGrouping(entityConfig) {
197
191
  * @returns initial sorting state.
198
192
  */
199
193
  function initSorting(entityConfig) {
200
- const { list: { defaultSort, tableOptions: { initialState: { sorting = [] } = {} } = {}, }, } = entityConfig;
201
- if (defaultSort)
202
- return [defaultSort];
194
+ const { list: { tableOptions: { initialState: { sorting = [] } = {} } = {} }, } = entityConfig;
203
195
  return sorting;
204
196
  }
205
197
  /**
@@ -1,4 +1,4 @@
1
- import { ColumnSort, GroupingState, RowSelectionState, VisibilityState } from "@tanstack/react-table";
1
+ import { ColumnSort, GroupingState, RowSelectionState } from "@tanstack/react-table";
2
2
  import { CategoryKey, CategoryValueKey, PaginationDirectionType, SelectCategory, SelectedFilter } from "../../../common/entities";
3
3
  import { RowPreviewState } from "../../../components/Table/features/RowPreview/entities";
4
4
  import { ListItems, PaginationResponse } from "../../exploreState";
@@ -35,10 +35,6 @@ export interface ProcessExploreResponsePayload {
35
35
  * Reset explore response payload.
36
36
  */
37
37
  export type ResetExploreResponsePayload = undefined;
38
- /**
39
- * Update column visibility payload.
40
- */
41
- export type UpdateColumnVisibilityPayload = VisibilityState;
42
38
  /**
43
39
  * Update entity filters payload.
44
40
  */
@@ -104,7 +104,7 @@ export declare function updateEntityPageStateWithCommonCategoryGroupConfigKey(st
104
104
  export declare function updateEntityStateByCategoryGroupConfigKey(state: ExploreState, nextEntityState: Partial<EntityState>, categoryGroupConfigKey?: string): void;
105
105
  /**
106
106
  * Updates the entity page state for each entity with row selection enabled,
107
- * by updating the visibility of the "select" column based on user access and resetting row selection state.
107
+ * by updating the visibility of the "rowSelection" column based on user access and resetting row selection state.
108
108
  * @param state - Explore state.
109
109
  * @param canEdit - User has edit access.
110
110
  * @returns new entity page state mapper with updated column visibility and row selection state.
@@ -1,4 +1,4 @@
1
- import { ACCESSOR_KEYS } from "../../components/TableCreator/common/constants";
1
+ import { COLUMN_IDENTIFIER } from "../../components/Table/common/columnIdentifier";
2
2
  import { DEFAULT_ENTITY_STATE } from "./initializer/constants";
3
3
  /**
4
4
  * Returns the entity state saved filter state for the given category key.
@@ -179,7 +179,7 @@ export function updateEntityStateByCategoryGroupConfigKey(state, nextEntityState
179
179
  }
180
180
  /**
181
181
  * Updates the entity page state for each entity with row selection enabled,
182
- * by updating the visibility of the "select" column based on user access and resetting row selection state.
182
+ * by updating the visibility of the "rowSelection" column based on user access and resetting row selection state.
183
183
  * @param state - Explore state.
184
184
  * @param canEdit - User has edit access.
185
185
  * @returns new entity page state mapper with updated column visibility and row selection state.
@@ -191,9 +191,9 @@ export function updateSelectColumnVisibility(state, canEdit) {
191
191
  ...acc,
192
192
  [entityPath]: {
193
193
  ...entityPageState,
194
- columnsVisibility: {
195
- ...entityPageState.columnsVisibility,
196
- [ACCESSOR_KEYS.SELECT]: canEdit,
194
+ columnVisibility: {
195
+ ...entityPageState.columnVisibility,
196
+ [COLUMN_IDENTIFIER.ROW_SELECTION]: canEdit,
197
197
  },
198
198
  rowSelection: {},
199
199
  },
@@ -4,8 +4,9 @@ import { SelectCategoryView, SelectedFilter } from "../common/entities";
4
4
  import { RowPreviewState } from "../components/Table/features/RowPreview/entities";
5
5
  import { CategoryGroup, SiteConfig } from "../config/entities";
6
6
  import { UpdateGroupingAction } from "./exploreState/actions/updateGrouping/types";
7
+ import { UpdateColumnVisibilityAction } from "./exploreState/actions/updateVisibility/types";
7
8
  import { EntityPageStateMapper, EntityStateByCategoryGroupConfigKey, ListItem } from "./exploreState/entities";
8
- import { ApplySavedFilterPayload, PaginateTablePayload, PatchExploreResponsePayload, ProcessExploreResponsePayload, ResetExploreResponsePayload, UpdateColumnVisibilityPayload, UpdateEntityFiltersPayload, UpdateEntityViewAccessPayload, UpdateFilterPayload, UpdateRowPreviewPayload, UpdateRowSelectionPayload, UpdateSortingPayload } from "./exploreState/payloads/entities";
9
+ import { ApplySavedFilterPayload, PaginateTablePayload, PatchExploreResponsePayload, ProcessExploreResponsePayload, ResetExploreResponsePayload, UpdateEntityFiltersPayload, UpdateEntityViewAccessPayload, UpdateFilterPayload, UpdateRowPreviewPayload, UpdateRowSelectionPayload, UpdateSortingPayload } from "./exploreState/payloads/entities";
9
10
  export type CatalogState = string | undefined;
10
11
  /**
11
12
  * Explore context.
@@ -169,13 +170,6 @@ type SelectEntityTypeAction = {
169
170
  payload: string;
170
171
  type: ExploreActionKind.SelectEntityType;
171
172
  };
172
- /**
173
- * Update column visibility action.
174
- */
175
- type UpdateColumnVisibilityAction = {
176
- payload: UpdateColumnVisibilityPayload;
177
- type: ExploreActionKind.UpdateColumnVisibility;
178
- };
179
173
  /**
180
174
  * Update entity filters action.
181
175
  */
@@ -4,6 +4,7 @@ import { buildCategoryViews, buildNextFilterState, } from "../hooks/useCategoryF
4
4
  import { useConfig } from "../hooks/useConfig";
5
5
  import { useURLFilterParams } from "../hooks/useURLFilterParams";
6
6
  import { updateGroupingAction } from "./exploreState/actions/updateGrouping/action";
7
+ import { updateColumnVisibilityAction } from "./exploreState/actions/updateVisibility/action";
7
8
  import { DEFAULT_PAGINATION_STATE, INITIAL_STATE, } from "./exploreState/initializer/constants";
8
9
  import { initReducerArguments } from "./exploreState/initializer/utils";
9
10
  import { buildEntityStateSavedFilterState, buildNextSavedFilterState, closeRowPreview, getEntityCategoryGroupConfigKey, getEntityState, getEntityStateSavedProperty, getFilterCount, patchEntityListItems, resetPage, updateEntityPageState, updateEntityPageStateWithCommonCategoryGroupConfigKey, updateEntityStateByCategoryGroupConfigKey, updateSelectColumnVisibility, } from "./exploreState/utils";
@@ -234,11 +235,7 @@ function exploreReducer(state, action, exploreContext) {
234
235
  * Update column visibility
235
236
  **/
236
237
  case ExploreActionKind.UpdateColumnVisibility: {
237
- const columnsVisibility = payload;
238
- return {
239
- ...state,
240
- entityPageState: updateEntityPageState(state.tabValue, state.entityPageState, { columnsVisibility }),
241
- };
238
+ return updateColumnVisibilityAction(state, payload);
242
239
  }
243
240
  /**
244
241
  * Update entity filters.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@databiosphere/findable-ui",
3
- "version": "20.0.0",
3
+ "version": "21.0.0",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
@@ -1,7 +1,9 @@
1
1
  import { ColumnDef, RowData } from "@tanstack/react-table";
2
2
  import { TABLE_CELL_PROPS } from "../../../styles/common/mui/tableCell";
3
- import { ACCESSOR_KEYS } from "../../TableCreator/common/constants";
4
3
  import { RowPositionCell } from "../components/TableCell/components/RowPositionCell/rowPositionCell";
4
+ import { RowSelectionCell } from "../components/TableCell/components/RowSelectionCell/rowSelectionCell";
5
+ import { HeadSelectionCell } from "../components/TableHead/components/HeadSelectionCell/headSelectionCell";
6
+ import { COLUMN_IDENTIFIER } from "./columnIdentifier";
5
7
 
6
8
  export const COLUMN_DEF: Record<string, ColumnDef<RowData>> = {
7
9
  ROW_POSITION: {
@@ -10,9 +12,23 @@ export const COLUMN_DEF: Record<string, ColumnDef<RowData>> = {
10
12
  enableHiding: false,
11
13
  enableSorting: false,
12
14
  header: "",
13
- id: ACCESSOR_KEYS.ROW_POSITION,
15
+ id: COLUMN_IDENTIFIER.ROW_POSITION,
14
16
  meta: {
15
17
  align: TABLE_CELL_PROPS.ALIGN.RIGHT,
18
+ columnPinned: false,
19
+ header: "",
20
+ width: "max-content",
21
+ },
22
+ },
23
+ ROW_SELECTION: {
24
+ cell: RowSelectionCell,
25
+ enableGrouping: false,
26
+ enableHiding: false,
27
+ enableSorting: false,
28
+ header: HeadSelectionCell,
29
+ id: COLUMN_IDENTIFIER.ROW_SELECTION,
30
+ meta: {
31
+ columnPinned: false,
16
32
  header: "",
17
33
  width: "max-content",
18
34
  },
@@ -0,0 +1,4 @@
1
+ export const COLUMN_IDENTIFIER = {
2
+ ROW_POSITION: "rowPosition",
3
+ ROW_SELECTION: "rowSelection",
4
+ };
@@ -0,0 +1,12 @@
1
+ import { Column, RowData } from "@tanstack/react-table";
2
+
3
+ /**
4
+ * Type guard to check if a column's header is a string.
5
+ * @param column - Column.
6
+ * @returns true if the column has a string header.
7
+ */
8
+ export function isStringHeaderColumn<T extends RowData>(
9
+ column: Column<T>
10
+ ): column is Column<T> & { columnDef: { header: string } } {
11
+ return typeof column.columnDef.header === "string";
12
+ }