"use client"; import type { RouterOutputs } from "@openstatus/api"; import type { PrivateLocation } from "@openstatus/db/src/schema"; import type { ColumnDef } from "@tanstack/react-table"; import { HoverCardTimestamp } from "@/components/common/hover-card-timestamp"; import { Pill } from "@/components/common/pill"; import { TableCellDate } from "@/components/data-table/table-cell-date"; import { config, getMetadata } from "@/data/audit-logs.client"; import { cn } from "@/lib/utils"; type AuditLog = RouterOutputs["tinybird"]["auditLog"]["data"][number]; export function getColumns( privateLocations?: PrivateLocation[], ): ColumnDef[] { const metadata = getMetadata(privateLocations); return [ { id: "icon", accessorFn: (row) => row.action, header: () => null, enableSorting: false, enableHiding: false, cell: ({ row }) => { const value = row.getValue("action"); const { icon: Icon, color } = config[value as keyof typeof config]; if (!Icon) return null; return ; }, meta: { headerClassName: "w-7", }, }, { accessorKey: "action", header: "Action", enableSorting: false, enableHiding: false, cell: ({ row }) => { const value = row.getValue("action"); const { title } = config[value as keyof typeof config]; if (!title) return null; return
{title}
; }, }, { accessorKey: "metadata", header: "Information", enableSorting: false, enableHiding: false, cell: ({ row }) => { const value = row.getValue("metadata"); if (!value) return null; return (
{Object.entries(value) .filter(([key, value]) => metadata[key as keyof typeof metadata]?.visible(value), ) .map(([key, value]) => { return ( ); })}
); }, }, { accessorKey: "timestamp", header: "Timestamp", enableSorting: false, enableHiding: false, cell: ({ row }) => { const value = row.getValue("timestamp"); if (value instanceof Date) { return ( ); } const date = new Date(Number(value)); if (Number.isNaN(date.getTime())) { return
{String(value)}
; } return ( ); }, }, ]; }