@databiosphere/findable-ui 44.0.0 → 45.1.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 (95) hide show
  1. package/.release-please-manifest.json +1 -1
  2. package/CHANGELOG.md +29 -0
  3. package/lib/components/DataDictionary/components/Table/options/core/constants.js +2 -1
  4. package/lib/components/DataDictionary/components/Table/options/hook.js +2 -0
  5. package/lib/components/Detail/components/Table/common/utils.js +1 -1
  6. package/lib/components/Detail/components/Table/components/TableRows/components/CollapsableRows/collapsableRows.js +1 -1
  7. package/lib/components/Detail/components/Table/components/TableRows/tableRows.js +1 -1
  8. package/lib/components/Detail/components/Table/table.js +10 -1
  9. package/lib/components/Index/table/hook.js +10 -1
  10. package/lib/components/Table/common/columnDef.js +2 -0
  11. package/lib/components/Table/common/utils.d.ts +0 -6
  12. package/lib/components/Table/common/utils.js +0 -63
  13. package/lib/components/Table/components/TableCell/components/RowSelectionCell/constants.d.ts +2 -0
  14. package/lib/components/Table/components/TableCell/components/RowSelectionCell/constants.js +13 -0
  15. package/lib/components/Table/components/TableCell/components/RowSelectionCell/rowSelectionCell.js +12 -8
  16. package/lib/components/Table/components/TableFeatures/TableDownload/tableDownload.d.ts +3 -0
  17. package/lib/components/Table/components/TableFeatures/TableDownload/tableDownload.js +9 -0
  18. package/lib/components/Table/components/{DownloadEntityResults/downloadEntityResults.styles.js → TableFeatures/TableDownload/tableDownload.styles.js} +1 -1
  19. package/lib/components/Table/components/TableFeatures/TableDownload/types.d.ts +5 -0
  20. package/lib/components/Table/components/TableFeatures/TableDownload/types.js +1 -0
  21. package/lib/components/Table/components/TableRow/tableRow.styles.d.ts +2 -0
  22. package/lib/components/Table/components/TableRow/tableRow.styles.js +15 -1
  23. package/lib/components/Table/components/TableRows/components/CollapsableRows/collapsableRows.js +1 -1
  24. package/lib/components/Table/components/TableRows/tableRows.js +1 -1
  25. package/lib/components/Table/components/TableToolbar/tableToolbar.js +3 -3
  26. package/lib/components/Table/components/TableToolbar2/tableToolbar2.d.ts +3 -0
  27. package/lib/components/Table/components/TableToolbar2/tableToolbar2.js +8 -0
  28. package/lib/components/Table/components/TableToolbar2/tableToolbar2.styles.d.ts +10 -0
  29. package/lib/components/Table/components/TableToolbar2/tableToolbar2.styles.js +16 -0
  30. package/lib/components/Table/components/TableToolbar2/types.d.ts +4 -0
  31. package/lib/components/Table/components/TableToolbar2/types.js +1 -0
  32. package/lib/components/Table/featureOptions/tableDownload/constants.d.ts +3 -0
  33. package/lib/components/Table/featureOptions/tableDownload/constants.js +3 -0
  34. package/lib/components/Table/features/RowSelectionValidation/constants.d.ts +2 -0
  35. package/lib/components/Table/features/RowSelectionValidation/constants.js +14 -0
  36. package/lib/components/Table/features/RowSelectionValidation/types.d.ts +8 -0
  37. package/lib/components/Table/features/RowSelectionValidation/types.js +1 -0
  38. package/lib/components/Table/features/RowSelectionValidation/utils.d.ts +8 -0
  39. package/lib/components/Table/features/RowSelectionValidation/utils.js +11 -0
  40. package/lib/components/Table/features/TableDownload/constants.d.ts +2 -0
  41. package/lib/components/Table/features/TableDownload/constants.js +10 -0
  42. package/lib/components/Table/features/TableDownload/onDownload/utils.d.ts +14 -0
  43. package/lib/components/Table/features/TableDownload/onDownload/utils.js +63 -0
  44. package/lib/components/Table/features/TableDownload/types.d.ts +15 -0
  45. package/lib/components/Table/features/TableDownload/types.js +1 -0
  46. package/lib/components/Table/features/TableDownload/utils.d.ts +19 -0
  47. package/lib/components/Table/features/TableDownload/utils.js +46 -0
  48. package/lib/components/Table/features/entities.d.ts +9 -3
  49. package/lib/components/TableCreator/options/hook.js +0 -3
  50. package/lib/components/common/CustomIcon/components/UncheckedDisabledIcon/uncheckedDisabledIcon.d.ts +2 -0
  51. package/lib/components/common/CustomIcon/components/UncheckedDisabledIcon/uncheckedDisabledIcon.js +8 -0
  52. package/lib/config/entities.d.ts +0 -1
  53. package/package.json +1 -1
  54. package/src/components/DataDictionary/components/Table/options/core/constants.ts +2 -1
  55. package/src/components/DataDictionary/components/Table/options/hook.ts +2 -0
  56. package/src/components/Detail/components/Table/common/utils.ts +1 -1
  57. package/src/components/Detail/components/Table/components/TableRows/components/CollapsableRows/collapsableRows.tsx +1 -0
  58. package/src/components/Detail/components/Table/components/TableRows/tableRows.tsx +2 -0
  59. package/src/components/Detail/components/Table/table.tsx +10 -1
  60. package/src/components/Index/table/hook.ts +10 -1
  61. package/src/components/Table/common/columnDef.ts +2 -0
  62. package/src/components/Table/common/utils.ts +0 -75
  63. package/src/components/Table/components/TableCell/components/RowSelectionCell/constants.ts +15 -0
  64. package/src/components/Table/components/TableCell/components/RowSelectionCell/rowSelectionCell.tsx +25 -13
  65. package/src/components/Table/components/{DownloadEntityResults/downloadEntityResults.styles.ts → TableFeatures/TableDownload/tableDownload.styles.ts} +1 -1
  66. package/src/components/Table/components/TableFeatures/TableDownload/tableDownload.tsx +23 -0
  67. package/src/components/Table/components/TableFeatures/TableDownload/types.ts +7 -0
  68. package/src/components/Table/components/TableRow/tableRow.styles.ts +19 -1
  69. package/src/components/Table/components/TableRows/components/CollapsableRows/collapsableRows.tsx +1 -0
  70. package/src/components/Table/components/TableRows/tableRows.tsx +2 -0
  71. package/src/components/Table/components/TableToolbar/tableToolbar.tsx +3 -8
  72. package/src/components/Table/components/TableToolbar2/tableToolbar2.styles.ts +18 -0
  73. package/src/components/Table/components/TableToolbar2/tableToolbar2.tsx +17 -0
  74. package/src/components/Table/components/TableToolbar2/types.ts +5 -0
  75. package/src/components/Table/featureOptions/tableDownload/constants.ts +9 -0
  76. package/src/components/Table/features/RowSelectionValidation/constants.ts +24 -0
  77. package/src/components/Table/features/RowSelectionValidation/types.ts +10 -0
  78. package/src/components/Table/features/RowSelectionValidation/utils.ts +15 -0
  79. package/src/components/Table/features/TableDownload/constants.ts +24 -0
  80. package/src/components/Table/features/TableDownload/onDownload/utils.ts +76 -0
  81. package/src/components/Table/features/TableDownload/types.ts +19 -0
  82. package/src/components/Table/features/TableDownload/utils.ts +60 -0
  83. package/src/components/Table/features/entities.ts +27 -3
  84. package/src/components/TableCreator/options/hook.ts +0 -3
  85. package/src/components/common/CustomIcon/components/UncheckedDisabledIcon/uncheckedDisabledIcon.tsx +27 -0
  86. package/src/config/entities.ts +0 -1
  87. package/tests/rowSelectionValidation.test.ts +282 -0
  88. package/types/data-explorer-ui.d.ts +16 -2
  89. package/lib/components/Table/components/DownloadEntityResults/downloadEntityResults.d.ts +0 -6
  90. package/lib/components/Table/components/DownloadEntityResults/downloadEntityResults.js +0 -18
  91. package/lib/components/common/Button/components/FileDownloadButton/fileDownloadButton.d.ts +0 -5
  92. package/lib/components/common/Button/components/FileDownloadButton/fileDownloadButton.js +0 -14
  93. package/src/components/Table/components/DownloadEntityResults/downloadEntityResults.tsx +0 -39
  94. package/src/components/common/Button/components/FileDownloadButton/fileDownloadButton.tsx +0 -27
  95. /package/lib/components/Table/components/{DownloadEntityResults/downloadEntityResults.styles.d.ts → TableFeatures/TableDownload/tableDownload.styles.d.ts} +0 -0
