'use client'; import { format } from 'date-fns'; import { LoaderCircle, X } from 'lucide-react'; import { useTaskTimelineQuery } from '@/hooks/use-api-queries'; import { buildStageTimeline, stageLabel, taskTypeLabel } from '@/components/notifications/task-stage-helpers'; import { StatusPill } from '@/components/ui/status-pill'; import { Button } from '@/components/ui/button'; function formatTimestamp(value: string | null) { if (!value) { return 'n/a'; } const parsed = new Date(value); if (Number.isNaN(parsed.getTime())) { return 'n/a'; } return format(parsed, 'MMM dd, yyyy HH:mm:ss'); } type TaskDetailModalProps = { isOpen: boolean; taskId: string | null; onClose: () => void; }; export function TaskDetailModal({ isOpen, taskId, onClose }: TaskDetailModalProps) { const { data, isLoading, error } = useTaskTimelineQuery(taskId ?? '', isOpen && Boolean(taskId)); if (!isOpen || !taskId) { return null; } const task = data?.task ?? null; const events = data?.events ?? []; const timeline = task ? buildStageTimeline(task, events) : []; return (
Job details
{taskId}
Unable to load task timeline.
) : null} {task ? ( <>Stage: {stageLabel(task.stage)}
Workflow run: {task.workflow_run_id ?? 'n/a'}
Created: {formatTimestamp(task.created_at)}
Finished: {formatTimestamp(task.finished_at)}
Updated: {formatTimestamp(task.updated_at)}
Attempts: {task.attempts}/{task.max_attempts}
Stage timeline
{item.label}
{item.state}{item.detail}
: null}{formatTimestamp(item.timestamp)}
Error
{task.error}
Result summary
{JSON.stringify(task.result, null, 2)}