Skip to content

An open-source, faster Devin alternative

TypeScript

feat(web): reskin Templates + extend StatusBadge lifecycle map

Igor Zalutski76386551265b
diff --git a/web/src/components/status-badge.tsx b/web/src/components/status-badge.tsx
index 37278118..65972b3f 100644
--- a/web/src/components/status-badge.tsx
+++ b/web/src/components/status-badge.tsx
@@ -4,6 +4,7 @@ import {
CircleSlash,
Moon,
Clock,
+ Loader2,
type LucideIcon,
} from 'lucide-react'
import { cn } from '@/lib/utils'
@@ -19,17 +20,34 @@ const TONE_CLASS: Record<Tone, string> = {
pending: 'bg-status-pending-bg text-status-pending',
}
-type Meta = { tone: Tone; label: string; icon: LucideIcon }
+type Meta = { tone: Tone; label: string; icon: LucideIcon; spin?: boolean }
// Raw API status strings -> lifecycle tone + label + non-color (icon) cue.
const STATUS: Record<string, Meta> = {
running: { tone: 'running', label: 'Running', icon: CircleCheck },
ready: { tone: 'running', label: 'Ready', icon: CircleCheck },
+ active: { tone: 'running', label: 'Active', icon: CircleCheck },
+ success: { tone: 'running', label: 'Success', icon: CircleCheck },
stopped: { tone: 'stopped', label: 'Stopped', icon: CircleSlash },
+ canceled: { tone: 'stopped', label: 'Canceled', icon: CircleSlash },
+ unknown: { tone: 'stopped', label: 'Unknown', icon: CircleSlash },
hibernated: { tone: 'hibernated', label: 'Hibernated', icon: Moon },
+ paused: { tone: 'hibernated', label: 'Paused', icon: Moon },
pending: { tone: 'pending', label: 'Pending', icon: Clock },
+ queued: { tone: 'pending', label: 'Queued', icon: Clock },
+ building: { tone: 'pending', label: 'Building', icon: Loader2, spin: true },
+ processing: {
+ tone: 'pending',
+ label: 'Processing',
+ icon: Loader2,
+ spin: true,
+ },
+ starting: { tone: 'pending', label: 'Starting', icon: Loader2, spin: true },
+ creating: { tone: 'pending', label: 'Creating', icon: Loader2, spin: true },
+ deleting: { tone: 'pending', label: 'Deleting', icon: Loader2, spin: true },
error: { tone: 'error', label: 'Error', icon: CircleAlert },
failed: { tone: 'error', label: 'Failed', icon: CircleAlert },
+ degraded: { tone: 'error', label: 'Degraded', icon: CircleAlert },
}
function titleCase(s: string) {
@@ -60,7 +78,10 @@ export function StatusBadge({
className,
)}
>
- <Icon className="size-3.5" aria-hidden />
+ <Icon
+ className={cn('size-3.5', meta.spin && 'animate-spin')}
+ aria-hidden
+ />
{label ?? meta.label}
</span>
)
diff --git a/web/src/pages/Templates.tsx b/web/src/pages/Templates.tsx
index 4d152eeb..6db2a982 100644
--- a/web/src/pages/Templates.tsx
+++ b/web/src/pages/Templates.tsx
@@ -1,150 +1,171 @@
-import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
-import { getImages, deleteImage, type ImageCacheItem } from '../api/client'
-
-function StatusBadge({ status }: { status: string }) {
- const isReady = status === 'ready'
- const isFailed = status === 'failed'
- return (
- <span style={{
- fontSize: 11,
- fontWeight: 600,
- padding: '2px 8px',
- borderRadius: 10,
- background: isReady
- ? 'rgba(34, 197, 94, 0.08)'
- : isFailed
- ? 'rgba(251, 113, 133, 0.08)'
- : 'rgba(234, 179, 8, 0.08)',
- color: isReady
- ? 'var(--accent-green)'
- : isFailed
- ? 'var(--accent-rose)'
- : '#eab308',
- border: `1px solid ${
- isReady
- ? 'rgba(34, 197, 94, 0.15)'
- : isFailed
- ? 'rgba(251, 113, 133, 0.15)'
- : 'rgba(234, 179, 8, 0.15)'
- }`,
- }}>
- {isReady ? 'Ready' : isFailed ? 'Failed' : 'Building'}
- </span>
- )
-}
+import { useState } from 'react'
+import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
+import { toast } from 'sonner'
+import { Package } from 'lucide-react'
+import { deleteImage, getImages, type ImageCacheItem } from '@/api/client'
+import { PageHeader } from '@/components/page-header'
+import { Panel } from '@/components/panel'
+import { Button } from '@/components/ui/button'
+import { StatusBadge } from '@/components/status-badge'
+import { EmptyState } from '@/components/empty-state'
+import { ConfirmDialog } from '@/components/confirm-dialog'
+import { ResourceTable, type Column } from '@/components/resource-table'
function formatSteps(manifest: Record<string, unknown>): string {
const steps = manifest.steps as Array<Record<string, unknown>> | undefined
if (!steps || steps.length === 0) return 'base'
- return steps.map(s => {
- const t = s.type as string
- const args = s.args as Record<string, unknown> | undefined
- switch (t) {
- case 'apt_install': return `apt: ${(args?.packages as string[])?.join(', ') || '...'}`
- case 'pip_install': return `pip: ${(args?.packages as string[])?.join(', ') || '...'}`
- case 'run': return `run: ${((args?.commands as string[]) || []).length} cmd(s)`
- case 'env': return `env: ${Object.keys((args?.vars as Record<string, string>) || {}).length} var(s)`
- case 'workdir': return `workdir: ${args?.path || '...'}`
- case 'add_file': return `file: ${args?.path || '...'}`
- default: return t
- }
- }).join(' + ')
+ return steps
+ .map((s) => {
+ const t = s.type as string
+ const args = s.args as Record<string, unknown> | undefined
+ switch (t) {
+ case 'apt_install':
+ return `apt: ${(args?.packages as string[])?.join(', ') || '...'}`
+ case 'pip_install':
+ return `pip: ${(args?.packages as string[])?.join(', ') || '...'}`
+ case 'run':
+ return `run: ${((args?.commands as string[]) || []).length} cmd(s)`
+ case 'env':
+ return `env: ${Object.keys((args?.vars as Record<string, string>) || {}).length} var(s)`
+ case 'workdir':
+ return `workdir: ${args?.path || '...'}`
+ case 'add_file':
+ return `file: ${args?.path || '...'}`
+ default:
+ return t
+ }
+ })
+ .join(' + ')
}
export default function Templates() {
const queryClient = useQueryClient()
+ const [toDelete, setToDelete] = useState<ImageCacheItem | null>(null)
const { data: images, isLoading } = useQuery({
queryKey: ['images'],
queryFn: () => getImages(),
})
- const deleteImageMutation = useMutation({
+ const deleteMutation = useMutation({
mutationFn: (id: string) => deleteImage(id),
- onSuccess: () => {
- queryClient.invalidateQueries({ queryKey: ['images'] })
- },
+ onError: (error) =>
+ toast.error(
+ `Delete failed: ${error instanceof Error ? error.message : String(error)}`,
+ ),
+ onSettled: () => queryClient.invalidateQueries({ queryKey: ['images'] }),
})
- const imageCount = (images ?? []).length
+ const confirmDelete = () => {
+ if (!toDelete) return
+ deleteMutation.mutate(toDelete.id, { onSuccess: () => setToDelete(null) })
+ }
+
+ const columns: Column<ImageCacheItem>[] = [
+ {
+ key: 'name',
+ header: 'Name',
+ cell: (img) =>
+ img.name ? (
+ <span className="text-foreground font-medium">{img.name}</span>
+ ) : (
+ <span className="text-muted-foreground italic">auto-cached</span>
+ ),
+ },
+ {
+ key: 'steps',
+ header: 'Steps',
+ cell: (img) => (
+ <span className="text-muted-foreground block max-w-[300px] truncate text-xs">
+ {formatSteps(img.manifest)}
+ </span>
+ ),
+ },
+ {
+ key: 'status',
+ header: 'Status',
+ cell: (img) => <StatusBadge status={img.status} />,
+ },
+ {
+ key: 'checkpoint',
+ header: 'Checkpoint',
+ cell: (img) =>
+ img.checkpointId ? (
+ <code className="font-mono text-xs">
+ {img.checkpointId.slice(0, 8)}
+ </code>
+ ) : (
+ <span className="text-muted-foreground">—</span>
+ ),
+ },
+ {
+ key: 'lastUsed',
+ header: 'Last used',
+ cell: (img) => (
+ <span className="text-muted-foreground font-mono text-xs">
+ {new Date(img.lastUsedAt).toLocaleString()}
+ </span>
+ ),
+ },
+ {
+ key: 'created',
+ header: 'Created',
+ cell: (img) => (
+ <span className="text-muted-foreground font-mono text-xs">
+ {new Date(img.createdAt).toLocaleString()}
+ </span>
+ ),
+ },
+ {
+ key: 'actions',
+ header: '',
+ align: 'right',
+ cell: (img) => (
+ <Button
+ variant="ghost"
+ size="sm"
+ className="text-status-error hover:bg-status-error-bg hover:text-status-error"
+ onClick={() => setToDelete(img)}
+ >
+ Delete
+ </Button>
+ ),
+ },
+ ]
return (
<div>
- {/* Header */}
- <div style={{ marginBottom: 28 }}>
- <h1 className="page-title">Templates</h1>
- <p className="page-subtitle">Declarative image snapshots for your organization</p>
- </div>
+ <PageHeader
+ title="Templates"
+ description="Declarative image snapshots for your organization"
+ />
+
+ <Panel className="overflow-hidden">
+ <ResourceTable
+ columns={columns}
+ rows={images ?? []}
+ rowKey={(img) => img.id}
+ loading={isLoading}
+ empty={
+ <EmptyState
+ icon={Package}
+ title="No templates yet"
+ description="Create them with the SDK — Image.base().aptInstall([...]) — or snapshots.create()."
+ />
+ }
+ />
+ </Panel>
- {isLoading ? (
- <div style={{ display: 'flex', justifyContent: 'center', padding: 48 }}>
- <div className="loading-spinner" />
- </div>
- ) : (
- <div className="glass-card animate-in stagger-1" style={{ overflow: 'hidden' }}>
- <table className="data-table">
- <thead>
- <tr>
- <th>Name</th>
- <th>Steps</th>
- <th>Status</th>
- <th>Checkpoint</th>
- <th>Last Used</th>
- <th>Created</th>
- <th style={{ width: 80 }}></th>
- </tr>
- </thead>
- <tbody>
- {(images ?? []).map((img: ImageCacheItem) => (
- <tr key={img.id}>
- <td style={{ fontWeight: 500, color: 'var(--text-primary)' }}>
- {img.name || (
- <span style={{ color: 'var(--text-tertiary)', fontStyle: 'italic' }}>auto-cached</span>
- )}
- </td>
- <td style={{ fontSize: 12, color: 'var(--text-secondary)', maxWidth: 300, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
- {formatSteps(img.manifest)}
- </td>
- <td><StatusBadge status={img.status} /></td>
- <td>
- {img.checkpointId ? (
- <code style={{ fontSize: 11 }}>{img.checkpointId.slice(0, 8)}</code>
- ) : (
- <span style={{ color: 'var(--text-tertiary)' }}>-</span>
- )}
- </td>
- <td style={{ fontFamily: 'var(--font-mono)', fontSize: 12 }}>
- {new Date(img.lastUsedAt).toLocaleString()}
- </td>
- <td style={{ fontFamily: 'var(--font-mono)', fontSize: 12 }}>
- {new Date(img.createdAt).toLocaleString()}
- </td>
- <td>
- <button
- className="btn-danger"
- onClick={() => {
- const label = img.name ? `"${img.name}"` : 'this cached image'
- if (confirm(`Delete ${label}? Existing sandboxes will not be affected.`)) {
- deleteImageMutation.mutate(img.id)
- }
- }}
- >
- Delete
- </button>
- </td>
- </tr>
- ))}
- {imageCount === 0 && (
- <tr>
- <td colSpan={7} style={{ textAlign: 'center', padding: 32, color: 'var(--text-tertiary)' }}>
- No templates yet. Create them using the SDK with Image.base().aptInstall([...]) or snapshots.create().
- </td>
- </tr>
- )}
- </tbody>
- </table>
- </div>
- )}
+ <ConfirmDialog
+ open={toDelete !== null}
+ onOpenChange={(open) => !open && setToDelete(null)}
+ title={`Delete ${toDelete?.name ? `"${toDelete.name}"` : 'this cached image'}?`}
+ description="Existing sandboxes will not be affected."
+ confirmLabel="Delete template"
+ destructive
+ pending={deleteMutation.isPending}
+ onConfirm={confirmDelete}
+ />
</div>
)
}