Skip to content

An open-source, faster Devin alternative

TypeScript

feat(web): reskin Sessions (pilot) — reference migration pattern

Igor Zalutski0390c3a4ad66
diff --git a/web/src/pages/Sessions.tsx b/web/src/pages/Sessions.tsx
index 50c7d1ac..86f99081 100644
--- a/web/src/pages/Sessions.tsx
+++ b/web/src/pages/Sessions.tsx
@@ -1,19 +1,42 @@
-import { useState, useMemo } from 'react'
+import { useMemo, useState } from 'react'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
-import { useNavigate } from 'react-router-dom'
-import { deleteSession, getSessions, type Session } from '../api/client'
+import { Link } from 'react-router-dom'
+import { toast } from 'sonner'
+import { Boxes } from 'lucide-react'
+import { deleteSession, getSessions, type Session } from '@/api/client'
+import { PageHeader } from '@/components/page-header'
+import { Panel } from '@/components/panel'
+import { Button } from '@/components/ui/button'
+import { Skeleton } from '@/components/ui/skeleton'
+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'
+import { cn } from '@/lib/utils'
-const statusFilters = ['', 'running', 'stopped', 'hibernated', 'error'] as const
+const STATUS_FILTERS = [
+ { value: '', label: 'All' },
+ { value: 'running', label: 'Running' },
+ { value: 'stopped', label: 'Stopped' },
+ { value: 'hibernated', label: 'Hibernated' },
+ { value: 'error', label: 'Error' },
+] as const
+
+function canDeleteSession(session: Session) {
+ return session.status === 'running' || session.status === 'hibernated'
+}
export default function Sessions() {
const queryClient = useQueryClient()
const [status, setStatus] = useState<string>('')
+ const [toDelete, setToDelete] = useState<Session | null>(null)
+
const { data: sessions, isLoading } = useQuery({
queryKey: ['sessions', status],
queryFn: () => getSessions(status || undefined),
})
- // Always fetch all sessions for the activity chart
+ // Always fetch all sessions for the activity chart.
const { data: allSessions, isLoading: loadingAll } = useQuery({
queryKey: ['sessions', ''],
queryFn: () => getSessions(),
@@ -28,119 +51,171 @@ export default function Sessions() {
old?.map((session) =>
session.sandboxId === sandboxId
? { ...session, status: 'stopped', stoppedAt }
- : session
- )
+ : session,
+ ),
)
},
- onSuccess: () => {
+ onError: (error) => {
+ toast.error(
+ `Delete failed: ${error instanceof Error ? error.message : String(error)}`,
+ )
+ },
+ onSettled: () => {
queryClient.invalidateQueries({ queryKey: ['sessions'] })
},
})
- const handleDelete = (sandboxId: string) => {
- if (!confirm(`Delete sandbox ${sandboxId}?\n\nThe sandbox will be stopped and its preview URLs removed.`)) return
- deleteMutation.mutate(sandboxId)
+ const confirmDelete = () => {
+ if (!toDelete) return
+ deleteMutation.mutate(toDelete.sandboxId, {
+ onSuccess: () => setToDelete(null),
+ })
}
+ const columns: Column<Session>[] = [
+ {
+ key: 'id',
+ header: 'Sandbox ID',
+ cell: (s) => (
+ <Link
+ to={`/sessions/${s.sandboxId}`}
+ className="text-foreground font-mono text-[13px] underline-offset-4 hover:underline"
+ >
+ {s.sandboxId}
+ </Link>
+ ),
+ },
+ {
+ key: 'template',
+ header: 'Template',
+ cell: (s) => (
+ <span className="text-muted-foreground">{s.template || 'base'}</span>
+ ),
+ },
+ {
+ key: 'status',
+ header: 'Status',
+ cell: (s) => <StatusBadge status={s.status} />,
+ },
+ {
+ key: 'started',
+ header: 'Started',
+ cell: (s) => (
+ <span className="text-muted-foreground font-mono text-xs">
+ {new Date(s.startedAt).toLocaleString()}
+ </span>
+ ),
+ },
+ {
+ key: 'stopped',
+ header: 'Stopped',
+ cell: (s) => (
+ <span className="text-muted-foreground font-mono text-xs">
+ {s.stoppedAt ? new Date(s.stoppedAt).toLocaleString() : '—'}
+ </span>
+ ),
+ },
+ {
+ key: 'actions',
+ header: '',
+ align: 'right',
+ cell: (s) =>
+ canDeleteSession(s) ? (
+ <Button
+ variant="ghost"
+ size="sm"
+ className="text-status-error hover:bg-status-error-bg hover:text-status-error"
+ onClick={() => setToDelete(s)}
+ >
+ Delete
+ </Button>
+ ) : null,
+ },
+ ]
+
return (
<div>
- <div style={{ marginBottom: 28 }}>
- <h1 className="page-title">Sessions</h1>
- <p className="page-subtitle">Session history</p>
- </div>
+ <PageHeader title="Sessions" description="Session history" />
- {/* ── Activity Chart ── */}
<ActivityChart sessions={allSessions ?? []} loading={loadingAll} />
- {/* ── Filters ── */}
- <div style={{ marginBottom: 16, display: 'flex', gap: 6 }}>
- {statusFilters.map(f => (
- <button key={f} onClick={() => setStatus(f)}
- className={`filter-btn${status === f ? ' active' : ''}`}>
- {f || 'All'}
- </button>
+ <div className="mb-4 flex flex-wrap gap-1.5">
+ {STATUS_FILTERS.map((f) => (
+ <Button
+ key={f.value}
+ size="sm"
+ variant={status === f.value ? 'default' : 'ghost'}
+ onClick={() => setStatus(f.value)}
+ >
+ {f.label}
+ </Button>
))}
</div>
- {/* ── Table ── */}
- {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>Sandbox ID</th>
- <th>Template</th>
- <th>Status</th>
- <th>Started</th>
- <th>Stopped</th>
- <th style={{ width: 96 }}></th>
- </tr>
- </thead>
- <tbody>
- {(sessions ?? []).map((s: Session) => (
- <ClickableRow key={s.id} sandboxId={s.sandboxId}>
- <td><code style={{ color: 'var(--text-accent)' }}>{s.sandboxId}</code></td>
- <td>{s.template || 'base'}</td>
- <td><StatusBadge status={s.status} /></td>
- <td style={{ fontFamily: 'var(--font-mono)', fontSize: 12 }}>{new Date(s.startedAt).toLocaleString()}</td>
- <td style={{ fontFamily: 'var(--font-mono)', fontSize: 12 }}>{s.stoppedAt ? new Date(s.stoppedAt).toLocaleString() : '\u2014'}</td>
- <td>
- {canDeleteSession(s) && (
- <button
- className="btn-danger"
- disabled={deleteMutation.isPending && deleteMutation.variables === s.sandboxId}
- onClick={(e) => {
- e.stopPropagation()
- handleDelete(s.sandboxId)
- }}
- >
- {deleteMutation.isPending && deleteMutation.variables === s.sandboxId ? 'Deleting...' : 'Delete'}
- </button>
- )}
- </td>
- </ClickableRow>
- ))}
- {(sessions ?? []).length === 0 && (
- <tr>
- <td colSpan={6} style={{ textAlign: 'center', padding: 32, color: 'var(--text-tertiary)' }}>
- No sessions found
- </td>
- </tr>
- )}
- </tbody>
- </table>
- {deleteMutation.isError && (
- <div style={{
- padding: '10px 16px',
- borderTop: '1px solid var(--border-subtle)',
- color: 'var(--accent-rose)',
- fontSize: 13,
- }}>
- Delete failed: {deleteMutation.error instanceof Error ? deleteMutation.error.message : String(deleteMutation.error)}
- </div>
- )}
- </div>
- )}
+ <Panel className="overflow-hidden">
+ <ResourceTable
+ columns={columns}
+ rows={sessions ?? []}
+ rowKey={(s) => s.id}
+ loading={isLoading}
+ empty={
+ <EmptyState
+ icon={Boxes}
+ title="No sessions found"
+ description={
+ status
+ ? 'No sessions match this filter.'
+ : 'Sandboxes you start will show up here.'
+ }
+ />
+ }
+ />
+ </Panel>
+
+ <ConfirmDialog
+ open={toDelete !== null}
+ onOpenChange={(open) => !open && setToDelete(null)}
+ title={`Delete sandbox ${toDelete?.sandboxId ?? ''}?`}
+ description="The sandbox will be stopped and its preview URLs removed."
+ confirmLabel="Delete sandbox"
+ destructive
+ pending={deleteMutation.isPending}
+ onConfirm={confirmDelete}
+ />
</div>
)
}
-/* ── Activity Chart (last 14 days) ────────────────────────── */
-function ActivityChart({ sessions, loading }: { sessions: Session[]; loading: boolean }) {
+/* ── Activity chart (last 14 days) ──────────────────────────────────────────
+ Hand-built positioned divs (not recharts) — kept as a data-driven inline
+ geometry per the migration contract; only the chrome + colors are reskinned.
+ A recharts rebuild is a follow-up. */
+function ActivityChart({
+ sessions,
+ loading,
+}: {
+ sessions: Session[]
+ loading: boolean
+}) {
const { days, maxCount } = useMemo(() => {
const now = new Date()
- const dayBuckets: { label: string; date: string; count: number; hibernated: number; errored: number }[] = []
+ const dayBuckets: {
+ label: string
+ date: string
+ count: number
+ hibernated: number
+ errored: number
+ }[] = []
for (let i = 13; i >= 0; i--) {
const d = new Date(now)
d.setDate(d.getDate() - i)
const dateStr = d.toISOString().slice(0, 10)
dayBuckets.push({
- label: d.toLocaleDateString('en-US', { month: 'short', day: 'numeric' }),
+ label: d.toLocaleDateString('en-US', {
+ month: 'short',
+ day: 'numeric',
+ }),
date: dateStr,
count: 0,
hibernated: 0,
@@ -150,7 +225,7 @@ function ActivityChart({ sessions, loading }: { sessions: Session[]; loading: bo
for (const s of sessions) {
const dateStr = new Date(s.startedAt).toISOString().slice(0, 10)
- const bucket = dayBuckets.find(b => b.date === dateStr)
+ const bucket = dayBuckets.find((b) => b.date === dateStr)
if (bucket) {
bucket.count++
if (s.status === 'hibernated') bucket.hibernated++
@@ -158,75 +233,65 @@ function ActivityChart({ sessions, loading }: { sessions: Session[]; loading: bo
}
}
- const maxCount = Math.max(1, ...dayBuckets.map(b => b.count))
+ const maxCount = Math.max(1, ...dayBuckets.map((b) => b.count))
return { days: dayBuckets, maxCount }
}, [sessions])
+ const total = days.reduce((n, d) => n + d.count, 0)
+
return (
- <div className="glass-card animate-in" style={{ padding: '22px 24px', marginBottom: 24 }}>
- <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }}>
- <span className="section-title" style={{ marginBottom: 0 }}>Activity</span>
- <span style={{ fontSize: 11, color: 'var(--text-tertiary)', fontFamily: 'var(--font-mono)' }}>
+ <Panel className="mb-6 px-6 py-5">
+ <div className="mb-4 flex items-center justify-between">
+ <h2 className="text-sm font-semibold">Activity</h2>
+ <span className="text-muted-foreground font-mono text-xs">
Last 14 days
</span>
</div>
{loading ? (
- <div style={{ display: 'flex', justifyContent: 'center', padding: 40 }}>
- <div className="loading-spinner" />
- </div>
+ <Skeleton className="h-[150px] w-full" />
) : (
- <div style={{ position: 'relative' }}>
- {/* Y-axis labels */}
- <div style={{
- position: 'absolute', left: 0, top: 0, bottom: 24,
- display: 'flex', flexDirection: 'column', justifyContent: 'space-between',
- width: 32,
- }}>
- <span style={{ fontSize: 10, color: 'var(--text-tertiary)', fontFamily: 'var(--font-mono)' }}>
+ <div className="relative">
+ {/* Accessible summary (chart is decorative; this conveys the data). */}
+ <p className="sr-only">
+ {total} sessions started in the last 14 days.
+ </p>
+
+ {/* Y-axis */}
+ <div className="absolute top-0 bottom-6 left-0 flex w-8 flex-col justify-between">
+ <span className="text-muted-foreground font-mono text-[10px]">
{maxCount}
</span>
- <span style={{ fontSize: 10, color: 'var(--text-tertiary)', fontFamily: 'var(--font-mono)' }}>
+ <span className="text-muted-foreground font-mono text-[10px]">
0
</span>
</div>
- {/* Chart bars */}
- <div style={{
- display: 'flex', alignItems: 'flex-end', gap: 4, height: 120,
- marginLeft: 36,
- }}>
+ {/* Bars */}
+ <div className="ml-9 flex h-[120px] items-end gap-1" aria-hidden>
{days.map((day) => {
- const barHeight = maxCount > 0 ? Math.round((day.count / maxCount) * 110) : 0
- const hasHibernated = day.hibernated > 0
- const hasError = day.errored > 0
-
+ const barHeight =
+ maxCount > 0 ? Math.round((day.count / maxCount) * 110) : 0
+ const tone =
+ day.errored > 0
+ ? 'bg-status-error'
+ : day.hibernated > 0
+ ? 'bg-status-hibernated'
+ : 'bg-foreground/75'
return (
<div
key={day.date}
- title={`${day.label}: ${day.count} sessions${day.hibernated ? ` (${day.hibernated} hibernated)` : ''}${day.errored ? ` (${day.errored} errors)` : ''}`}
- style={{
- flex: 1,
- height: day.count > 0 ? Math.max(barHeight, 4) : 0,
- borderRadius: '4px 4px 2px 2px',
- background: hasError
- ? 'linear-gradient(to top, rgba(251,113,133,0.5), rgba(129,140,248,0.5))'
- : hasHibernated
- ? 'linear-gradient(to top, rgba(34,211,238,0.4), rgba(129,140,248,0.5))'
- : day.count > 0
- ? 'linear-gradient(to top, rgba(99,102,241,0.25), rgba(129,140,248,0.5))'
- : 'transparent',
- transition: 'height 0.3s ease',
- cursor: 'default',
- position: 'relative',
- }}
+ title={`${day.label}: ${day.count} sessions${
+ day.hibernated ? ` (${day.hibernated} hibernated)` : ''
+ }${day.errored ? ` (${day.errored} errors)` : ''}`}
+ className={cn(
+ 'relative flex-1 rounded-t-sm transition-[height] duration-300',
+ day.count > 0 ? tone : 'bg-transparent',
+ )}
+ style={{ height: day.count > 0 ? Math.max(barHeight, 4) : 0 }}
>
{day.count > 0 && (
- <span style={{
- position: 'absolute', top: -16, left: '50%', transform: 'translateX(-50%)',
- fontSize: 9, fontFamily: 'var(--font-mono)', color: 'var(--text-tertiary)',
- whiteSpace: 'nowrap',
- }}>
+ <span className="text-muted-foreground absolute -top-4 left-1/2 -translate-x-1/2 font-mono text-[9px] whitespace-nowrap">
{day.count}
</span>
)}
@@ -235,77 +300,41 @@ function ActivityChart({ sessions, loading }: { sessions: Session[]; loading: bo
})}
</div>
- {/* X-axis labels */}
- <div style={{
- display: 'flex', gap: 4, marginLeft: 36, marginTop: 6,
- }}>
+ {/* X-axis */}
+ <div className="mt-1.5 ml-9 flex gap-1" aria-hidden>
{days.map((day, i) => (
- <div key={day.date} style={{
- flex: 1, textAlign: 'center',
- fontSize: 9, color: 'var(--text-tertiary)',
- fontFamily: 'var(--font-mono)',
- }}>
+ <div
+ key={day.date}
+ className="text-muted-foreground flex-1 text-center font-mono text-[9px]"
+ >
{i % 2 === 0 ? day.label : ''}
</div>
))}
</div>
{/* Legend */}
- <div style={{
- display: 'flex', gap: 16, justifyContent: 'center', marginTop: 12,
- }}>
- <LegendItem color="rgba(129,140,248,0.5)" label="Sessions" />
- <LegendItem color="rgba(34,211,238,0.4)" label="Hibernated" />
- <LegendItem color="rgba(251,113,133,0.5)" label="Errors" />
+ <div className="mt-3 flex justify-center gap-4" aria-hidden>
+ <LegendItem className="bg-foreground/75" label="Sessions" />
+ <LegendItem className="bg-status-hibernated" label="Hibernated" />
+ <LegendItem className="bg-status-error" label="Errors" />
</div>
</div>
)}
- </div>
+ </Panel>
)
}
-function LegendItem({ color, label }: { color: string; label: string }) {
+function LegendItem({
+ className,
+ label,
+}: {
+ className: string
+ label: string
+}) {
return (
- <div style={{ display: 'flex', alignItems: 'center', gap: 5 }}>
- <div style={{ width: 8, height: 8, borderRadius: 2, background: color }} />
- <span style={{ fontSize: 10, color: 'var(--text-tertiary)' }}>{label}</span>
+ <div className="flex items-center gap-1.5">
+ <div className={cn('size-2 rounded-[2px]', className)} />
+ <span className="text-muted-foreground text-[10px]">{label}</span>
</div>
)
}
-
-function canDeleteSession(session: Session) {
- return session.status === 'running' || session.status === 'hibernated'
-}
-
-function ClickableRow({ sandboxId, children }: { sandboxId: string; children: React.ReactNode }) {
- const navigate = useNavigate()
- return (
- <tr
- onClick={() => navigate(`/sessions/${sandboxId}`)}
- style={{ cursor: 'pointer' }}
- onMouseOver={e => { e.currentTarget.style.background = 'rgba(99,102,241,0.04)' }}
- onMouseOut={e => { e.currentTarget.style.background = '' }}
- >
- {children}
- </tr>
- )
-}
-
-function StatusBadge({ status }: { status: string }) {
- const cls =
- status === 'running' ? 'badge-running'
- : status === 'hibernated' ? 'badge-hibernated'
- : status === 'error' ? 'badge-error'
- : 'badge-stopped'
- return (
- <span className={`badge ${cls}`}>
- {status === 'running' && (
- <span className="pulse-dot" style={{
- width: 5, height: 5, borderRadius: '50%',
- background: 'currentColor', display: 'inline-block',
- }} />
- )}
- {status}
- </span>
- )
-}