"use client"; import type { RouterOutputs } from "@openstatus/api"; import { Badge } from "@openstatus/ui/components/ui/badge"; import { Checkbox } from "@openstatus/ui/components/ui/checkbox"; import type { ColumnDef } from "@tanstack/react-table"; import { formatDistanceToNow } from "date-fns"; import { TableCellLink } from "@/components/data-table/table-cell-link"; import { DataTableColumnHeader } from "@/components/ui/data-table/data-table-column-header"; import { TableCellSkeleton } from "../dable-cell-skeleton"; import { TableCellDate } from "../table-cell-date"; import { TableCellNumber } from "../table-cell-number"; import { TableCellUnavailable } from "../table-cell-unavailable"; import { DataTableRowActions } from "./data-table-row-actions"; type Monitor = RouterOutputs["monitor"]["list"][number] & { globalMetrics?: | RouterOutputs["tinybird"]["globalMetrics"]["data"][number] // NOTE: after loading the data, if the monitor has no metrics, the value will be `false` | false; }; export const columns: ColumnDef[] = [ { id: "select", header: ({ table }) => ( table.toggleAllPageRowsSelected(!!value)} aria-label="Select all" /> ), cell: ({ row }) => ( row.toggleSelected(!!value)} aria-label="Select row" /> ), enableSorting: false, enableHiding: false, }, { accessorKey: "name", header: ({ column }) => ( ), cell: ({ row }) => { return ( ); }, enableHiding: false, meta: { cellClassName: "max-w-[150px] min-w-max", }, }, { accessorKey: "url", header: ({ column }) => ( ), cell: ({ row }) => { return ( ); }, enableHiding: true, meta: { cellClassName: "max-w-[150px] min-w-max", }, }, { accessorKey: "jobType", header: "Type", enableHiding: true, }, { id: "status", accessorFn: (row) => { console.log(row); return row.active ? row.status : "inactive"; }, header: "Status", cell: ({ row }) => { const value = String(row.getValue("status")); switch (value) { case "active": return
{value}
; case "degraded": return
{value}
; case "error": return
{value}
; default: return
{value}
; } }, filterFn: (row, _, value) => { if (Array.isArray(value)) { if (value.includes("inactive")) { return !row.original.active; } if (value.includes("active")) { return !!row.original.active && row.original.status === "active"; } return value.includes(row.original.status); } return row.original.status === value; }, enableSorting: false, enableHiding: false, enableGlobalFilter: false, }, { accessorKey: "active", enableHiding: true, enableGlobalFilter: false, }, { accessorKey: "tags", header: "Tags", cell: ({ row }) => { const value = row.getValue("tags"); if (!Array.isArray(value)) return null; if (value.length === 0) { return
-
; } return (
{value.map((tag) => (
{tag.name} ))}
); }, filterFn: (row, _, value) => { const tagIds = row.original.tags.map((tag) => tag.id); if (Array.isArray(value)) { return value.some((v) => tagIds.includes(v)); } return tagIds.includes(value); }, getUniqueValues: (row) => row.tags.map((tag) => tag.id), enableSorting: false, enableHiding: false, enableGlobalFilter: false, }, { id: "lastIncident", header: "Last Incident", accessorFn: (row) => row.incidents?.[0]?.createdAt, cell: ({ row }) => { const value = row.getValue("lastIncident"); return ; }, enableHiding: false, enableGlobalFilter: false, }, // { // id: "uptime", // accessorFn: (row) => `uptime-${row.id}`, // header: "Last Week", // cell: ({ row }) => { // return ( // // ); // }, // enableHiding: false, // enableGlobalFilter: false, // }, { id: "lastTimestamp", header: "Last Checked", accessorFn: (row) => typeof row.globalMetrics === "object" ? row.globalMetrics.lastTimestamp : row.globalMetrics, cell: ({ row }) => { const value = row.getValue("lastTimestamp"); if (value === undefined) return ; return ( ); }, enableHiding: false, enableGlobalFilter: false, }, { id: "p50", accessorFn: (row) => typeof row.globalMetrics === "object" ? row.globalMetrics.p50Latency : row.globalMetrics, header: ({ column }) => ( ), cell: ({ row }) => { const value = row.getValue("p50"); if (value === undefined) return ; if (!value) return ; return ; }, enableHiding: false, }, { id: "p90", accessorFn: (row) => typeof row.globalMetrics === "object" ? row.globalMetrics.p90Latency : row.globalMetrics, header: ({ column }) => ( ), cell: ({ row }) => { const value = row.getValue("p90"); if (value === undefined) return ; if (!value) return ; return ; }, enableHiding: false, enableGlobalFilter: false, }, { id: "p95", accessorFn: (row) => typeof row.globalMetrics === "object" ? row.globalMetrics.p95Latency : row.globalMetrics, header: ({ column }) => ( ), cell: ({ row }) => { const value = row.getValue("p95"); if (value === undefined) return ; if (!value) return ; return ; }, enableHiding: false, enableGlobalFilter: false, }, { id: "actions", cell: ({ row }) => , meta: { cellClassName: "w-8", }, }, ];