"use client"; import type { RouterOutputs } from "@openstatus/api"; import { type PageComponentImpact, worstImpact, } from "@openstatus/db/src/schema/page_components/constants"; import { ChevronDown, ChevronUp } from "@openstatus/icons"; import { Button } from "@openstatus/ui/components/ui/button"; import { cn } from "@openstatus/ui/lib/utils"; import type { ColumnDef } from "@tanstack/react-table"; import Link from "next/link"; import { TableCellBadge } from "@/components/data-table/table-cell-badge"; import { TableCellDate } from "@/components/data-table/table-cell-date"; import { TableCellLink } from "@/components/data-table/table-cell-link"; import { TableCellNumber } from "@/components/data-table/table-cell-number"; import { DataTableColumnHeader } from "@/components/ui/data-table/data-table-column-header"; import { colors, impactConfig, untriagedImpact, } from "@/data/status-report-updates.client"; import { DataTableRowActions } from "./data-table-row-actions"; type StatusReport = RouterOutputs["statusReport"]["list"][number]; // derived top-level impact = worst impact set by any update, not the // current one (a resolved report would always read "Operational"); // legacy reports (no impact rows) read "Untriaged" function worstReportImpact(report: StatusReport) { const impacts = report.updates.flatMap((u) => u.componentImpacts.map((ci) => ci.impact), ); if (impacts.length === 0) return null; return worstImpact(impacts); } export const columns: ColumnDef[] = [ { id: "expander", header: () => null, cell: ({ row }) => { return row.getCanExpand() ? ( ) : undefined; }, meta: { headerClassName: "w-7", }, }, { accessorKey: "title", header: "Title", cell: ({ row }) => { const { id, pageId } = row.original; return ( { // avoid expanding the row e.stopPropagation(); }} value={row.getValue("title")} /> ); }, enableSorting: false, enableHiding: false, meta: { cellClassName: "max-w-[200px] truncate", }, }, { accessorKey: "status", header: "Current Status", cell: ({ row }) => { const value = String(row.getValue("status")); return (
{value}
); }, enableSorting: false, enableHiding: false, }, { id: "impact", accessorFn: (row) => worstReportImpact(row), header: "Impact", cell: ({ row }) => { const impact = row.getValue("impact"); const config = impact ? impactConfig[impact] : untriagedImpact; return (
{config.label}
); }, enableSorting: false, }, { id: "updates", accessorFn: (row) => row.updates.length, header: "Updates", cell: ({ row }) => { const value = row.getValue("updates"); return ; }, }, { id: "pageComponents", accessorFn: (row) => row?.pageComponents, header: "Affected", cell: ({ row }) => { const value = row.getValue("pageComponents"); if (Array.isArray(value) && value.length > 0 && "name" in value[0]) { return (
{value.map((m) => m.monitorId ? ( ) : ( ), )}
); } return
-
; }, }, { id: "startedAt", accessorFn: (row) => row.updates.sort((a, b) => a.date.getTime() - b.date.getTime())[0] ?.date ?? row.createdAt, header: ({ column }) => ( ), cell: ({ row }) => , enableHiding: false, meta: { cellClassName: "w-[170px]", }, }, { id: "actions", cell: ({ row }) => , meta: { cellClassName: "w-8", }, }, ];