@@ -0,0 +1,282 @@
1
+ import { jest } from "@jest/globals";
2
+ import {
3
+ createColumnHelper,
4
+ getCoreRowModel,
5
+ Row,
6
+ Table,
7
+ TableOptions,
8
+ useReactTable,
9
+ } from "@tanstack/react-table";
10
+ import { renderHook, RenderHookResult } from "@testing-library/react";
11
+ import { ROW_SELECTION_VALIDATION } from "../src/components/Table/features/RowSelectionValidation/constants";
12
+ import { RowSelectionValidationOptions } from "../src/components/Table/features/RowSelectionValidation/types";
13
+ import { getSelectionValidation } from "../src/components/Table/features/RowSelectionValidation/utils";
14
+
15
+ type ValidationFn = NonNullable<
16
+ RowSelectionValidationOptions<RowData>["getRowSelectionValidation"]
17
+ >;
18
+
19
+ interface RowData {
20
+ id: number;
21
+ isValid: boolean;
22
+ name: string;
23
+ status: "active" | "inactive";
24
+ }
25
+
26
+ const ACCESSOR_KEY: Record<string, keyof RowData> = {
27
+ ID: "id",
28
+ IS_VALID: "isValid",
29
+ NAME: "name",
30
+ STATUS: "status",
31
+ };
32
+
33
+ // Mock data.
34
+ const DATA: RowData[] = [
35
+ { id: 1, isValid: true, name: "Item 1", status: "active" },
36
+ { id: 2, isValid: false, name: "Item 2", status: "inactive" },
37
+ { id: 3, isValid: true, name: "Item 3", status: "active" },
38
+ { id: 4, isValid: false, name: "Item 4", status: "inactive" },
39
+ ];
40
+
41
+ const columnHelper = createColumnHelper<RowData>();
42
+
43
+ // Mock column definitions.
44
+ const COLUMNS = [
45
+ columnHelper.accessor(ACCESSOR_KEY.ID, { header: "ID" }),
46
+ columnHelper.accessor(ACCESSOR_KEY.NAME, { header: "Name" }),
47
+ columnHelper.accessor(ACCESSOR_KEY.IS_VALID, { header: "Valid" }),
48
+ columnHelper.accessor(ACCESSOR_KEY.STATUS, { header: "Status" }),
49
+ ];
50
+
51
+ // Test constants.
52
+ const VALIDATION_MESSAGE = {
53
+ INVALID: "This item is invalid",
54
+ VALID: "This item is valid",
55
+ };
56
+
57
+ const createTable = (
58
+ tableOptions?: Omit<
59
+ TableOptions<RowData>,
60
+ "columns" | "data" | "getCoreRowModel"
61
+ >
62
+ ): RenderHookResult<Table<RowData>, unknown> => {
63
+ return renderHook(() =>
64
+ useReactTable({
65
+ _features: [ROW_SELECTION_VALIDATION],
66
+ columns: COLUMNS,
67
+ data: DATA,
68
+ enableRowSelectionValidation: true,
69
+ getCoreRowModel: getCoreRowModel(),
70
+ ...tableOptions,
71
+ })
72
+ );
73
+ };
74
+
75
+ describe("RowSelectionValidation Feature", () => {
76
+ let tableWithoutValidation: any;
77
+ let firstRowWithoutValidation: any;
78
+ let tableWithValidation: any;
79
+ let firstRowWithValidation: any;
80
+
81
+ beforeEach(() => {
82
+ const resultWithoutValidation = createTable();
83
+ const resultWithValidation = createTable({
84
+ getRowSelectionValidation: () => VALIDATION_MESSAGE.INVALID,
85
+ });
86
+ tableWithoutValidation = resultWithoutValidation.result.current;
87
+ firstRowWithoutValidation = tableWithoutValidation.getRowModel().rows[0];
88
+ tableWithValidation = resultWithValidation.result.current;
89
+ firstRowWithValidation = tableWithValidation.getRowModel().rows[0];
90
+ });
91
+
92
+ describe("ROW_SELECTION_VALIDATION TableFeature", () => {
93
+ test("should have correct structure", () => {
94
+ expect(ROW_SELECTION_VALIDATION).toHaveProperty("createRow");
95
+ expect(ROW_SELECTION_VALIDATION).toHaveProperty("getDefaultOptions");
96
+ expect(typeof ROW_SELECTION_VALIDATION.createRow).toBe("function");
97
+ expect(typeof ROW_SELECTION_VALIDATION.getDefaultOptions).toBe(
98
+ "function"
99
+ );
100
+ });
101
+
102
+ test("getDefaultOptions should return correct default options", () => {
103
+ const { getDefaultOptions } = ROW_SELECTION_VALIDATION;
104
+ expect(getDefaultOptions!(tableWithoutValidation)).toEqual({
105
+ enableRowSelectionValidation: false,
106
+ getRowSelectionValidation: undefined,
107
+ });
108
+ });
109
+ });
110
+
111
+ describe("getSelectionValidation utility", () => {
112
+ test("should return undefined when no validation function is provided", () => {
113
+ expect(
114
+ getSelectionValidation(
115
+ firstRowWithoutValidation,
116
+ tableWithoutValidation
117
+ )
118
+ ).toBeUndefined();
119
+ });
120
+
121
+ test("should return validation message when validation function is provided", () => {
122
+ expect(
123
+ getSelectionValidation(firstRowWithValidation, tableWithValidation)
124
+ ).toBe(VALIDATION_MESSAGE.INVALID);
125
+ });
126
+
127
+ test("should return undefined when validation function returns undefined", () => {
128
+ const getRowSelectionValidation = jest
129
+ .fn<ValidationFn>()
130
+ .mockReturnValue(undefined);
131
+
132
+ const { result } = createTable({ getRowSelectionValidation });
133
+
134
+ const table = result.current;
135
+ const firstRow = table.getRowModel().rows[0];
136
+
137
+ const validationResult = getSelectionValidation(firstRow, table);
138
+
139
+ expect(validationResult).toBeUndefined();
140
+ expect(getRowSelectionValidation).toHaveBeenCalledWith(firstRow);
141
+ });
142
+
143
+ test("should work with different rows from the same table", () => {
144
+ const getRowSelectionValidation = jest
145
+ .fn<ValidationFn>()
146
+ .mockImplementation((row) => {
147
+ const status = row.getValue(ACCESSOR_KEY.STATUS);
148
+ return status === "inactive" ? VALIDATION_MESSAGE.INVALID : undefined;
149
+ });
150
+
151
+ const { result } = createTable({ getRowSelectionValidation });
152
+
153
+ const table = result.current;
154
+ const rows = table.getRowModel().rows;
155
+
156
+ expect(getSelectionValidation(rows[0], table)).toBeUndefined();
157
+ expect(getSelectionValidation(rows[2], table)).toBeUndefined();
158
+ expect(getSelectionValidation(rows[1], table)).toBe(
159
+ VALIDATION_MESSAGE.INVALID
160
+ );
161
+ expect(getRowSelectionValidation).toHaveBeenCalledTimes(3);
162
+ });
163
+ });
164
+
165
+ describe("row.getSelectionValidation method", () => {
166
+ test("should be attached to rows when feature is included", () => {
167
+ const rows = tableWithoutValidation.getRowModel().rows;
168
+
169
+ rows.forEach((row: any) => {
170
+ expect(row).toHaveProperty("getSelectionValidation");
171
+ expect(typeof row.getSelectionValidation).toBe("function");
172
+ });
173
+ });
174
+
175
+ test("should return undefined when no validation function is configured", () => {
176
+ expect(
177
+ firstRowWithoutValidation.getSelectionValidation()
178
+ ).toBeUndefined();
179
+ });
180
+
181
+ test("should return validation message when validation function is configured", () => {
182
+ expect(firstRowWithValidation.getSelectionValidation()).toBe(
183
+ VALIDATION_MESSAGE.INVALID
184
+ );
185
+ });
186
+ });
187
+
188
+ describe("Integration with table options", () => {
189
+ test("should work with getRowSelectionValidation function", () => {
190
+ const enableRowSelection = jest
191
+ .fn<(row: Row<RowData>) => boolean>()
192
+ .mockImplementation((row) => row.getValue(ACCESSOR_KEY.IS_VALID));
193
+
194
+ const getRowSelectionValidation = jest
195
+ .fn<ValidationFn>()
196
+ .mockImplementation((row) => {
197
+ const isValid = row.getValue(ACCESSOR_KEY.IS_VALID);
198
+ return isValid ? undefined : VALIDATION_MESSAGE.INVALID;
199
+ });
200
+
201
+ const { result } = createTable({
202
+ enableRowSelection,
203
+ getRowSelectionValidation,
204
+ });
205
+
206
+ const table = result.current;
207
+ const rows = table.getRowModel().rows;
208
+
209
+ rows.forEach((row) => {
210
+ const isValid = row.getValue(ACCESSOR_KEY.IS_VALID);
211
+ const canSelect = row.getCanSelect();
212
+ const validationMessage = row.getSelectionValidation?.();
213
+
214
+ if (isValid) {
215
+ expect(canSelect).toBe(true);
216
+ expect(validationMessage).toBeUndefined();
217
+ } else {
218
+ expect(canSelect).toBe(false);
219
+ expect(validationMessage).toBe(VALIDATION_MESSAGE.INVALID);
220
+ }
221
+ });
222
+ });
223
+
224
+ test("should handle complex validation scenarios", () => {
225
+ const getRowSelectionValidation = jest
226
+ .fn<ValidationFn>()
227
+ .mockImplementation((row) => {
228
+ const id = row.getValue(ACCESSOR_KEY.ID);
229
+ const isValid = row.getValue(ACCESSOR_KEY.IS_VALID);
230
+
231
+ if (!isValid) return VALIDATION_MESSAGE.INVALID;
232
+ if (id === 1) return VALIDATION_MESSAGE.VALID;
233
+ return undefined;
234
+ });
235
+
236
+ const { result } = createTable({ getRowSelectionValidation });
237
+
238
+ const table = result.current;
239
+ const rows = table.getRowModel().rows;
240
+
241
+ expect(rows[0].getSelectionValidation?.()).toBe(VALIDATION_MESSAGE.VALID);
242
+ expect(rows[1].getSelectionValidation?.()).toBe(
243
+ VALIDATION_MESSAGE.INVALID
244
+ );
245
+ expect(rows[2].getSelectionValidation?.()).toBeUndefined();
246
+ expect(rows[3].getSelectionValidation?.()).toBe(
247
+ VALIDATION_MESSAGE.INVALID
248
+ );
249
+ });
250
+ });
251
+
252
+ describe("Edge cases", () => {
253
+ test("should work when feature is not included", () => {
254
+ const { result } = createTable({
255
+ _features: [],
256
+ enableRowSelectionValidation: false,
257
+ });
258
+
259
+ const table = result.current;
260
+ const firstRow = table.getRowModel().rows[0];
261
+
262
+ expect(firstRow).not.toHaveProperty("getSelectionValidation");
263
+ });
264
+
265
+ test("should return undefined when feature is disabled", () => {
266
+ const getRowSelectionValidation = jest
267
+ .fn<ValidationFn>()
268
+ .mockReturnValue(VALIDATION_MESSAGE.INVALID);
269
+
270
+ const { result } = createTable({
271
+ enableRowSelectionValidation: false,
272
+ getRowSelectionValidation,
273
+ });
274
+
275
+ const table = result.current;
276
+ const firstRow = table.getRowModel().rows[0];
277
+
278
+ expect(firstRow.getSelectionValidation?.()).toBeUndefined();
279
+ expect(getRowSelectionValidation).not.toHaveBeenCalled();
280
+ });
281
+ });
282
+ });
@@ -23,6 +23,7 @@ import { Components } from "rehype-react";
23
23
  import { DataLayer } from "../src/common/analytics/entities";
