Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions frontend/src/pages/data.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useContext, useMemo } from "react";
import { List, ListItemButton, ListItemText, ListSubheader } from "@mui/material";
import React, { useContext, useEffect, useMemo, useState } from "react";
import { FormControlLabel, List, ListItemButton, ListItemText, ListSubheader, Switch } from "@mui/material";
import { JobsContext } from "../contexts/JobsContext";
import { JobView } from "../components/JobView";
import { useSearchParams } from "react-router";
Expand Down Expand Up @@ -39,6 +39,19 @@ export function DataPage() {
return Object.values(groupedJobs).some((list) => list.length > 0);
}, [groupedJobs]);

const [alwaysShowLatest, setAlwaysShowLatest] = useState(false);

const latestJobId = useMemo(() => {
const ids = Object.keys(jobs).map(Number);
return ids.length > 0 ? Math.max(...ids) : null;
}, [jobs]);

useEffect(() => {
if (alwaysShowLatest && latestJobId !== null) {
setSearchParams({ jobId: String(latestJobId) });
}
}, [alwaysShowLatest, latestJobId]);

const handleSelectJob = (jobId: number) => {
setSearchParams({ jobId: String(jobId) });
};
Expand All @@ -54,6 +67,17 @@ export function DataPage() {
borderRight: "1px solid var(--mui-palette-divider)",
}}
>
<FormControlLabel
control={
<Switch
size="small"
checked={alwaysShowLatest}
onChange={(_, v) => setAlwaysShowLatest(v)}
/>
}
label="Latest"
sx={{ mx: 1, my: 0.5 }}
/>
<List dense disablePadding>
{(Object.entries(groupedJobs) as [JobStatus, Job[]][]).map(
([status, jobList]) =>
Expand Down
Loading