/** * Pipeline Health Alerts Component * * Displays critical pipeline alerts on the admin error monitoring dashboard. * Shows top 10 active alerts with severity-based styling and resolution actions. */ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { useSystemAlerts } from '@/hooks/useSystemHealth'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { AlertTriangle, CheckCircle, XCircle, AlertCircle } from 'lucide-react'; import { format } from 'date-fns'; import { supabase } from '@/lib/supabaseClient'; import { toast } from 'sonner'; const SEVERITY_CONFIG = { critical: { color: 'destructive', icon: XCircle }, high: { color: 'destructive', icon: AlertCircle }, medium: { color: 'default', icon: AlertTriangle }, low: { color: 'secondary', icon: CheckCircle }, } as const; const ALERT_TYPE_LABELS: Record = { failed_submissions: 'Failed Submissions', high_ban_rate: 'High Ban Attempt Rate', temp_ref_error: 'Temp Reference Error', orphaned_images: 'Orphaned Images', slow_approval: 'Slow Approvals', submission_queue_backlog: 'Queue Backlog', ban_attempt: 'Ban Attempt', upload_timeout: 'Upload Timeout', high_error_rate: 'High Error Rate', validation_error: 'Validation Error', stale_submissions: 'Stale Submissions', circular_dependency: 'Circular Dependency', rate_limit_violation: 'Rate Limit Violation', }; export function PipelineHealthAlerts() { const { data: criticalAlerts } = useSystemAlerts('critical'); const { data: highAlerts } = useSystemAlerts('high'); const { data: mediumAlerts } = useSystemAlerts('medium'); const allAlerts = [ ...(criticalAlerts || []), ...(highAlerts || []), ...(mediumAlerts || []) ].slice(0, 10); const resolveAlert = async (alertId: string) => { const { error } = await supabase .from('system_alerts') .update({ resolved_at: new Date().toISOString() }) .eq('id', alertId); if (error) { toast.error('Failed to resolve alert'); } else { toast.success('Alert resolved'); } }; if (!allAlerts.length) { return ( Pipeline Health: All Systems Operational

No active alerts. The sacred pipeline is flowing smoothly.

); } return ( 🚨 Active Pipeline Alerts Critical issues requiring attention ({allAlerts.length} active) {allAlerts.map((alert) => { const config = SEVERITY_CONFIG[alert.severity]; const Icon = config.icon; const label = ALERT_TYPE_LABELS[alert.alert_type] || alert.alert_type; return (
{alert.severity.toUpperCase()} {label}

{alert.message}

{format(new Date(alert.created_at), 'PPp')}

); })}
); }