@databiosphere/findable-ui 44.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.
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +20 -0
- package/lib/components/DataDictionary/components/Table/options/core/constants.js +2 -1
- package/lib/components/DataDictionary/components/Table/options/hook.js +2 -0
- package/lib/components/Detail/components/Table/table.js +4 -1
- package/lib/components/Index/table/hook.js +4 -1
- package/lib/components/Table/common/columnDef.js +2 -0
- package/lib/components/Table/common/utils.d.ts +0 -6
- package/lib/components/Table/common/utils.js +0 -63
- package/lib/components/Table/components/TableFeatures/TableDownload/tableDownload.d.ts +3 -0
- package/lib/components/Table/components/TableFeatures/TableDownload/tableDownload.js +9 -0
- package/lib/components/Table/components/{DownloadEntityResults/downloadEntityResults.styles.js → TableFeatures/TableDownload/tableDownload.styles.js} +1 -1
- package/lib/components/Table/components/TableFeatures/TableDownload/types.d.ts +5 -0
- package/lib/components/Table/components/TableFeatures/TableDownload/types.js +1 -0
- package/lib/components/Table/components/TableToolbar/tableToolbar.js +3 -3
- package/lib/components/Table/components/TableToolbar2/tableToolbar2.d.ts +3 -0
- package/lib/components/Table/components/TableToolbar2/tableToolbar2.js +8 -0
- package/lib/components/Table/components/TableToolbar2/tableToolbar2.styles.d.ts +10 -0
- package/lib/components/Table/components/TableToolbar2/tableToolbar2.styles.js +16 -0
- package/lib/components/Table/components/TableToolbar2/types.d.ts +4 -0
- package/lib/components/Table/components/TableToolbar2/types.js +1 -0
- package/lib/components/Table/featureOptions/tableDownload/constants.d.ts +3 -0
- package/lib/components/Table/featureOptions/tableDownload/constants.js +3 -0
- package/lib/components/Table/features/TableDownload/constants.d.ts +2 -0
- package/lib/components/Table/features/TableDownload/constants.js +10 -0
- package/lib/components/Table/features/TableDownload/onDownload/utils.d.ts +14 -0
- package/lib/components/Table/features/TableDownload/onDownload/utils.js +63 -0
- package/lib/components/Table/features/TableDownload/types.d.ts +15 -0
- package/lib/components/Table/features/TableDownload/types.js +1 -0
- package/lib/components/Table/features/TableDownload/utils.d.ts +19 -0
- package/lib/components/Table/features/TableDownload/utils.js +46 -0
- package/lib/components/Table/features/entities.d.ts +8 -3
- package/lib/config/entities.d.ts +0 -1
- package/package.json +1 -1
- package/src/components/DataDictionary/components/Table/options/core/constants.ts +2 -1
- package/src/components/DataDictionary/components/Table/options/hook.ts +2 -0
- package/src/components/Detail/components/Table/table.tsx +4 -1
- package/src/components/Index/table/hook.ts +4 -1
- package/src/components/Table/common/columnDef.ts +2 -0
- package/src/components/Table/common/utils.ts +0 -75
- package/src/components/Table/components/{DownloadEntityResults/downloadEntityResults.styles.ts → TableFeatures/TableDownload/tableDownload.styles.ts} +1 -1
- package/src/components/Table/components/TableFeatures/TableDownload/tableDownload.tsx +23 -0
- package/src/components/Table/components/TableFeatures/TableDownload/types.ts +7 -0
- package/src/components/Table/components/TableToolbar/tableToolbar.tsx +3 -8
- package/src/components/Table/components/TableToolbar2/tableToolbar2.styles.ts +18 -0
- package/src/components/Table/components/TableToolbar2/tableToolbar2.tsx +17 -0
- package/src/components/Table/components/TableToolbar2/types.ts +5 -0
- package/src/components/Table/featureOptions/tableDownload/constants.ts +9 -0
- package/src/components/Table/features/TableDownload/constants.ts +24 -0
- package/src/components/Table/features/TableDownload/onDownload/utils.ts +76 -0
- package/src/components/Table/features/TableDownload/types.ts +19 -0
- package/src/components/Table/features/TableDownload/utils.ts +60 -0
- package/src/components/Table/features/entities.ts +19 -3
- package/src/config/entities.ts +0 -1
- package/types/data-explorer-ui.d.ts +16 -2
- package/lib/components/Table/components/DownloadEntityResults/downloadEntityResults.d.ts +0 -6
- package/lib/components/Table/components/DownloadEntityResults/downloadEntityResults.js +0 -18
- package/lib/components/common/Button/components/FileDownloadButton/fileDownloadButton.d.ts +0 -5
- package/lib/components/common/Button/components/FileDownloadButton/fileDownloadButton.js +0 -14
- package/src/components/Table/components/DownloadEntityResults/downloadEntityResults.tsx +0 -39
- package/src/components/common/Button/components/FileDownloadButton/fileDownloadButton.tsx +0 -27
- /package/lib/components/Table/components/{DownloadEntityResults/downloadEntityResults.styles.d.ts → TableFeatures/TableDownload/tableDownload.styles.d.ts} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [45.0.0](https://github.com/DataBiosphere/findable-ui/compare/v44.0.0...v45.0.0) (2025-09-10)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### ⚠ BREAKING CHANGES
|
|
7
|
+
|
|
8
|
+
* refactor existing tabletoolbar with download button component ([#652](https://github.com/DataBiosphere/findable-ui/issues/652)) (#656)
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* create download button ([#651](https://github.com/DataBiosphere/findable-ui/issues/651)) ([#655](https://github.com/DataBiosphere/findable-ui/issues/655)) ([2c4959a](https://github.com/DataBiosphere/findable-ui/commit/2c4959ac3f30e81d65466d3b3edfa559997053d6))
|
|
13
|
+
* create new tabletoolbar with download button - independent of explorestate ([#653](https://github.com/DataBiosphere/findable-ui/issues/653)) ([028558a](https://github.com/DataBiosphere/findable-ui/commit/028558a3f0d7bc51da5bc30a1e847b04c41c32c0))
|
|
14
|
+
* create new tabletoolbar with download button - independent of explorestate ([#653](https://github.com/DataBiosphere/findable-ui/issues/653)) ([#657](https://github.com/DataBiosphere/findable-ui/issues/657)) ([028558a](https://github.com/DataBiosphere/findable-ui/commit/028558a3f0d7bc51da5bc30a1e847b04c41c32c0))
|
|
15
|
+
* implement tanstack custom feature to support download table data ([#650](https://github.com/DataBiosphere/findable-ui/issues/650)) ([#654](https://github.com/DataBiosphere/findable-ui/issues/654)) ([c897fbb](https://github.com/DataBiosphere/findable-ui/commit/c897fbb68003af09fe04ccbfed18ec71fe8ef5a7))
|
|
16
|
+
* refactor existing tabletoolbar with download button component ([#652](https://github.com/DataBiosphere/findable-ui/issues/652)) ([#656](https://github.com/DataBiosphere/findable-ui/issues/656)) ([f4d5695](https://github.com/DataBiosphere/findable-ui/commit/f4d5695c28e1f4a6d7a3df2d684d4472005f33c0))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Code Refactoring
|
|
20
|
+
|
|
21
|
+
* align table download feature more closely with tanstack standards ([#659](https://github.com/DataBiosphere/findable-ui/issues/659)) ([#660](https://github.com/DataBiosphere/findable-ui/issues/660)) ([46d3bb3](https://github.com/DataBiosphere/findable-ui/commit/46d3bb315f8aaf4ed25c7c5c81e364d7c000f332))
|
|
22
|
+
|
|
3
23
|
## [44.0.0](https://github.com/DataBiosphere/findable-ui/compare/v43.0.0...v44.0.0) (2025-08-28)
|
|
4
24
|
|
|
5
25
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { getCoreRowModel } from "@tanstack/react-table";
|
|
2
2
|
import { ROW_POSITION } from "../../../../../Table/features/RowPosition/constants";
|
|
3
3
|
import { ROW_PREVIEW } from "../../../../../Table/features/RowPreview/constants";
|
|
4
|
+
import { TABLE_DOWNLOAD } from "../../../../../Table/features/TableDownload/constants";
|
|
4
5
|
export const CORE_OPTIONS = {
|
|
5
|
-
_features: [ROW_POSITION, ROW_PREVIEW],
|
|
6
|
+
_features: [ROW_POSITION, ROW_PREVIEW, TABLE_DOWNLOAD],
|
|
6
7
|
getCoreRowModel: getCoreRowModel(),
|
|
7
8
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TABLE_DOWNLOAD_OPTIONS } from "../../../../Table/featureOptions/tableDownload/constants";
|
|
1
2
|
import { useColumnFiltersOptions } from "./columnFilters/hook";
|
|
2
3
|
import { CORE_OPTIONS } from "./core/constants";
|
|
3
4
|
import { EXPANDED_OPTIONS } from "./expanded/constants";
|
|
@@ -22,6 +23,7 @@ export const useTableOptions = () => {
|
|
|
22
23
|
...GROUPING_OPTIONS,
|
|
23
24
|
...PAGINATION_OPTIONS,
|
|
24
25
|
...SORTING_OPTIONS,
|
|
26
|
+
...TABLE_DOWNLOAD_OPTIONS,
|
|
25
27
|
...VISIBILITY_OPTIONS,
|
|
26
28
|
};
|
|
27
29
|
};
|
|
@@ -6,8 +6,10 @@ import { arrIncludesSome } from "../../../Table/columnDef/columnFilters/filterFn
|
|
|
6
6
|
import { COLUMN_DEF } from "../../../Table/common/columnDef";
|
|
7
7
|
import { ROW_DIRECTION } from "../../../Table/common/entities";
|
|
8
8
|
import { TableHead } from "../../../Table/components/TableHead/tableHead";
|
|
9
|
+
import { TABLE_DOWNLOAD_OPTIONS } from "../../../Table/featureOptions/tableDownload/constants";
|
|
9
10
|
import { ROW_POSITION } from "../../../Table/features/RowPosition/constants";
|
|
10
11
|
import { ROW_PREVIEW } from "../../../Table/features/RowPreview/constants";
|
|
12
|
+
import { TABLE_DOWNLOAD } from "../../../Table/features/TableDownload/constants";
|
|
11
13
|
import { GridTable } from "../../../Table/table.styles";
|
|
12
14
|
import { generateColumnDefinitions } from "./common/utils";
|
|
13
15
|
import { TableBody } from "./components/TableBody/tableBody";
|
|
@@ -18,7 +20,7 @@ export const Table = ({ className, collapsable = true, columns, gridTemplateColu
|
|
|
18
20
|
const { stickyHeader = false } = table || {};
|
|
19
21
|
const { sx: tableContainerSx } = tableContainer || {};
|
|
20
22
|
const tableInstance = useReactTable({
|
|
21
|
-
_features: [ROW_POSITION, ROW_PREVIEW],
|
|
23
|
+
_features: [ROW_POSITION, ROW_PREVIEW, TABLE_DOWNLOAD],
|
|
22
24
|
columns: generateColumnDefinitions([
|
|
23
25
|
COLUMN_DEF.ROW_POSITION,
|
|
24
26
|
...columns,
|
|
@@ -27,6 +29,7 @@ export const Table = ({ className, collapsable = true, columns, gridTemplateColu
|
|
|
27
29
|
enableSorting: false,
|
|
28
30
|
filterFns: { arrIncludesSome },
|
|
29
31
|
getCoreRowModel: getCoreRowModel(),
|
|
32
|
+
...TABLE_DOWNLOAD_OPTIONS,
|
|
30
33
|
...tableOptions,
|
|
31
34
|
});
|
|
32
35
|
return (React.createElement(TableContainer, { className: className, sx: tableContainerSx },
|
|
@@ -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,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 "
|
|
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 @@
|
|
|
1
|
+
export {};
|
|
@@ -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 {
|
|
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
|
-
|
|
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,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 @@
|
|
|
1
|
+
export {};
|
|
@@ -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 @@
|
|
|
1
|
+
export {};
|
|
@@ -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
|
|
6
|
-
|
|
7
|
-
export
|
|
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;
|
package/lib/config/entities.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { CoreOptions, getCoreRowModel, RowData } from "@tanstack/react-table";
|
|
2
2
|
import { ROW_POSITION } from "../../../../../Table/features/RowPosition/constants";
|
|
3
3
|
import { ROW_PREVIEW } from "../../../../../Table/features/RowPreview/constants";
|
|
4
|
+
import { TABLE_DOWNLOAD } from "../../../../../Table/features/TableDownload/constants";
|
|
4
5
|
|
|
5
6
|
export const CORE_OPTIONS: Pick<
|
|
6
7
|
CoreOptions<RowData>,
|
|
7
8
|
"_features" | "getCoreRowModel"
|
|
8
9
|
> = {
|
|
9
|
-
_features: [ROW_POSITION, ROW_PREVIEW],
|
|
10
|
+
_features: [ROW_POSITION, ROW_PREVIEW, TABLE_DOWNLOAD],
|
|
10
11
|
getCoreRowModel: getCoreRowModel(),
|
|
11
12
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RowData, TableOptions } from "@tanstack/react-table";
|
|
2
2
|
import { Attribute } from "../../../../../common/entities";
|
|
3
|
+
import { TABLE_DOWNLOAD_OPTIONS } from "../../../../Table/featureOptions/tableDownload/constants";
|
|
3
4
|
import { useColumnFiltersOptions } from "./columnFilters/hook";
|
|
4
5
|
import { CORE_OPTIONS } from "./core/constants";
|
|
5
6
|
import { EXPANDED_OPTIONS } from "./expanded/constants";
|
|
@@ -30,6 +31,7 @@ export const useTableOptions = <T extends RowData = Attribute>(): Omit<
|
|
|
30
31
|
...GROUPING_OPTIONS,
|
|
31
32
|
...PAGINATION_OPTIONS,
|
|
32
33
|
...SORTING_OPTIONS,
|
|
34
|
+
...TABLE_DOWNLOAD_OPTIONS,
|
|
33
35
|
...VISIBILITY_OPTIONS,
|
|
34
36
|
} as TableOptions<T>;
|
|
35
37
|
};
|
|
@@ -20,8 +20,10 @@ import { arrIncludesSome } from "../../../Table/columnDef/columnFilters/filterFn
|
|
|
20
20
|
import { COLUMN_DEF } from "../../../Table/common/columnDef";
|
|
21
21
|
import { ROW_DIRECTION } from "../../../Table/common/entities";
|
|
22
22
|
import { TableHead } from "../../../Table/components/TableHead/tableHead";
|
|
23
|
+
import { TABLE_DOWNLOAD_OPTIONS } from "../../../Table/featureOptions/tableDownload/constants";
|
|
23
24
|
import { ROW_POSITION } from "../../../Table/features/RowPosition/constants";
|
|
24
25
|
import { ROW_PREVIEW } from "../../../Table/features/RowPreview/constants";
|
|
26
|
+
import { TABLE_DOWNLOAD } from "../../../Table/features/TableDownload/constants";
|
|
25
27
|
import { GridTable } from "../../../Table/table.styles";
|
|
26
28
|
import { generateColumnDefinitions } from "./common/utils";
|
|
27
29
|
import { TableBody } from "./components/TableBody/tableBody";
|
|
@@ -58,7 +60,7 @@ export const Table = <T extends RowData>({
|
|
|
58
60
|
const { stickyHeader = false } = table || {};
|
|
59
61
|
const { sx: tableContainerSx } = tableContainer || {};
|
|
60
62
|
const tableInstance = useReactTable({
|
|
61
|
-
_features: [ROW_POSITION, ROW_PREVIEW],
|
|
63
|
+
_features: [ROW_POSITION, ROW_PREVIEW, TABLE_DOWNLOAD],
|
|
62
64
|
columns: generateColumnDefinitions([
|
|
63
65
|
COLUMN_DEF.ROW_POSITION as ColumnDef<T>,
|
|
64
66
|
...columns,
|
|
@@ -67,6 +69,7 @@ export const Table = <T extends RowData>({
|
|
|
67
69
|
enableSorting: false,
|
|
68
70
|
filterFns: { arrIncludesSome },
|
|
69
71
|
getCoreRowModel: getCoreRowModel(),
|
|
72
|
+
...TABLE_DOWNLOAD_OPTIONS,
|
|
70
73
|
...tableOptions,
|
|
71
74
|
});
|
|
72
75
|
return (
|