From 463ae3e57a8bbfc5a5201d82c17425e0597545a7 Mon Sep 17 00:00:00 2001 From: Florian Boulnois Date: Fri, 11 Aug 2023 10:19:11 -0400 Subject: [PATCH] refactor: move subtable into own component --- src/components/CollapsibleTable.js | 72 +++++++++++-------- .../data_search/DatasetSearchTable.js | 2 +- 2 files changed, 42 insertions(+), 32 deletions(-) diff --git a/src/components/CollapsibleTable.js b/src/components/CollapsibleTable.js index 63a97c1d55..91654a8367 100644 --- a/src/components/CollapsibleTable.js +++ b/src/components/CollapsibleTable.js @@ -44,7 +44,7 @@ const table = { value: 'Row 1, Cell 3', } ], - table: { + subtable: { headers: [ { value: 'Sub header 1', @@ -112,6 +112,43 @@ const StyledTableCell = styled(TableCell)(() => ({ }, })); +const SubTable = (props) => { + const { subtable, open } = props; + + return ( + + + + + + {/* subtable header */} + + + {subtable.headers.map((header, i) => ( + {header.value} + ))} + + + {/* subtable rows */} + + {subtable.rows.map((subRow, j) => ( + + {subRow.data.map((cell, k) => ( + + {cell.value} + + ))} + + ))} + +
+
+
+
+
+ ) +}; + const CollapsibleRow = (props) => { const { row } = props; const [open, setOpen] = React.useState(false); @@ -128,40 +165,13 @@ const CollapsibleRow = (props) => { {open ? : } - {row.data.map((cell) => ( - + {row.data.map((cell, i) => ( + {cell.value} ))} - - - - - - - - {row.table.headers.map((header) => ( - {header.value} - ))} - - - - {row.table.rows.map((subRow) => ( - - {subRow.data.map((cell) => ( - - {cell.value} - - ))} - - ))} - -
-
-
-
-
+ ); }; diff --git a/src/components/data_search/DatasetSearchTable.js b/src/components/data_search/DatasetSearchTable.js index 0ed686cab2..15e097064e 100644 --- a/src/components/data_search/DatasetSearchTable.js +++ b/src/components/data_search/DatasetSearchTable.js @@ -74,7 +74,7 @@ export const DatasetSearchTable = (props) => { value: entry[0].study.dataCustodian, }, ], - table: { + subtable: { headers: datasetTableHeader.map((header) => ({ value: header })), rows: entry.map((dataset) => { return {