24
24
  import { DataDictionaryAnnotation } from "../src/common/entities";
25
25
  import {
26
+ CustomFeatureColumn,
26
27
  CustomFeatureInitialTableState,
27
28
  CustomFeatureInstance,
28
29
  CustomFeatureOptions,
@@ -244,6 +245,14 @@ declare module "@emotion/react" {
244
245
  }
245
246
 
246
247
  declare module "@tanstack/react-table" {
248
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars -- TData and TValue are unused variables.
249
+ interface Column<TData extends RowData, TValue> extends CustomFeatureColumn {}
250
+
251
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars -- TData and TValue are unused variables.
252
+ interface ColumnDefBase<TData extends RowData, TValue> {
253
+ enableTableDownload?: boolean;
254
+ }
255
+
247
256
  // eslint-disable-next-line @typescript-eslint/no-unused-vars -- TData and TValue are unused variables.
248
257
  interface ColumnMeta<TData extends RowData, TValue> {
249
258
  align?: TableCellProps["align"];
@@ -253,10 +262,13 @@ declare module "@tanstack/react-table" {
253
262
  header?: string;
254
263
  width?: GridTrackSize;
255
264
  }
265
+
256
266
  // eslint-disable-next-line @typescript-eslint/no-empty-interface -- empty interface is needed for extending.
257
267
  interface InitialTableState extends CustomFeatureInitialTableState {}
268
+
258
269
  // eslint-disable-next-line @typescript-eslint/no-empty-interface, @typescript-eslint/no-unused-vars -- empty interface is needed for extending, TData is an unused variable.
259
270
  interface Row<TData extends RowData> extends CustomFeatureRow {}
271
+
260
272
  // eslint-disable-next-line @typescript-eslint/no-unused-vars -- TData is an unused variables.
261
273
  interface SortingOptions<TData extends RowData> {
262
274
  /**
@@ -265,11 +277,13 @@ declare module "@tanstack/react-table" {
265
277
  */
266
278
  enableSortingInteraction?: boolean;
267
279
  }
280
+
268
281
  // eslint-disable-next-line @typescript-eslint/no-empty-interface -- empty interface is needed for extending.
269
282
  interface Table<TData extends RowData> extends CustomFeatureInstance<TData> {}
270
- // eslint-disable-next-line @typescript-eslint/no-empty-interface, @typescript-eslint/no-unused-vars -- empty interface is needed for extending, TData is an unused variable.
283
+
271
284
  interface TableOptionsResolved<TData extends RowData>
272
- extends CustomFeatureOptions {}
285
+ extends CustomFeatureOptions<TData> {}
286
+
273
287
  // eslint-disable-next-line @typescript-eslint/no-empty-interface -- empty interface is needed for extending.
274
288
  interface TableState extends CustomFeatureTableState {}
275
289
  }
@@ -1,6 +0,0 @@
1
- import { Row, RowData } from "@tanstack/react-table";
2
- export interface DownloadEntityResultsProps<T extends RowData> {
3
- entityName: string;
4
- rows: Row<T>[];
5
- }
6
- export declare const DownloadEntityResults: <T extends RowData>({ entityName, rows, }: DownloadEntityResultsProps<T>) => JSX.Element;
@@ -1,18 +0,0 @@
1
- import React from "react";
2
- import { FileDownloadButton } from "../../../common/Button/components/FileDownloadButton/fileDownloadButton";
3
- import { BUTTON_PROPS } from "../../../common/Button/constants";
4
- import { DownloadIcon } from "../../../common/CustomIcon/components/DownloadIcon/downloadIcon";
5
- import { generateDownloadBlob } from "../../common/utils";
6
- import { StyledButton } from "./downloadEntityResults.styles";
7
- export const DownloadEntityResults = ({ entityName, rows, }) => {
8
- const [fileUrl, setFileUrl] = React.useState(undefined);
9
- const onDownload = () => {
10
- const blob = generateDownloadBlob(rows);
11
- if (blob) {
12
- setFileUrl(window.URL.createObjectURL(blob));
13
- }
14
- };
15
- return (React.createElement(React.Fragment, null,
16
- React.createElement(StyledButton, { ...BUTTON_PROPS.SECONDARY_CONTAINED, onClick: () => onDownload(), startIcon: React.createElement(DownloadIcon, null) }, "Download TSV"),
17
- React.createElement(FileDownloadButton, { fileName: `${entityName}.tsv`, fileUrl: fileUrl })));
18
- };
@@ -1,5 +0,0 @@
1
- export interface FileDownloadButtonProps {
2
- fileName?: string;
3
- fileUrl?: string;
4
- }
5
- export declare const FileDownloadButton: ({ fileName, fileUrl, }: FileDownloadButtonProps) => JSX.Element;
@@ -1,14 +0,0 @@
1
- import { Box } from "@mui/material";
2
- import React, { useEffect, useRef } from "react";
3
- export const FileDownloadButton = ({ fileName, fileUrl, }) => {
4
- const downloadRef = useRef(null);
5
- // Initiates file download when file url request is successful.
6
- useEffect(() => {
7
- if (downloadRef.current && fileName && fileUrl) {
8
- downloadRef.current.setAttribute("href", fileUrl);
9
- downloadRef.current.setAttribute("download", fileName);
10
- downloadRef.current.click();
11
- }
12
- }, [fileName, fileUrl]);
13
- return (React.createElement(Box, { component: "a", download: true, ref: downloadRef, sx: { display: "none" } }));
14
- };
@@ -1,39 +0,0 @@
1
- import { Row, RowData } from "@tanstack/react-table";
2
- import React from "react";
3
- import { FileDownloadButton } from "../../../common/Button/components/FileDownloadButton/fileDownloadButton";
4
- import { BUTTON_PROPS } from "../../../common/Button/constants";
5
- import { DownloadIcon } from "../../../common/CustomIcon/components/DownloadIcon/downloadIcon";
6
- import { generateDownloadBlob } from "../../common/utils";
7
- import { StyledButton } from "./downloadEntityResults.styles";
8
-
9
- export interface DownloadEntityResultsProps<T extends RowData> {
10
- entityName: string;
11
- rows: Row<T>[];
12
- }
13
-
14
- export const DownloadEntityResults = <T extends RowData>({
15
- entityName,
16
- rows,
17
- }: DownloadEntityResultsProps<T>): JSX.Element => {
18
- const [fileUrl, setFileUrl] = React.useState<string | undefined>(undefined);
19
-
20
- const onDownload = (): void => {
21
- const blob = generateDownloadBlob(rows);
22
- if (blob) {
23
- setFileUrl(window.URL.createObjectURL(blob));
24
- }
25
- };
26
-
27
- return (
28
- <>
29
- <StyledButton
30
- {...BUTTON_PROPS.SECONDARY_CONTAINED}
31
- onClick={(): void => onDownload()}
32
- startIcon={<DownloadIcon />}
33
- >
34
- Download TSV
35
- </StyledButton>
36
- <FileDownloadButton fileName={`${entityName}.tsv`} fileUrl={fileUrl} />
37
- </>
38
- );
39
- };
@@ -1,27 +0,0 @@
1
- import { Box } from "@mui/material";
2
- import React, { useEffect, useRef } from "react";
3
-
4
- export interface FileDownloadButtonProps {
5
- fileName?: string;
6
- fileUrl?: string;
7
- }
8
-
9
- export const FileDownloadButton = ({
10
- fileName,
11
- fileUrl,
12
- }: FileDownloadButtonProps): JSX.Element => {
13
- const downloadRef = useRef<HTMLAnchorElement>(null);
14
-
15
- // Initiates file download when file url request is successful.
16
- useEffect(() => {
17
- if (downloadRef.current && fileName && fileUrl) {
18
- downloadRef.current.setAttribute("href", fileUrl);
19
- downloadRef.current.setAttribute("download", fileName);
20
- downloadRef.current.click();
21
- }
22
- }, [fileName, fileUrl]);
23
-
24
- return (
25
- <Box component="a" download ref={downloadRef} sx={{ display: "none" }} />
26
- );
27
- };