Files
ThothII/frontend/src/viewers/statusBadge.ts
marcopanandClaude Fable 5 b59b57c4e6 fix(review-gates): green success badges, null-safe preview rows, optional section items
- Extract shared statusBadgeClass() helper (src/viewers/statusBadge.ts) so
  SqlViewer, CteResultViewer and PhaseSummaryViewer can't drift: ok/success/
  passed/promoted render green (--success), warn renders amber (--warning),
  error/failed stay destructive red, everything else stays neutral outline.
  Previously CteResultViewer/PhaseSummaryViewer mapped "ok"/"promoted" to the
  default badge variant, which is bg-primary (GSD red) — success states
  rendered red.
- enrich.js: buildCteResultV2 now falls back preview.rows to [] instead of
  null when last_test.preview_rows is missing (pre-upgrade ok records), and
  CteResultViewer reads result.preview?.rows?.length with a null-safe
  fallback so it degrades to the "No preview rows" empty state instead of
  crashing.
- PhaseSummaryViewer: section.items is optional (model-authored sections can
  be prose-only); render (section.items ?? []) instead of crashing.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-07 01:37:35 +02:00

26 lines
1.3 KiB
TypeScript

// Shared status → badge class mapping so success/warning/error colors can't drift
// between SqlViewer, CteResultViewer and PhaseSummaryViewer.
// ok/success/passed/promoted -> green (--success)
// warn/untested-with-warning -> amber (--warning)
// error/failed -> destructive/red
// anything else -> neutral outline
const SUCCESS_STATUSES = new Set(["ok", "success", "passed", "promoted"]);
const WARN_STATUSES = new Set(["warn", "warning"]);
const ERROR_STATUSES = new Set(["error", "failed", "fail"]);
export const STATUS_BADGE_CLASSES = {
success:
"bg-[oklch(var(--success)/0.15)] text-[oklch(0.45_0.12_165)] ring-1 ring-[oklch(var(--success)/0.3)]",
warning:
"bg-[oklch(var(--warning)/0.15)] text-[oklch(0.46_0.11_79)] ring-1 ring-[oklch(var(--warning)/0.4)]",
error: "bg-destructive/10 text-destructive ring-1 ring-destructive/25",
neutral: "bg-muted text-muted-foreground ring-1 ring-border",
} as const;
export function statusBadgeClass(status: string): string {
if (SUCCESS_STATUSES.has(status)) return STATUS_BADGE_CLASSES.success;
if (WARN_STATUSES.has(status)) return STATUS_BADGE_CLASSES.warning;
if (ERROR_STATUSES.has(status)) return STATUS_BADGE_CLASSES.error;
return STATUS_BADGE_CLASSES.neutral;
}