import { Badge } from "../components/ui/badge"; import { SqlViewer, type SqlBlock } from "./SqlViewer"; import { PreviewGrid } from "./PreviewGrid"; import { statusBadgeClass } from "./statusBadge"; import type { CteResultV2 } from "./artifactV2"; import { useI18n } from "../i18n"; const CHIP = "rounded-md bg-muted px-1.5 py-0.5 font-mono text-xs text-foreground/90"; function statusLabel(status: string): string { if (status === "ok") return "success"; if (status === "error") return "error"; return status; } function testStatus(status: string): SqlBlock["testStatus"] { if (status === "ok") return "passed"; if (status === "error") return "failed"; return "untested"; } export function CteResultViewer({ result }: { result: CteResultV2 }) { const { t } = useI18n(); const hasPreviewRows = (result.preview?.rows?.length ?? 0) > 0; const descriptions = (result.columns ?? []).map((c) => c.description ?? ""); const showColumns = descriptions.some((d) => d.trim() !== ""); const dependsOn = result.depends_on ?? []; const block: SqlBlock = { name: result.name, sql: result.sql, testStatus: testStatus(result.status), }; return (
CTE {result.index}/{result.total} {result.name} {t(statusLabel(result.status))} {result.execution_ms !== undefined && ( {result.execution_ms} ms )} {result.row_sample !== undefined && ( {t(result.row_sample === 1 ? "{count} row" : "{count} rows", { count: result.row_sample })} )}
{result.warnings && result.warnings.length > 0 && (
{result.warnings.map((w, i) => ( {w} ))}
)} {(result.purpose || result.rationale || dependsOn.length > 0) && (
{result.purpose &&

{result.purpose}

} {result.rationale &&

{result.rationale}

} {dependsOn.length > 0 && (
{dependsOn.map((d) => ( {d} ))}
)}
)} {hasPreviewRows ? ( ) : (

{t("No preview rows")}

)} {showColumns && (
{result.columns!.map((c) => (
{c.name}
{c.description}
))}
)} {result.note &&

{result.note}

}
); }