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 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 20x 20x 20x 20x 1x 20x 20x 20x 20x 1x 40x 40x 20x 20x 40x 1x 1x 1x 1x 19x 19x 38x 10x 10x 9x 9x 9x 1x 1x 1x 1x 1x 1x 11x 11x 11x 11x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 13x 13x 13x 20x 20x 7x 7x 7x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 11x 11x 11x 1x 1x 1x 11x 11x 11x 11x 1x 1x | 'use client';
import { formatDistanceToNow, format } from 'date-fns';
import { Icon, type IconName } from '@/components/ui/icons';
import type { ErrorAction } from '@prisma/client';
/**
* History entry data structure
*/
export interface ErrorHistoryEntry {
id: string;
userId: number;
userEmail: string;
action: ErrorAction | string;
previousValue: string | null;
newValue: string | null;
createdAt: Date | string;
}
export interface ErrorHistoryTabProps {
/** List of history entries */
history: ErrorHistoryEntry[];
}
const actionConfig: Record<string, { label: string; icon: IconName; color: string }> = {
CREATED: {
label: 'created this error',
icon: 'plus-circle',
color: 'text-green-500',
},
ASSIGNED: {
label: 'assigned to',
icon: 'user-plus',
color: 'text-blue-500',
},
UNASSIGNED: {
label: 'unassigned',
icon: 'user-minus',
color: 'text-gray-500',
},
PRIORITY_CHANGED: {
label: 'changed priority',
icon: 'flag',
color: 'text-orange-500',
},
STATUS_CHANGED: {
label: 'changed status',
icon: 'activity',
color: 'text-purple-500',
},
COMMENTED: {
label: 'added a comment',
icon: 'message-circle',
color: 'text-blue-400',
},
SNOOZED: {
label: 'snoozed until',
icon: 'clock',
color: 'text-purple-400',
},
UNSNOOZED: {
label: 'unsnoozed',
icon: 'bell',
color: 'text-yellow-500',
},
IGNORED: {
label: 'ignored',
icon: 'eye-off',
color: 'text-gray-400',
},
REOPENED: {
label: 'reopened',
icon: 'refresh-cw',
color: 'text-green-400',
},
};
function formatRelativeTime(date: Date | string): string {
const d = typeof date === 'string' ? new Date(date) : date;
return formatDistanceToNow(d, { addSuffix: true });
}
function formatDateFull(date: Date | string): string {
const d = typeof date === 'string' ? new Date(date) : date;
return format(d, 'PPpp');
}
function formatValue(value: string | null, action: string): string | null {
if (!value) return null;
// Format dates for snooze
if (action === 'SNOOZED' && value) {
try {
return format(new Date(value), 'PPp');
} catch {
return value;
}
}
// Format priority values
if (action === 'PRIORITY_CHANGED') {
return value.charAt(0) + value.slice(1).toLowerCase();
}
return value;
}
/**
* ErrorHistoryTab Component
*
* Displays audit trail/history of all actions taken on an error.
*/
export function ErrorHistoryTab({ history }: ErrorHistoryTabProps) {
return (
<div className="space-y-2" data-testid="error-history-tab">
{history.map((entry) => {
const config = actionConfig[entry.action] || {
label: entry.action.toLowerCase().replace(/_/g, ' '),
icon: 'activity' as IconName,
color: 'text-gray-500',
};
const formattedPrevious = formatValue(entry.previousValue, entry.action);
const formattedNew = formatValue(entry.newValue, entry.action);
return (
<div
key={entry.id}
className="flex items-start gap-3 py-3 border-b border-gray-200 dark:border-gray-700 last:border-0"
data-testid="history-entry"
>
<div className={`mt-0.5 ${config.color}`}>
<Icon name={config.icon} size={16} />
</div>
<div className="flex-1 min-w-0">
<div className="flex flex-wrap items-center gap-1 text-sm">
<span className="font-medium text-gray-900 dark:text-white">
{entry.userEmail}
</span>
<span className="text-gray-500 dark:text-gray-400">
{config.label}
</span>
{formattedNew && (
<span className="font-medium text-gray-900 dark:text-white">
{formattedNew}
</span>
)}
{formattedPrevious && formattedNew && entry.action !== 'SNOOZED' && (
<span className="text-gray-500 dark:text-gray-400">
(from {formattedPrevious})
</span>
)}
</div>
<p
className="text-xs text-gray-500 dark:text-gray-400 mt-0.5"
title={formatDateFull(entry.createdAt)}
>
{formatRelativeTime(entry.createdAt)}
</p>
</div>
</div>
);
})}
{history.length === 0 && (
<p className="text-gray-500 dark:text-gray-400 text-center py-8">
No history available
</p>
)}
</div>
);
}
export default ErrorHistoryTab;
|