@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,28 @@
1
+ import { RowData } from "@tanstack/react-table";
2
+ import React from "react";
3
+ import { DropdownButton } from "../../../../../common/Button/components/DropdownButton/dropdownButton";
4
+ import { StyledDropdownMenu } from "./columnVisibility.styles";
5
+ import { MenuItems } from "./components/MenuItems/menuItems";
6
+ import { MENU_PROPS } from "./constants";
7
+ import { ColumnVisibilityProps } from "./types";
8
+
9
+ export const ColumnVisibility = <T extends RowData>({
10
+ tableInstance,
11
+ }: ColumnVisibilityProps<T>): JSX.Element | null => {
12
+ const {
13
+ options: { enableHiding },
14
+ } = tableInstance;
15
+ if (!enableHiding) return null;
16
+ return (
17
+ <StyledDropdownMenu
18
+ {...MENU_PROPS}
19
+ button={(props) => (
20
+ <DropdownButton {...props}>Edit Columns</DropdownButton>
21
+ )}
22
+ >
23
+ {(): JSX.Element[] => [
24
+ <MenuItems key="column-visibility" tableInstance={tableInstance} />,
25
+ ]}
26
+ </StyledDropdownMenu>
27
+ );
28
+ };
@@ -0,0 +1,9 @@
1
+ import { ListItemTextProps } from "@mui/material";
2
+
3
+ export const LIST_ITEM_TEXT_PROPS: Partial<ListItemTextProps> = {
4
+ primaryTypographyProps: {
5
+ color: "primary",
6
+ component: "span",
7
+ variant: "inherit",
8
+ },
9
+ };
@@ -0,0 +1,17 @@
1
+ import styled from "@emotion/styled";
2
+ import { MenuItem } from "@mui/material";
3
+
4
+ export const StyledMenuItem = styled(MenuItem)`
5
+ &:hover {
6
+ background-color: transparent;
7
+
8
+ .MuiListItemText-root {
9
+ .MuiListItemText-primary {
10
+ text-decoration: underline;
11
+ text-decoration-skip-ink: none;
12
+ text-underline-color: currentColor;
13
+ text-underline-position: from-font;
14
+ }
15
+ }
16
+ }
17
+ ` as typeof MenuItem;
@@ -0,0 +1,53 @@
1
+ import { Checkbox, ListItemButton, ListItemText } from "@mui/material";
2
+ import { RowData } from "@tanstack/react-table";
3
+ import React, { Fragment } from "react";
4
+ import { CheckedIcon } from "../../../../../../../common/CustomIcon/components/CheckedIcon/checkedIcon";
5
+ import { UncheckedIcon } from "../../../../../../../common/CustomIcon/components/UncheckedIcon/uncheckedIcon";
6
+ import { handleResetVisibilityState } from "../../../../../TableFeatures/ColumnVisibility/utils";
7
+ import { LIST_ITEM_TEXT_PROPS } from "./constants";
8
+ import { StyledMenuItem } from "./menuItems.styles";
9
+ import { MenuItemsProps } from "./types";
10
+ import {
11
+ getCanHideColumns,
12
+ getVisibleColumnCount,
13
+ isToggleVisibilityDisabled,
14
+ } from "./utils";
15
+
16
+ export const MenuItems = <T extends RowData>({
17
+ tableInstance,
18
+ }: MenuItemsProps<T>): JSX.Element => {
19
+ const { getAllColumns } = tableInstance;
20
+ const columns = getCanHideColumns(getAllColumns());
21
+ const visibleCount = getVisibleColumnCount(columns);
22
+ return (
23
+ <Fragment>
24
+ {columns.map((column) => {
25
+ const isDisabled = isToggleVisibilityDisabled(column, visibleCount);
26
+ return (
27
+ <ListItemButton
28
+ key={column.id}
29
+ component="li"
30
+ disabled={isDisabled}
31
+ onClick={() => column.toggleVisibility()}
32
+ >
33
+ <Checkbox
34
+ checked={column.getIsVisible()}
35
+ checkedIcon={<CheckedIcon />}
36
+ disabled={isDisabled}
37
+ icon={<UncheckedIcon />}
38
+ />
39
+ <ListItemText disableTypography>
40
+ {column.columnDef.header}
41
+ </ListItemText>
42
+ </ListItemButton>
43
+ );
44
+ })}
45
+ <StyledMenuItem
46
+ component="li"
47
+ onClick={() => handleResetVisibilityState(tableInstance)}
48
+ >
49
+ <ListItemText {...LIST_ITEM_TEXT_PROPS}>Reset</ListItemText>
50
+ </StyledMenuItem>
51
+ </Fragment>
52
+ );
53
+ };
@@ -0,0 +1,5 @@
1
+ import { RowData, Table } from "@tanstack/react-table";
2
+
3
+ export interface MenuItemsProps<T extends RowData> {
4
+ tableInstance: Table<T>;
5
+ }
@@ -0,0 +1,44 @@
1
+ import { Column, RowData } from "@tanstack/react-table";
2
+ import { isStringHeaderColumn } from "../../../../../../common/typeGuards";
3
+
4
+ /**
5
+ * Returns columns that are enabled to be hidden.
6
+ * @param columns - Columns.
7
+ * @returns columns that are enabled to be hidden.
8
+ */
9
+ export function getCanHideColumns<T extends RowData>(
10
+ columns: Column<T>[]
11
+ ): (Column<T> & { columnDef: { header: string } })[] {
12
+ return columns
13
+ .filter(isStringHeaderColumn) // Currently, headers are configured as strings. Only include columns that have a string header (for now).
14
+ .filter(({ getCanHide }) => getCanHide());
15
+ }
16
+
17
+ /**
18
+ * Returns the number of visible columns, excluding grouped columns.
19
+ * @param columns - Columns.
20
+ * @returns number of visible, un-grouped columns.
21
+ */
22
+ export function getVisibleColumnCount<T extends RowData>(
23
+ columns: Column<T>[]
24
+ ): number {
25
+ return columns.filter(
26
+ ({ getIsGrouped, getIsVisible }) => getIsVisible() && !getIsGrouped()
27
+ ).length;
28
+ }
29
+
30
+ /**
31
+ * Returns whether the column visibility toggle is disabled.
32
+ * - If the column is grouped, the toggle is disabled.
33
+ * - If the column is visible and the count of visible, un-grouped columns is 1, the toggle is disabled.
34
+ * @param column - Column.
35
+ * @param visibleCount - Count of visible, un-grouped columns.
36
+ * @returns true if the column visibility toggle is disabled.
37
+ */
38
+ export function isToggleVisibilityDisabled<T extends RowData>(
39
+ column: Column<T>,
40
+ visibleCount: number
41
+ ): boolean {
42
+ if (column.getIsGrouped()) return true;
43
+ return column.getIsVisible() && visibleCount === 1;
44
+ }
@@ -0,0 +1,5 @@
1
+ import { MenuProps } from "@mui/material";
2
+
3
+ export const MENU_PROPS: Partial<MenuProps> = {
4
+ variant: "menu",
5
+ };
@@ -0,0 +1,5 @@
1
+ import { RowData, Table } from "@tanstack/react-table";
2
+
3
+ export interface ColumnVisibilityProps<T extends RowData> {
4
+ tableInstance: Table<T>;
5
+ }
@@ -3,11 +3,11 @@ import React, { Fragment } from "react";
3
3
  import { ListViewConfig } from "../../../../config/entities";
