Skip to content

Commit

Permalink
refactor: move subtable into own component
Browse files Browse the repository at this point in the history
  • Loading branch information
fboulnois committed Aug 11, 2023
1 parent ba689dc commit 463ae3e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 32 deletions.
72 changes: 41 additions & 31 deletions src/components/CollapsibleTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const table = {
value: 'Row 1, Cell 3',
}
],
table: {
subtable: {
headers: [
{
value: 'Sub header 1',
Expand Down Expand Up @@ -112,6 +112,43 @@ const StyledTableCell = styled(TableCell)(() => ({
},
}));

const SubTable = (props) => {
const { subtable, open } = props;

return (
<TableRow>
<StyledTableCell style={{ paddingBottom: 0, paddingTop: 0 }} colSpan={6} component="th">
<Collapse in={open} timeout="auto" unmountOnExit>
<Box sx={{ margin: 2 }}>
<Table>
{/* subtable header */}
<TableHead>
<TableRow>
{subtable.headers.map((header, i) => (
<StyledTableCell key={i}>{header.value}</StyledTableCell>
))}
</TableRow>
</TableHead>
{/* subtable rows */}
<TableBody>
{subtable.rows.map((subRow, j) => (
<TableRow key={j}>
{subRow.data.map((cell, k) => (
<StyledTableCell key={k} component="th">
{cell.value}
</StyledTableCell>
))}
</TableRow>
))}
</TableBody>
</Table>
</Box>
</Collapse>
</StyledTableCell>
</TableRow>
)

Check notice on line 149 in src/components/CollapsibleTable.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/components/CollapsibleTable.js#L149

Missing semicolon.
};

const CollapsibleRow = (props) => {
const { row } = props;
const [open, setOpen] = React.useState(false);
Expand All @@ -128,40 +165,13 @@ const CollapsibleRow = (props) => {
{open ? <KeyboardArrowUpIcon /> : <KeyboardArrowDownIcon />}
</IconButton>
</StyledTableCell>
{row.data.map((cell) => (
<StyledTableCell key={cell.id} component="th">
{row.data.map((cell, i) => (
<StyledTableCell key={i} component="th">
{cell.value}
</StyledTableCell>
))}
</TableRow>
<TableRow>
<StyledTableCell style={{ paddingBottom: 0, paddingTop: 0 }} colSpan={6} component="th">
<Collapse in={open} timeout="auto" unmountOnExit>
<Box sx={{ margin: 2 }}>
<Table>
<TableHead>
<TableRow>
{row.table.headers.map((header) => (
<StyledTableCell key={header.value}>{header.value}</StyledTableCell>
))}
</TableRow>
</TableHead>
<TableBody>
{row.table.rows.map((subRow) => (
<TableRow key={subRow.id}>
{subRow.data.map((cell) => (
<StyledTableCell key={cell.id} component="th">
{cell.value}
</StyledTableCell>
))}
</TableRow>
))}
</TableBody>
</Table>
</Box>
</Collapse>
</StyledTableCell>
</TableRow>
<SubTable subtable={row.subtable} open={open} />
</React.Fragment>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/data_search/DatasetSearchTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 463ae3e

Please sign in to comment.