/** * Read-only results table for the SQL editor. Renders a clean, dense grid with a * sticky header, zebra striping, dim NULL tokens, stringified objects, and * horizontal scrolling. DDL/DML statements that return no columns render a * "Query OK" placeholder instead. * * Results are LIMIT-capped upstream, so no virtualization is needed. */ import { IconCircleCheck } from "@tabler/icons-react"; import { cn } from "../utils.js"; export interface ResultsGridProps { columns: string[]; rows: Record[]; } function renderCell(value: unknown): React.ReactNode { if (value === null || value === undefined) { return NULL; } if (typeof value === "object") { let str: string; try { str = JSON.stringify(value); } catch { str = String(value); } return {str}; } if (typeof value === "boolean") { return {String(value)}; } return {String(value)}; } export function ResultsGrid({ columns, rows }: ResultsGridProps) { if (columns.length === 0) { return (
Query OK
); } return (
{columns.map((col, i) => ( ))} {rows.length === 0 ? ( ) : ( rows.map((row, rowIndex) => ( {columns.map((col, colIndex) => ( ))} )) )}
# {col}
No rows returned
{rowIndex + 1} {renderCell(row[col])}
); }