From e2f0ed955ec7e8a0c8ba215a1b9208ddcb06f15e Mon Sep 17 00:00:00 2001 From: Hemang Kandwal Date: Tue, 28 Jan 2025 11:41:29 +0530 Subject: [PATCH 1/2] feat(frontend): fix table header logic to have unique ids --- frontend/src/components/table.tsx | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/frontend/src/components/table.tsx b/frontend/src/components/table.tsx index 60f8ae4b..567ca380 100644 --- a/frontend/src/components/table.tsx +++ b/frontend/src/components/table.tsx @@ -385,12 +385,23 @@ export const Table: FC = ({ className, columns: actualColumns, rows const columns = useMemo(() => { const indexWidth = 50; const colWidth = Math.max(((width - indexWidth)/actualColumns.length), 150); - const cols = actualColumns.map(col => ({ - id: col, - Header: col, - accessor: col, - width: colWidth, - })); + const headerCount: Record = {}; + const cols = actualColumns.map((col) => { + if (headerCount[col] === undefined) { + headerCount[col] = 0; + } else { + headerCount[col] += 1; + } + + const id = headerCount[col] > 0 ? `${col}-${headerCount[col]}` : col; + + return { + id, + Header: col, + accessor: id, + width: colWidth, + }; + }); cols.unshift({ id: "#", Header: "#", @@ -403,7 +414,11 @@ export const Table: FC = ({ className, columns: actualColumns, rows useEffect(() => { setData(actualRows.map((row, rowIndex) => { const newRow = row.reduce((all, one, colIndex) => { - all[actualColumns[colIndex]] = one; + if (actualColumns[colIndex] === "#") { + all[actualColumns[colIndex]] = one; + } else { + all[columns[colIndex+1].accessor] = one; + } return all; }, { "#": (rowIndex+1).toString() } as Record); newRow.originalIndex = rowIndex; From 114522f2a00056a7176bb673e74637f81d7f19a7 Mon Sep 17 00:00:00 2001 From: Hemang Kandwal Date: Tue, 28 Jan 2025 11:47:31 +0530 Subject: [PATCH 2/2] feat(frontend): fix up undefined --- frontend/src/components/table.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/table.tsx b/frontend/src/components/table.tsx index 567ca380..b80eb837 100644 --- a/frontend/src/components/table.tsx +++ b/frontend/src/components/table.tsx @@ -387,7 +387,7 @@ export const Table: FC = ({ className, columns: actualColumns, rows const colWidth = Math.max(((width - indexWidth)/actualColumns.length), 150); const headerCount: Record = {}; const cols = actualColumns.map((col) => { - if (headerCount[col] === undefined) { + if (headerCount[col] == null) { headerCount[col] = 0; } else { headerCount[col] += 1;