import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { MobileCardRow, type MobileCardField, } from "@/components/ui/mobile-card"; import { useIsMobile } from "../hooks/useIsMobile"; import type { BackupAlert } from "../types/backups"; interface Props { alerts: BackupAlert[]; onAcknowledge: (alertId: string) => void; } function formatTimestamp(ts: number): string { return new Date(ts * 1000).toLocaleString(); } type SeverityVariant = "destructive" | "warning"; /** * Map an alert severity onto a Badge variant per design §2.3. * `critical` → destructive (chart-4); `warning` → warning (chart-3). */ function severityVariant(severity: string): SeverityVariant { return severity === "critical" ? "destructive" : "warning"; } // Mobile card fields (spec R3.2): message is the primary identifier; // severity/type/created give the at-a-glance info. See OpenSpec change // `mobile-responsive-parity`, tasks slice 5.2. const alertCardFields: MobileCardField[] = [ { key: "message", label: "Message", render: (a) => a.message, primary: true }, { key: "severity", label: "Severity", render: (a) => ( {a.severity} ), }, { key: "type", label: "Type", render: (a) => a.alert_type }, { key: "created", label: "Created", render: (a) => formatTimestamp(a.created_at), }, ]; export default function BackupAlertsTable({ alerts, onAcknowledge }: Props) { const isMobile = useIsMobile(); if (isMobile) { return ( a.id} actions={(a) => !a.acknowledged ? ( ) : null } /> ); } return (
Severity Type Message Created Actions {alerts.map((alert) => ( {alert.severity} {alert.alert_type} {alert.message} {formatTimestamp(alert.created_at)} {!alert.acknowledged && ( )} ))}
); }