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 | 69x 69x 18x 18x 18x 18x 18x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 36x 17x 14x 2x 36x 36x 36x 12x 24x 24x 24x 24x 24x 24x 24x 24x 24x | import { useState, useEffect, useCallback, useRef } from 'react'
import { useParams, useNavigate } from 'react-router-dom'
import { useRun } from './runsApi'
import { RunPhaseIcon } from '@/shared/components/RunPhaseIcon'
import { SourceBadge } from '@/shared/components/SourceBadge'
import { DurationDisplay } from '@/shared/components/DurationDisplay'
import { TokenDisplay } from '@/shared/components/TokenDisplay'
import { Breadcrumb } from '@/shared/components/Breadcrumb'
import { MetadataCard } from '@/shared/components/MetadataCard'
import { CrudModal } from '@/shared/components/CrudModal'
import { Page } from '@/shared/components/Page'
import { RunForm } from '@/features/runs/components/RunForm'
import type { CrudFormRef } from '@/features/runs/components/RunForm'
import { formatDateTime } from '@/shared/utils/format'
import { Button } from '@/components/ui/button'
import { Card, CardContent } from '@/components/ui/card'
import { ChevronDown, ChevronRight, Copy } from 'lucide-react'
import { toast } from 'sonner'
function formatLiveDuration(startedAt: string | undefined): string {
if (!startedAt) return '\u2014'
I const diff = Date.now() - new Date(startedAt).getTime()
const mins = Math.floor(diff / 60000)
if (mins < 1) return 'now'
I if (mins < 60) return `${mins} min`
E const hours = Math.floor(mins / 60)
if (hours < 24) return `${hours}h ${mins % 60}m`
return `${Math.floor(hours / 24)}d ${hours % 24}h`
}
function is404(err: Error): boolean {
return (err as { response?: { status?: number } })?.response?.status === 404
}
export function RunDetailPage() {
const { id } = useParams<{ id: string }>()
const nav = useNavigate()
const { data: run, isLoading, error, refetch } = useRun(id ?? '')
const [showTechDetails, setShowTechDetails] = useState(false)
const [menuOpen, setMenuOpen] = useState(false)
const [formDirty, setFormDirty] = useState(false)
const [formPending, setFormPending] = useState(false)
const formRef = useRef<CrudFormRef>(null)
const [modalOpen, setModalOpen] = useState(false)
const [, forceUpdate] = useState(0)
useEffect(() => {
if (run?.phase === 'running') {
const timer = setInterval(() => forceUpdate((n) => n + 1), 1000)
return () => clearInterval(timer)
}
}, [run?.phase])
const handleCopyRunId = useCallback(() => {
if (run?.run_id) {
navigator.clipboard.writeText(run.run_id)
I toast.success('Run ID copied')
}
setMenuOpen(false)
}, [run])
if (error) {
return (
<div className="flex flex-col items-center gap-4 py-12">
<p className="text-destructive">{is404(error) ? 'Run not found' : 'Failed to load run'}</p>
<Button variant="outline" onClick={() => refetch()}>Retry</Button>
</div>
)
}
if (isLoading || !run) {
return (
<div className="flex flex-col gap-6">
<div className="h-8 w-48 animate-pulse rounded bg-muted" />
<div className="h-48 animate-pulse rounded-lg bg-muted" />
</div>
)
}
const started = run.started_at ?? null
const completed = run.completed_at ?? null
const ms =
started && completed
? new Date(completed).getTime() - new Date(started).getTime()
: null
const totalTokens = (run.token_input ?? 0) + (run.token_output ?? 0)
return (
<Page>
<Breadcrumb items={[
{ label: 'Dashboard', href: '/' },
{ label: 'Runs', href: '/runs' },
{ label: `Run ${run.run_id?.split('-')[0] ?? id}` },
]} />
<div className="flex items-center justify-between">
<h1 className="text-2xl font-bold">{run.project_name} / {run.pipeline_name}</h1>
<div className="flex gap-2">
<Button variant="outline" onClick={() => nav('/runs')}>Back to Runs</Button>
<Button variant="default" onClick={() => setModalOpen(true)}>Re-run</Button>
<div className="relative">
<button
onClick={(e) => { e.stopPropagation(); setMenuOpen(!menuOpen) }}
className="rounded-md border border-input px-2 py-1 text-muted-foreground hover:bg-accent"
aria-label="More options"
>
⋮
</button>
{menuOpen && (
<>
<div className="fixed inset-0 z-10" onClick={() => setMenuOpen(false)} />
<div className="absolute right-0 z-20 w-40 rounded-md border border-border bg-card shadow-lg">
<button
onClick={handleCopyRunId}
className="block w-full px-4 py-2 text-left text-sm hover:bg-accent"
>
Copy Run ID
</button>
<button
onClick={() => { nav(`/projects/${run.project_id}`); setMenuOpen(false) }}
className="block w-full px-4 py-2 text-left text-sm hover:bg-accent"
>
View Project
</button>
</div>
</>
)}
</div>
</div>
</div>
<MetadataCard
fields={[
{
label: 'Run ID',
render: () => (
<span className="flex items-center gap-2 font-mono text-xs">
{run.run_id}
<button
onClick={() => { navigator.clipboard.writeText(run.run_id ?? ''); toast.success('Run ID copied') }}
className="text-muted-foreground hover:text-foreground"
aria-label="Copy Run ID"
>
<Copy className="h-3.5 w-3.5" />
</button>
</span>
),
spanFull: true,
},
{ label: 'Phase', render: () => <RunPhaseIcon phase={run.phase ?? 'pending'} /> },
{
label: 'Source',
render: () => (
<>
{run.source_type && <SourceBadge source={run.source_type} />}
{run.source_metadata?.issue_key && (
<span className="ml-1 text-muted-foreground">
({run.source_metadata.issue_key})
</span>
)}
</>
),
},
{
label: 'Project',
render: () => (
<a href={`#/projects/${run.project_id}`} className="text-primary hover:underline">
{run.project_name}
</a>
),
},
{
label: 'Pipeline',
render: () => (
<a href={`#/pipelines/${run.pipeline_id}`} className="text-primary hover:underline">
{run.pipeline_name}
</a>
),
},
{
label: 'Duration',
render: () =>
run.phase === 'running' ? (
<span className="text-blue-500">{formatLiveDuration(run.started_at ?? undefined)}</span>
) : (
<DurationDisplay ms={ms} />
),
},
{ label: 'Started', value: formatDateTime(run.started_at) },
{
label: 'Completed',
value: run.phase === 'running' ? <span className="text-blue-500">Running...</span> : formatDateTime(run.completed_at),
},
{ label: 'Created', value: formatDateTime(run.created_at) },
{
label: 'Tokens',
render: () =>
run.token_input != null && run.token_output != null ? (
<span>{run.token_input.toLocaleString()} in / {run.token_output.toLocaleString()} out</span>
) : (
<span className="text-muted-foreground">{'\u2014'}</span>
),
},
{
label: 'Exit Code',
render: () => <span className="font-mono">{run.exit_code ?? '\u2014'}</span>,
},
]}
/>
<div className="grid grid-cols-3 gap-4">
<Card>
<CardContent className="flex flex-col gap-1 p-4">
<span className="text-sm text-muted-foreground">Token Input</span>
<span className="text-lg font-bold"><TokenDisplay value={run.token_input ?? 0} /></span>
</CardContent>
</Card>
<Card>
<CardContent className="flex flex-col gap-1 p-4">
<span className="text-sm text-muted-foreground">Token Output</span>
<span className="text-lg font-bold"><TokenDisplay value={run.token_output ?? 0} /></span>
</CardContent>
</Card>
<Card>
<CardContent className="flex flex-col gap-1 p-4">
<span className="text-sm text-muted-foreground">Total</span>
<span className="text-lg font-bold"><TokenDisplay value={totalTokens} /></span>
</CardContent>
</Card>
</div>
{run.error && (
<Card className="border-red-500">
<CardContent className="p-4">
<h3 className="mb-2 font-semibold text-destructive">Error</h3>
<p className="text-sm">{run.error.message}</p>
{run.error.code && (
<p className="mt-1 text-xs text-muted-foreground">
Code: {run.error.code}
</p>
)}
{run.error.details && (
<div className="mt-2">
<button
onClick={() => setShowTechDetails(!showTechDetails)}
className="inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground"
>
{showTechDetails ? <ChevronDown className="h-3 w-3" /> : <ChevronRight className="h-3 w-3" />}
{showTechDetails ? 'Hide Technical Details' : 'Show Technical Details'}
</button>
{showTechDetails && (
<pre className="mt-2 overflow-auto rounded bg-muted p-2 text-xs">
{run.error.details}
</pre>
)}
</div>
)}
</CardContent>
</Card>
)}
{run.output && (
<Card className="border-l-4 border-l-green-500">
<CardContent className="p-4">
<h3 className="mb-2 font-semibold text-green-600">Output</h3>
<pre className="overflow-auto whitespace-pre-wrap rounded bg-muted p-3 text-xs leading-relaxed">
{run.output}
</pre>
</CardContent>
</Card>
)}
<CrudModal
open={modalOpen}
title="Re-run"
isDirty={formDirty}
isPending={formPending}
onClose={() => setModalOpen(false)}
onSave={() => formRef.current?.submit()}
>
<RunForm
ref={formRef}
defaults={{ project_id: run.project_id }}
onSuccess={() => { setModalOpen(false); nav('/runs') }}
onClose={() => setModalOpen(false)}
onDirtyChange={setFormDirty}
onPendingChange={setFormPending}
/>
</CrudModal>
</Page>
)
}
|