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 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | 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 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 26x 26x 26x 13x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 13x 1x 1x 1x 13x 13x 13x 13x 26x 26x 26x 26x 26x 26x 4x 26x 26x 26x 26x 26x 26x 26x 26x 13x 13x 13x 13x 26x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 13x 13x 39x 39x 39x 39x 13x 13x 26x 13x 13x 11x 11x 11x 11x 11x 11x 11x 13x 13x 1x 1x 1x 1x 1x 13x 13x 1x 13x 13x 13x 26x 26x 26x 26x 26x 13x 13x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 13x 13x 13x 1x 1x 1x 1x 1x 1x 1x 1x 1x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 26x 26x 26x 26x 26x 1x 1x 1x 1x 78x 78x 78x 78x 78x 78x 78x 78x 78x 78x 78x 78x 78x 78x 78x 78x 78x 78x 78x 78x 78x 78x 13x 13x 13x 78x 78x 78x 78x 1x 1x | 'use client';
import { useState, useEffect, useCallback } from 'react';
import { Button } from '@/components/ui';
import { Icon } from '@/components/ui/icons';
import { useToast } from '@/hooks/useToast';
import { CategoryBadge } from './CategoryBadge';
import { PriorityBadge } from './PriorityBadge';
import { StatusBadge } from './StatusBadge';
import { SnoozeDropdown } from './SnoozeDropdown';
import { ErrorDetailsTab } from './ErrorDetailsTab';
import { ErrorCommentsTab, type ErrorCommentData } from './ErrorCommentsTab';
import { ErrorHistoryTab, type ErrorHistoryEntry } from './ErrorHistoryTab';
import type { ErrorPriority, Prisma } from '@prisma/client';
type JsonValue = Prisma.JsonValue;
/**
* Error statistic data from API
*/
interface ErrorStatData {
id: number;
fingerprint: string;
category: string;
message: string;
count: number;
lastSeen: string;
firstSeen: string;
status: string;
resolvedAt: string | null;
resolvedBy: number | null;
assignedTo: number | null;
assignedAt: string | null;
priority: ErrorPriority;
snoozedUntil: string | null;
ignoredReason: string | null;
comments: ErrorCommentData[];
history: ErrorHistoryEntry[];
}
/**
* Recent log data from API
*/
interface RecentLogData {
id: number;
level: string;
message: string;
stack: string | null;
url: string | null;
metadata: JsonValue;
createdAt: string;
}
type TabType = 'details' | 'comments' | 'history';
export interface ErrorDetailPanelProps {
/** Error fingerprint to display */
fingerprint: string;
/** Callback when panel is closed */
onClose: () => void;
/** Callback when error is resolved/updated (for parent refresh) */
onUpdate?: () => void;
/** Available team members for assignment */
teamMembers?: Array<{ id: number; email: string; name?: string }>;
}
/**
* ErrorDetailPanel Component
*
* A slide-out panel/modal showing detailed error information with tabs
* for details, comments, and history.
*/
export function ErrorDetailPanel({
fingerprint,
onClose,
onUpdate,
teamMembers = [],
}: ErrorDetailPanelProps) {
const { addToast } = useToast();
const [error, setError] = useState<ErrorStatData | null>(null);
const [recentLogs, setRecentLogs] = useState<RecentLogData[]>([]);
const [isLoading, setIsLoading] = useState(true);
const [isUpdating, setIsUpdating] = useState(false);
const [isAddingComment, setIsAddingComment] = useState(false);
const [activeTab, setActiveTab] = useState<TabType>('details');
// Fetch error details
const fetchErrorDetails = useCallback(async () => {
setIsLoading(true);
try {
const response = await fetch(`/api/admin/monitoring/errors/${fingerprint}`);
const result = await response.json();
if (result.success) {
setError(result.data.error);
setRecentLogs(result.data.recentLogs);
} else {
addToast({ variant: 'error', message: 'Failed to load error details' });
}
} catch {
addToast({ variant: 'error', message: 'Failed to load error details' });
} finally {
setIsLoading(false);
}
}, [fingerprint, addToast]);
useEffect(() => {
fetchErrorDetails();
}, [fetchErrorDetails]);
// Handle error updates (status, priority, assignment, etc.)
const handleUpdate = async (updates: Record<string, unknown>) => {
if (!error) return;
setIsUpdating(true);
try {
const response = await fetch(`/api/admin/monitoring/errors/${fingerprint}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(updates),
});
const result = await response.json();
if (result.success) {
// Refresh to get updated data including history
await fetchErrorDetails();
onUpdate?.();
addToast({ variant: 'success', message: 'Error updated' });
} else {
addToast({ variant: 'error', message: result.error || 'Failed to update error' });
}
} catch {
addToast({ variant: 'error', message: 'Failed to update error' });
} finally {
setIsUpdating(false);
}
};
// Handle adding comments
const handleAddComment = async (content: string) => {
if (!error) return;
setIsAddingComment(true);
try {
const response = await fetch(`/api/admin/monitoring/errors/${fingerprint}/comments`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ content }),
});
const result = await response.json();
if (result.success) {
// Refresh to get updated comments and history
await fetchErrorDetails();
addToast({ variant: 'success', message: 'Comment added' });
} else {
addToast({ variant: 'error', message: result.error || 'Failed to add comment' });
}
} catch {
addToast({ variant: 'error', message: 'Failed to add comment' });
} finally {
setIsAddingComment(false);
}
};
// Handle status changes
const handleStatusChange = (status: string) => {
handleUpdate({ status });
};
// Handle snooze
const handleSnooze = (until: Date | null) => {
handleUpdate({ snoozedUntil: until?.toISOString() || null });
};
// Handle ignore with reason prompt
const handleIgnore = () => {
const reason = window.prompt('Reason for ignoring this error (optional):');
if (reason !== null) {
handleUpdate({ status: 'ignored', ignoredReason: reason || null });
}
};
// Handle keyboard escape
useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
if (e.key === 'Escape') {
onClose();
}
};
document.addEventListener('keydown', handleKeyDown);
return () => document.removeEventListener('keydown', handleKeyDown);
}, [onClose]);
return (
<div
className="fixed inset-0 bg-black/50 flex items-center justify-center z-50"
onClick={(e) => {
if (e.target === e.currentTarget) onClose();
}}
data-testid="error-detail-panel"
>
<div className="bg-white dark:bg-gray-800 rounded-lg w-full max-w-4xl max-h-[90vh] overflow-hidden flex flex-col shadow-xl mx-4">
{/* Header */}
<div className="flex items-start justify-between p-4 border-b dark:border-gray-700">
<div className="flex-1 min-w-0 pr-4">
{isLoading ? (
<div className="animate-pulse">
<div className="h-6 bg-gray-200 dark:bg-gray-700 rounded w-3/4 mb-2" />
<div className="h-4 bg-gray-200 dark:bg-gray-700 rounded w-1/4" />
</div>
) : error ? (
<>
<h2 className="font-semibold text-lg text-gray-900 dark:text-white line-clamp-2">
{error.message}
</h2>
<div className="flex flex-wrap gap-2 mt-2">
<CategoryBadge category={error.category} />
<PriorityBadge priority={error.priority} />
<StatusBadge status={error.status} />
</div>
</>
) : (
<p className="text-gray-500 dark:text-gray-400">Error not found</p>
)}
</div>
<Button
variant="ghost"
size="sm"
onClick={onClose}
className="flex-shrink-0"
aria-label="Close panel"
>
<Icon name="x" size={20} />
</Button>
</div>
{/* Tabs */}
<div className="flex border-b dark:border-gray-700">
<TabButton
active={activeTab === 'details'}
onClick={() => setActiveTab('details')}
>
Details
</TabButton>
<TabButton
active={activeTab === 'comments'}
onClick={() => setActiveTab('comments')}
count={error?.comments.length}
>
Comments
</TabButton>
<TabButton
active={activeTab === 'history'}
onClick={() => setActiveTab('history')}
>
History
</TabButton>
</div>
{/* Content */}
<div className="flex-1 overflow-y-auto p-4">
{isLoading ? (
<div className="space-y-4">
{[...Array(3)].map((_, i) => (
<div key={i} className="animate-pulse">
<div className="h-4 bg-gray-200 dark:bg-gray-700 rounded w-full mb-2" />
<div className="h-4 bg-gray-200 dark:bg-gray-700 rounded w-3/4" />
</div>
))}
</div>
) : error ? (
<>
{activeTab === 'details' && (
<ErrorDetailsTab
error={error}
recentLogs={recentLogs}
onUpdate={handleUpdate}
isUpdating={isUpdating}
teamMembers={teamMembers}
/>
)}
{activeTab === 'comments' && (
<ErrorCommentsTab
comments={error.comments}
onAddComment={handleAddComment}
isAdding={isAddingComment}
/>
)}
{activeTab === 'history' && (
<ErrorHistoryTab history={error.history} />
)}
</>
) : (
<p className="text-center text-gray-500 dark:text-gray-400 py-8">
Error not found
</p>
)}
</div>
{/* Actions Footer */}
{error && (
<div className="flex flex-wrap gap-2 p-4 border-t dark:border-gray-700 bg-gray-50 dark:bg-gray-900">
{error.status !== 'resolved' && (
<Button
onClick={() => handleStatusChange('resolved')}
disabled={isUpdating}
data-testid="resolve-button"
>
{isUpdating ? (
<Icon name="loader" size={16} className="mr-1 animate-spin" />
) : (
<Icon name="check" size={16} className="mr-1" />
)}
Mark Resolved
</Button>
)}
{error.status === 'resolved' && (
<Button
variant="secondary"
onClick={() => handleStatusChange('open')}
disabled={isUpdating}
data-testid="reopen-button"
>
<Icon name="refresh-cw" size={16} className="mr-1" />
Reopen
</Button>
)}
{error.status !== 'ignored' && (
<Button
variant="secondary"
onClick={handleIgnore}
disabled={isUpdating}
data-testid="ignore-button"
>
<Icon name="eye-off" size={16} className="mr-1" />
Ignore
</Button>
)}
<SnoozeDropdown
currentSnoozedUntil={error.snoozedUntil}
onSnooze={handleSnooze}
disabled={isUpdating}
/>
</div>
)}
</div>
</div>
);
}
/**
* Tab button helper component
*/
function TabButton({
active,
onClick,
children,
count,
}: {
active: boolean;
onClick: () => void;
children: React.ReactNode;
count?: number;
}) {
return (
<button
onClick={onClick}
className={`px-4 py-3 text-sm font-medium border-b-2 transition-colors ${
active
? 'border-blue-500 text-blue-600 dark:text-blue-400'
: 'border-transparent text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300'
}`}
>
{children}
{count !== undefined && count > 0 && (
<span className="ml-1 text-xs bg-gray-200 dark:bg-gray-700 rounded-full px-1.5 py-0.5">
{count}
</span>
)}
</button>
);
}
export default ErrorDetailPanel;
|