Skip to content

Commit 66c6f2c

Browse files
authored
Merge pull request #1997 from dxc-technology/Mil4n0r/resultset-typing
Fixed resultSet typing for rows
2 parents 1695f29 + 0bbded2 commit 66c6f2c

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

lib/src/resultset-table/ResultsetTable.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import CoreTokens from "../common/coreTokens";
1212
const normalizeSortValue = (sortValue: string | React.ReactNode) =>
1313
typeof sortValue === "string" ? sortValue.toUpperCase() : sortValue;
1414

15-
const sortArray = (index: number, order: "ascending" | "descending", resultset: { id: string; cells: Row[] }[]) =>
15+
const sortArray = (index: number, order: "ascending" | "descending", resultset: { id: string; cells: Row }[]) =>
1616
resultset.slice().sort((element1, element2) => {
1717
const sortValueA = normalizeSortValue(element1.cells[index].sortValue || element1[index].displayValue);
1818
const sortValueB = normalizeSortValue(element2.cells[index].sortValue || element2[index].displayValue);
@@ -35,11 +35,11 @@ const getMinItemsPerPageIndex = (currentPageInternal: number, itemsPerPage: numb
3535
const getMaxItemsPerPageIndex = (
3636
minItemsPerPageIndex: number,
3737
itemsPerPage: number,
38-
resultset: Row[][],
38+
resultset: Row[],
3939
page: number,
4040
) => (minItemsPerPageIndex + itemsPerPage > resultset.length ? resultset.length : itemsPerPage * page - 1);
4141

42-
const assignIdsToRows = (resultset: Row[][]) => {
42+
const assignIdsToRows = (resultset: Row[]) => {
4343
if (resultset.length > 0) {
4444
return resultset.map((row, index) => ({
4545
cells: row,

lib/src/resultset-table/types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export type Column = {
1717
isSortable?: boolean;
1818
};
1919

20-
export type Row = {
20+
type Cell = {
2121
/**
2222
* Value to be displayed in the cell.
2323
*/
@@ -29,6 +29,8 @@ export type Row = {
2929
sortValue?: string;
3030
};
3131

32+
export type Row = Cell[];
33+
3234
type CommonProps = {
3335
/**
3436
* An array of objects representing the columns of the table.
@@ -38,7 +40,7 @@ type CommonProps = {
3840
* An array of objects representing the rows of the table, you will have
3941
* as many objects as columns in the table.
4042
*/
41-
rows: Row[][];
43+
rows: Row[];
4244
/**
4345
* Size of the margin to be applied to the component. You can pass an object with 'top',
4446
* 'bottom', 'left' and 'right' properties in order to specify different margin sizes.

website/screens/components/resultset-table/code/ResultsetTableCodePage.tsx

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ const actionsType = `{
3131
options: Option[];
3232
}[]`;
3333

34+
const cellTypeString = `{
35+
displayValue: React.ReactNode;
36+
sortValue?: string;
37+
}[]`;
38+
const columnTypeString = `{
39+
displayValue: React.ReactNode;
40+
isSortable?: boolean;
41+
}`;
42+
3443
const sections = [
3544
{
3645
title: "Props",
@@ -53,9 +62,12 @@ const sections = [
5362
</DxcFlex>
5463
</td>
5564
<td>
56-
<TableCode>
57-
{"{ displayValue: React.ReactNode; isSortable?: boolean; }[]"}
58-
</TableCode>
65+
<TableCode>Column[]</TableCode>
66+
<p>
67+
being <Code>Column</Code> an object with the following
68+
properties:
69+
</p>
70+
<ExtendedTableCode>{columnTypeString}</ExtendedTableCode>
5971
</td>
6072
<td>
6173
An array of objects representing the columns of the table. Each
@@ -80,14 +92,17 @@ const sections = [
8092
</DxcFlex>
8193
</td>
8294
<td>
83-
<TableCode>
84-
{"{ displayValue: React.ReactNode; sortValue?: string; }[]"}
85-
</TableCode>
95+
<TableCode>Row[]</TableCode>
96+
<p>
97+
being <Code>Row</Code> a <Code>Cell[]</Code> and being{" "}
98+
<Code>Cell</Code> an object with the following properties:
99+
</p>
100+
<ExtendedTableCode>{cellTypeString}</ExtendedTableCode>
86101
</td>
87102
<td>
88103
An array of objects representing the rows of the table, you will
89-
have as many objects as columns in the table. Each object has the
90-
following properties:
104+
have as many objects as columns in the table. Each row is a set of
105+
cells that have the following properties:
91106
<ul>
92107
<li>
93108
<b>displayValue</b>: Value to be displayed in the cell.

0 commit comments

Comments
 (0)