@databiosphere/findable-ui 43.0.0 → 45.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 (153) hide show
  1. package/.release-please-manifest.json +1 -1
  2. package/CHANGELOG.md +34 -0
  3. package/lib/common/filters/sort/config/types.d.ts +13 -0
  4. package/lib/common/filters/sort/config/types.js +8 -0
  5. package/lib/common/filters/sort/config/utils.d.ts +8 -0
  6. package/lib/common/filters/sort/config/utils.js +9 -0
  7. package/lib/common/filters/sort/models/utils.d.ts +23 -0
  8. package/lib/common/filters/sort/models/utils.js +41 -0
  9. package/lib/components/DataDictionary/components/Table/options/core/constants.js +2 -1
  10. package/lib/components/DataDictionary/components/Table/options/hook.js +2 -0
  11. package/lib/components/Detail/components/Table/table.js +4 -1
  12. package/lib/components/Filter/components/adapters/tanstack/ColumnFiltersAdapter/columnFiltersAdapter.js +6 -1
  13. package/lib/components/Filter/components/adapters/tanstack/ColumnFiltersAdapter/hooks/UseUpdateFilterSort/hook.d.ts +3 -0
  14. package/lib/components/Filter/components/adapters/tanstack/ColumnFiltersAdapter/hooks/UseUpdateFilterSort/hook.js +8 -0
  15. package/lib/components/Filter/components/adapters/tanstack/ColumnFiltersAdapter/hooks/UseUpdateFilterSort/types.d.ts +6 -0
  16. package/lib/components/Filter/components/adapters/tanstack/ColumnFiltersAdapter/hooks/UseUpdateFilterSort/types.js +1 -0
  17. package/lib/components/Filter/components/adapters/tanstack/ColumnFiltersAdapter/hooks/UseUpdateFilterSort/utils.d.ts +14 -0
  18. package/lib/components/Filter/components/adapters/tanstack/ColumnFiltersAdapter/hooks/UseUpdateFilterSort/utils.js +23 -0
  19. package/lib/components/Filter/components/adapters/tanstack/ColumnFiltersAdapter/types.d.ts +2 -0
  20. package/lib/components/Filter/components/adapters/tanstack/ColumnFiltersAdapter/utils.d.ts +3 -1
  21. package/lib/components/Filter/components/adapters/tanstack/ColumnFiltersAdapter/utils.js +24 -16
  22. package/lib/components/Filter/components/controls/Controls/components/FilterSort/constants.d.ts +5 -0
  23. package/lib/components/Filter/components/controls/Controls/components/FilterSort/constants.js +17 -0
  24. package/lib/components/Filter/components/controls/Controls/components/FilterSort/filterSort.d.ts +2 -0
  25. package/lib/components/Filter/components/controls/Controls/components/FilterSort/filterSort.js +28 -0
  26. package/lib/components/Filter/components/controls/Controls/components/FilterSort/filterSort.styles.d.ts +9 -0
  27. package/lib/components/Filter/components/controls/Controls/components/FilterSort/filterSort.styles.js +25 -0
  28. package/lib/components/Filter/components/controls/Controls/components/FilterSort/stories/filterSort.stories.d.ts +6 -0
  29. package/lib/components/Filter/components/controls/Controls/components/FilterSort/stories/filterSort.stories.js +9 -0
  30. package/lib/components/Filter/components/controls/Controls/components/FilterSort/types.d.ts +6 -0
  31. package/lib/components/Filter/components/controls/Controls/components/FilterSort/types.js +1 -0
  32. package/lib/components/Filter/components/controls/Controls/controls.d.ts +2 -3
  33. package/lib/components/Filter/components/controls/Controls/controls.js +4 -2
  34. package/lib/components/Filter/components/controls/Controls/controls.styles.js +2 -1
  35. package/lib/components/Filter/components/controls/Controls/types.d.ts +6 -0
  36. package/lib/components/Filter/components/controls/Controls/types.js +1 -0
  37. package/lib/components/Filter/components/surfaces/types.d.ts +3 -1
  38. package/lib/components/Index/components/EntityView/components/views/ChartView/components/Chart/hooks/UsePlotOptions/hook.js +2 -2
  39. package/lib/components/Index/components/EntityView/components/views/ChartView/components/Chart/utils.d.ts +0 -7
  40. package/lib/components/Index/components/EntityView/components/views/ChartView/components/Chart/utils.js +0 -11
  41. package/lib/components/Index/table/hook.js +4 -1
  42. package/lib/components/Table/common/columnDef.js +2 -0
  43. package/lib/components/Table/common/utils.d.ts +0 -6
  44. package/lib/components/Table/common/utils.js +0 -63
  45. package/lib/components/Table/components/TableFeatures/TableDownload/tableDownload.d.ts +3 -0
  46. package/lib/components/Table/components/TableFeatures/TableDownload/tableDownload.js +9 -0
  47. package/lib/components/Table/components/{DownloadEntityResults/downloadEntityResults.styles.js → TableFeatures/TableDownload/tableDownload.styles.js} +1 -1
  48. package/lib/components/Table/components/TableFeatures/TableDownload/types.d.ts +5 -0
  49. package/lib/components/Table/components/TableFeatures/TableDownload/types.js +1 -0
  50. package/lib/components/Table/components/TableToolbar/tableToolbar.js +3 -3
  51. package/lib/components/Table/components/TableToolbar2/tableToolbar2.d.ts +3 -0
  52. package/lib/components/Table/components/TableToolbar2/tableToolbar2.js +8 -0
  53. package/lib/components/Table/components/TableToolbar2/tableToolbar2.styles.d.ts +10 -0
  54. package/lib/components/Table/components/TableToolbar2/tableToolbar2.styles.js +16 -0
  55. package/lib/components/Table/components/TableToolbar2/types.d.ts +4 -0
  56. package/lib/components/Table/components/TableToolbar2/types.js +1 -0
  57. package/lib/components/Table/featureOptions/tableDownload/constants.d.ts +3 -0
  58. package/lib/components/Table/featureOptions/tableDownload/constants.js +3 -0
  59. package/lib/components/Table/features/TableDownload/constants.d.ts +2 -0
  60. package/lib/components/Table/features/TableDownload/constants.js +10 -0
  61. package/lib/components/Table/features/TableDownload/onDownload/utils.d.ts +14 -0
  62. package/lib/components/Table/features/TableDownload/onDownload/utils.js +63 -0
  63. package/lib/components/Table/features/TableDownload/types.d.ts +15 -0
  64. package/lib/components/Table/features/TableDownload/types.js +1 -0
  65. package/lib/components/Table/features/TableDownload/utils.d.ts +19 -0
  66. package/lib/components/Table/features/TableDownload/utils.js +46 -0
  67. package/lib/components/Table/features/entities.d.ts +8 -3
  68. package/lib/config/entities.d.ts +2 -1
  69. package/lib/hooks/useCategoryFilter.d.ts +4 -9
  70. package/lib/hooks/useCategoryFilter.js +5 -15
  71. package/lib/providers/exploreState/actions/updateFilterSort/action.d.ts +10 -0
  72. package/lib/providers/exploreState/actions/updateFilterSort/action.js +21 -0
  73. package/lib/providers/exploreState/actions/updateFilterSort/dispatch.d.ts +7 -0
  74. package/lib/providers/exploreState/actions/updateFilterSort/dispatch.js +12 -0
  75. package/lib/providers/exploreState/actions/updateFilterSort/types.d.ts +7 -0
  76. package/lib/providers/exploreState/actions/updateFilterSort/types.js +1 -0
  77. package/lib/providers/exploreState/actions/updateFilterSort/utils.d.ts +10 -0
  78. package/lib/providers/exploreState/actions/updateFilterSort/utils.js +22 -0
  79. package/lib/providers/exploreState/initializer/constants.js +2 -0
  80. package/lib/providers/exploreState/initializer/utils.js +2 -0
  81. package/lib/providers/exploreState.d.ts +5 -1
  82. package/lib/providers/exploreState.js +9 -1
  83. package/lib/tests/testIds.d.ts +2 -0
  84. package/lib/tests/testIds.js +2 -0
  85. package/lib/views/ExploreView/exploreView.js +7 -1
  86. package/lib/views/ExploreView/hooks/UseUpdateFilterSort/hook.d.ts +2 -0
  87. package/lib/views/ExploreView/hooks/UseUpdateFilterSort/hook.js +12 -0
  88. package/lib/views/ExploreView/hooks/UseUpdateFilterSort/types.d.ts +6 -0
  89. package/lib/views/ExploreView/hooks/UseUpdateFilterSort/types.js +1 -0
  90. package/package.json +1 -1
  91. package/src/common/filters/sort/config/types.ts +14 -0
  92. package/src/common/filters/sort/config/utils.ts +11 -0
  93. package/src/common/filters/sort/models/utils.ts +57 -0
  94. package/src/components/DataDictionary/components/Table/options/core/constants.ts +2 -1
  95. package/src/components/DataDictionary/components/Table/options/hook.ts +2 -0
  96. package/src/components/Detail/components/Table/table.tsx +4 -1
  97. package/src/components/Filter/components/adapters/tanstack/ColumnFiltersAdapter/columnFiltersAdapter.tsx +11 -1
  98. package/src/components/Filter/components/adapters/tanstack/ColumnFiltersAdapter/hooks/UseUpdateFilterSort/hook.ts +22 -0
  99. package/src/components/Filter/components/adapters/tanstack/ColumnFiltersAdapter/hooks/UseUpdateFilterSort/types.ts +7 -0
  100. package/src/components/Filter/components/adapters/tanstack/ColumnFiltersAdapter/hooks/UseUpdateFilterSort/utils.ts +33 -0
  101. package/src/components/Filter/components/adapters/tanstack/ColumnFiltersAdapter/types.ts +2 -0
  102. package/src/components/Filter/components/adapters/tanstack/ColumnFiltersAdapter/utils.ts +36 -13
  103. package/src/components/Filter/components/controls/Controls/components/FilterSort/constants.ts +22 -0
  104. package/src/components/Filter/components/controls/Controls/components/FilterSort/filterSort.styles.ts +34 -0
  105. package/src/components/Filter/components/controls/Controls/components/FilterSort/filterSort.tsx +73 -0
  106. package/src/components/Filter/components/controls/Controls/components/FilterSort/stories/filterSort.stories.tsx +15 -0
  107. package/src/components/Filter/components/controls/Controls/components/FilterSort/types.ts +7 -0
  108. package/src/components/Filter/components/controls/Controls/controls.styles.ts +2 -1
  109. package/src/components/Filter/components/controls/Controls/controls.tsx +11 -3
  110. package/src/components/Filter/components/controls/Controls/types.ts +10 -0
  111. package/src/components/Filter/components/surfaces/types.ts +3 -1
  112. package/src/components/Index/components/EntityView/components/views/ChartView/components/Chart/hooks/UsePlotOptions/hook.ts +2 -2
  113. package/src/components/Index/components/EntityView/components/views/ChartView/components/Chart/utils.ts +0 -15
  114. package/src/components/Index/table/hook.ts +4 -1
  115. package/src/components/Table/common/columnDef.ts +2 -0
  116. package/src/components/Table/common/utils.ts +0 -75
  117. package/src/components/Table/components/{DownloadEntityResults/downloadEntityResults.styles.ts → TableFeatures/TableDownload/tableDownload.styles.ts} +1 -1
  118. package/src/components/Table/components/TableFeatures/TableDownload/tableDownload.tsx +23 -0
  119. package/src/components/Table/components/TableFeatures/TableDownload/types.ts +7 -0
  120. package/src/components/Table/components/TableToolbar/tableToolbar.tsx +3 -8
  121. package/src/components/Table/components/TableToolbar2/tableToolbar2.styles.ts +18 -0
  122. package/src/components/Table/components/TableToolbar2/tableToolbar2.tsx +17 -0
  123. package/src/components/Table/components/TableToolbar2/types.ts +5 -0
  124. package/src/components/Table/featureOptions/tableDownload/constants.ts +9 -0
  125. package/src/components/Table/features/TableDownload/constants.ts +24 -0
  126. package/src/components/Table/features/TableDownload/onDownload/utils.ts +76 -0
  127. package/src/components/Table/features/TableDownload/types.ts +19 -0
  128. package/src/components/Table/features/TableDownload/utils.ts +60 -0
  129. package/src/components/Table/features/entities.ts +19 -3
  130. package/src/config/entities.ts +2 -1
  131. package/src/hooks/useCategoryFilter.ts +8 -19
  132. package/src/providers/exploreState/actions/updateFilterSort/action.ts +30 -0
  133. package/src/providers/exploreState/actions/updateFilterSort/dispatch.ts +16 -0
  134. package/src/providers/exploreState/actions/updateFilterSort/types.ts +9 -0
  135. package/src/providers/exploreState/actions/updateFilterSort/utils.ts +30 -0
  136. package/src/providers/exploreState/initializer/constants.ts +2 -0
  137. package/src/providers/exploreState/initializer/utils.ts +2 -0
  138. package/src/providers/exploreState.tsx +14 -1
  139. package/src/tests/testIds.ts +2 -0
  140. package/src/views/ExploreView/exploreView.tsx +16 -1
  141. package/src/views/ExploreView/hooks/UseUpdateFilterSort/hook.ts +20 -0
  142. package/src/views/ExploreView/hooks/UseUpdateFilterSort/types.ts +7 -0
  143. package/tests/buildCategoryViews.test.ts +282 -0
  144. package/tests/filterSortUtils.test.ts +180 -0
  145. package/tests/getFilterSortType.test.ts +45 -0
  146. package/types/data-explorer-ui.d.ts +16 -2
  147. package/lib/components/Table/components/DownloadEntityResults/downloadEntityResults.d.ts +0 -6
  148. package/lib/components/Table/components/DownloadEntityResults/downloadEntityResults.js +0 -18
  149. package/lib/components/common/Button/components/FileDownloadButton/fileDownloadButton.d.ts +0 -5
  150. package/lib/components/common/Button/components/FileDownloadButton/fileDownloadButton.js +0 -14
  151. package/src/components/Table/components/DownloadEntityResults/downloadEntityResults.tsx +0 -39
  152. package/src/components/common/Button/components/FileDownloadButton/fileDownloadButton.tsx +0 -27
  153. /package/lib/components/Table/components/{DownloadEntityResults/downloadEntityResults.styles.d.ts → TableFeatures/TableDownload/tableDownload.styles.d.ts} +0 -0
@@ -1,8 +1,10 @@
1
1
  import { OnFilterFn } from "../../../../hooks/useCategoryFilter";
2
2
  import { CategoryFilter } from "../Filters/filters";
3
- export interface SurfaceProps {
3
+ import { FilterSortProps } from "../controls/Controls/components/FilterSort/types";
4
+ export interface SurfaceProps extends Omit<FilterSortProps, "enabled"> {
4
5
  categoryFilters: CategoryFilter[];
5
6
  count?: number;
7
+ filterSortEnabled: boolean;
6
8
  onFilter: OnFilterFn;
7
9
  }
8
10
  export declare enum SURFACE_TYPE {
@@ -1,12 +1,12 @@
1
1
  import { useMemo } from "react";
2
+ import { sortCategoryValueViewsCount } from "../../../../../../../../../../../common/filters/sort/models/utils";
2
3
  import { getPlotOptions } from "../../barX/plot";
3
4
  import { getCategoryTotalCount } from "../../barX/utils";
4
- import { sortByCountThenLabel } from "../../utils";
5
5
  export const usePlotOptions = (selectCategoryValueViews, width, barCount) => {
6
6
  // Organise the select category value views (sort and slice) for chart display.
7
7
  const data = selectCategoryValueViews
8
8
  // Sort the category values by count and label.
9
- .sort(sortByCountThenLabel)
9
+ .sort(sortCategoryValueViewsCount)
10
10
  // Slice the category values to the number of bars to display.
11
11
  .slice(0, barCount);
12
12
  // Build the plot options.
@@ -6,10 +6,3 @@ import { SelectCategoryValueView } from "../../../../../../../../../common/entit
6
6
  * @returns Button text.
7
7
  */
8
8
  export declare function renderButtonText(maxBarCount: number | undefined, selectCategoryValueViews: SelectCategoryValueView[]): string;
9
- /**
10
- * Sorts category value views by count in descending order, then label in ascending order.
11
- * @param a - First category value view.
12
- * @param b - Second category value view.
13
- * @returns Sorted category value views.
14
- */
15
- export declare function sortByCountThenLabel(a: SelectCategoryValueView, b: SelectCategoryValueView): number;
@@ -1,4 +1,3 @@
1
- import { sortCategoryValueViews } from "../../../../../../../../../hooks/useCategoryFilter";
2
1
  /**
3
2
  * Renders the button text for the chart.
4
3
  * @param maxBarCount - Maximum number of bars to display.
@@ -13,13 +12,3 @@ export function renderButtonText(maxBarCount, selectCategoryValueViews) {
13
12
  const count = totalBars - maxBarCount;
14
13
  return `Show ${count} additional results`;
15
14
  }
16
- /**
17
- * Sorts category value views by count in descending order, then label in ascending order.
18
- * @param a - First category value view.
19
- * @param b - Second category value view.
20
- * @returns Sorted category value views.
21
- */
22
- export function sortByCountThenLabel(a, b) {
23
- const compare = b.count - a.count;
24
- return compare === 0 ? sortCategoryValueViews(a, b) : compare;
25
- }
@@ -11,8 +11,10 @@ import { arrIncludesSome } from "../../Table/columnDef/columnFilters/filterFn";
11
11
  import { COLUMN_DEF } from "../../Table/common/columnDef";
12
12
  import { buildCategoryViews, getFacetedUniqueValuesWithArrayValues, getTableStatePagination, isClientFilteringEnabled, sortingFn, } from "../../Table/common/utils";
13
13
  import { getFacetedMinMaxValues } from "../../Table/featureOptions/facetedColumn/getFacetedMinMaxValues";
14
+ import { TABLE_DOWNLOAD_OPTIONS } from "../../Table/featureOptions/tableDownload/constants";
14
15
  import { ROW_POSITION } from "../../Table/features/RowPosition/constants";
15
16
  import { ROW_PREVIEW } from "../../Table/features/RowPreview/constants";
17
+ import { TABLE_DOWNLOAD } from "../../Table/features/TableDownload/constants";
16
18
  import { buildBaseColumnDef } from "../../TableCreator/common/utils";
17
19
  import { useTableOptions } from "../../TableCreator/options/hook";
18
20
  import { createCell } from "./coreOptions/columns/cellFactory";
@@ -97,7 +99,7 @@ export const useTable = ({ entityListType, }) => {
97
99
  * - This will simplify the configuration structure and centralize table state definitions, reducing redundancy and improving clarity.
98
100
  */
99
101
  const table = useReactTable({
100
- _features: [ROW_POSITION, ROW_PREVIEW],
102
+ _features: [ROW_POSITION, ROW_PREVIEW, TABLE_DOWNLOAD],
101
103
  columns: columnDefs,
102
104
  data: listItems || [],
103
105
  enableColumnFilters: true, // client-side filtering.
@@ -122,6 +124,7 @@ export const useTable = ({ entityListType, }) => {
122
124
  onRowSelectionChange,
123
125
  onSortingChange,
124
126
  pageCount,
127
+ ...TABLE_DOWNLOAD_OPTIONS,
125
128
  state,
126
129
  ...tableOptions,
127
130
  });
@@ -10,6 +10,7 @@ export const COLUMN_DEF = {
10
10
  enableGrouping: false,
11
11
  enableHiding: false,
12
12
  enableSorting: false,
13
+ enableTableDownload: false,
13
14
  header: "",
14
15
  id: COLUMN_IDENTIFIER.ROW_POSITION,
15
16
  meta: {
@@ -25,6 +26,7 @@ export const COLUMN_DEF = {
25
26
  enableGrouping: false,
26
27
  enableHiding: false,
27
28
  enableSorting: false,
29
+ enableTableDownload: false,
28
30
  header: HeadSelectionCell,
29
31
  id: COLUMN_IDENTIFIER.ROW_SELECTION,
30
32
  meta: {
@@ -22,12 +22,6 @@ export declare function buildCategoryViews<T extends RowData>(columns: Column<T>
22
22
  * @returns column header.
23
23
  */
24
24
  export declare function getColumnHeader<T extends RowData>(column: Column<T>): string;
25
- /**
26
- * Returns filtered entity results as a blob.
27
- * @param rows - Table rows.
28
- * @returns filtered entity results as a blob.
29
- */
30
- export declare function generateDownloadBlob<T extends RowData>(rows: Row<T>[]): Blob | undefined;
31
25
  /**
32
26
  * Returns unique category term counts keyed by category terms.
33
27
  * Custom function based off react table function getFacetedUniqueValues, see
@@ -1,6 +1,5 @@
1
1
  import { memo, sortingFns, } from "@tanstack/react-table";
2
2
  import { EXPLORE_MODE } from "../../../hooks/useExploreMode/types";
3
- import { COLUMN_IDENTIFIER } from "./columnIdentifier";
4
3
  /**
5
4
  * Build view-specific models from react table faceted values function.
6
5
  * @param columns - Table columns.
@@ -60,46 +59,6 @@ export function getColumnHeader(column) {
60
59
  // Return header from meta or id.
61
60
  return meta?.header || id;
62
61
  }
63
- /**
64
- * Format data to TSV string.
65
- * @param data - Table data.
66
- * @returns table data formatted into a TSV string.
67
- */
68
- function formatDataToTSV(data) {
69
- return data
70
- .map((row) => {
71
- return row
72
- .map((data) => {
73
- // Use empty string in place of undefined and null.
74
- if (data === undefined || data === null)
75
- return "";
76
- // Convert to string.
77
- const dataString = Array.isArray(data)
78
- ? data.join(", ")
79
- : String(data);
80
- // Quote if necessary.
81
- return /[\t\r\n"]/.test(dataString)
82
- ? `"${dataString.replaceAll('"', '""')}"`
83
- : dataString;
84
- })
85
- .join("\t");
86
- })
87
- .join("\n");
88
- }
89
- /**
90
- * Returns filtered entity results as a blob.
91
- * @param rows - Table rows.
92
- * @returns filtered entity results as a blob.
93
- */
94
- export function generateDownloadBlob(rows) {
95
- if (rows.length === 0) {
96
- return;
97
- }
98
- const tableHeaders = getHeadersTableData(rows);
99
- const tableData = getRowsTableData(rows);
100
- const tsv = formatDataToTSV([tableHeaders, ...tableData]);
101
- return new Blob([tsv], { type: "text/tab-separated-values" });
102
- }
103
62
  /**
104
63
  * Returns unique category term counts keyed by category terms.
105
64
  * Custom function based off react table function getFacetedUniqueValues, see
@@ -166,28 +125,6 @@ export function getTableStatePagination(pageIndex = 0, pageSize) {
166
125
  pageSize,
167
126
  };
168
127
  }
169
- /**
170
- * Returns the list of table headers, excluding "rowSelection" column.
171
- * @param rows - Table rows.
172
- * @returns list of headers.
173
- */
174
- function getHeadersTableData(rows) {
175
- return rows[0]
176
- .getAllCells()
177
- .filter((cell) => cell.column.id !== COLUMN_IDENTIFIER.ROW_SELECTION)
178
- .map((cell) => cell.column.columnDef.header);
179
- }
180
- /**
181
- * Returns the list of table data, excluding "rowSelection" column.
182
- * @param rows - Table rows.
183
- * @returns list of data.
184
- */
185
- function getRowsTableData(rows) {
186
- return rows.map((row) => row
187
- .getAllCells()
188
- .filter((cell) => cell.column.id !== COLUMN_IDENTIFIER.ROW_SELECTION)
189
- .map((cell) => cell.getValue()));
190
- }
191
128
  /**
192
129
  * Returns true if any or all table rows are selected.
193
130
  * @param table - Table.
@@ -0,0 +1,3 @@
1
+ import { RowData } from "@tanstack/react-table";
2
+ import { TableDownloadProps } from "./types";
3
+ export declare const TableDownload: <T extends RowData>({ className, table, }: TableDownloadProps<T>) => JSX.Element | null;
@@ -0,0 +1,9 @@
1
+ import React from "react";
2
+ import { BUTTON_PROPS } from "../../../../common/Button/constants";
3
+ import { DownloadIcon } from "../../../../common/CustomIcon/components/DownloadIcon/downloadIcon";
4
+ import { StyledButton } from "./tableDownload.styles";
5
+ export const TableDownload = ({ className, table, }) => {
6
+ if (!table.options.enableTableDownload)
7
+ return null;
8
+ return (React.createElement(StyledButton, { ...BUTTON_PROPS.SECONDARY_CONTAINED, className: className, onClick: () => table.downloadData(), startIcon: React.createElement(DownloadIcon, null) }, "Download TSV"));
9
+ };
@@ -1,6 +1,6 @@
1
1
  import styled from "@emotion/styled";
2
2
  import { Button } from "@mui/material";
3
- import { bpDownSm } from "../../../../styles/common/mixins/breakpoints";
3
+ import { bpDownSm } from "../../../../../styles/common/mixins/breakpoints";
4
4
  export const StyledButton = styled(Button) `
5
5
  ${bpDownSm} {
6
6
  display: none;
@@ -0,0 +1,5 @@
1
+ import { RowData, Table } from "@tanstack/react-table";
2
+ import { BaseComponentProps } from "../../../../types";
3
+ export interface TableDownloadProps<T extends RowData> extends BaseComponentProps {
4
+ table: Table<T>;
5
+ }
@@ -3,8 +3,8 @@ import React, { Fragment } from "react";
3
3
  import { useExploreState } from "../../../../hooks/useExploreState";
4
4
  import { ViewToggle } from "../../../Index/components/EntityView/components/controls/ViewToggle/viewToggle";
5
5
  import { isAnyRowSelected } from "../../common/utils";
6
- import { DownloadEntityResults } from "../DownloadEntityResults/downloadEntityResults";
7
6
  import { PaginationSummary } from "../PaginationSummary/paginationSummary";
7
+ import { TableDownload } from "../TableFeatures/TableDownload/tableDownload";
8
8
  import { ColumnGrouping } from "./components/ColumnGrouping/columnGrouping";
9
9
  import { ColumnVisibility } from "./components/ColumnVisibility/columnVisibility";
10
10
  import { RowPreview } from "./components/RowPreview/rowPreview";
@@ -16,14 +16,14 @@ export const TableToolbar = ({ listView, tableInstance, }) => {
16
16
  const { paginationState } = exploreState;
17
17
  const { currentPage, pages, pageSize, rows } = paginationState;
18
18
  const { getSelectedRowModel } = tableInstance;
19
- const { enableDownload, rowPreviewView } = listView || {};
19
+ const { rowPreviewView } = listView || {};
20
20
  return (React.createElement(Fragment, null,
21
21
  React.createElement(StyledToolbar, null,
22
22
  React.createElement(Grid, { ...GRID_PROPS, gap: 6 },
23
23
  React.createElement(ViewToggle, null),
24
24
  isAnyRowSelected(tableInstance) ? (React.createElement(RowSelection, { rows: getSelectedRowModel().rows, rowSelectionView: listView?.rowSelectionView })) : (React.createElement(PaginationSummary, { firstResult: (currentPage - 1) * pageSize + 1, lastResult: currentPage === pages ? rows : pageSize * currentPage, totalResult: rows }))),
25
25
  React.createElement(Grid, { ...GRID_PROPS },
26
- enableDownload && (React.createElement(DownloadEntityResults, { entityName: exploreState.tabValue, rows: tableInstance.getFilteredRowModel().rows })),
26
+ React.createElement(TableDownload, { table: tableInstance }),
27
27
  React.createElement(ColumnGrouping, { tableInstance: tableInstance }),
28
28
  React.createElement(ColumnVisibility, { tableInstance: tableInstance }))),
29
29
  React.createElement(RowPreview, { rowPreviewView: rowPreviewView, tableInstance: tableInstance })));
@@ -0,0 +1,3 @@
1
+ import { RowData } from "@tanstack/react-table";
2
+ import { TableToolbar2Props } from "./types";
3
+ export declare const TableToolbar2: <T extends RowData>({ table, }: TableToolbar2Props<T>) => JSX.Element;
@@ -0,0 +1,8 @@
1
+ import React from "react";
2
+ import { TableDownload } from "../TableFeatures/TableDownload/tableDownload";
3
+ import { StyledStack, StyledToolbar } from "./tableToolbar2.styles";
4
+ export const TableToolbar2 = ({ table, }) => {
5
+ return (React.createElement(StyledToolbar, null,
6
+ React.createElement(StyledStack, null,
7
+ React.createElement(TableDownload, { table: table }))));
8
+ };
@@ -0,0 +1,10 @@
1
+ export declare const StyledToolbar: import("@emotion/styled").StyledComponent<import("@mui/material").ToolbarOwnProps & import("@mui/material/OverridableComponent").CommonProps & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
2
+ ref?: ((instance: HTMLDivElement | null) => void | import("react").DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES[keyof import("react").DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES]) | import("react").RefObject<HTMLDivElement> | null | undefined;
3
+ }, "style" | "className" | "classes" | "children" | "sx" | "variant" | "disableGutters"> & {
4
+ theme?: import("@emotion/react").Theme;
5
+ }, {}, {}>;
6
+ export declare const StyledStack: import("@emotion/styled").StyledComponent<import("@mui/material").StackOwnProps & import("@mui/material/OverridableComponent").CommonProps & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
7
+ ref?: ((instance: HTMLDivElement | null) => void | import("react").DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES[keyof import("react").DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES]) | import("react").RefObject<HTMLDivElement> | null | undefined;
8
+ }, keyof import("@mui/material/OverridableComponent").CommonProps | keyof import("@mui/material").StackOwnProps> & {
9
+ theme?: import("@emotion/react").Theme;
10
+ }, {}, {}>;
@@ -0,0 +1,16 @@
1
+ import styled from "@emotion/styled";
2
+ import { Toolbar as MToolbar, Stack } from "@mui/material";
3
+ import { PALETTE } from "../../../../styles/common/constants/palette";
4
+ export const StyledToolbar = styled(MToolbar) `
5
+ align-items: center;
6
+ background-color: ${PALETTE.COMMON_WHITE};
7
+ display: flex;
8
+ padding: 16px;
9
+ `;
10
+ export const StyledStack = styled(Stack) `
11
+ align-items: center;
12
+ flex: 1;
13
+ flex-direction: row;
14
+ gap: 8px;
15
+ justify-content: flex-end;
16
+ `;
@@ -0,0 +1,4 @@
1
+ import { RowData, Table } from "@tanstack/react-table";
2
+ export interface TableToolbar2Props<T extends RowData> {
3
+ table: Table<T>;
4
+ }
@@ -0,0 +1,3 @@
1
+ import { RowData } from "@tanstack/react-table";
2
+ import { TableDownloadOptions } from "../../features/TableDownload/types";
3
+ export declare const TABLE_DOWNLOAD_OPTIONS: Pick<TableDownloadOptions<RowData>, "enableTableDownload">;
@@ -0,0 +1,3 @@
1
+ export const TABLE_DOWNLOAD_OPTIONS = {
2
+ enableTableDownload: false,
3
+ };
@@ -0,0 +1,2 @@
1
+ import { TableFeature } from "@tanstack/react-table";
2
+ export declare const TABLE_DOWNLOAD: TableFeature;
@@ -0,0 +1,10 @@
1
+ import { downloadData, getCanTableDownload, onTableDownload } from "./utils";
2
+ export const TABLE_DOWNLOAD = {
3
+ createColumn: (column, table) => {
4
+ column.getCanTableDownload = () => getCanTableDownload(column, table);
5
+ },
6
+ createTable: (table) => {
7
+ table.downloadData = () => downloadData(table);
8
+ },
9
+ getDefaultOptions: () => ({ enableTableDownload: false, onTableDownload }),
10
+ };
@@ -0,0 +1,14 @@
1
+ import { Column, RowData, Table } from "@tanstack/react-table";
2
+ /**
3
+ * Format data to TSV string.
4
+ * @param data - Table data.
5
+ * @returns table data formatted into a TSV string.
6
+ */
7
+ export declare function formatDataToTSV(data: unknown[][]): string;
8
+ export declare function getBlob<T extends RowData>(table: Table<T>): Blob | undefined;
9
+ /**
10
+ * Filters table columns from column.getCanDownload API.
11
+ * @param table - Table.
12
+ * @returns Columns configured to be downloadable.
13
+ */
14
+ export declare function getDownloadableColumns<T extends RowData>(table: Table<T>): Column<T>[];
@@ -0,0 +1,63 @@
1
+ import { getColumnHeader } from "../../../common/utils";
2
+ /**
3
+ * Format data to TSV string.
4
+ * @param data - Table data.
5
+ * @returns table data formatted into a TSV string.
6
+ */
7
+ export function formatDataToTSV(data) {
8
+ return data
9
+ .map((row) => {
10
+ return row
11
+ .map((value) => {
12
+ // Use empty string in place of undefined and null.
13
+ if (value === undefined || value === null)
14
+ return "";
15
+ // Convert unknown value to string.
16
+ let valueStr;
17
+ // Test if object / array.
18
+ if (typeof value === "object") {
19
+ if (Array.isArray(value)) {
20
+ // Handle array.
21
+ valueStr = value.join(", ") || "";
22
+ }
23
+ else {
24
+ // Handle object.
25
+ valueStr = JSON.stringify(value);
26
+ }
27
+ }
28
+ else {
29
+ // Handle primitive.
30
+ valueStr = String(value);
31
+ }
32
+ // Quote if necessary.
33
+ return /[\t\r\n"]/.test(valueStr)
34
+ ? `"${valueStr.replaceAll('"', '""')}"`
35
+ : valueStr;
36
+ })
37
+ .join("\t");
38
+ })
39
+ .join("\n");
40
+ }
41
+ export function getBlob(table) {
42
+ const rows = table.getRowModel().rows;
43
+ if (rows.length === 0)
44
+ return;
45
+ // Get downloadable columns based on getCanDownload property.
46
+ const downloadableColumns = getDownloadableColumns(table);
47
+ // Extract column IDs for filtering.
48
+ const downloadableColumnIds = downloadableColumns.map((column) => column.id);
49
+ // Get table headers from downloadable columns.
50
+ const tableHeaders = downloadableColumns.map(getColumnHeader);
51
+ // Get row data but only for downloadable columns.
52
+ const tableData = rows.map((row) => downloadableColumnIds.map((columnId) => row.getValue(columnId)));
53
+ const tsv = formatDataToTSV([tableHeaders, ...tableData]);
54
+ return new Blob([tsv], { type: "text/tab-separated-values" });
55
+ }
56
+ /**
57
+ * Filters table columns from column.getCanDownload API.
58
+ * @param table - Table.
59
+ * @returns Columns configured to be downloadable.
60
+ */
61
+ export function getDownloadableColumns(table) {
62
+ return table.getAllColumns().filter((column) => column.getCanTableDownload());
63
+ }
@@ -0,0 +1,15 @@
1
+ import { RowData, Table } from "@tanstack/react-table";
2
+ export interface TableDownloadColumn {
3
+ getCanTableDownload: () => boolean;
4
+ }
5
+ export interface TableDownloadColumnDef {
6
+ enableTableDownload?: boolean;
7
+ }
8
+ export interface TableDownloadInstance {
9
+ downloadData: () => void;
10
+ }
11
+ export interface TableDownloadOptions<T extends RowData> {
12
+ downloadFilename?: string;
13
+ enableTableDownload?: boolean;
14
+ onTableDownload?: (table: Table<T>) => void;
15
+ }
@@ -0,0 +1,19 @@
1
+ import { Column, RowData, Table } from "@tanstack/react-table";
2
+ /**
3
+ * Function that downloads the table data as a TSV file.
4
+ * Uses the onDownload callback, or a custom download function if provided.
5
+ * @param table - Table.
6
+ */
7
+ export declare function downloadData<T extends RowData>(table: Table<T>): void;
8
+ /**
9
+ * Returns true if column can be downloaded.
10
+ * @param column - Column.
11
+ * @param table - Table.
12
+ * @returns True if column can be downloaded.
13
+ */
14
+ export declare function getCanTableDownload<T extends RowData, TValue>(column: Column<T, TValue>, table: Table<T>): boolean;
15
+ /**
16
+ * Default download function that downloads the table data as a TSV file.
17
+ * @param table - Table.
18
+ */
19
+ export declare function onTableDownload<T extends RowData>(table: Table<T>): void;
@@ -0,0 +1,46 @@
1
+ import { getBlob } from "./onDownload/utils";
2
+ /**
3
+ * Function that downloads the table data as a TSV file.
4
+ * Uses the onDownload callback, or a custom download function if provided.
5
+ * @param table - Table.
6
+ */
7
+ export function downloadData(table) {
8
+ table.options.onTableDownload?.(table);
9
+ }
10
+ /**
11
+ * Returns true if column can be downloaded.
12
+ * @param column - Column.
13
+ * @param table - Table.
14
+ * @returns True if column can be downloaded.
15
+ */
16
+ export function getCanTableDownload(column, table) {
17
+ return ((column.columnDef.enableTableDownload ?? true) &&
18
+ (table.options.enableTableDownload ?? false));
19
+ }
20
+ /**
21
+ * Default download function that downloads the table data as a TSV file.
22
+ * @param table - Table.
23
+ */
24
+ export function onTableDownload(table) {
25
+ // Check if download is enabled.
26
+ if (!(table.options.enableTableDownload ?? false))
27
+ return;
28
+ // Generate the blob.
29
+ const blob = getBlob(table);
30
+ if (!blob)
31
+ return;
32
+ // Create an object URL for the blob.
33
+ const url = URL.createObjectURL(blob);
34
+ // Create a download link.
35
+ const anchorEl = document.createElement("a");
36
+ anchorEl.href = url;
37
+ anchorEl.download = table.options.downloadFilename || "table-data.tsv";
38
+ // Append to the document body for better cross-browser support.
39
+ document.body.appendChild(anchorEl);
40
+ // Trigger the download.
41
+ anchorEl.click();
42
+ // Remove the element after triggering download.
43
+ document.body.removeChild(anchorEl);
44
+ // Clean up.
45
+ URL.revokeObjectURL(url);
46
+ }
@@ -1,8 +1,13 @@
1
1
  import { RowData } from "@tanstack/react-table";
2
2
  import { RowPositionOptions, RowPositionRow } from "./RowPosition/types";
3
3
  import { RowPreviewInstance, RowPreviewOptions, RowPreviewRow, RowPreviewTableState } from "./RowPreview/entities";
4
+ import { TableDownloadColumn, TableDownloadInstance, TableDownloadOptions } from "./TableDownload/types";
5
+ export type CustomFeatureColumn = TableDownloadColumn;
6
+ export interface CustomFeatureInstance<T extends RowData> extends TableDownloadInstance, RowPreviewInstance<T> {
7
+ }
4
8
  export type CustomFeatureInitialTableState = Partial<RowPreviewTableState>;
5
- export type CustomFeatureInstance<T extends RowData> = RowPreviewInstance<T>;
6
- export type CustomFeatureOptions = RowPreviewOptions & RowPositionOptions;
7
- export type CustomFeatureRow = RowPositionRow & RowPreviewRow;
9
+ export interface CustomFeatureOptions<T extends RowData> extends TableDownloadOptions<T>, RowPositionOptions, RowPreviewOptions {
10
+ }
11
+ export interface CustomFeatureRow extends RowPositionRow, RowPreviewRow {
12
+ }
8
13
  export type CustomFeatureTableState = RowPreviewTableState;
@@ -4,6 +4,7 @@ import { JSXElementConstructor, ReactNode } from "react";
4
4
  import { AzulSummaryResponse } from "../apis/azul/common/entities";
5
5
  import { CategoryConfig } from "../common/categories/config/types";
6
6
  import { DataDictionaryAnnotation, DataDictionaryConfig, SelectedFilter } from "../common/entities";
7
+ import { FilterSortConfig } from "../common/filters/sort/config/types";
7
8
  import { FooterProps } from "../components/Layout/components/Footer/footer";
8
9
  import { HeaderProps } from "../components/Layout/components/Header/header";
9
10
  import { ExploreMode } from "../hooks/useExploreMode/types";
@@ -214,7 +215,6 @@ export interface ListConfig<T extends RowData> {
214
215
  */
215
216
  export interface ListViewConfig {
216
217
  disablePagination?: boolean;
217
- enableDownload?: boolean;
218
218
  rowPreviewView?: ComponentsConfig;
219
219
  rowSelectionView?: ComponentsConfig;
220
220
  }
@@ -305,6 +305,7 @@ export interface SiteConfig {
305
305
  export?: ExportConfig;
306
306
  exportsRequireAuth?: boolean;
307
307
  exportToTerraUrl?: string;
308
+ filterSort?: FilterSortConfig;
308
309
  gitHubUrl?: string;
309
310
  layout: {
310
311
  floating?: FloatingConfig;
@@ -1,7 +1,8 @@
1
1
  import { CategoryConfig } from "../common/categories/config/types";
2
2
  import { Category } from "../common/categories/models/types";
3
3
  import { CategoryView, VIEW_KIND } from "../common/categories/views/types";
4
- import { CategoryKey, CategoryValueKey, ClearAll, Filters, SelectCategoryValue, SelectCategoryValueView } from "../common/entities";
4
+ import { CategoryKey, CategoryValueKey, ClearAll, Filters, SelectCategoryValue } from "../common/entities";
5
+ import { FILTER_SORT } from "../common/filters/sort/config/types";
5
6
  /**
6
7
  * State backing filter functionality and calculations. Converted to view model for display.
7
8
  */
@@ -15,9 +16,10 @@ export type OnFilterFn = (categoryKey: CategoryKey | ClearAll, selectedCategoryV
15
16
  * @param categories - Categories, category value and their counts with the current filter applied.
16
17
  * @param categoryConfigs - Category configs indicating accept list as well as label configuration.
17
18
  * @param filterState - Current set of selected category and category values.
19
+ * @param filterSort - Sort configuration (ALPHA or COUNT).
18
20
  * @returns Array of category view objects.
19
21
  */
20
- export declare function buildCategoryViews(categories: Category[], categoryConfigs: CategoryConfig[] | undefined, filterState: FilterState): CategoryView[];
22
+ export declare function buildCategoryViews(categories: Category[], categoryConfigs: CategoryConfig[] | undefined, filterState: FilterState, filterSort: FILTER_SORT): CategoryView[];
21
23
  /**
22
24
  * Build new set of selected filters on de/select of filter.
23
25
  * @param filterState - Current set of selected category and category values.
@@ -34,10 +36,3 @@ export declare function buildNextFilterState(filterState: FilterState, categoryK
34
36
  * @returns original select category value.
35
37
  */
36
38
  export declare function getSelectCategoryValue(selectCategoryValue: SelectCategoryValue): SelectCategoryValue;
37
- /**
38
- * Sort category value views by key, ascending.
39
- * @param cvv0 - First category value view to compare.
40
- * @param cvv1 - Second category value view to compare.
41
- * @returns Number indicating sort precedence of cv0 vs cv1.
42
- */
43
- export declare function sortCategoryValueViews(cvv0: SelectCategoryValueView, cvv1: SelectCategoryValueView): number;
@@ -5,6 +5,7 @@ import { buildNextSelectFilterState } from "../common/categories/models/select/u
5
5
  import { buildRangeCategoryView } from "../common/categories/views/range/utils";
6
6
  import { VIEW_KIND } from "../common/categories/views/types";
7
7
  import { COLLATOR_CASE_INSENSITIVE } from "../common/constants";
8
+ import { sortCategoryValueViews } from "../common/filters/sort/models/utils";
8
9
  /**
9
10
  * Build the view-specific model of the given category value.
10
11
  * @param categoryValue - The category value to build a view model of.
@@ -46,9 +47,10 @@ function buildCategoryView(selectCategory, selectCategoryValueViews, categoryCon
46
47
  * @param categories - Categories, category value and their counts with the current filter applied.
47
48
  * @param categoryConfigs - Category configs indicating accept list as well as label configuration.
48
49
  * @param filterState - Current set of selected category and category values.
50
+ * @param filterSort - Sort configuration (ALPHA or COUNT).
49
51
  * @returns Array of category view objects.
50
52
  */
51
- export function buildCategoryViews(categories, categoryConfigs, filterState) {
53
+ export function buildCategoryViews(categories, categoryConfigs, filterState, filterSort) {
52
54
  if (!categories || !categoryConfigs) {
53
55
  return [];
54
56
  }
@@ -64,7 +66,8 @@ export function buildCategoryViews(categories, categoryConfigs, filterState) {
64
66
  }
65
67
  // Build view model for single or multiselect categories.
66
68
  const categoryValueViews = category.values.map((categoryValue) => buildCategoryValueView(categoryValue, categorySelectedFilter));
67
- categoryValueViews.sort(sortCategoryValueViews);
69
+ // Sort category value views based on filter sort configuration.
70
+ sortCategoryValueViews(categoryValueViews, filterSort);
68
71
  // Build category view model.
69
72
  return buildCategoryView(category, categoryValueViews, categoryConfigs);
70
73
  });
@@ -156,19 +159,6 @@ function isCategoryValueSelected(categoryValueKey, categorySelectedFilter) {
156
159
  function isCategoryAcceptListed(category, categoryConfigs) {
157
160
  return categoryConfigs.some((categoryConfig) => categoryConfig.key === category.key);
158
161
  }
159
- /**
160
- * Sort category value views by key, ascending.
161
- * @param cvv0 - First category value view to compare.
162
- * @param cvv1 - Second category value view to compare.
163
- * @returns Number indicating sort precedence of cv0 vs cv1.
164
- */
165
- export function sortCategoryValueViews(cvv0, cvv1) {
166
- return !cvv0.label
167
- ? 1
168
- : !cvv1.label
169
- ? -1
170
- : COLLATOR_CASE_INSENSITIVE.compare(cvv0.label, cvv1.label);
171
- }
172
162
  /**
173
163
  * Sort category views by display label, ascending.
174
164
  * @param c0 - First category view to compare.