import { useQuery } from "@tanstack/react-query"; import { FlaskConical, ChevronRight } from "lucide-react"; import { Link } from "@/lib/router"; import { smokeLabApi } from "@/api/smokeLab"; import { queryKeys } from "@/lib/queryKeys"; import { useSmokeLabEnabled } from "@/hooks/useSmokeLabEnabled"; import { advancedTabHref } from "@/pages/tools/tool-tabs"; import { cn } from "@/lib/utils"; import { failingPaths, runHealth, type SmokeHealth } from "@/pages/tools/smoke-lab-matrix"; const HEALTH_DOT: Record = { green: "bg-emerald-500", amber: "bg-amber-500", red: "bg-destructive", unknown: "bg-muted-foreground/40", }; const HEALTH_LABEL: Record = { green: "All paths passing", amber: "Needs a run", red: "Failing paths", unknown: "No runs yet", }; function formatTime(value: string | Date | null | undefined): string { if (!value) return "—"; const date = new Date(value as string | Date); if (Number.isNaN(date.getTime())) return "—"; return new Intl.DateTimeFormat(undefined, { dateStyle: "medium", timeStyle: "short" }).format(date); } /** * Compact "Integration smoke" dashboard card (PAP-13347 / S2, plan §D3). * Renders only when `experimental.enableSmokeLab` is on (board-readable flag), * so the dashboard stays clean for everyone who isn't running the Smoke Lab. * Operator-facing copy stays plain; protocol depth lives behind the link into * the Developer › Smoke Lab tab. */ export function SmokeLabDashboardCard({ companyId }: { companyId: string }) { const { enabled, loaded } = useSmokeLabEnabled(); const runsQuery = useQuery({ queryKey: queryKeys.smokeLab.runs(companyId), queryFn: () => smokeLabApi.listRuns(companyId), enabled: enabled && loaded, }); const latestRun = runsQuery.data?.runs?.[0]; const detailQuery = useQuery({ queryKey: queryKeys.smokeLab.run(companyId, latestRun?.id ?? "__none__"), queryFn: () => smokeLabApi.getRun(companyId, latestRun!.id), enabled: enabled && loaded && !!latestRun, }); if (!loaded || !enabled) return null; const steps = detailQuery.data?.steps ?? []; const health = runHealth(latestRun, steps); const failing = failingPaths(steps); return (

Integration smoke

{HEALTH_LABEL[health]} {failing.length > 0 && `: ${failing.join(", ")}`}

{latestRun ? `Last run ${formatTime(latestRun.startedAt)}` : "Run one from the Smoke Lab tab"}

); }