import type { LedKind } from "@unlocalhosted/metalui"; import type { CommitStatus, JobStatus, RunStatus, StepStatus } from "@/lib/runs"; // Run, job and step states, drawn like the issue status glyphs (MetalUI's 24 grid, 1.7 stroke) and // coloured like its LEDs: green passed, red failed, amber working or waiting, unlit (ink3) the rest. export type AnyStatus = RunStatus | JobStatus | StepStatus | CommitStatus; const AMBER = "text-[#c98a18]"; const COLORS: Record = { success: "text-green-deep", failure: "text-red", in_progress: AMBER, queued: AMBER, pending: "text-ink3", waiting: "text-ink3", cancelled: "text-ink3", skipped: "text-ink3", }; const LABELS: Record = { success: "Success", failure: "Failure", in_progress: "In progress", queued: "Queued", pending: "Pending", waiting: "Waiting", cancelled: "Cancelled", skipped: "Skipped", }; export const statusText = (status: AnyStatus) => LABELS[status]; /** The LED for a status beside its words (StatusBadge). */ export function statusLed(status: AnyStatus): LedKind { if (status === "success") return "live"; if (status === "failure") return "failed"; if (status === "in_progress" || status === "queued") return "waiting"; return "off"; } const R = 9.15; export function RunStatusIcon({ status, size = 16, className = "" }: { status: AnyStatus; size?: number; className?: string }) { return ( {LABELS[status]} {status === "success" && ( <> )} {status === "failure" && ( <> )} {status === "in_progress" && ( <> )} {(status === "queued" || status === "waiting" || status === "pending") && ( <> {status === "queued" && } )} {status === "cancelled" && ( <> )} {status === "skipped" && ( <> )} ); }