@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
@@ -1,3 +1,3 @@
1
1
  {
2
- ".": "20.0.0"
2
+ ".": "21.0.0"
3
3
  }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## [21.0.0](https://github.com/DataBiosphere/findable-ui/compare/v20.0.0...v21.0.0) (2025-01-06)
4
+
5
+
6
+ ### ⚠ BREAKING CHANGES
7
+
8
+ * update column visibility to use only tanstack api ([#307](https://github.com/DataBiosphere/findable-ui/issues/307)) (#308)
9
+
10
+ ### Features
11
+
12
+ * update column visibility to use only tanstack api ([#307](https://github.com/DataBiosphere/findable-ui/issues/307)) ([#308](https://github.com/DataBiosphere/findable-ui/issues/308)) ([4baf212](https://github.com/DataBiosphere/findable-ui/commit/4baf212bf564d539b757dd82144511fc97ca7717))
13
+
3
14
  ## [20.0.0](https://github.com/DataBiosphere/findable-ui/compare/v19.0.0...v20.0.0) (2025-01-06)
4
15
 
5
16
 
@@ -1,6 +1,8 @@
1
1
  import { TABLE_CELL_PROPS } from "../../../styles/common/mui/tableCell";
2
- import { ACCESSOR_KEYS } from "../../TableCreator/common/constants";
3
2
  import { RowPositionCell } from "../components/TableCell/components/RowPositionCell/rowPositionCell";
3
+ import { RowSelectionCell } from "../components/TableCell/components/RowSelectionCell/rowSelectionCell";
4
+ import { HeadSelectionCell } from "../components/TableHead/components/HeadSelectionCell/headSelectionCell";
5
+ import { COLUMN_IDENTIFIER } from "./columnIdentifier";
4
6
  export const COLUMN_DEF = {
5
7
  ROW_POSITION: {
6
8
  cell: RowPositionCell,
@@ -8,9 +10,23 @@ export const COLUMN_DEF = {
8
10
  enableHiding: false,
9
11
  enableSorting: false,
10
12
  header: "",
11
- id: ACCESSOR_KEYS.ROW_POSITION,
13
+ id: COLUMN_IDENTIFIER.ROW_POSITION,
12
14
  meta: {
13
15
  align: TABLE_CELL_PROPS.ALIGN.RIGHT,
16
+ columnPinned: false,
17
+ header: "",
18
+ width: "max-content",
19
+ },
20
+ },
21
+ ROW_SELECTION: {
22
+ cell: RowSelectionCell,
23
+ enableGrouping: false,
24
+ enableHiding: false,
25
+ enableSorting: false,
26
+ header: HeadSelectionCell,
27
+ id: COLUMN_IDENTIFIER.ROW_SELECTION,
28
+ meta: {
29
+ columnPinned: false,
14
30
  header: "",
15
31
  width: "max-content",
16
32
  },
@@ -0,0 +1,4 @@
1
+ export declare const COLUMN_IDENTIFIER: {
2
+ ROW_POSITION: string;
3
+ ROW_SELECTION: string;
4
+ };
@@ -0,0 +1,4 @@
1
+ export const COLUMN_IDENTIFIER = {
2
+ ROW_POSITION: "rowPosition",
3
+ ROW_SELECTION: "rowSelection",
4
+ };
@@ -0,0 +1,11 @@
1
+ import { Column, RowData } from "@tanstack/react-table";
2
+ /**
3
+ * Type guard to check if a column's header is a string.
4
+ * @param column - Column.
5
+ * @returns true if the column has a string header.
6
+ */
7
+ export declare function isStringHeaderColumn<T extends RowData>(column: Column<T>): column is Column<T> & {
8
+ columnDef: {
9
+ header: string;
10
+ };
11
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Type guard to check if a column's header is a string.
3
+ * @param column - Column.
4
+ * @returns true if the column has a string header.
5
+ */
6
+ export function isStringHeaderColumn(column) {
7
+ return typeof column.columnDef.header === "string";
8
+ }
@@ -1,8 +1,6 @@
1
- import { Cell, Column, ColumnFiltersState, InitialTableState, PaginationState, Row, RowData, Table, VisibilityState } from "@tanstack/react-table";
1
+ import { Cell, Column, ColumnFiltersState, PaginationState, Row, RowData, Table } from "@tanstack/react-table";
2
2
  import { SelectCategory } from "../../../common/entities";
3
- import { ColumnConfig } from "../../../config/entities";
4
3
  import { ExploreMode } from "../../../hooks/useExploreMode";
5
- import { CheckboxMenuListItem } from "../components/CheckboxMenu/checkboxMenu";
6
4
  /**
7
5
  * Internal model of a category term count keyed by category term.
8
6
  */
@@ -36,12 +34,6 @@ export declare function buildCategoryViews<T extends RowData>(columns: Column<T>
36
34
  * @returns filtered entity results as a blob.
37
35
  */
38
36
  export declare function generateDownloadBlob<T extends RowData>(rows: Row<T>[]): Blob | undefined;
39
- /**
40
- * Returns edit column checkbox menu options.
41
- * @param table - Table.
42
- * @returns a list of edit column options.
43
- */
44
- export declare function getEditColumnOptions<T extends RowData>(table: Table<T>): CheckboxMenuListItem[];
45
37
  /**
46
38
  * Returns unique category term counts keyed by category terms.
47
39
  * Custom function based off react table function getFacetedUniqueValues, see
@@ -50,19 +42,6 @@ export declare function getEditColumnOptions<T extends RowData>(table: Table<T>)
50
42
  * @returns Unique category term counts keyed by category terms.
51
43
  */
52
44
  export declare function getFacetedUniqueValuesWithArrayValues<T extends RowData>(): (table: Table<T>, columnId: string) => () => CountByTerms;
53
- /**
54
- * Generates a string value for the CSS property grid-template-columns.
55
- * Defines grid table track sizing (for each visible column).
56
- * @param columns - Table columns.
57
- * @returns string value for the css property grid-template-columns.
58
- */
59
- export declare function getGridTemplateColumns<T extends RowData>(columns: Column<T>[]): string;
60
- /**
61
- * Returns initial table state.
62
- * @param columns - Column configuration.
63
- * @returns initial table state.
64
- */
65
- export declare function getInitialState<T extends RowData>(columns: ColumnConfig<T>[]): InitialTableState;
66
45
  /**
67
46
  * Returns the pinned cell and its index tuple.
68
47
  * @param row - Row.
@@ -105,10 +84,4 @@ export declare function isCollapsableRowDisabled<T extends RowData>(tableInstanc
105
84
  * @returns sort return value from the compare function (0 | 1 | -1).
106
85
  */
107
86
  export declare function sortingFn<T>(rowA: Row<T>, rowB: Row<T>, columnId: string): number;
108
- /**
109
- * Returns the initial table visibility state for the specified column configuration.
110
- * @param columns - Column configuration.
111
- * @returns initial table visibility state.
112
- */
113
- export declare function getInitialTableColumnVisibility<T extends RowData>(columns: ColumnConfig<T>[]): VisibilityState;
114
87
  export {};
@@ -1,7 +1,6 @@
1
1
  import { memo, sortingFns, } from "@tanstack/react-table";
2
2
  import { EXPLORE_MODE } from "../../../hooks/useExploreMode";
3
- import { ACCESSOR_KEYS } from "../../TableCreator/common/constants";
4
- import { handleToggleVisibility } from "../components/TableFeatures/ColumnVisibility/utils";
3
+ import { COLUMN_IDENTIFIER } from "./columnIdentifier";
5
4
  /**
6
5
  * Returns true if the row should be included in the filtered rows.
7
6
  * The row will be included if:
@@ -88,32 +87,6 @@ export function generateDownloadBlob(rows) {
88
87
  const tsv = formatDataToTSV([tableHeaders, ...tableData]);
89
88
  return new Blob([tsv], { type: "text/tab-separated-values" });
90
89
  }
91
- /**
92
- * Returns edit column checkbox menu options.
93
- * @param table - Table.
94
- * @returns a list of edit column options.
95
- */
96
- export function getEditColumnOptions(table) {
97
- const { getAllColumns, initialState } = table;
98
- const { columnVisibility: initialVisibilityState } = initialState;
99
- const allColumns = getAllColumns();
100
- return allColumns.reduce((acc, column) => {
101
- const { columnDef: { header }, getCanHide, getIsVisible, id, } = column;
102
- if (getCanHide()) {
103
- const option = {
104
- checked: getIsVisible(),
105
- disabled: initialVisibilityState[id], // TODO(cc) column visibility toggle should be disabled when table enableGrouping is false, and column is grouped.
106
- label: header, // TODO revisit type assertion here
107
- onChange: () => {
108
- handleToggleVisibility(table, column);
109
- },
110
- value: id,
111
- };
112
- acc.push(option);
113
- }
114
- return acc;
115
- }, []);
116
- }
117
90
  /**
118
91
  * Returns unique category term counts keyed by category terms.
119
92
  * Custom function based off react table function getFacetedUniqueValues, see
@@ -147,35 +120,6 @@ export function getFacetedUniqueValuesWithArrayValues() {
147
120
  onChange: () => { },
148
121
  });
149
122
  }
150
- /**
151
- * Generates a string value for the CSS property grid-template-columns.
152
- * Defines grid table track sizing (for each visible column).
153
- * @param columns - Table columns.
154
- * @returns string value for the css property grid-template-columns.
155
- */
156
- export function getGridTemplateColumns(columns) {
157
- return columns
158
- .filter(filterGroupedColumn)
159
- .map(({ columnDef: { meta } }) => {
160
- const width = meta?.width;
161
- if (isGridTrackMinMax(width)) {
162
- return `minmax(${width.min}, ${width.max})`;
163
- }
164
- return width;
165
- })
166
- .join(" ");
167
- }
168
- /**
169
- * Returns initial table state.
170
- * @param columns - Column configuration.
171
- * @returns initial table state.
172
- */
173
- export function getInitialState(columns) {
174
- const columnVisibility = getInitialTableColumnVisibility(columns);
175
- return {
176
- columnVisibility,
177
- };
178
- }
179
123
  /**
180
124
  * Returns the pinned cell and its index tuple.
181
125
  * @param row - Row.
@@ -210,35 +154,27 @@ export function getTableStatePagination(pageIndex = 0, pageSize) {
210
154
  };
211
155
  }
212
156
  /**
213
- * Returns the list of table headers, excluding "select" column.
157
+ * Returns the list of table headers, excluding "rowSelection" column.
214
158
  * @param rows - Table rows.
215
159
  * @returns list of headers.
216
160
  */
217
161
  function getHeadersTableData(rows) {
218
162
  return rows[0]
219
163
  .getAllCells()
220
- .filter((cell) => cell.column.id !== ACCESSOR_KEYS.SELECT)
164
+ .filter((cell) => cell.column.id !== COLUMN_IDENTIFIER.ROW_SELECTION)
221
165
  .map((cell) => cell.column.columnDef.header);
222
166
  }
223
167
  /**
224
- * Returns the list of table data, excluding "select" column.
168
+ * Returns the list of table data, excluding "rowSelection" column.
225
169
  * @param rows - Table rows.
226
170
  * @returns list of data.
227
171
  */
228
172
  function getRowsTableData(rows) {
229
173
  return rows.map((row) => row
230
174
  .getAllCells()
231
- .filter((cell) => cell.column.id !== ACCESSOR_KEYS.SELECT)
175
+ .filter((cell) => cell.column.id !== COLUMN_IDENTIFIER.ROW_SELECTION)
232
176
  .map((cell) => cell.getValue()));
233
177
  }
234
- /**
235
- * Returns true if the column is not grouped (filters out grouped columns).
236
- * @param column - Table column.
237
- * @returns true if the column is not grouped.
238
- */
239
- function filterGroupedColumn(column) {
240
- return !column.getIsGrouped();
241
- }
242
178
  /**
243
179
  * Returns true if any or all table rows are selected.
244
180
  * @param table - Table.
@@ -298,25 +234,6 @@ export function sortingFn(rowA, rowB, columnId) {
298
234
  function basicSort(val0, val1) {
299
235
  return val0 === val1 ? 0 : val0 > val1 ? 1 : -1;
300
236
  }
301
- /**
302
- * Returns the initial table visibility state for the specified column configuration.
303
- * @param columns - Column configuration.
304
- * @returns initial table visibility state.
305
- */
306
- export function getInitialTableColumnVisibility(columns) {
307
- return columns.reduce((acc, { columnVisible = true, id }) => {
308
- Object.assign(acc, { [id]: columnVisible });
309
- return acc;
310
- }, {});
311
- }
312
- /**
313
- * Determine if the given track size width is a size range.
314
- * @param width - Grid table track size.
315
- * @returns true if the given track size width is a size range.
316
- */
317
- function isGridTrackMinMax(width) {
318
- return width.min !== undefined;
319
- }
320
237
  /**
321
238
  * Returns the given value as a string.
322
239
  * See React Table "toString" function
@@ -1,5 +1,5 @@
1
1
  import { TABLE_CELL_PROPS } from "../../../../../styles/common/mui/tableCell";
2
- import { ACCESSOR_KEYS } from "../../../../TableCreator/common/constants";
2
+ import { COLUMN_IDENTIFIER } from "../../../common/columnIdentifier";
3
3
  /**
4
4
  * Returns table cell alignment based on the cell.
5
5
  * @param column - Column.
@@ -15,9 +15,9 @@ export function getTableCellAlign(column) {
15
15
  */
16
16
  export function getTableCellPadding(id) {
17
17
  switch (id) {
18
- case ACCESSOR_KEYS.ROW_POSITION:
18
+ case COLUMN_IDENTIFIER.ROW_POSITION:
19
19
  return TABLE_CELL_PROPS.PADDING.NORMAL;
20
- case ACCESSOR_KEYS.SELECT:
20
+ case COLUMN_IDENTIFIER.ROW_SELECTION:
21
21
  return TABLE_CELL_PROPS.PADDING.CHECKBOX;
22
22
  default:
23
23
  return TABLE_CELL_PROPS.PADDING.NORMAL;
@@ -1,5 +1,2 @@
1
- import { Row, RowData } from "@tanstack/react-table";
2
- export interface RowSelectionCellProps<T extends RowData> {
3
- row: Row<T>;
4
- }
5
- export declare const RowSelectionCell: <T extends RowData>({ row, }: RowSelectionCellProps<T>) => JSX.Element;
1
+ import { CellContext, RowData } from "@tanstack/react-table";
2
+ export declare const RowSelectionCell: <T extends RowData, TValue = unknown>({ row, }: CellContext<T, TValue>) => JSX.Element;
@@ -1,21 +1,10 @@
1
- import { Column, RowData, Table } from "@tanstack/react-table";
1
+ import { RowData, Table } from "@tanstack/react-table";
2
2
  /**
3
- * Toggles the visibility state for the given column.
4
- * ### Column Visibility State
5
- * - **Column visibility is not enabled**:
6
- * - No column visibility action (exit).
7
- * - **Column visibility is enabled**:
8
- * - Toggles the visibility state of the specified column.
9
- * ### Grouping and Sorting State
10
- * - **Column is not visible**:
11
- * - No grouping or sorting action (exit).
12
- * - **Column is visible**:
13
- * - **Column is grouped**:
14
- * - Resets grouping state to `[]`.
15
- * - Clears column from sorting state.
16
- * - **Column is not grouped**:
17
- * - No grouping or sorting action.
3
+ * Resets column visibility state of the table.
4
+ * ### Default Behavior:
5
+ * - Column visibility state is reset to initial state.
6
+ * ### Grouping State:
7
+ * - Column visibility state is reset to initial state, with any grouped columns remaining visible.
18
8
  * @param table - Table.
19
- * @param column - Column.
20
9
  */
21
- export declare function handleToggleVisibility<T extends RowData>(table: Table<T>, column: Column<T>): void;
10
+ export declare function handleResetVisibilityState<T extends RowData>(table: Table<T>): void;
@@ -1,37 +1,26 @@
1
1
  /**
2
- * Toggles the visibility state for the given column.
3
- * ### Column Visibility State
4
- * - **Column visibility is not enabled**:
5
- * - No column visibility action (exit).
6
- * - **Column visibility is enabled**:
7
- * - Toggles the visibility state of the specified column.
8
- * ### Grouping and Sorting State
9
- * - **Column is not visible**:
10
- * - No grouping or sorting action (exit).
11
- * - **Column is visible**:
12
- * - **Column is grouped**:
13
- * - Resets grouping state to `[]`.
14
- * - Clears column from sorting state.
15
- * - **Column is not grouped**:
16
- * - No grouping or sorting action.
2
+ * Resets column visibility state of the table.
3
+ * ### Default Behavior:
4
+ * - Column visibility state is reset to initial state.
5
+ * ### Grouping State:
6
+ * - Column visibility state is reset to initial state, with any grouped columns remaining visible.
17
7
  * @param table - Table.
18
- * @param column - Column.
19
8
  */
20
- export function handleToggleVisibility(table, column) {
21
- const { options: { enableGrouping }, resetGrouping, } = table;
22
- const { clearSorting, getCanHide, getIsGrouped, getIsVisible, toggleVisibility, } = column;
23
- if (!getCanHide())
9
+ export function handleResetVisibilityState(table) {
10
+ const { getState, initialState, resetColumnVisibility, setColumnVisibility } = table;
11
+ const { grouping } = getState();
12
+ if (grouping.length === 0) {
13
+ resetColumnVisibility(); // Resets column visibility state.
24
14
  return;
25
- // Toggle column visibility.
26
- toggleVisibility();
27
- // Column is not visible i.e. requesting column visibility and therefore no further action is needed.
28
- if (!getIsVisible())
29
- return;
30
- // Column is visible.
31
- // Table grouping is enabled, and column is grouped.
32
- if (enableGrouping && getIsGrouped()) {
33
- resetGrouping(true); // Clears grouping state to `[]`.
34
- // Currently, only a grouped column's sorting state is cleared.
35
- clearSorting(); // Clears column sorting.
36
15
  }
16
+ // Table is grouped.
17
+ // Ensure grouped columns remain visible (as their initial visibility state may have been `false`).
18
+ const groupedColumnVisibility = {};
19
+ for (const id of grouping) {
20
+ groupedColumnVisibility[id] = true;
21
+ }
22
+ setColumnVisibility({
23
+ ...initialState.columnVisibility,
24
+ ...groupedColumnVisibility,
25
+ });
37
26
  }
@@ -1,5 +1,2 @@
1
- import { RowData, Table } from "@tanstack/react-table";
2
- export interface HeadSelectionCellProps<T extends RowData> {
3
- tableInstance: Table<T>;
4
- }
5
- export declare const HeadSelectionCell: <T extends RowData>({ tableInstance, }: HeadSelectionCellProps<T>) => JSX.Element;
1
+ import { HeaderContext, RowData } from "@tanstack/react-table";
2
+ export declare const HeadSelectionCell: <T extends RowData, TValue = unknown>({ table, }: HeaderContext<T, TValue>) => JSX.Element;
@@ -3,7 +3,7 @@ import React from "react";
3
3
  import { CheckedIcon } from "../../../../../common/CustomIcon/components/CheckedIcon/checkedIcon";
4
4
  import { IndeterminateIcon } from "../../../../../common/CustomIcon/components/IndeterminateIcon/indeterminateIcon";
5
5
  import { UncheckedIcon } from "../../../../../common/CustomIcon/components/UncheckedIcon/uncheckedIcon";
6
- export const HeadSelectionCell = ({ tableInstance, }) => {
7
- const { getIsAllPageRowsSelected, getIsSomePageRowsSelected, getToggleAllRowsSelectedHandler, } = tableInstance;
6
+ export const HeadSelectionCell = ({ table, }) => {
7
+ const { getIsAllPageRowsSelected, getIsSomePageRowsSelected, getToggleAllRowsSelectedHandler, } = table;
8
8
  return (React.createElement(Checkbox, { checked: getIsAllPageRowsSelected(), checkedIcon: React.createElement(CheckedIcon, null), icon: React.createElement(UncheckedIcon, null), indeterminate: getIsSomePageRowsSelected(), indeterminateIcon: React.createElement(IndeterminateIcon, null), onChange: getToggleAllRowsSelectedHandler() }));
9
9
  };
@@ -1,26 +1,14 @@
1
- import { ListItemText } from "@mui/material";
2
1
  import React from "react";
3
2
  import { DropdownButton } from "../../../../../common/Button/components/DropdownButton/dropdownButton";
4
3
  import { DropdownMenu } from "../../../../../common/DropdownMenu/dropdownMenu";
5
- import { handleClearGroupingState } from "../../../TableFeatures/ColumnGrouping/utils";
6
- import { StyledMenuItem } from "./columnGrouping.styles";
7
4
  import { MenuItems } from "./components/MenuItems/menuItems";
8
- import { LIST_ITEM_TEXT_PROPS, MENU_ITEM_PROPS, MENU_PROPS } from "./constants";
9
- import { getButtonLabel, getColumnGrouping } from "./utils";
5
+ import { MENU_PROPS } from "./constants";
6
+ import { getButtonLabel } from "./utils";
10
7
  export const ColumnGrouping = ({ tableInstance, }) => {
11
- const { getState, options: { enableGrouping }, } = tableInstance;
12
- const { grouping } = getState();
13
- const groupingByColumnId = getColumnGrouping(tableInstance);
8
+ const { getAllColumns, options: { enableGrouping }, } = tableInstance;
14
9
  if (!enableGrouping)
15
10
  return null;
16
- if (groupingByColumnId.size === 0)
17
- return null;
18
- return (React.createElement(DropdownMenu, { ...MENU_PROPS, button: (props) => (React.createElement(DropdownButton, { ...props }, getButtonLabel(groupingByColumnId, grouping))) }, ({ closeMenu }) => [
19
- React.createElement(MenuItems, { key: "column-grouping", closeMenu: closeMenu, groupingByColumnId: groupingByColumnId, tableInstance: tableInstance }),
20
- React.createElement(StyledMenuItem, { ...MENU_ITEM_PROPS, key: "reset-grouping-state", disabled: grouping.length === 0, onClick: () => {
21
- handleClearGroupingState(tableInstance);
22
- closeMenu();
23
- } },
24
- React.createElement(ListItemText, { ...LIST_ITEM_TEXT_PROPS }, "Clear Grouping")),
11
+ return (React.createElement(DropdownMenu, { ...MENU_PROPS, button: (props) => (React.createElement(DropdownButton, { ...props }, getButtonLabel(getAllColumns()))) }, ({ closeMenu }) => [
12
+ React.createElement(MenuItems, { key: "column-grouping", closeMenu: closeMenu, tableInstance: tableInstance }),
25
13
  ]));
26
14
  };
@@ -0,0 +1,3 @@
1
+ import { ListItemTextProps, MenuItemProps } from "@mui/material";
2
+ export declare const LIST_ITEM_TEXT_PROPS: Partial<ListItemTextProps>;
3
+ export declare const MENU_ITEM_PROPS: Partial<MenuItemProps>;
@@ -0,0 +1,10 @@
1
+ export const LIST_ITEM_TEXT_PROPS = {
2
+ primaryTypographyProps: {
3
+ color: "primary",
4
+ component: "span",
5
+ variant: "inherit",
6
+ },
7
+ };
8
+ export const MENU_ITEM_PROPS = {
9
+ component: "li",
10
+ };
@@ -1,3 +1,3 @@
1
1
  import { RowData } from "@tanstack/react-table";
2
2
  import { MenuItemsProps } from "./types";
3
- export declare const MenuItems: <T extends RowData>({ closeMenu, groupingByColumnId, tableInstance, }: MenuItemsProps<T>) => JSX.Element[];
3
+ export declare const MenuItems: <T extends RowData>({ closeMenu, tableInstance, }: MenuItemsProps<T>) => JSX.Element;
@@ -1,12 +1,24 @@
1
1
  import { ListItemText, MenuItem } from "@mui/material";
2
- import React from "react";
3
- import { handleToggleGrouping } from "../../../../../TableFeatures/ColumnGrouping/utils";
4
- import { MENU_ITEM_PROPS } from "../../constants";
5
- export const MenuItems = ({ closeMenu, groupingByColumnId, tableInstance, }) => {
6
- const columnByMenuItem = [...groupingByColumnId.values()];
7
- return columnByMenuItem.map(([menuItem, column]) => (React.createElement(MenuItem, { ...MENU_ITEM_PROPS, key: column.id, disabled: !column.getCanGroup(), onClick: () => {
8
- handleToggleGrouping(tableInstance, column);
9
- closeMenu();
10
- }, selected: column.getIsGrouped() },
11
- React.createElement(ListItemText, { disableTypography: true }, menuItem))));
2
+ import React, { Fragment } from "react";
3
+ import { handleClearGroupingState, handleToggleGrouping, } from "../../../../../TableFeatures/ColumnGrouping/utils";
4
+ import { LIST_ITEM_TEXT_PROPS, MENU_ITEM_PROPS } from "./constants";
5
+ import { StyledMenuItem } from "./menuItems.styles";
6
+ import { getCanGroupColumns, getVisibleColumnCount, isToggleGroupingDisabled, } from "./utils";
7
+ export const MenuItems = ({ closeMenu, tableInstance, }) => {
8
+ const { getAllColumns } = tableInstance;
9
+ const columns = getCanGroupColumns(getAllColumns());
10
+ const visibleCount = getVisibleColumnCount(getAllColumns());
11
+ return (React.createElement(Fragment, null,
12
+ columns.map((column) => {
13
+ return (React.createElement(MenuItem, { ...MENU_ITEM_PROPS, key: column.id, disabled: isToggleGroupingDisabled(column, visibleCount), onClick: () => {
14
+ handleToggleGrouping(tableInstance, column);
15
+ closeMenu();
16
+ }, selected: column.getIsGrouped() },
17
+ React.createElement(ListItemText, { disableTypography: true }, column.columnDef.header)));
18
+ }),
19
+ React.createElement(StyledMenuItem, { ...MENU_ITEM_PROPS, onClick: () => {
20
+ handleClearGroupingState(tableInstance);
21
+ closeMenu();
22
+ } },
23
+ React.createElement(ListItemText, { ...LIST_ITEM_TEXT_PROPS }, "Clear Grouping"))));
12
24
  };
@@ -1,7 +1,6 @@
1
- import { Column, RowData, Table } from "@tanstack/react-table";
1
+ import { RowData, Table } from "@tanstack/react-table";
2
2
  import { UseMenu } from "../../../../../../../common/Menu/hooks/useMenu";
3
3
  export interface MenuItemsProps<T extends RowData> {
4
4
  closeMenu: UseMenu<HTMLButtonElement>["onClose"];
5
- groupingByColumnId: Map<string, [string, Column<T>]>;
6
5
  tableInstance: Table<T>;
7
6
  }
@@ -0,0 +1,27 @@
1
+ import { Column, RowData } from "@tanstack/react-table";
2
+ /**
3
+ * Returns columns that are enabled to be grouped.
4
+ * @param columns - Columns.
5
+ * @returns columns that are enabled to be grouped.
6
+ */
7
+ export declare function getCanGroupColumns<T extends RowData>(columns: Column<T>[]): (Column<T> & {
8
+ columnDef: {
9
+ header: string;
10
+ };
11
+ })[];
12
+ /**
13
+ * Returns the number of visible columns, excluding system columns "rowPosition" and "rowSelection".
14
+ * @param columns - Columns.
15
+ * @returns number of visible columns.
16
+ */
17
+ export declare function getVisibleColumnCount<T extends RowData>(columns: Column<T>[]): number;
18
+ /**
19
+ * Returns whether the column grouping toggle is disabled.
20
+ * - If the column is not enabled to be grouped, the toggle is disabled.
21
+ * - If the column is not visible, the toggle is disabled.
22
+ * - If the count of visible columns is 1, the toggle is disabled.
23
+ * @param column - Column.
24
+ * @param visibleCount - Count of visible, un-grouped columns.
25
+ * @returns true if the column visibility toggle is disabled.
26
+ */
27
+ export declare function isToggleGroupingDisabled<T extends RowData>(column: Column<T>, visibleCount: number): boolean;
@@ -0,0 +1,45 @@
1
+ import { COLUMN_IDENTIFIER } from "../../../../../../common/columnIdentifier";
2
+ import { isStringHeaderColumn } from "../../../../../../common/typeGuards";
3
+ /**
4
+ * Returns columns that are enabled to be grouped.
5
+ * @param columns - Columns.
6
+ * @returns columns that are enabled to be grouped.
7
+ */
8
+ export function getCanGroupColumns(columns) {
9
+ return columns
10
+ .filter(isStringHeaderColumn)
11
+ .filter(({ getCanGroup }) => getCanGroup());
12
+ }
13
+ /**
14
+ * Returns the number of visible columns, excluding system columns "rowPosition" and "rowSelection".
15
+ * @param columns - Columns.
16
+ * @returns number of visible columns.
17
+ */
18
+ export function getVisibleColumnCount(columns) {
19
+ return columns
20
+ .filter((column) => !isSystemColumn(column))
21
+ .filter(({ getIsVisible }) => getIsVisible()).length;
22
+ }
23
+ /**
24
+ * Returns true if the column is a system column "rowPosition" or "rowSelection".
25
+ * @param column - Column.
26
+ * @returns true if the column is a system column.
27
+ */
28
+ function isSystemColumn(column) {
29
+ return (column.id === COLUMN_IDENTIFIER.ROW_POSITION ||
30
+ column.id === COLUMN_IDENTIFIER.ROW_SELECTION);
31
+ }
32
+ /**
33
+ * Returns whether the column grouping toggle is disabled.
34
+ * - If the column is not enabled to be grouped, the toggle is disabled.
35
+ * - If the column is not visible, the toggle is disabled.
36
+ * - If the count of visible columns is 1, the toggle is disabled.
37
+ * @param column - Column.
38
+ * @param visibleCount - Count of visible, un-grouped columns.
39
+ * @returns true if the column visibility toggle is disabled.
40
+ */
41
+ export function isToggleGroupingDisabled(column, visibleCount) {
42
+ if (!column.getCanGroup() || !column.getIsVisible())
43
+ return true;
44
+ return visibleCount === 1; // We should not be able to group the last visible column; at least one un-grouped column should be visible.
45
+ }
@@ -1,4 +1,2 @@
1
- import { ListItemTextProps, MenuItemProps, MenuProps } from "@mui/material";
2
- export declare const LIST_ITEM_TEXT_PROPS: Partial<ListItemTextProps>;
1
+ import { MenuProps } from "@mui/material";
3
2
  export declare const MENU_PROPS: Partial<MenuProps>;
4
- export declare const MENU_ITEM_PROPS: Partial<MenuItemProps>;
@@ -1,13 +1,3 @@
1
- export const LIST_ITEM_TEXT_PROPS = {
2
- primaryTypographyProps: {
3
- color: "primary",
4
- component: "span",
5
- variant: "inherit",
6
- },
7
- };
8
1
  export const MENU_PROPS = {
9
2
  variant: "menu",
10
3
  };
11
- export const MENU_ITEM_PROPS = {
12
- component: "li",
13
- };