@databiosphere/findable-ui 45.0.0 → 46.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 (89) hide show
  1. package/.release-please-manifest.json +1 -1
  2. package/CHANGELOG.md +36 -0
  3. package/lib/components/Detail/components/Table/common/utils.js +1 -1
  4. package/lib/components/Detail/components/Table/components/TableRows/components/CollapsableRows/collapsableRows.js +1 -1
  5. package/lib/components/Detail/components/Table/components/TableRows/tableRows.js +1 -1
  6. package/lib/components/Detail/components/Table/table.js +7 -1
  7. package/lib/components/Index/components/EntityView/components/layout/Summary/summary.js +1 -1
  8. package/lib/components/Index/table/hook.js +7 -1
  9. package/lib/components/Layout/components/Outline/outline.js +3 -1
  10. package/lib/components/Layout/components/Outline/types.d.ts +1 -1
  11. package/lib/components/Table/components/TableCell/components/RowSelectionCell/constants.d.ts +2 -0
  12. package/lib/components/Table/components/TableCell/components/RowSelectionCell/constants.js +13 -0
  13. package/lib/components/Table/components/TableCell/components/RowSelectionCell/rowSelectionCell.js +12 -8
  14. package/lib/components/Table/components/TableRow/tableRow.styles.d.ts +2 -0
  15. package/lib/components/Table/components/TableRow/tableRow.styles.js +15 -1
  16. package/lib/components/Table/components/TableRows/components/CollapsableRows/collapsableRows.js +1 -1
  17. package/lib/components/Table/components/TableRows/tableRows.js +1 -1
  18. package/lib/components/Table/features/RowSelectionValidation/constants.d.ts +2 -0
  19. package/lib/components/Table/features/RowSelectionValidation/constants.js +14 -0
  20. package/lib/components/Table/features/RowSelectionValidation/types.d.ts +8 -0
  21. package/lib/components/Table/features/RowSelectionValidation/types.js +1 -0
  22. package/lib/components/Table/features/RowSelectionValidation/utils.d.ts +8 -0
  23. package/lib/components/Table/features/RowSelectionValidation/utils.js +11 -0
  24. package/lib/components/Table/features/entities.d.ts +3 -2
  25. package/lib/components/TableCreator/options/hook.js +0 -3
  26. package/lib/components/common/Button/components/FileDownloadButton/fileDownloadButton.d.ts +5 -0
  27. package/lib/components/common/Button/components/FileDownloadButton/fileDownloadButton.js +14 -0
  28. package/lib/components/common/CustomIcon/components/UncheckedDisabledIcon/uncheckedDisabledIcon.d.ts +2 -0
  29. package/lib/components/common/CustomIcon/components/UncheckedDisabledIcon/uncheckedDisabledIcon.js +8 -0
  30. package/lib/utils/mdx/files/mapMDXSlugByFilePaths.d.ts +8 -0
  31. package/lib/utils/mdx/files/mapMDXSlugByFilePaths.js +39 -0
  32. package/lib/utils/mdx/files/resolveRelativeDirs.d.ts +6 -0
  33. package/lib/utils/mdx/files/resolveRelativeDirs.js +9 -0
  34. package/lib/utils/mdx/frontmatter/getMatter.d.ts +8 -0
  35. package/lib/utils/mdx/frontmatter/getMatter.js +12 -0
  36. package/lib/utils/mdx/frontmatter/types.d.ts +7 -0
  37. package/lib/utils/mdx/frontmatter/types.js +1 -0
  38. package/lib/utils/mdx/frontmatter/validateMatter.d.ts +8 -0
  39. package/lib/utils/mdx/frontmatter/validateMatter.js +13 -0
  40. package/lib/utils/mdx/plugins/rehypeSlug.d.ts +6 -0
  41. package/lib/utils/mdx/plugins/rehypeSlug.js +34 -0
  42. package/lib/utils/mdx/plugins/remarkHeadings.d.ts +29 -0
  43. package/lib/utils/mdx/plugins/remarkHeadings.js +50 -0
  44. package/lib/utils/mdx/plugins/utils.d.ts +13 -0
  45. package/lib/utils/mdx/plugins/utils.js +25 -0
  46. package/lib/utils/mdx/staticGeneration/staticPaths.d.ts +8 -0
  47. package/lib/utils/mdx/staticGeneration/staticPaths.js +12 -0
  48. package/lib/utils/mdx/staticGeneration/staticProps.d.ts +5 -0
  49. package/lib/utils/mdx/staticGeneration/staticProps.js +44 -0
  50. package/lib/utils/mdx/staticGeneration/types.d.ts +12 -0
  51. package/lib/utils/mdx/staticGeneration/types.js +1 -0
  52. package/lib/utils/mdx/staticGeneration/utils.d.ts +15 -0
  53. package/lib/utils/mdx/staticGeneration/utils.js +26 -0
  54. package/package.json +8 -5
  55. package/src/components/Detail/components/Table/common/utils.ts +1 -1
  56. package/src/components/Detail/components/Table/components/TableRows/components/CollapsableRows/collapsableRows.tsx +1 -0
  57. package/src/components/Detail/components/Table/components/TableRows/tableRows.tsx +2 -0
  58. package/src/components/Detail/components/Table/table.tsx +7 -1
  59. package/src/components/Index/components/EntityView/components/layout/Summary/summary.tsx +8 -6
  60. package/src/components/Index/table/hook.ts +7 -1
  61. package/src/components/Layout/components/Outline/outline.tsx +6 -1
  62. package/src/components/Layout/components/Outline/types.ts +1 -1
  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/TableRow/tableRow.styles.ts +19 -1
  66. package/src/components/Table/components/TableRows/components/CollapsableRows/collapsableRows.tsx +1 -0
  67. package/src/components/Table/components/TableRows/tableRows.tsx +2 -0
  68. package/src/components/Table/features/RowSelectionValidation/constants.ts +24 -0
  69. package/src/components/Table/features/RowSelectionValidation/types.ts +10 -0
  70. package/src/components/Table/features/RowSelectionValidation/utils.ts +15 -0
  71. package/src/components/Table/features/entities.ts +10 -2
  72. package/src/components/TableCreator/options/hook.ts +0 -3
  73. package/src/components/common/Button/components/FileDownloadButton/fileDownloadButton.tsx +27 -0
  74. package/src/components/common/CustomIcon/components/UncheckedDisabledIcon/uncheckedDisabledIcon.tsx +27 -0
  75. package/src/utils/mdx/files/mapMDXSlugByFilePaths.ts +48 -0
  76. package/src/utils/mdx/files/resolveRelativeDirs.ts +10 -0
  77. package/src/utils/mdx/frontmatter/getMatter.ts +13 -0
  78. package/src/utils/mdx/frontmatter/types.ts +7 -0
  79. package/src/utils/mdx/frontmatter/validateMatter.ts +20 -0
  80. package/src/utils/mdx/plugins/rehypeSlug.ts +36 -0
  81. package/src/utils/mdx/plugins/remarkHeadings.ts +67 -0
  82. package/src/utils/mdx/plugins/utils.ts +27 -0
  83. package/src/utils/mdx/staticGeneration/staticPaths.ts +18 -0
  84. package/src/utils/mdx/staticGeneration/staticProps.ts +62 -0
  85. package/src/utils/mdx/staticGeneration/types.ts +16 -0
  86. package/src/utils/mdx/staticGeneration/utils.ts +32 -0
  87. package/tests/chart.test.tsx +4 -2
  88. package/tests/markdownCell.test.tsx +1 -2
  89. package/tests/rowSelectionValidation.test.ts +282 -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
+ });