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 | 85x 85x 182x 182x 182x 182x 182x 182x 182x 84x 84x 84x 42x 28x 14x 42x 28x 14x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 42x 42x 42x 42x 32x 32x 32x 18x 18x 14x 14x | import { useState } from 'react'
import { useParams, useNavigate } from 'react-router-dom'
import { useProject, useDeleteProject } from './projectsApi'
import { useRuns } from '@/features/runs/runsApi'
import { DataTable, type Column } from '@/shared/components/DataTable'
import { Breadcrumb } from '@/shared/components/Breadcrumb'
import { ConfirmDialog } from '@/shared/components/ConfirmDialog'
import { RunPhaseIcon } from '@/shared/components/RunPhaseIcon'
import { SourceBadge } from '@/shared/components/SourceBadge'
import { DurationDisplay } from '@/shared/components/DurationDisplay'
import { Button } from '@/components/ui/button'
import { Card, CardContent } from '@/components/ui/card'
import { formatDateTime } from '@/shared/utils/format'
function relativeTime(dateStr: string | undefined): string {
if (!dateStr) return '\u2014'
const diff = Date.now() - new Date(dateStr).getTime()
I const mins = Math.floor(diff / 60000)
if (mins < 1) return 'now'
if (mins < 60) return `${mins} min ago`
I const hours = Math.floor(mins / 60)
I if (hours < 24) return `${hours}h ago`
const days = Math.floor(hours / 24)
if (days < 7) return `${days}d ago`
return new Date(dateStr).toLocaleDateString()
}I
function statusIcon(status: string | undefined): string {
switch (status) {
case 'succeeded': return '\u2705'
case 'failed': return '\u274C'
case 'running': return '\u26A0\uFE0F'
default: return '\u26AA'
}
}
function statusColor(status: string | undefined): string {
switch (status) {
case 'succeeded': return 'text-green-500'
case 'failed': return 'text-red-500'
case 'running': return 'text-yellow-500'
default: return 'text-muted-foreground'
}
}
export function ProjectDetailPage() {
const { id } = useParams<{ id: string }>()
const navigate = useNavigate()
const { data, isLoading, error, refetch } = useProject(id ?? '')
const deleteProject = useDeleteProject()
const [deleteProjectId, setDeleteProjectId] = useState<string | null>(null)
const project = data?.project
const pipelines = data?.pipelines ?? []
const { data: runsData, isLoading: runsLoading } = useRuns({
project_id: id,
limit: 10,
})
const runs = runsData?.data ?? []
function handleDeleteProject() {
if (deleteProjectId) {
deleteProject.mutate(deleteProjectId)
setDeleteProjectId(null)
navigate('/projects', { replace: true })
}
}
const pipelineColumns: Column[] = [
{
key: 'name',
label: 'Name',
render: (item) => (
<a
href={`#/pipelines/${item.id as string}`}
className="text-primary hover:underline"
onClick={(e) => e.stopPropagation()}
>
{item.name as string}
</a>
),
},
{ key: 'manifest_source_url', label: 'Manifest Source' },
{
key: 'last_run_status',
label: 'Status',
render: (item) => {
const status = item.last_run_status as string | undefined
return (
<span className={statusColor(status)}>
{statusIcon(status)}
</span>
)
},
},
{
key: 'last_run_at',
label: 'Last Run',
render: (item) => (
<span className="text-sm text-muted-foreground">
{relativeTime(item.last_run_at as string | undefined)}
</span>
),
},
]
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 ? 'Project not found' : 'Failed to load project'}</p>
I <Button variant="outline" onClick={() => refetch()}>Retry</Button>
</div>
)
}
if (isLoading || !project) {
return (
<div className="flex flex-col gap-6">
<div className="h-8 w-48 animate-pulse rounded bg-muted" />
<div className="h-32 animate-pulse rounded-lg bg-muted" />
</div>
)
}
return (
<div className="flex flex-col gap-6">
<Breadcrumb items={[
{ label: 'Dashboard', href: '/' },
{ label: 'Projects', href: '/projects' },
{ label: project.name },
]} />
<div className="flex items-center justify-between">
<h1 className="text-2xl font-bold">{project.name}</h1>
<div className="flex gap-2">
<Button variant="ghost" onClick={() => navigate(`/runs?project_id=${id}`)}>
View Runs
</Button>
<Button variant="outline" onClick={() => navigate(`/projects/${id}/edit`)}>
Edit
</Button>
<Button variant="destructive" onClick={() => setDeleteProjectId(project.id)}>
Delete
</Button>
</div>
</div>
<Card>
<CardContent className="grid grid-cols-2 gap-4 p-4 text-sm">
<div>
<span className="text-muted-foreground">Description</span>
<p>{project.description ?? '\u2014'}</p>
</div>
<div>
<span className="text-muted-foreground">Pipeline count</span>
<p>{project.pipeline_count}</p>
</div>
<div>
<span className="text-muted-foreground">Created</span>
<p>{formatDateTime(project.created_at)}</p>
</div>
<div>
<span className="text-muted-foreground">Updated</span>
<p>{formatDateTime(project.updated_at)}</p>
</div>
</CardContent>
</Card>
<div className="flex items-center justify-between">
<h2 className="text-lg font-semibold">Pipelines</h2>
<Button onClick={() => navigate(`/projects/${id}/pipelines/new`)}>
New Pipeline
</Button>
</div>
<DataTable
columns={pipelineColumns}
data={pipelines as unknown as Record<string, unknown>[]}
emptyMessage="No pipelines configured"
emptyAction={
<Button
variant="outline"
onClick={() => navigate(`/projects/${id}/pipelines/new`)}
>
Create your first pipeline
</Button>
}
onRowClick={(item) => navigate(`/pipelines/${item.id as string}`)}
/>
<h2 className="text-lg font-semibold">Recent Runs</h2>
<DataTable
columns={[
{
key: 'phase',
label: 'Phase',
render: (item) => (
<RunPhaseIcon phase={item.phase as 'pending' | 'running' | 'succeeded' | 'failed'} />
),
},
{
key: 'pipeline_name',
label: 'Pipeline',
render: (item) => (
<a
href={`#/pipelines/${item.pipeline_id as string}`}
className="text-primary hover:underline"
onClick={(e) => e.stopPropagation()}
>
{item.pipeline_name as string}
</a>
),
},
{
key: 'source_type',
label: 'Source',
render: (item) => (
<SourceBadge source={item.source_type as 'manual' | 'webhook' | 'schedule' | 'cli'} />
),
},
{
key: 'created_at',
label: 'Created',
render: (item) => (
<span className="text-sm text-muted-foreground">{relativeTime(item.created_at as string)}</span>
),
},
{
key: 'tokens',
label: 'Tokens',
render: (item) => {
const input = item.token_input as number
const output = item.token_output as number
return <span>{(input + output).toLocaleString()}</span>
},
},
{
key: 'duration',
label: 'Duration',
render: (item) => {
const started = item.started_at as string | null
const completed = item.completed_at as string | null
const ms =
started && completed
? new Date(completed).getTime() - new Date(started).getTime()
: null
return <DurationDisplay ms={ms} />
},
},
]}
data={runs as unknown as Record<string, unknown>[]}
isLoading={runsLoading}
emptyMessage="No runs for this project"
onRowClick={(item) => navigate(`/runs/${item.run_id as string}`)}
/>
<ConfirmDialog
open={!!deleteProjectId}
title="Delete project"
message="Are you sure? This will also delete all pipelines."
onConfirm={handleDeleteProject}
onCancel={() => setDeleteProjectId(null)}
/>
</div>
)
}
|