54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
/**
|
|
* Health Alert Display Object
|
|
*
|
|
* Provides formatting and display logic for health alerts.
|
|
* This display object isolates UI-specific formatting from business logic.
|
|
*/
|
|
|
|
export class HealthAlertDisplay {
|
|
static formatSeverity(type: 'critical' | 'warning' | 'info'): string {
|
|
const severities: Record<string, string> = {
|
|
critical: 'Critical',
|
|
warning: 'Warning',
|
|
info: 'Info',
|
|
};
|
|
return severities[type] || 'Info';
|
|
}
|
|
|
|
static formatSeverityColor(type: 'critical' | 'warning' | 'info'): string {
|
|
const colors: Record<string, string> = {
|
|
critical: '#ef4444', // red-500
|
|
warning: '#f59e0b', // amber-500
|
|
info: '#3b82f6', // blue-500
|
|
};
|
|
return colors[type] || '#3b82f6';
|
|
}
|
|
|
|
static formatTimestamp(timestamp: string): string {
|
|
const date = new Date(timestamp);
|
|
return date.toLocaleString('en-US', {
|
|
year: 'numeric',
|
|
month: 'short',
|
|
day: 'numeric',
|
|
hour: '2-digit',
|
|
minute: '2-digit',
|
|
second: '2-digit',
|
|
});
|
|
}
|
|
|
|
static formatRelativeTime(timestamp: string): string {
|
|
const now = new Date();
|
|
const date = new Date(timestamp);
|
|
const diffMs = now.getTime() - date.getTime();
|
|
const diffMins = Math.floor(diffMs / 60000);
|
|
const diffHours = Math.floor(diffMs / 3600000);
|
|
const diffDays = Math.floor(diffMs / 86400000);
|
|
|
|
if (diffMins < 1) return 'Just now';
|
|
if (diffMins < 60) return `${diffMins}m ago`;
|
|
if (diffHours < 24) return `${diffHours}h ago`;
|
|
if (diffDays < 7) return `${diffDays}d ago`;
|
|
return `${Math.floor(diffDays / 7)}w ago`;
|
|
}
|
|
}
|