Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 21x 21x 21x 21x 19x 21x 1x 21x 1x 21x 21x 21x 1x 1x 1x 1x 21x 21x 21x 21x 21x 21x 21x 21x 1x 1x 1x 1x 1x 22x 22x 22x 22x 22x 22x 22x 22x 22x 2x 2x 2x 2x 2x 2x 2x 22x 22x 22x 1x 1x 1x 1x 1x 1x 1x 22x 22x 22x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 20x 20x 20x 20x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 20x 20x 20x 20x 20x 20x 20x 20x 3x 20x 17x 20x 20x 20x 20x 20x 20x 20x 20x 20x 3x 20x 17x 20x 20x 20x 21x 21x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 21x 21x 21x 21x 21x 20x 20x 20x 20x 1x 1x | 'use client';
import { useState } from 'react';
import { cn } from '@/lib/core';
import { StatusIndicator } from '../StatusIndicator';
import { Button } from '@/components/ui/Button';
import { Icon } from '@/components/ui/icons';
import type { PerformanceAlert, PerformanceAlertConfig } from '@prisma/client';
export interface ActiveAlertsListProps {
/** List of active alerts with their configs */
alerts: (PerformanceAlert & { config: PerformanceAlertConfig })[];
/** Callback when acknowledging an alert */
onAcknowledge?: (alertId: string) => Promise<void>;
/** Callback when resolving an alert */
onResolve?: (alertId: string) => Promise<void>;
/** Additional CSS classes */
className?: string;
}
/**
* Get metric unit for display
*/
function getMetricUnit(metricType: string): string {
switch (metricType) {
case 'response_time':
case 'p95_latency':
return 'ms';
case 'error_rate':
return '%';
case 'throughput':
return ' req/min';
default:
return '';
}
}
/**
* Format time ago
*/
function formatTimeAgo(date: Date): string {
const now = new Date();
const diffMs = now.getTime() - new Date(date).getTime();
const diffMins = Math.floor(diffMs / 60000);
const diffHours = Math.floor(diffMins / 60);
const diffDays = Math.floor(diffHours / 24);
if (diffMins < 1) return 'Just now';
if (diffMins < 60) return `${diffMins}m ago`;
if (diffHours < 24) return `${diffHours}h ago`;
return `${diffDays}d ago`;
}
/**
* ActiveAlertsList displays a list of currently active performance alerts
* with options to acknowledge or resolve them.
*/
export function ActiveAlertsList({
alerts,
onAcknowledge,
onResolve,
className,
}: ActiveAlertsListProps) {
const [loadingId, setLoadingId] = useState<string | null>(null);
const handleAcknowledge = async (alertId: string) => {
if (!onAcknowledge) return;
setLoadingId(alertId);
try {
await onAcknowledge(alertId);
} finally {
setLoadingId(null);
}
};
const handleResolve = async (alertId: string) => {
if (!onResolve) return;
setLoadingId(alertId);
try {
await onResolve(alertId);
} finally {
setLoadingId(null);
}
};
if (alerts.length === 0) {
return (
<div className={cn('bg-green-50 dark:bg-green-900/20 rounded-lg p-6 text-center', className)}>
<Icon name="check-circle" className="mx-auto h-12 w-12 text-green-500" />
<h3 className="mt-3 text-lg font-medium text-green-800 dark:text-green-200">
All Clear
</h3>
<p className="mt-1 text-sm text-green-600 dark:text-green-400">
No active performance alerts at this time.
</p>
</div>
);
}
return (
<div className={cn('space-y-3', className)}>
{alerts.map((alert) => {
const unit = getMetricUnit(alert.metricType);
const isLoading = loadingId === alert.id;
return (
<div
key={alert.id}
className={cn(
'rounded-lg border p-4',
alert.severity === 'critical'
? 'bg-red-50 dark:bg-red-900/20 border-red-200 dark:border-red-800'
: 'bg-yellow-50 dark:bg-yellow-900/20 border-yellow-200 dark:border-yellow-800'
)}
>
<div className="flex items-start justify-between gap-4">
<div className="flex items-start gap-3">
<StatusIndicator
status={alert.severity as 'warning' | 'critical'}
size="lg"
animate
/>
<div>
<h4 className="font-medium text-gray-900 dark:text-white">
{alert.config.name}
</h4>
<p className="mt-1 text-sm text-gray-600 dark:text-gray-400">
{alert.message}
</p>
<div className="mt-2 flex flex-wrap items-center gap-x-4 gap-y-1 text-xs text-gray-500 dark:text-gray-400">
<span>
Value: <strong>{alert.value.toFixed(2)}{unit}</strong>
</span>
<span>
Threshold: {alert.threshold.toFixed(2)}{unit}
</span>
<span>
Scope: <code className="bg-gray-100 dark:bg-gray-800 px-1 rounded">{alert.scope}</code>
</span>
<span>
{formatTimeAgo(alert.triggeredAt)}
</span>
</div>
</div>
</div>
<div className="flex items-center gap-2 shrink-0">
{alert.status === 'active' && (
<>
<Button
variant="outline"
size="sm"
onClick={() => handleAcknowledge(alert.id)}
disabled={isLoading}
>
{isLoading ? (
<Icon name="spinner" className="h-4 w-4 animate-spin" />
) : (
'Acknowledge'
)}
</Button>
<Button
variant="primary"
size="sm"
onClick={() => handleResolve(alert.id)}
disabled={isLoading}
>
{isLoading ? (
<Icon name="spinner" className="h-4 w-4 animate-spin" />
) : (
'Resolve'
)}
</Button>
</>
)}
{alert.status === 'acknowledged' && (
<Button
variant="primary"
size="sm"
onClick={() => handleResolve(alert.id)}
disabled={isLoading}
>
{isLoading ? (
<Icon name="spinner" className="h-4 w-4 animate-spin" />
) : (
'Resolve'
)}
</Button>
)}
</div>
</div>
</div>
);
})}
</div>
);
}
export default ActiveAlertsList;
|