/** * One run in detail (RFC-0008 §11.7, §15.1 History): its state and outcome, the error, the summary * the job or the agent wrote (plain text), the counts, and the findings of a built-in job — broken * links with their redirect proposals, stale articles, feed problems, the digest's sections — each * with its stable code in words. Text that came from visitors or a fetched document is marked and * shown as plain text only. */ import type { ScheduleRun } from "@cloudhal/core-contracts"; import { formatNumber } from "@cloudhal/messages/format"; import { Badge, InsetPanel, LayerDialog, Link, ScheduleStatusBadge, SectionEmpty, SkeletonLine, Text, Tooltip, } from "@cloudhal/ui"; import { ShieldWarning } from "@phosphor-icons/react"; import { useQuery } from "@tanstack/react-query"; import type { RunFinding } from "../lib/api.ts"; import { entryHref } from "../lib/entry-href.ts"; import { formatWhen } from "../lib/schedules.ts"; import { schedulesApi } from "../lib/schedules-api.ts"; import { type ST, scheduleKeys, useScheduleWords, useSiteZone } from "./Schedules.tsx"; const CODES = [ "broken-internal-link", "broken-media-reference", "broken-menu-target", "link-to-gated-content", "not-found-path", "stale-entry", "feed-unreachable", "feed-invalid", "feed-item-incomplete", "feed-future-date", "feed-missing-entry", "feed-gated-node", "feed-asset-not-live", "digest-published", "digest-scheduled", "digest-attention", "digest-open-findings", "stale-draft", ] as const; type Code = (typeof CODES)[number]; const isCode = (c: string): c is Code => (CODES as readonly string[]).includes(c); const SEVERITY = { error: "error", warning: "warning", info: "secondary" } as const; /** Where a node is edited, from its id's prefix. */ function nodeHref(siteId: string, id: string | undefined): string | undefined { if (!id) return undefined; if (id.startsWith("entry_")) return entryHref(siteId, id); if (id.startsWith("page_")) return `/sites/${siteId}/pages/${id}`; if (id.startsWith("term_")) return `/sites/${siteId}/taxonomy/${id}`; if (id.startsWith("rel_")) return `/sites/${siteId}/schedules/releases/${id}`; return undefined; } function FindingRow({ t, siteId, finding }: { t: ST; siteId: string; finding: RunFinding }) { const r = "schedules.history.run" as const; const code = isCode(finding.code) ? finding.code : "other"; const href = nodeHref(siteId, finding.nodeId); // Everything below is data from the site or from visitors: plain text, never HTML or a link out. const lines = [finding.title, finding.path, finding.href, finding.url, finding.detail].filter( (x): x is string => typeof x === "string" && x.length > 0, ); return (
{t(`${r}.severity.${finding.severity ?? "info"}`)} {t(`${r}.codes.${code}`)} {typeof finding.count === "number" && {finding.count}} {finding.untrusted && ( }> {t(`${r}.untrusted`)} )} {lines.map((line) => ( {line} ))} {(typeof finding.hits === "number" || typeof finding.ageDays === "number") && ( {typeof finding.hits === "number" ? t(`${r}.hits`, { count: finding.hits }) : t(`${r}.age`, { count: finding.ageDays ?? 0 })} )} {finding.proposal && ( {t(`${r}.proposal`, { path: finding.proposal.path })} )} {finding.items && finding.items.length > 0 && ( {finding.items.map((item) => { const link = nodeHref(siteId, item.id); return ( {link ? {item.title} : item.title} ); })} )} {href && ( {t(`${r}.open`)} )}
); } export function ScheduleRunDialog({ siteId, run, title, onOpenChange, }: { siteId: string; run: ScheduleRun | undefined; title: string; onOpenChange: (open: boolean) => void; }) { const { t, locale, words } = useScheduleWords(); const zone = useSiteZone(siteId); const detail = useQuery({ queryKey: [...scheduleKeys.runs(siteId), "run", run?.id ?? ""], queryFn: () => schedulesApi.runs.get(siteId, run?.id ?? ""), enabled: run !== undefined, }); const r = "schedules.history.run" as const; const d = detail.data; const shown = d?.run ?? run; const counts = Object.entries(shown?.counts ?? {}).filter( (e): e is [string, number] => typeof e[1] === "number", ); return ( {t("schedules.history.detailsOf", { name: title })} {shown ? formatWhen(shown.startedAt ?? shown.occurrenceAt, locale, zone.timeZone, "long") : ""}
{shown && ( {shown.outcome && ( {t(`schedules.history.row.outcome.${shown.outcome}`)} )} {shown.trigger && ( {t(`schedules.history.row.trigger.${shown.trigger}`)} )} )} {shown?.error && ( {t(`${r}.error`)} {shown.error.code} {shown.error.message && {shown.error.message}} )} {shown?.summary && ( {t(`${r}.summary`)} {/* Written by a job or an agent: plain text only. */} {shown.summary} {t(`${r}.summaryHint`)} )} {counts.length > 0 && (
{t(`${r}.counts`)} {counts.map(([key, n]) => ( {isCode(key) ? t(`${r}.codes.${key}`) : key}: {formatNumber(locale, n)} ))}
)}
{d && d.findings.length > 0 ? t(`${r}.findingsCount`, { count: d.findings.length }) : t(`${r}.findings`)} {detail.isPending ? (
{t(`${r}.loading`)}
) : !d || d.findings.length === 0 ? ( ) : (
{d.findings.map((f, i) => ( // Findings have no id; their order is the job's and stable. ))}
)}
); }