4
4
  import { useExploreState } from "../../../../hooks/useExploreState";
5
5
  import { ROW_DIRECTION } from "../../common/entities";
6
- import { getEditColumnOptions, isAnyRowSelected } from "../../common/utils";
7
- import { CheckboxMenu } from "../CheckboxMenu/checkboxMenu";
6
+ import { isAnyRowSelected } from "../../common/utils";
8
7
  import { DownloadEntityResults } from "../DownloadEntityResults/downloadEntityResults";
9
8
  import { PaginationSummary } from "../PaginationSummary/paginationSummary";
10
9
  import { ColumnGrouping } from "./components/ColumnGrouping/columnGrouping";
10
+ import { ColumnVisibility } from "./components/ColumnVisibility/columnVisibility";
11
11
  import { RowPreview } from "./components/RowPreview/rowPreview";
12
12
  import { RowSelection } from "./components/RowSelection/rowSelection";
13
13
  import { Toolbar, ToolbarActions } from "./tableToolbar.styles";
@@ -28,23 +28,13 @@ export const TableToolbar = <T extends RowData>({
28
28
  const { currentPage, pages, pageSize, rows } = paginationState;
29
29
  const {
30
30
  getSelectedRowModel,
31
- options: { enableGrouping },
32
- resetColumnVisibility,
31
+ options: { enableGrouping, enableHiding },
33
32
  } = tableInstance;
34
33
  const { enableDownload, rowPreviewView } = listView || {};
35
34
  const isLastPage = currentPage === pages;
36
- const editColumnOptions = getEditColumnOptions(tableInstance);
37
35
  const showToolbar =
38
36
  rowDirection === ROW_DIRECTION.DEFAULT &&
39
- (editColumnOptions || enableDownload || enableGrouping);
40
-
41
- /**
42
- * Resets column visibility to default state.
43
- */
44
- const onResetColumnVisibility = (): void => {
45
- resetColumnVisibility(false);
46
- };
47
-
37
+ (enableHiding || enableDownload || enableGrouping);
48
38
  return (
49
39
  <Fragment>
50
40
  {showToolbar && (
@@ -69,11 +59,7 @@ export const TableToolbar = <T extends RowData>({
69
59
  />
70
60
  )}
71
61
  <ColumnGrouping tableInstance={tableInstance} />
72
- <CheckboxMenu
73
- label="Edit Columns"
74
- onReset={onResetColumnVisibility}
75
- options={editColumnOptions}
76
- />
62
+ <ColumnVisibility tableInstance={tableInstance} />
77
63
  </ToolbarActions>
78
64
  </Toolbar>
79
65
  )}
@@ -6,10 +6,9 @@ import {
6
6
  RowModel,
7
7
  Table,
8
8
  TableFeature,
9
- TableState,
9
+ TableOptionsResolved,
10
10
  } from "@tanstack/react-table";
11
- import { InitialTableState } from "@tanstack/table-core/src/types";
12
- import { getRowModel, getRowPosition, initInitialState } from "./utils";
11
+ import { getRowModel, getRowPosition } from "./utils";
13
12
 
14
13
  export const ROW_POSITION: TableFeature = {
15
14
  createCell: <T extends RowData, TValue>(
@@ -28,7 +27,11 @@ export const ROW_POSITION: TableFeature = {
28
27
  return getRowModel(table, rowModel);
29
28
  };
30
29
  },
31
- getInitialState: (initialState?: InitialTableState): Partial<TableState> => {
32
- return initInitialState(initialState);
30
+ getDefaultOptions: <T extends RowData>(): Partial<
31
+ TableOptionsResolved<T>
32
+ > => {
33
+ return {
34
+ enableRowPosition: false,
35
+ };
33
36
  },
34
37
  };
@@ -1,3 +1,7 @@
1
+ export interface RowPositionOptions {
2
+ enableRowPosition?: boolean;
3
+ }
4
+
1
5
  export interface RowPositionRow {
2
6
  getRowPosition: () => number;
3
7
  }
@@ -1,12 +1,4 @@
1
- import {
2
- InitialTableState,
3
- RowData,
4
- RowModel,
5
- Table,
6
- TableState,
7
- } from "@tanstack/react-table";
8
- import { ACCESSOR_KEYS } from "../../../TableCreator/common/constants";
9
- import { DEFAULT_PAGINATION } from "../constants";
1
+ import { RowData, RowModel, Table } from "@tanstack/react-table";
10
2
 
11
3
  /**
12
4
  * Returns row model, with getter for row position.
@@ -62,24 +54,3 @@ function calculateRowPosition<T extends RowData>(
62
54
  } = getState();
63
55
  return pageIndex * pageSize + (index + 1);
64
56
  }
65
-
66
- /**
67
- * Returns the initial table state.
68
- * @param initialState - Initial state.
69
- * @returns initial state.
70
- */
71
- export function initInitialState(
72
- initialState?: InitialTableState
73
- ): Partial<TableState> {
74
- return {
75
- ...initialState,
76
- columnVisibility: {
77
- [ACCESSOR_KEYS.ROW_POSITION]: false,
78
- ...initialState?.columnVisibility,
79
- },
80
- pagination: {
81
- ...DEFAULT_PAGINATION,
82
- ...initialState?.pagination,
83
- },
84
- };
85
- }
@@ -52,7 +52,7 @@ export const ROW_PREVIEW: TableFeature = {
52
52
  table: Table<T>
53
53
  ): Partial<TableOptionsResolved<T>> => {
54
54
  return {
55
- enableRowPreview: true,
55
+ enableRowPreview: false,
56
56
  onRowPreviewChange: makeStateUpdater("rowPreview", table),
57
57
  };
58
58
  },
@@ -1,5 +1,5 @@
1
1
  import { RowData } from "@tanstack/react-table";
2
- import { RowPositionRow } from "./RowPosition/types";
2
+ import { RowPositionOptions, RowPositionRow } from "./RowPosition/types";
3
3
  import {
4
4
  RowPreviewInstance,
5
5
  RowPreviewOptions,
@@ -9,6 +9,6 @@ import {
9
9
 
10
10
  export type CustomFeatureInitialTableState = Partial<RowPreviewTableState>;
11
11
  export type CustomFeatureInstance<T extends RowData> = RowPreviewInstance<T>;
12
- export type CustomFeatureOptions = RowPreviewOptions;
12
+ export type CustomFeatureOptions = RowPreviewOptions & RowPositionOptions;
13
13
  export type CustomFeatureRow = RowPositionRow & RowPreviewRow;
14
14
  export type CustomFeatureTableState = RowPreviewTableState;
@@ -8,13 +8,11 @@ import {
8
8
  getFilteredRowModel,
9
9
  getPaginationRowModel,
10
10
  getSortedRowModel,
11
- InitialTableState,
12
11
  RowData,
13
12
  RowSelectionState,
14
13
  TableState,
15
14
  Updater,
16
15
  useReactTable,
17
- VisibilityState,
18
16
  } from "@tanstack/react-table";
19
17
  import React, { useCallback, useEffect, useMemo } from "react";
20
18
  import { track } from "../../common/analytics/analytics";
@@ -37,11 +35,11 @@ import { DEFAULT_PAGINATION_STATE } from "../../providers/exploreState/initializ
37
35
  import { TABLET } from "../../theme/common/breakpoints";
38
36
  import { FluidPaper, GridPaper } from "../common/Paper/paper.styles";
39
37
  import { NoResults } from "../NoResults/noResults";
38
+ import { getColumnTrackSizing } from "../TableCreator/options/columnTrackSizing/utils";
40
39
  import { ROW_DIRECTION } from "./common/entities";
41
40
  import {
42
41
  buildCategoryViews,
43
42
  getFacetedUniqueValuesWithArrayValues,
44
- getGridTemplateColumns,
45
43
  getTableStatePagination,
46
44
  isClientFilteringEnabled,
47
45
  } from "./common/utils";
@@ -57,7 +55,6 @@ import { GridTable } from "./table.styles";
57
55
  export interface TableProps<T extends RowData> {
58
56
  columns: ColumnDef<T>[];
59
57
  getRowId?: CoreOptions<T>["getRowId"];
60
- initialState: InitialTableState;
61
58
  items: T[];
62
59
  listView?: ListViewConfig;
63
60
  loading?: boolean;
@@ -71,7 +68,6 @@ export interface TableProps<T extends RowData> {
71
68
  * @param tableProps - Set of props required for displaying the table.
72
69
  * @param tableProps.columns - Set of columns to display.
73
70
  * @param tableProps.getRowId - Function to customize the row ID.
74
- * @param tableProps.initialState - Initial table state.
75
71
  * @param tableProps.items - Row data to display.
76
72
  * @param tableProps.listView - List view configuration.
77
73
  * @param tableProps.tableOptions - TanStack table options.
@@ -80,7 +76,6 @@ export interface TableProps<T extends RowData> {
80
76
  export const TableComponent = <T extends RowData>({
81
77
  columns,
82
78
  getRowId,
83
- initialState,
84
79
  items,
85
80
  listView,
86
81
  tableOptions,
@@ -98,16 +93,10 @@ TableProps<T>): JSX.Element => {
98
93
  rowPreview,
99
94
  tabValue,
100
95
  } = exploreState;
101
- const {
102
- columnsVisibility,
103
- enableRowSelection,
104
- grouping,
105
- rowSelection,
106
- sorting,
107
- } = entityPageState[tabValue];
96
+ const { columnVisibility, grouping, rowSelection, sorting } =
97
+ entityPageState[tabValue];
108
98
  const { currentPage, pages, pageSize, rows: pageCount } = paginationState;
109
- const { disablePagination = false, enableRowPreview = false } =
110
- listView || {};
99
+ const { disablePagination = false } = listView || {};
111
100
  const clientFiltering = isClientFilteringEnabled(exploreMode);
112
101
  const rowDirection = tabletDown
113
102
  ? ROW_DIRECTION.VERTICAL
@@ -136,17 +125,6 @@ TableProps<T>): JSX.Element => {
136
125
  });
137
126
  };
138
127
 
139
- const onColumnVisibilityChange = (
140
- updater: Updater<VisibilityState>
141
- ): void => {
142
- // TODO(cc) memoize `onColumnVisibilityChange` with `useCallback`.
143
- exploreDispatch({
144
- payload:
145
- typeof updater === "function" ? updater(columnsVisibility) : updater,
146
- type: ExploreActionKind.UpdateColumnVisibility,
147
- });
148
- };
149
-
150
128
  const onRowPreviewChange = useCallback(
151
129
  (updater: Updater<RowPreviewState>): void => {
152
130
  exploreDispatch({
@@ -170,7 +148,7 @@ TableProps<T>): JSX.Element => {
170
148
  );
171
149
 
172
150
  const state: Partial<TableState> = {
173
- columnVisibility: columnsVisibility,
151
+ columnVisibility,
174
152
  grouping,
175
153
  pagination,
176
154
  rowPreview,
@@ -178,21 +156,11 @@ TableProps<T>): JSX.Element => {
178
156
  sorting,
179
157
  };
180
158
  /**
181
- * TODO: Refactor `ListConfig` to follow the API patterns of the TanStack Table library.
182
159
  * TODO: Update `ColumnConfig` to follow the `ColumnDef` API of TanStack Table.
183
160
  * - Standardize column definitions to leverage the full power of TanStack Table's feature set and improve compatibility.
184
- * TODO: Deprecate the following properties:
185
- * - `defaultSort` in `ListConfig`: Replace this with TanStack Table's `tableOptions.initialState.sorting` feature.
186
- * - `columnVisible` in `ColumnConfig`: Replace this with TanStack Table's `tableOptions.initialState.columnVisibility` feature.
187
- * TODO: Define `columnVisibility` and `sorting` directly within `ListConfig` via the `tableOptions.initialState` property.
161
+ * TODO: Define `sorting` directly within `ListConfig` via the `tableOptions.initialState` property.
188
162
  * - This will simplify the configuration structure and centralize table state definitions, reducing redundancy and improving clarity.
189
- * - It will also allow for direct configuration of other TanStack Table options such as `columnOrder` via `tableOptions.initialState.columnOrder`.
190
- *
191
- * Current Workaround:
192
- * - The `initialState` property from `tableOptions` is destructured to separate it from other options. This allows the remaining properties in `tableOptions` to be passed directly to the TanStack Table configuration without breaking the current ListConfig `defaultSort` and `columnVisible` properties.
193
163
  */
194
- const { initialState: _initialState, ...restTableOptions } =
195
- tableOptions ?? {};
196
164
  const tableInstance = useReactTable({
197
165
  _features: [ROW_POSITION, ROW_PREVIEW],
198
166
  columns,
@@ -200,8 +168,6 @@ TableProps<T>): JSX.Element => {
200
168
  enableColumnFilters: true, // client-side filtering.
201
169
  enableFilters: true, // client-side filtering.
202
170
  enableMultiSort: clientFiltering, // TODO(cc) move to sorting options; default to false and let the table options in config flag this value.
203
- enableRowPreview,
204
- enableRowSelection,
205
171
  getCoreRowModel: getCoreRowModel(),
206
172
  getFacetedRowModel: clientFiltering ? getFacetedRowModel() : undefined,
207
173
  getFacetedUniqueValues: clientFiltering
@@ -211,16 +177,14 @@ TableProps<T>): JSX.Element => {
211
177
  getPaginationRowModel: getPaginationRowModel(),
212
178
  getRowId,
213
179
  getSortedRowModel: clientFiltering ? getSortedRowModel() : undefined,
214
- initialState: { ...initialState, ..._initialState }, // `sorting` and `columnVisibility` are managed by the ExploreState.
215
180
  manualPagination: true,
216
181
  manualSorting: !clientFiltering,
217
- onColumnVisibilityChange,
218
182
  onRowPreviewChange,
219
183
  onRowSelectionChange,
220
184
  onSortingChange,
221
185
  pageCount,
222
186
  state,
223
- ...restTableOptions,
187
+ ...tableOptions,
224
188
  });
225
189
  const {
226
190
  getAllColumns,
@@ -235,8 +199,6 @@ TableProps<T>): JSX.Element => {
235
199
  const { rows } = getRowModel();
236
200
  const noResults = !loading && (!rows || rows.length === 0);
237
201
  const scrollTop = useScroll();
238
- const visibleColumns = getVisibleFlatColumns();
239
- const gridTemplateColumns = getGridTemplateColumns(visibleColumns);
240
202
 
241
203
  const handleTableNextPage = (): void => {
242
204
  let nextPage = tableNextPage;
@@ -335,7 +297,7 @@ TableProps<T>): JSX.Element => {
335
297
  <TableContainer>
336
298
  <GridTable
337
299
  collapsable={true}
338
- gridTemplateColumns={gridTemplateColumns}
300
+ gridTemplateColumns={getColumnTrackSizing(getVisibleFlatColumns())}
339
301
  >
340
302
  <TableHead
341
303
  rowDirection={rowDirection}
@@ -15,10 +15,7 @@ export function buildBaseColumnDef<T>(
15
15
  const {
16
16
  columnPinned,
17
17
  // eslint-disable-next-line @typescript-eslint/no-unused-vars -- Destructure to avoid passing it to the columnDef.
18
- columnVisible,
19
- // eslint-disable-next-line @typescript-eslint/no-unused-vars -- Destructure to avoid passing it to the columnDef.
20
18
  componentConfig,
21
- disableHiding,
22
19
  header,
23
20
  id,
24
21
  meta,
@@ -28,7 +25,6 @@ export function buildBaseColumnDef<T>(
28
25
  return {
29
26
  ...columnDef,
30
27
  accessorKey: id,
31
- enableHiding: !disableHiding,
32
28
  header,
33
29
  id,
34
30
  meta: {
@@ -0,0 +1,12 @@
1
+ import { GridTrackMinMax, GridTrackSize } from "../../../../config/entities";
2
+
3
+ /**
4
+ * Type guard to determine if the given track size represents a size range (min-max).
5
+ * @param width - Grid table track size.
6
+ * @returns `true` if the given grid track size is a `GridTrackMinMax`, otherwise `false`.
7
+ */
8
+ export function isGridTrackMinMax(
9
+ width?: GridTrackSize
10
+ ): width is GridTrackMinMax {
11
+ return (width as GridTrackMinMax)?.min !== undefined;
12
+ }
@@ -0,0 +1,99 @@
1
+ import { Column, RowData } from "@tanstack/react-table";
2
+ import { COLUMN_IDENTIFIER } from "../../../Table/common/columnIdentifier";
3
+ import { isGridTrackMinMax } from "./typeGuards";
4
+
5
+ /**
6
+ * Generates the grid track sizing for a table using a grid layout.
7
+ * Creates a string value for the `grid-template-columns` CSS property based on the visible columns.
8
+ * It ensures proper sizing for grouped, system, and non-system columns.
9
+ * - Grouped columns are excluded from grid sizing as they flex across the table.
10
+ * - System columns (e.g., "rowPosition" and "rowSelection") have pre-defined sizing.
11
+ * - 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.
12
+ * @param visibleColumns - Visible columns.
13
+ * @returns string defining the CSS `grid-template-columns` value for the table.
14
+ */
15
+ export function getColumnTrackSizing<T extends RowData>(
16
+ visibleColumns: Column<T>[]
17
+ ): string {
18
+ // Precompute track sizing.
19
+ const trackSizing: string[] = [];
20
+
21
+ let columnCount = 0; // Non-system column count.
22
+ let firstNonSystemColumnIndex = -1;
23
+ let totalFractionalSize = 0;
24
+
25
+ for (const [i, column] of visibleColumns.entries()) {
26
+ if (column.getIsGrouped()) continue;
27
+
28
+ // Get the column's track size.
29
+ const columnTrackSize = getColumnTrackSize(column);
30
+ trackSizing.push(columnTrackSize);
31
+
32
+ // Extract the fractional value (if it exists), and accumulate the total.
33
+ const frSize = extractFractionalValue(columnTrackSize);
34
+ if (frSize) totalFractionalSize += frSize;
35
+
36
+ // Skip system columns; track the first non-system column index.
37
+ if (isSystemColumn(column)) continue;
38
+ if (firstNonSystemColumnIndex < 0) firstNonSystemColumnIndex = i;
39
+
40
+ columnCount++;
41
+ }
42
+
43
+ // Adjust track sizing for the first non-system column when:
44
+ // - the table is a single-column table, or
45
+ // - the total `fr` value is less than 1.
46
+ if (
47
+ firstNonSystemColumnIndex >= 0 &&
48
+ (columnCount === 1 || totalFractionalSize < 1)
49
+ ) {
50
+ trackSizing[firstNonSystemColumnIndex] = "1fr";
51
+ }
52
+
53
+ return trackSizing.join(" ");
54
+ }
55
+
56
+ /**
57
+ * Determines the CSS grid track size for a given column.
58
+ * Calculates the track size for a column based on its width configuration.
59
+ * If the column's width is defined as a min-max range, it returns a `minmax()` CSS function.
60
+ * Otherwise, it defaults to the column's width or `1fr` if no width is specified.
61
+ * @param column - Column.
62
+ * @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`).
63
+ */
64
+ export function getColumnTrackSize<T extends RowData>(
65
+ column: Column<T>
66
+ ): string {
67
+ const width = column.columnDef.meta?.width || "1fr";
68
+ if (isGridTrackMinMax(width)) {
69
+ return `minmax(${width.min}, ${width.max})`;
70
+ }
71
+ return width;
72
+ }
73
+
74
+ /**
75
+ * Returns true if the column is a system column "rowPosition" or "rowSelection".
76
+ * @param column - Column.
77
+ * @returns true if the column is a system column.
78
+ */
79
+ function isSystemColumn<T extends RowData>(column: Column<T>): boolean {
80
+ return (
81
+ column.id === COLUMN_IDENTIFIER.ROW_POSITION ||
82
+ column.id === COLUMN_IDENTIFIER.ROW_SELECTION
83
+ );
84
+ }
85
+
86
+ /**
87
+ * Extracts the fractional value (`fr`) from a CSS track size string.
88
+ * This function parses a CSS track size (e.g., `1fr`, `minmax(168px, 0.5fr)`)
89
+ * and extracts the numeric fractional value that appears before `fr`.
90
+ * If the input does not contain a valid fractional value, the function returns `0`.
91
+ * @param columnTrackSize - The CSS track size string e.g. `1fr`, `minmax(100px, 0.5fr)`, `200px`, or `auto`.
92
+ * @returns The fractional value as a number, or `0` if no fractional value is found.
93
+ */
94
+ export function extractFractionalValue(columnTrackSize: string): number {
95
+ const match = columnTrackSize.match(/([\d.]+)fr/);
96
+ if (!match) return 0;
97
+ const value = parseFloat(match[1]);
98
+ return Number.isNaN(value) ? 0 : value;
99
+ }
@@ -2,30 +2,27 @@ import { RowData, TableOptions } from "@tanstack/react-table";
2
2
  import { useConfig } from "../../../hooks/useConfig";
3
3
  import { useExpandedOptions } from "./expanded/hook";
4
4
  import { useGroupingOptions } from "./grouping/hook";
5
+ import { useInitialState } from "./initialState/hook";
5
6
  import { useRowSelectionOptions } from "./rowSelection/hook";
6
7
  import { useSortingOptions } from "./sorting/hook";
8
+ import { useVisibilityOptions } from "./visibility/hook";
7
9
 
8
10
  export function useTableOptions<T extends RowData>(): Partial<TableOptions<T>> {
9
- const {
10
- entityConfig: {
11
- list: { defaultSort, tableOptions },
12
- },
13
- } = useConfig();
11
+ const { entityConfig } = useConfig();
12
+ const tableOptions = entityConfig.list.tableOptions;
14
13
  const expandedOptions = useExpandedOptions<T>();
15
14
  const groupingOptions = useGroupingOptions();
16
15
  const rowSelectionOptions = useRowSelectionOptions<T>();
17
16
  const sortingOptions = useSortingOptions<T>();
17
+ const visibilityOptions = useVisibilityOptions();
18
+ const initialState = useInitialState<T>(tableOptions);
18
19
  return {
19
20
  ...expandedOptions,
20
21
  ...groupingOptions,
21
22
  ...rowSelectionOptions,
22
23
  ...sortingOptions, // TODO(cc) merge of all sorting options.
24
+ ...visibilityOptions,
23
25
  ...tableOptions,
24
- initialState: {
25
- ...tableOptions?.initialState,
26
- sorting: defaultSort
27
- ? [defaultSort] // TODO(cc) deprecate `defaultSort` in favor of `initialState.sorting`.
28
- : tableOptions?.initialState?.sorting,
29
- },
26
+ initialState,
30
27
  };
31
28
  }