const MAX_ROWS = 10 const MAX_CELL_LEN = 30 function truncate(val: unknown): string { const s = val === null || val === undefined ? 'null' : String(val) return s.length > MAX_CELL_LEN ? s.slice(0, MAX_CELL_LEN) + '…' : s } interface ResultsTableProps { rows: Record[] rowCount: number } export function ResultsTable({ rows, rowCount }: ResultsTableProps) { if (rows.length === 0) { return (
No rows returned.
) } const columns = Object.keys(rows[0]) const displayRows = rows.slice(0, MAX_ROWS) return (
{rowCount > MAX_ROWS && (
Showing {MAX_ROWS} of {rowCount} rows
)} {columns.map((col) => ( ))} {displayRows.map((row, i) => ( {columns.map((col) => ( ))} ))}
{col}
{truncate(row[col])}
Showing {displayRows.length} of {rowCount} rows
) }