From 3489ebc5c4909ba662166602ac5122cf8c43e47a Mon Sep 17 00:00:00 2001 From: Luis-Hebendanz Date: Mon, 14 Aug 2023 18:25:06 +0200 Subject: [PATCH] Added collapse to table --- pkgs/ui/src/app/nodes/NodeList.tsx | 427 ++++++++++++++++------------- pkgs/ui/src/app/theme/themes.ts | 18 ++ 2 files changed, 258 insertions(+), 187 deletions(-) diff --git a/pkgs/ui/src/app/nodes/NodeList.tsx b/pkgs/ui/src/app/nodes/NodeList.tsx index 98ce5e182..2228e7b19 100644 --- a/pkgs/ui/src/app/nodes/NodeList.tsx +++ b/pkgs/ui/src/app/nodes/NodeList.tsx @@ -27,11 +27,14 @@ import Stack from "@mui/material/Stack/Stack"; import ModeIcon from "@mui/icons-material/Mode"; import ClearIcon from "@mui/icons-material/Clear"; import Fade from "@mui/material/Fade/Fade"; +import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown"; +import KeyboardArrowUpIcon from "@mui/icons-material/KeyboardArrowUp"; import NodePieChart, { PieData } from "./NodePieChart"; import Grid2 from "@mui/material/Unstable_Grid2"; // Grid version 2 import { Card, CardContent, + Collapse, Container, FormGroup, useTheme, @@ -111,52 +114,6 @@ function stableSort( return stabilizedThis.map((el) => el[0]); } -interface EnhancedTableProps { - onRequestSort: ( - event: React.MouseEvent, - property: keyof TableData, - ) => void; - order: Order; - orderBy: string; - rowCount: number; -} - -function EnhancedTableHead(props: EnhancedTableProps) { - const { order, orderBy, onRequestSort } = props; - const createSortHandler = - (property: keyof TableData) => (event: React.MouseEvent) => { - onRequestSort(event, property); - }; - - return ( - - - {headCells.map((headCell) => ( - - - {headCell.label} - {orderBy === headCell.id ? ( - - {order === "desc" ? "sorted descending" : "sorted ascending"} - - ) : null} - - - ))} - - - ); -} - interface EnhancedTableToolbarProps { selected: string | undefined; tableData: TableData[]; @@ -337,7 +294,7 @@ function EnhancedTableToolbar(props: EnhancedTableToolbarProps) { {/* Pie Chart Grid */} {cardStack} @@ -366,64 +323,189 @@ function EnhancedTableToolbar(props: EnhancedTableToolbarProps) { ); } -function renderLastSeen(last_seen: number) { - return ( - - {last_seen} days ago - - ); -} - -function renderName(name: string, id: string) { - return ( - - - {name} - - - {id} - - - ); -} - -function renderStatus(status: NodeStatus) { - switch (status) { - case NodeStatus.Online: - return ( - - - - Online - - - ); - - case NodeStatus.Offline: - return ( - - - - Offline - - - ); - case NodeStatus.Pending: - return ( - - - - Pending - - - ); - } -} - export interface NodeTableProps { tableData: TableData[]; } +interface EnhancedTableProps { + onRequestSort: ( + event: React.MouseEvent, + property: keyof TableData, + ) => void; + order: Order; + orderBy: string; + rowCount: number; +} + +function EnhancedTableHead(props: EnhancedTableProps) { + const { order, orderBy, onRequestSort } = props; + const createSortHandler = + (property: keyof TableData) => (event: React.MouseEvent) => { + onRequestSort(event, property); + }; + + return ( + + + + {headCells.map((headCell) => ( + + + {headCell.label} + {orderBy === headCell.id ? ( + + {order === "desc" ? "sorted descending" : "sorted ascending"} + + ) : null} + + + ))} + + + ); +} + +function Row(props: { + row: TableData; + selected: string | undefined; + setSelected: (a: string | undefined) => void; +}) { + function renderStatus(status: NodeStatus) { + switch (status) { + case NodeStatus.Online: + return ( + + + + Online + + + ); + + case NodeStatus.Offline: + return ( + + + + Offline + + + ); + case NodeStatus.Pending: + return ( + + + + Pending + + + ); + } + } + + const { row, selected, setSelected } = props; + const [open, setOpen] = React.useState(false); + //const labelId = `enhanced-table-checkbox-${index}`; + + // Speed optimization. We compare string pointers here instead of the string content. + const isSelected = selected == row.name; + + const handleClick = (event: React.MouseEvent, name: string) => { + if (isSelected) { + setSelected(undefined); + } else { + setSelected(name); + } + }; + + return ( + + + {/* Rendered Row */} + + + setOpen(!open)} + > + {open ? : } + + + handleClick(event, row.name)}> + + + {row.name} + + + {row.id} + + + + handleClick(event, row.name)}>{renderStatus(row.status)} + handleClick(event, row.name)}> + + {row.last_seen} days ago + + + + + {/* Row Expansion */} + + + + + + History + + + + + Date + Customer + Amount + Total price ($) + + + + + Test1 + Test2 + Test + Test + + +
+
+
+
+
+
+ ); +} + export default function NodeTable(props: NodeTableProps) { let { tableData } = props; @@ -446,15 +528,6 @@ export default function NodeTable(props: NodeTableProps) { setOrderBy(property); }; - const handleClick = (event: React.MouseEvent, name: string) => { - // Speed optimization. We compare string pointers here instead of the string content. - if (selected == name) { - setSelected(undefined); - } else { - setSelected(name); - } - }; - const handleChangePage = (event: unknown, newPage: number) => { setPage(newPage); }; @@ -466,9 +539,6 @@ export default function NodeTable(props: NodeTableProps) { setPage(0); }; - // Speed optimization. We compare string pointers here instead of the string content. - const isSelected = (name: string) => name == selected; - // Avoid a layout jump when reaching the last page with empty rows. const emptyRows = page > 0 ? Math.max(0, (1 + page) * rowsPerPage - tableData.length) : 0; @@ -483,79 +553,62 @@ export default function NodeTable(props: NodeTableProps) { ); return ( + + + setSelected(undefined)} + /> + + + + + {visibleRows.map((row, index) => { + const labelId = `enhanced-table-checkbox-${index}`; - - - setSelected(undefined)} - /> - -
- - - {visibleRows.map((row, index) => { - const isItemSelected = isSelected(row.name); - const labelId = `enhanced-table-checkbox-${index}`; - - return ( - handleClick(event, row.name)} - role="checkbox" - aria-checked={isItemSelected} - tabIndex={-1} - key={row.name} - selected={isItemSelected} - sx={{ cursor: "pointer" }} - > - - {renderName(row.name, row.id)} - - - {renderStatus(row.status)} - - - {renderLastSeen(row.last_seen)} - - - ); - })} - {emptyRows > 0 && ( - - - - )} - -
-
- {/* TODO: This creates the error Warning: Prop `id` did not match. Server: ":RspmmcqH1:" Client: ":R3j6qpj9H1:" */} - -
-
- + return ( + + ); + })} + {emptyRows > 0 && ( + + + + )} + + + + {/* TODO: This creates the error Warning: Prop `id` did not match. Server: ":RspmmcqH1:" Client: ":R3j6qpj9H1:" */} + + + ); } diff --git a/pkgs/ui/src/app/theme/themes.ts b/pkgs/ui/src/app/theme/themes.ts index fd845dec0..edd2786ee 100644 --- a/pkgs/ui/src/app/theme/themes.ts +++ b/pkgs/ui/src/app/theme/themes.ts @@ -1,12 +1,30 @@ import { createTheme } from "@mui/material/styles"; export const darkTheme = createTheme({ + breakpoints: { + values: { + xs: 0, + sm: 400, + md: 900, + lg: 1200, + xl: 1536, + }, + }, palette: { mode: "dark", }, }); export const lightTheme = createTheme({ + breakpoints: { + values: { + xs: 0, + sm: 400, + md: 900, + lg: 1200, + xl: 1536, + }, + }, palette: { mode: "light", },