import type { JobSpec } from "./jobSpec"; // The one extra phrase a job row carries beyond its kind. // // "Fetch window" on its own is the least useful row on /jobs: every fetch-window // job has that kind, and the question the operator has is which tool asked and // for what. The answer is already on the job — the replay spec's params — so // this reads it rather than adding a second place to store it. // // A PUBLISH STAGE (release 18, `publish-`) reads `run · `: every stage one Publish now, one lane pass or one CLI // command enqueued carries the same run id, so a run reads as a group on // /jobs. The target is the spec's slug ("_index", a site id, "_hub", …). // // Pure and total: a kind with nothing to add returns undefined and the row // renders exactly as it did. export function jobSpecDetail( kind: string | undefined, spec: JobSpec | null | undefined, ): string | undefined { const p = spec?.params ?? {}; const s = (v: unknown): string | null => typeof v === "string" && v.trim() !== "" ? v.trim() : null; if (typeof kind === "string" && kind.startsWith("publish-")) { const runId = s(p.runId); const target = s(spec?.slug); if (!runId || !target) return undefined; return `run ${runId.slice(-6)} · ${target}`; } if (kind !== "fetch-window" && kind !== "fetch-windows") return undefined; const by = s(p.requestedBy); if (!by) return undefined; if (kind === "fetch-windows") { // A batch: who asked, for what, and how many windows. const n = Array.isArray(p.items) ? p.items.length : 0; return [by, s(p.manifest), `${n} window${n === 1 ? "" : "s"}`] .filter(Boolean) .join(" · "); } const what = [s(p.manifest), s(p.clipId)].filter(Boolean).join("/"); return what ? `${by} · ${what}` : by; }