From fe060525364be3150e3c8a6813a7bf384d14a7f6 Mon Sep 17 00:00:00 2001 From: Mil4n0r Date: Wed, 15 May 2024 12:34:12 +0200 Subject: [PATCH 1/5] Fixed resultSet typing for rows --- lib/src/resultset-table/ResultsetTable.tsx | 6 +++--- lib/src/resultset-table/types.ts | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/src/resultset-table/ResultsetTable.tsx b/lib/src/resultset-table/ResultsetTable.tsx index 4f783c3726..fe416241a3 100644 --- a/lib/src/resultset-table/ResultsetTable.tsx +++ b/lib/src/resultset-table/ResultsetTable.tsx @@ -12,7 +12,7 @@ import CoreTokens from "../common/coreTokens"; const normalizeSortValue = (sortValue: string | React.ReactNode) => typeof sortValue === "string" ? sortValue.toUpperCase() : sortValue; -const sortArray = (index: number, order: "ascending" | "descending", resultset: { id: string; cells: Row[] }[]) => +const sortArray = (index: number, order: "ascending" | "descending", resultset: { id: string; cells: Row }[]) => resultset.slice().sort((element1, element2) => { const sortValueA = normalizeSortValue(element1.cells[index].sortValue || element1[index].displayValue); const sortValueB = normalizeSortValue(element2.cells[index].sortValue || element2[index].displayValue); @@ -35,11 +35,11 @@ const getMinItemsPerPageIndex = (currentPageInternal: number, itemsPerPage: numb const getMaxItemsPerPageIndex = ( minItemsPerPageIndex: number, itemsPerPage: number, - resultset: Row[][], + resultset: Row[], page: number, ) => (minItemsPerPageIndex + itemsPerPage > resultset.length ? resultset.length : itemsPerPage * page - 1); -const assignIdsToRows = (resultset: Row[][]) => { +const assignIdsToRows = (resultset: Row[]) => { if (resultset.length > 0) { return resultset.map((row, index) => ({ cells: row, diff --git a/lib/src/resultset-table/types.ts b/lib/src/resultset-table/types.ts index 20fac4edfa..278c0bd683 100644 --- a/lib/src/resultset-table/types.ts +++ b/lib/src/resultset-table/types.ts @@ -17,7 +17,7 @@ export type Column = { isSortable?: boolean; }; -export type Row = { +type Cell = { /** * Value to be displayed in the cell. */ @@ -29,6 +29,8 @@ export type Row = { sortValue?: string; }; +export type Row = Cell[]; + type CommonProps = { /** * An array of objects representing the columns of the table. @@ -38,7 +40,7 @@ type CommonProps = { * An array of objects representing the rows of the table, you will have * as many objects as columns in the table. */ - rows: Row[][]; + rows: Row[]; /** * Size of the margin to be applied to the component. You can pass an object with 'top', * 'bottom', 'left' and 'right' properties in order to specify different margin sizes. From 008d4cc6998b4ee3079e2cdca2981d8d224bf277 Mon Sep 17 00:00:00 2001 From: Mil4n0r Date: Wed, 15 May 2024 12:42:21 +0200 Subject: [PATCH 2/5] Clarified code page typing --- .../resultset-table/code/ResultsetTableCodePage.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/screens/components/resultset-table/code/ResultsetTableCodePage.tsx b/website/screens/components/resultset-table/code/ResultsetTableCodePage.tsx index 638deecb76..476186491e 100644 --- a/website/screens/components/resultset-table/code/ResultsetTableCodePage.tsx +++ b/website/screens/components/resultset-table/code/ResultsetTableCodePage.tsx @@ -81,12 +81,12 @@ const sections = [ - {"{ displayValue: React.ReactNode; sortValue?: string; }[]"} + {"{ displayValue: React.ReactNode; sortValue?: string; }[][]"} An array of objects representing the rows of the table, you will - have as many objects as columns in the table. Each object has the + have as many objects as columns in the table. Each row is composed of cells that have the following properties: