"use client"; import type { RouterOutputs } from "@openstatus/api"; import type { PrivateLocation } from "@openstatus/db/src/schema"; import { Api, TableProperties } from "@openstatus/icons"; import { getRegionInfo } from "@openstatus/regions"; import { Table, TableBody, TableCell, TableHead, TableRow, } from "@openstatus/ui/components/ui/table"; import { Tabs, TabsContent, TabsList, TabsTrigger, } from "@openstatus/ui/components/ui/tabs"; import { cn } from "@openstatus/ui/lib/utils"; import { IconCloudProvider } from "@/components/common/icon-cloud-provider"; import { BlockWrapper } from "@/components/content/block-wrapper"; import { TableCellDate } from "@/components/data-table/table-cell-date"; import { TableCellNumber } from "@/components/data-table/table-cell-number"; import { getStatusCodeVariant, textColors } from "@/data/status-codes"; import { formatMilliseconds, formatPercentage } from "@/lib/formatter"; type ResponseLog = RouterOutputs["tinybird"]["get"]["data"][number]; export function DataTableBasics({ data, privateLocations, }: { data: ResponseLog; privateLocations?: PrivateLocation[]; }) { if (data.type === "http") { return ( ); } if (data.type === "tcp") { return ( ); } if (data.type === "dns") { return ( ); } return null; } export function DataTableBasicsHTTP({ data, privateLocations, }: { data: Extract & { trigger?: "cron" | "api" | "test" | null; }; privateLocations?: PrivateLocation[]; }) { const privateLocataion = privateLocations?.find( (location) => String(location.id) === String(data.region), ); const regionConfig = getRegionInfo(data.region, { location: privateLocataion?.name, }); return ( Request Result {/* TODO: add colored square like list (see columns) */}
{data?.requestStatus ?? "unknown"}
{data.id ? ( ID {data.id} ) : null} Timestamp URL {data.url} {/* TODO: store method in TB 🤦 */} {/* Method {data?.method} */} Status Latency Region {regionConfig?.code}{" "} {regionConfig?.location} {regionConfig?.flag} Cloud Provider {regionConfig?.provider} {data.trigger ? ( Trigger {data?.trigger} ) : null} {data.headers ? ( <> Headers
{Object.entries(data?.headers ?? {}).map( ([key, value]) => ( {key} {value} ), )}
                      {JSON.stringify(data?.headers, null, 2)}
                    
) : null} {data.timing ? ( <> Timing {Object.entries(data?.timing ?? {}).map(([key, value], index) => ( {key}
{formatPercentage(value / (data?.latency || 100))}
{formatMilliseconds(value)}
))} ) : null} {data?.message ? ( <> Message
                  {data.message}
                
) : null} {data.body ? ( <> Body
                    {data.body}
                  
) : null} {data.assertions ? ( <> Assertions {!data.assertions || data.assertions === "[]" ? (
Default status code 2xx assertion
) : (
                    {JSON.stringify(data.assertions, null, 2)}
                  
)}
) : null} ); } export function DataTableBasicsTCP({ data, privateLocations, }: { data: Extract & { trigger?: "cron" | "api" | "test" | null; }; privateLocations?: PrivateLocation[]; }) { const privateLocataion = privateLocations?.find( (location) => String(location.id) === String(data.region), ); const regionConfig = getRegionInfo(data.region, { location: privateLocataion?.name, }); return ( Request Result {/* TODO: add colored square like list (see columns) */}
{data?.requestStatus ?? "unknown"}
{data.id ? ( ID {data.id} ) : null} Timestamp URI {data.uri} Latency Region {regionConfig?.flag} {regionConfig?.code}{" "} {regionConfig?.location} Cloud Provider {regionConfig?.provider} {data.trigger ? ( Trigger {data?.trigger} ) : null} {data?.errorMessage ? ( <> Error Message
                  {data.errorMessage}
                
) : null}
); } export function DataTableBasicsDNS({ data, privateLocations, }: { data: Extract & { trigger?: "cron" | "api" | "test" | null; }; privateLocations?: PrivateLocation[]; }) { const privateLocataion = privateLocations?.find( (location) => String(location.id) === String(data.region), ); const regionConfig = getRegionInfo(data.region, { location: privateLocataion?.name, }); return ( Request Result {/* TODO: add colored square like list (see columns) */}
{data?.requestStatus ?? "unknown"}
{data.id ? ( ID {data.id} ) : null} Timestamp URI {data.uri} Latency Region {regionConfig?.flag} {regionConfig?.code}{" "} {regionConfig?.location} Cloud Provider {regionConfig?.provider} {data.trigger ? ( Trigger {data?.trigger} ) : null} {data?.records ? ( <> Records
{Object.entries(data?.records ?? {}).map( ([key, value]) => ( {key.toUpperCase()} {Array.isArray(value) ? value.join(", ") : value} ), )}
                      {JSON.stringify(data?.records, null, 2)}
                    
) : null} {data?.errorMessage ? ( <> Error Message
                  {data.errorMessage}
                
) : null} {data.assertions ? ( <> Assertions {!data.assertions || data.assertions === "[]" ? (
No assertions
) : (
                    {JSON.stringify(data.assertions, null, 2)}
                  
)}
) : null} ); }