import { Table } from "@/Components/design-elements"; import { Typography, useTheme } from "@mui/material"; import prettyMilliseconds from "pretty-ms"; import { formatTimestamp } from "@/Utils/TimeUtils"; import { useTranslation } from "react-i18next"; import type { QueueJobFailure, QueueJobSummary, QueueMetrics } from "@/Types/Queue"; import type { Header } from "@/Components/design-elements"; type QueueJobWithId = QueueJobSummary & { id: string | number }; interface TableJobsProps { jobs: QueueJobSummary[]; } export const TableJobs = ({ jobs }: TableJobsProps) => { const { t } = useTranslation(); const theme = useTheme(); const jobsWithId: QueueJobWithId[] = jobs.map((job) => ({ ...job, id: job.monitorId, })); const cellSx = { whiteSpace: "nowrap" as const, overflow: "hidden", textOverflow: "ellipsis", maxWidth: 220, }; const headers: Header[] = [ { id: "state", content: t("pages.logs.table.headers.state"), render: (row) => { if (row.lockedAt) { return t("common.labels.running"); } if (row.monitorActive === true) { return t("common.labels.active"); } if (row.monitorActive === false) { return t("common.labels.paused"); } return t("common.labels.idle"); }, }, { id: "id", content: t("common.table.headers.monitorId"), render: (row) => ( {row.monitorId} ), }, { id: "url", content: t("common.table.headers.url"), render: (row) => ( {row.monitorUrl} ), }, { id: "type", content: t("common.table.headers.type"), render: (row) => {row.monitorType}, }, { id: "interval", content: t("common.table.headers.interval"), render: (row) => { let interval; if (row.monitorId.toString().includes("geo")) { interval = row.monitorGeoInterval ?? 0; } else { interval = row.repeat ?? 0; } return {prettyMilliseconds(interval)}; }, }, { id: "lastRun", content: t("pages.logs.table.headers.lastRunAt"), render: (row) => { const v = formatTimestamp(row.lastRunAt) ?? "-"; return ( {v} ); }, }, { id: "lastRunTook", content: t("pages.logs.table.headers.lastRunTook"), render: (row) => { const value = row.lastRunTook ? prettyMilliseconds(row.lastRunTook) : "-"; return {value}; }, }, { id: "lockedAt", content: t("pages.logs.table.headers.lockedAt"), render: (row) => { const v = formatTimestamp(row.lockedAt) ?? "-"; return ( {v} ); }, }, ]; return ( ({ ...(row.lockedAt && { "& td": { backgroundColor: theme.palette.rowStatus.running }, }), ...(row.monitorActive === false && { "& td": { backgroundColor: theme.palette.rowStatus.paused }, }), })} /> ); }; type QueueJobFailureWithId = QueueJobFailure & { id: string | number }; interface TableFailedJobsProps { metrics: QueueMetrics | null; } export const TableFailedJobs = ({ metrics }: TableFailedJobsProps) => { const { t } = useTranslation(); const theme = useTheme(); if (!metrics) { return null; } const jobFailuresWithId: QueueJobFailureWithId[] = metrics.jobsWithFailures.map( (job) => ({ ...job, id: job.monitorId, }) ); const headers: Header[] = [ { id: "monitorId", content: t("common.table.headers.monitorId"), render: (row) => { return ( {row.monitorId} ); }, }, { id: "monitorUrl", content: t("common.table.headers.url"), render: (row) => { return {row.monitorUrl}; }, }, { id: "failCount", content: t("pages.logs.table.headers.failCount"), render: (row) => { return {row.failCount}; }, }, { id: "failedAt", content: t("pages.logs.table.headers.lastFailedAt"), render: (row) => { return {formatTimestamp(row.failedAt)}; }, }, { id: "failReason", content: t("pages.logs.table.headers.failReason"), render: (row) => { return {row.failReason}; }, }, ]; return (
); };