Files
Checkmate/client/src/Pages/Logs/TabQueue.tsx
T

106 lines
2.9 KiB
TypeScript
Raw Normal View History

2026-02-05 21:40:36 +00:00
import Stack from "@mui/material/Stack";
2026-02-06 17:24:16 +00:00
import Typography from "@mui/material/Typography";
import Box from "@mui/material/Box";
2026-02-06 18:56:10 +00:00
import { TableJobs, TableFailedJobs } from "./components/TableJobs";
2026-02-05 21:40:36 +00:00
import { useTheme } from "@mui/material";
import { useTranslation, Trans } from "react-i18next";
2026-02-05 21:40:36 +00:00
import { useGet, usePost } from "@/Hooks/UseApi";
import type { QueueData } from "@/Types/Queue";
2026-02-06 18:56:10 +00:00
import { Metrics } from "@/Pages/Logs/components/Metrics";
2026-02-20 18:13:39 +00:00
import { Button } from "@/Components/inputs";
import { EmptyState } from "@/Components/design-elements";
2026-05-04 11:59:02 -07:00
import { SPACING } from "@/Utils/Theme/constants";
2026-02-05 21:40:36 +00:00
2026-02-05 20:23:04 +00:00
export const TabQueue = () => {
2026-02-05 21:40:36 +00:00
const theme = useTheme();
const { t } = useTranslation();
const {
data: queueData,
isLoading,
2026-02-05 21:40:36 +00:00
// error,
refetch,
2026-05-04 11:53:12 -07:00
} = useGet<QueueData>("/queue/all-metrics", {}, { refreshInterval: 1000 });
2026-02-05 21:40:36 +00:00
const { post, loading: isFlushing } = usePost();
const jobs = queueData?.jobs ?? [];
const metrics = queueData?.metrics ?? null;
const hasNeverRun = !isLoading && metrics !== null && (metrics.totalRuns ?? 0) === 0;
const noQueueData = !isLoading && metrics === null && jobs.length === 0;
if (hasNeverRun || noQueueData) {
return (
<EmptyState
fullscreen
title={t("pages.logs.queueFallback.title")}
description={t("pages.logs.queueFallback.description")}
/>
);
}
2026-02-05 21:40:36 +00:00
const handleFlushQueue = async () => {
await post("/queue/flush", {});
refetch();
};
return (
<Stack gap={theme.spacing(16)}>
2026-02-05 21:40:36 +00:00
<Metrics metrics={metrics} />
<Stack gap={theme.spacing(3)}>
<Stack gap={theme.spacing(1)}>
<Typography
variant="eyebrow"
2026-05-04 11:59:02 -07:00
color={theme.palette.text.secondary}
>
{t("pages.logs.jobQueue")}
</Typography>
2026-05-04 11:59:02 -07:00
<Typography color={theme.palette.text.secondary}>
<Trans
i18nKey="pages.logs.jobQueueExplainer"
components={{
highlight: (
<Box
component="span"
2026-05-04 11:59:02 -07:00
bgcolor={
theme.palette.mode === "dark"
? "rgba(19, 113, 91, 0.18)"
: "#ECF7F2"
}
color={theme.palette.text.primary}
px={SPACING.SM}
py={SPACING.XXS}
borderRadius={theme.shape.borderRadius}
/>
),
}}
/>
</Typography>
</Stack>
<TableJobs jobs={jobs} />
</Stack>
<Stack gap={theme.spacing(3)}>
<Stack gap={theme.spacing(1)}>
<Typography
variant="eyebrow"
2026-05-04 11:59:02 -07:00
color={theme.palette.text.secondary}
>
{t("pages.logs.failedJobs")}
</Typography>
2026-05-04 11:59:02 -07:00
<Typography color={theme.palette.text.secondary}>
{t("pages.logs.failedJobsExplainer")}
</Typography>
</Stack>
<TableFailedJobs metrics={metrics} />
</Stack>
2026-02-05 21:40:36 +00:00
<Stack alignItems={"flex-end"}>
<Button
variant="contained"
onClick={handleFlushQueue}
loading={isFlushing}
>
{t("common.buttons.flushQueue")}
</Button>
</Stack>
</Stack>
);
2026-02-05 20:23:04 +00:00
};