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,27 +88,40 @@ 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]) => (
<Accordion key={name}>
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
<Typography variant="h6">{name}</Typography>
</AccordionSummary>
<AccordionDetails>
<Table stickyHeader aria-label="sticky table">
<TableHead> <TableHead>
<TableRow> <TableRow>
<TableCell /> <TableCell />
@@ -122,9 +137,7 @@ export const RunsTable = (
</TableRow> </TableRow>
</TableHead> </TableHead>
<TableBody> <TableBody>
{rows.length !== 0 ? rows {group.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage).map((row) => (
.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
.map((row, index) =>
<CollapsibleRow <CollapsibleRow
row={row} row={row}
handleDelete={handleDelete} handleDelete={handleDelete}
@@ -134,15 +147,17 @@ export const RunsTable = (
abortRunHandler={abortRunHandler} abortRunHandler={abortRunHandler}
runningRecordingName={runningRecordingName} runningRecordingName={runningRecordingName}
/> />
) ))}
: null }
</TableBody> </TableBody>
</Table> </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}
@@ -150,4 +165,4 @@ export const RunsTable = (
/> />
</React.Fragment> </React.Fragment>
); );
} };