g1t/apps/web/app/components/checks.tsx
| 1 | import { CircleCheck, CircleX, LoaderCircle, TriangleAlert } from "lucide-react"; |
| 2 | |
| 3 | import type { CheckStatus } from "@g1t/contracts"; |
| 4 | |
| 5 | import { Hint } from "./ui/hint"; |
| 6 | |
| 7 | /** |
| 8 | * What a pull request's own check status says. A pull request's checks are |
| 9 | * the workflows run on it (see the merge box); this is set when the merge |
| 10 | * queue took it out, and on older pull requests, by commands their issue |
| 11 | * once had run. |
| 12 | */ |
| 13 | const LABELS: Record<CheckStatus, string> = { |
| 14 | queued: "Checks queued", |
| 15 | running: "Checks running", |
| 16 | passed: "Checks passed", |
| 17 | failed: "Failed in the merge queue", |
| 18 | errored: "Checks could not run", |
| 19 | }; |
| 20 | |
| 21 | export function CheckIcon({ status, size = 15 }: { status: CheckStatus; size?: number }) { |
| 22 | if (status === "passed") return <CircleCheck size={size} className="shrink-0 text-success" />; |
| 23 | if (status === "failed") return <CircleX size={size} className="shrink-0 text-danger" />; |
| 24 | if (status === "errored") return <TriangleAlert size={size} className="shrink-0 text-muted" />; |
| 25 | return <LoaderCircle size={size} className="shrink-0 animate-spin text-info" />; |
| 26 | } |
| 27 | |
| 28 | /** The state of a pull request's checks at a glance, for lists. */ |
| 29 | export function CheckBadge({ status }: { status: CheckStatus | null }) { |
| 30 | if (!status) return null; |
| 31 | return ( |
| 32 | <Hint label={LABELS[status]}> |
| 33 | <span className="flex shrink-0 items-center gap-1 text-xs text-muted"> |
| 34 | <CheckIcon status={status} size={13} /> |
| 35 | <span className="sr-only">{LABELS[status]}</span> |
| 36 | </span> |
| 37 | </Hint> |
| 38 | ); |
| 39 | } |