import { ColumnDef } from "@tanstack/react-table" import { AlertsHistoryRecord } from "@/types" import { Button } from "@/components/ui/button" import { Badge } from "@/components/ui/badge" import { formatShortDate, toFixedFloat, formatDuration, cn } from "@/lib/utils" import { alertInfo } from "@/lib/alerts" import { Trans } from "@lingui/react/macro" import { t } from "@lingui/core/macro" export const alertsHistoryColumns: ColumnDef[] = [ { accessorKey: "system", enableSorting: true, header: ({ column }) => ( ), cell: ({ row }) => (
{row.original.expand?.system?.name || row.original.system}
), filterFn: (row, _, filterValue) => { const display = row.original.expand?.system?.name || row.original.system || "" return display.toLowerCase().includes(filterValue.toLowerCase()) }, }, { // accessorKey: "name", id: "name", accessorFn: (record) => { const name = record.name const info = alertInfo[name] return info?.name().replace("cpu", "CPU") || name }, header: ({ column }) => ( ), cell: ({ getValue, row }) => { let name = getValue() as string const info = alertInfo[row.original.name] const Icon = info?.icon return ( {Icon && } {name} ) }, }, { accessorKey: "value", enableSorting: false, header: () => ( ), cell({ row, getValue }) { const name = row.original.name if (name === "Status") { return {t`Down`} } const value = getValue() as number const unit = alertInfo[name]?.unit return ( {toFixedFloat(value, value < 10 ? 2 : 1)} {unit} ) }, }, { accessorKey: "state", enableSorting: true, sortingFn: (rowA, rowB) => (rowA.original.resolved ? 1 : 0) - (rowB.original.resolved ? 1 : 0), header: ({ column }) => ( ), cell: ({ row }) => { const resolved = row.original.resolved return ( {/* {resolved ? : } */} {resolved ? Resolved : Active} ) }, }, { accessorKey: "created", accessorFn: (record) => formatShortDate(record.created), enableSorting: true, invertSorting: true, header: ({ column }) => ( ), cell: ({ getValue, row }) => ( {getValue() as string} ), }, { accessorKey: "resolved", enableSorting: true, invertSorting: true, header: ({ column }) => ( ), cell: ({ row, getValue }) => { const resolved = getValue() as string | null if (!resolved) { return null } return ( {formatShortDate(resolved)} ) }, }, { accessorKey: "duration", invertSorting: true, enableSorting: true, sortingFn: (rowA, rowB) => { const aCreated = new Date(rowA.original.created) const bCreated = new Date(rowB.original.created) const aResolved = rowA.original.resolved ? new Date(rowA.original.resolved) : null const bResolved = rowB.original.resolved ? new Date(rowB.original.resolved) : null const aDuration = aResolved ? aResolved.getTime() - aCreated.getTime() : null const bDuration = bResolved ? bResolved.getTime() - bCreated.getTime() : null if (!aDuration && bDuration) return -1 if (aDuration && !bDuration) return 1 return (aDuration || 0) - (bDuration || 0) }, header: ({ column }) => ( ), cell: ({ row }) => { const duration = formatDuration(row.original.created, row.original.resolved) if (!duration) { return null } return {duration} }, }, ]