feat: group runs of same recording

This commit is contained in:
karishmas6
2024-09-09 08:00:48 +05:30
parent 62c02860a8
commit 9af82721c0

View File

@@ -12,6 +12,8 @@ import { useGlobalInfoStore } from "../../context/globalInfo";
import { getStoredRuns } from "../../api/storage"; import { getStoredRuns } from "../../api/storage";
import { RunSettings } from "./RunSettings"; import { RunSettings } from "./RunSettings";
import { CollapsibleRow } from "./ColapsibleRow"; import { CollapsibleRow } from "./ColapsibleRow";
import { Accordion, AccordionSummary, AccordionDetails, Typography } from '@mui/material';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
interface Column { interface Column {
id: 'status' | 'name' | 'startedAt' | 'finishedAt' | 'duration' | 'task' | 'runId' | 'delete'; id: 'status' | 'name' | 'startedAt' | 'finishedAt' | 'duration' | 'task' | 'runId' | 'delete';
@@ -86,68 +88,81 @@ export const RunsTable = (
} else { } else {
console.log('No runs found.'); console.log('No runs found.');
} }
} };
useEffect( () => { useEffect(() => {
if (rows.length === 0 || rerenderRuns) { if (rows.length === 0 || rerenderRuns) {
fetchRuns(); fetchRuns();
setRerenderRuns(false); setRerenderRuns(false);
} }
}, [rerenderRuns]); }, [rerenderRuns]);
const handleDelete = () => { const handleDelete = () => {
setRows([]); setRows([]);
notify('success', 'Run deleted successfully'); notify('success', 'Run deleted successfully');
fetchRuns(); fetchRuns();
} };
// Group runs by recording name
const groupedRows = rows.reduce((acc, row) => {
if (!acc[row.name]) {
acc[row.name] = [];
}
acc[row.name].push(row);
return acc;
}, {} as Record<string, Data[]>);
return ( return (
<React.Fragment> <React.Fragment>
<TableContainer component={Paper} sx={{ width: '100%', overflow: 'hidden' }}> <TableContainer component={Paper} sx={{ width: '100%', overflow: 'hidden' }}>
<Table stickyHeader aria-label="sticky table" > {Object.entries(groupedRows).map(([name, group]) => (
<TableHead> <Accordion key={name}>
<TableRow> <AccordionSummary expandIcon={<ExpandMoreIcon />}>
<TableCell /> <Typography variant="h6">{name}</Typography>
{columns.map((column) => ( </AccordionSummary>
<TableCell <AccordionDetails>
key={column.id} <Table stickyHeader aria-label="sticky table">
align={column.align} <TableHead>
style={{ minWidth: column.minWidth }} <TableRow>
> <TableCell />
{column.label} {columns.map((column) => (
</TableCell> <TableCell
))} key={column.id}
</TableRow> align={column.align}
</TableHead> style={{ minWidth: column.minWidth }}
<TableBody> >
{rows.length !== 0 ? rows {column.label}
.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage) </TableCell>
.map((row, index) => ))}
<CollapsibleRow </TableRow>
row={row} </TableHead>
handleDelete={handleDelete} <TableBody>
key={`row-${row.id}`} {group.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage).map((row) => (
isOpen={runId === row.runId && runningRecordingName === row.name} <CollapsibleRow
currentLog={currentInterpretationLog} row={row}
abortRunHandler={abortRunHandler} handleDelete={handleDelete}
runningRecordingName={runningRecordingName} key={`row-${row.id}`}
/> isOpen={runId === row.runId && runningRecordingName === row.name}
) currentLog={currentInterpretationLog}
: null } abortRunHandler={abortRunHandler}
</TableBody> runningRecordingName={runningRecordingName}
</Table> />
))}
</TableBody>
</Table>
</AccordionDetails>
</Accordion>
))}
</TableContainer> </TableContainer>
<TablePagination <TablePagination
rowsPerPageOptions={[10, 25, 50]} rowsPerPageOptions={[10, 25, 50]}
component="div" component="div"
count={rows ? rows.length : 0} count={rows.length}
rowsPerPage={rowsPerPage} rowsPerPage={rowsPerPage}
page={page} page={page}
onPageChange={handleChangePage} onPageChange={handleChangePage}
onRowsPerPageChange={handleChangeRowsPerPage} onRowsPerPageChange={handleChangeRowsPerPage}
/> />
</React.Fragment> </React.Fragment>
); );
} };