"use client"; import type { RouterOutputs } from "@openstatus/api"; import { Warning, Refresh } from "@openstatus/icons"; import { Button } from "@openstatus/ui/components/ui/button"; import { TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@openstatus/ui/components/ui/table"; import { cn } from "@openstatus/ui/lib/utils"; import { type ColumnDef, flexRender, getCoreRowModel, useReactTable, } from "@tanstack/react-table"; import { useState } from "react"; import { getColumns } from "@/components/data-table/response-logs/columns"; import { Sheet } from "@/components/data-table/response-logs/data-table-sheet"; import { DataTableSkeleton } from "@/components/ui/data-table/data-table-skeleton"; // Use the wider `get`-shape so the row also satisfies the Sheet's input. // The column defs are typed against `list` shape, but every list field // is also present on `get`, so casting is safe. export type OnboardingChecksRow = RouterOutputs["tinybird"]["get"]["data"][number]; const COLUMNS = getColumns([]) as unknown as ColumnDef[]; export function OnboardingChecksTable({ rows, totalRegions, isStreaming, allFailed, url, onRetry, className, ...props }: Omit, "children"> & { rows: OnboardingChecksRow[]; totalRegions: number; isStreaming: boolean; allFailed: boolean; url?: string; onRetry: () => void; }) { // Track selection by row id so new rows arriving via streaming don't // make the Sheet point at a stale object reference. const [selectedId, setSelectedId] = useState(null); const table = useReactTable({ data: rows, columns: COLUMNS, getCoreRowModel: getCoreRowModel(), initialState: { columnVisibility: { trigger: false }, }, }); const selected = selectedId == null ? null : (rows.find((r) => r.id === selectedId) ?? null); if (allFailed) { return (

Couldn't reach {url ? {url} : "your URL"}

Common causes: the URL is internal, blocks our checkers, or has a typo.

); } if (rows.length === 0 && isStreaming) { return (
); } return ( <>
{table.getHeaderGroups().map((headerGroup) => ( {headerGroup.headers.map((header) => ( {header.isPlaceholder ? null : flexRender( header.column.columnDef.header, header.getContext(), )} ))} ))} {table.getRowModel().rows.map((row) => ( setSelectedId(row.original.id ?? null)} > {row.getVisibleCells().map((cell) => ( {flexRender(cell.column.columnDef.cell, cell.getContext())} ))} ))} {isStreaming && rows.length < totalRegions ? ( Streaming results from {totalRegions - rows.length} more region{totalRegions - rows.length === 1 ? "" : "s"}… ) : null}
setSelectedId(null)} showCopyUrl={false} /> ); }