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 | 37x 37x 6x 6x 6x 6x 6x 6x 6x 6x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 11x 1x 1x 26x 11x 1x 26x 11x 26x 26x 26x 8x 18x 18x 18x 18x | import { useState, useEffect, useCallback } from 'react'
import { useParams, useNavigate } from 'react-router-dom'
import { useRun, useCreateRun } from './runsApi'
import { useProjects } from '@/features/projects/projectsApi'
import { usePipelines } from '@/features/pipelines/pipelinesApi'
import { ManualTriggerModal } from '@/shared/components/ManualTriggerModal'
import { RunPhaseIcon } from '@/shared/components/RunPhaseIcon'
import { SourceBadge } from '@/shared/components/SourceBadge'
import { TokenDisplay } from '@/shared/components/TokenDisplay'
import { DurationDisplay } from '@/shared/components/DurationDisplay'
import { Breadcrumb } from '@/shared/components/Breadcrumb'
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'
const diff = Date.now() - new Date(startedAt).getTime()
I const totalSeconds = Math.floor(diff / 1000)
const hours = Math.floor(totalSeconds / 3600)
const minutes = Math.floor((totalSeconds % 3600) / 60)
const seconds = totalSeconds % 60
if (hours > 0) return `${hours}h ${minutes}m ${seconds}s`
if (minutes > 0) return `${minutes}m ${seconds}s`
I return `${seconds}s`
}E
export function RunDetailPage() {
const { id } = useParams<{ id: string }>()
const navigate = useNavigate()
const { data: run, isLoading, error, refetch } = useRun(id ?? '')
const createRun = useCreateRun()
const [menuOpen, setMenuOpen] = useState(false)
const [showTechDetails, setShowTechDetails] = useState(false)
const [, setTick] = useState(0)
const [modalOpen, setModalOpen] = useState(false)
const [selectedProjectId, setSelectedProjectId] = useState('')
const { data: projectsData } = useProjects()
const { data: pipelinesData } = usePipelines(selectedProjectId)
const projects = projectsData?.data ?? []
const pipelines = pipelinesData?.data ?? []
useEffect(() => {
if (run?.phase === 'running') {
const timer = setInterval(() => setTick((t) => t + 1), 1000)
return () => clearInterval(timer)
}
}, [run?.phase])
useEffect(() => {
if (run?.phase === 'running') {
setTick(1)
}
}, [run?.phase, run?.started_at])
useEffect(() => {
setSelectedProjectId(run?.project_id ?? '')
}, [run?.project_id])
const handleCopyRunId = useCallback(() => {
if (run?.run_id) {
navigator.clipboard.writeText(run.run_id)
toast.success('Run ID copied')
}
setMenuOpen(false)
}, [run])
function handleTriggerRun(pipelineId: string, issueKey?: string, additionalData?: string) {
let sourceMetadata: Record<string, unknown> | null = null
if (issueKey || additionalData) {
sourceMetadata = {}
if (issueKey) sourceMetadata.issue_key = issueKey
if (additionalData) {
try {
const parsed = JSON.parse(additionalData)
Object.assign(sourceMetadata, parsed)
} catch {
sourceMetadata.additional_data = additionalData
}
}
}
createRun.mutate(
{ pipeline_id: pipelineId, source_type: 'manual', source_metadata: sourceMetadata as never },
{
onSuccess: (newRun) => {
setModalOpen(false)
I navigate(`/runs/${newRun.run_id}`, { replace: true })
},
},
)
}
if (error) {
const is404 = (error as { response?: { status?: number } })?.response?.status === 404
return (
<div className="flex flex-col items-center gap-4 py-12">
<p className="text-destructive">{is404 ? '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
return (
<div className="flex flex-col gap-6">
<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={() => navigate('/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={() => { navigate(`/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>
<Card>
<CardContent className="grid grid-cols-2 gap-4 p-4 text-sm">
<div>
<span className="text-muted-foreground">Run ID</span>
<p 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>
</p>
</div>
<div>
<span className="text-muted-foreground">Phase</span>
<p>{run.phase && <RunPhaseIcon phase={run.phase} />}</p>
</div>
<div>
<span className="text-muted-foreground">Source</span>
<p>
{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>
)}
</p>
</div>
<div>
<span className="text-muted-foreground">Project</span>
<p>
<a
href={`#/projects/${run.project_id}`}
className="text-primary hover:underline"
>
{run.project_name}
</a>
</p>
</div>
<div>
<span className="text-muted-foreground">Pipeline</span>
<p>
<a
href={`#/pipelines/${run.pipeline_id}`}
className="text-primary hover:underline"
>
{run.pipeline_name}
</a>
</p>
</div>
<div>
<span className="text-muted-foreground">Duration</span>
<p>
{run.phase === 'running'
? <span className="tabular-nums">{formatLiveDuration(run.started_at ?? undefined)}</span>
: <DurationDisplay ms={ms} />
}
</p>
</div>
<div>
<span className="text-muted-foreground">Started</span>
<p>{formatDateTime(run.started_at)}</p>
</div>
<div>
<span className="text-muted-foreground">Completed</span>
<p>
{run.phase === 'running'
? <span className="text-blue-500">Running...</span>
: formatDateTime(run.completed_at)
}
</p>
</div>
<div>
<span className="text-muted-foreground">Created</span>
<p>{formatDateTime(run.created_at)}</p>
</div>
</CardContent>
</Card>
<div className="grid grid-cols-3 gap-4">
<Card>
<CardContent className="p-4 text-center">
<span className="text-sm text-muted-foreground">Token Input</span>
<p className="text-xl font-bold">
<TokenDisplay value={run.token_input ?? 0} />
</p>
</CardContent>
</Card>
<Card>
<CardContent className="p-4 text-center">
<span className="text-sm text-muted-foreground">Token Output</span>
<p className="text-xl font-bold">
<TokenDisplay value={run.token_output ?? 0} />
</p>
</CardContent>
</Card>
<Card>
<CardContent className="p-4 text-center">
<span className="text-sm text-muted-foreground">Total</span>
<p className="text-xl font-bold">
<TokenDisplay value={(run.token_input ?? 0) + (run.token_output ?? 0)} />
</p>
</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>
)}
<ManualTriggerModal
open={modalOpen}
projects={projects}
pipelines={pipelines}
initialProjectId={run.project_id ?? undefined}
initialPipelineId={run.pipeline_id ?? undefined}
onProjectChange={(pid) => setSelectedProjectId(pid)}
onSubmit={handleTriggerRun}
onCancel={() => setModalOpen(false)}
/>
</div>
)
}
|