Skip to content

Commit e9f382b

Browse files
exe.dev userexe.dev user
authored andcommitted
Unify run state indicators
1 parent 08eb62c commit e9f382b

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

‎packages/app/src/features/runs/detail.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Badge, Button, Breadcrumb, Page, ResourceHeader } from "../../shared/ui";
1+
import { Button, Breadcrumb, Page, ResourceHeader, RunStatusLabel } from "../../shared/ui";
22
import { ContinuousTrace } from "./continuous-trace";
33
import { ExpandedRunDetail } from "./expanded-detail";
44
import { ReplayTrace } from "./replay";
@@ -58,7 +58,7 @@ export function RunDetail() {
5858
{status.isPending && <p role="status">Loading run…</p>}{status.error && <p role="alert">{status.error.message}</p>}
5959
<Breadcrumb>{status.data ? <Link className="break-words min-w-0" to="/jobs/$jobId" params={{ jobId: status.data.job_id }}>{status.data.job_name}</Link> : <Link to="/projects">Projects</Link>}</Breadcrumb>
6060
{status.data && <>
61-
<ResourceHeader type="Run" title={status.data.run_name || "Run"} titleActions={renaming ? <form className="flex flex-wrap items-center gap-2" onSubmit={event => { event.preventDefault(); setNameError(""); rename.mutate(); }}><label className="sr-only" htmlFor="run-name">Run name</label><input autoFocus id="run-name" className="w-64 rounded-lg border border-stone-300 bg-white px-3 py-2 text-base font-normal dark:border-slate-700 dark:bg-slate-950" value={nameDraft} maxLength={120} aria-invalid={!!nameError} aria-describedby={nameError ? "run-name-error" : undefined} onChange={event => { setNameDraft(event.target.value); setNameError(""); }} onKeyDown={event => { if (event.key === "Escape") { event.preventDefault(); cancelRename(); } }} /><Button type="submit" disabled={rename.isPending}>Save</Button><Button type="button" disabled={rename.isPending} onClick={cancelRename}>Cancel</Button>{nameError && <span id="run-name-error" role="alert" className="basis-full text-sm text-red-700 dark:text-red-300">{nameError}</span>}</form> : <Button type="button" onClick={startRename}>Rename</Button>} description={<p role="status"><Badge active={active}>{status.data.state === "failed" && status.data.failure_source ? status.data.failure_source === "agent" ? "Agent failed" : "System failed" : status.data.state}</Badge>{status.data.finalizing ? " · Finalizing trace and artifacts" : ""}{(status.data.agent_error as any)?.reason && <span className="mt-1 block max-w-3xl text-left">{(status.data.agent_error as any).reason}</span>}</p>}>{["starting", "running", "blocked", "stopping"].includes(status.data.state) && <Button className="shrink-0" disabled={stop.isPending || status.data.state === "stopping"} onClick={() => stop.mutate()}>Stop run</Button>}</ResourceHeader>
61+
<ResourceHeader type="Run" title={status.data.run_name || "Run"} titleActions={renaming ? <form className="flex flex-wrap items-center gap-2" onSubmit={event => { event.preventDefault(); setNameError(""); rename.mutate(); }}><label className="sr-only" htmlFor="run-name">Run name</label><input autoFocus id="run-name" className="w-64 rounded-lg border border-stone-300 bg-white px-3 py-2 text-base font-normal dark:border-slate-700 dark:bg-slate-950" value={nameDraft} maxLength={120} aria-invalid={!!nameError} aria-describedby={nameError ? "run-name-error" : undefined} onChange={event => { setNameDraft(event.target.value); setNameError(""); }} onKeyDown={event => { if (event.key === "Escape") { event.preventDefault(); cancelRename(); } }} /><Button type="submit" disabled={rename.isPending}>Save</Button><Button type="button" disabled={rename.isPending} onClick={cancelRename}>Cancel</Button>{nameError && <span id="run-name-error" role="alert" className="basis-full text-sm text-red-700 dark:text-red-300">{nameError}</span>}</form> : <Button type="button" onClick={startRename}>Rename</Button>} description={<p role="status"><RunStatusLabel state={status.data.state} failureSource={status.data.failure_source} />{status.data.finalizing ? " · Finalizing trace and artifacts" : ""}{(status.data.agent_error as any)?.reason && <span className="mt-1 block max-w-3xl text-left">{(status.data.agent_error as any).reason}</span>}</p>}>{["starting", "running", "blocked", "stopping"].includes(status.data.state) && <Button className="shrink-0" disabled={stop.isPending || status.data.state === "stopping"} onClick={() => stop.mutate()}>Stop run</Button>}</ResourceHeader>
6262
</>}
6363
{!status.data && <ResourceHeader type="Run" title="Run" />}
6464
{stop.error && <p role="alert">{stop.error.message}</p>}

‎packages/app/src/routes/index.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Badge, Card, Page, RunStatusDot } from "../shared/ui";
1+
import { Card, Page, RunStatusLabel } from "../shared/ui";
22
import { Link } from "@tanstack/react-router";
33
import { useQuery } from "@tanstack/react-query";
44
import { sessionQuery } from "../features/auth/session";
@@ -14,7 +14,7 @@ function RecentSection({ title, children, empty }: { title: string; children: Re
1414
function RecentDashboard() {
1515
const projects = useQuery(recentProjectsQuery), jobs = useQuery(recentJobsQuery), runs = useQuery(runPageQuery({ limit: 5 }));
1616
const error = projects.error || jobs.error || runs.error;
17-
return <Page><div className="mb-8"><p className="mb-2 text-xs font-semibold uppercase tracking-widest text-factorize-700 dark:text-factorize-500">Your software factory</p><h1>Recent work</h1><p className="mt-2 text-slate-600 dark:text-slate-400">Pick up where you left off.</p></div>{error && <p className="mb-6" role="alert">{error.message}</p>}<div className="grid gap-5 lg:grid-cols-3"><RecentSection title="Recent projects" empty="Projects you update will appear here.">{projects.data?.length ? <ul className="mt-4 divide-y divide-stone-200 dark:divide-slate-800">{projects.data.map(project => <li key={project.id} className="py-3 first:pt-0 last:pb-0"><Link to="/projects/$projectId" params={{ projectId: project.id }} className="block rounded-md hover:text-factorize-700"><span className="font-semibold">{project.name}</span><span className="mt-1 block text-xs text-slate-500">{project.jobCount} {project.jobCount === 1 ? "job" : "jobs"} · Updated {timestamp(project.updatedAt)}</span></Link></li>)}</ul> : null}</RecentSection><RecentSection title="Recent jobs" empty="Jobs you update will appear here.">{jobs.data?.items.length ? <ul className="mt-4 divide-y divide-stone-200 dark:divide-slate-800">{jobs.data.items.map(job => <li key={job.id} className="py-3 first:pt-0 last:pb-0"><Link to="/jobs/$jobId" params={{ jobId: job.id }} className="block rounded-md hover:text-factorize-700"><span className="font-semibold">{job.name}</span><span className="mt-1 block text-xs text-slate-500">{job.lastRunState ? <><RunStatusDot state={job.lastRunState} decorative /> <span className="ml-1">{job.lastRunState}</span> · </> : "No runs · "}Updated {timestamp(job.updatedAt)}</span></Link></li>)}</ul> : null}</RecentSection><RecentSection title="Recent runs" empty="Runs from your jobs will appear here.">{runs.data?.items.length ? <ul className="mt-4 divide-y divide-stone-200 dark:divide-slate-800">{runs.data.items.map(run => <li key={run.id} className="py-3 first:pt-0 last:pb-0"><Link to="/job-runs/$runId" params={{ runId: run.id }} className="block rounded-md hover:text-factorize-700"><span className="font-semibold">{run.run_name || "Unnamed run"}</span><span className="mt-1 block text-xs text-slate-500"><Badge>{run.state}</Badge><span className="ml-2">{run.job_name} · {timestamp(run.created_at)}</span></span></Link></li>)}</ul> : null}</RecentSection></div></Page>;
17+
return <Page><div className="mb-8"><p className="mb-2 text-xs font-semibold uppercase tracking-widest text-factorize-700 dark:text-factorize-500">Your software factory</p><h1>Recent work</h1><p className="mt-2 text-slate-600 dark:text-slate-400">Pick up where you left off.</p></div>{error && <p className="mb-6" role="alert">{error.message}</p>}<div className="grid gap-5 lg:grid-cols-3"><RecentSection title="Recent projects" empty="Projects you update will appear here.">{projects.data?.length ? <ul className="mt-4 divide-y divide-stone-200 dark:divide-slate-800">{projects.data.map(project => <li key={project.id} className="py-3 first:pt-0 last:pb-0"><Link to="/projects/$projectId" params={{ projectId: project.id }} className="block rounded-md hover:text-factorize-700"><span className="font-semibold">{project.name}</span><span className="mt-1 block text-xs text-slate-500">{project.jobCount} {project.jobCount === 1 ? "job" : "jobs"} · Updated {timestamp(project.updatedAt)}</span></Link></li>)}</ul> : null}</RecentSection><RecentSection title="Recent jobs" empty="Jobs you update will appear here.">{jobs.data?.items.length ? <ul className="mt-4 divide-y divide-stone-200 dark:divide-slate-800">{jobs.data.items.map(job => <li key={job.id} className="py-3 first:pt-0 last:pb-0"><Link to="/jobs/$jobId" params={{ jobId: job.id }} className="block rounded-md hover:text-factorize-700"><span className="font-semibold">{job.name}</span><span className="mt-1 block text-xs text-slate-500">{job.lastRunState ? <><RunStatusLabel state={job.lastRunState} /> · </> : "No runs · "}Updated {timestamp(job.updatedAt)}</span></Link></li>)}</ul> : null}</RecentSection><RecentSection title="Recent runs" empty="Runs from your jobs will appear here.">{runs.data?.items.length ? <ul className="mt-4 divide-y divide-stone-200 dark:divide-slate-800">{runs.data.items.map(run => <li key={run.id} className="py-3 first:pt-0 last:pb-0"><Link to="/job-runs/$runId" params={{ runId: run.id }} className="block rounded-md hover:text-factorize-700"><span className="font-semibold">{run.run_name || "Unnamed run"}</span><span className="mt-1 block text-xs text-slate-500"><RunStatusLabel state={run.state} /><span className="ml-2">{run.job_name} · {timestamp(run.created_at)}</span></span></Link></li>)}</ul> : null}</RecentSection></div></Page>;
1818
}
1919
export function MigrationIndex() {
2020
const session = useQuery(sessionQuery);

‎packages/app/src/shared/ui.tsx‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,19 @@ const runStatusStyles: Record<string, { label: string; color: string; pulse?: bo
6060
blocked: { label: "Blocked", color: "bg-amber-500" }, stopping: { label: "Stopping", color: "bg-amber-500" }, succeeded: { label: "Succeeded", color: "bg-emerald-500" }, done: { label: "Done", color: "bg-emerald-500" },
6161
failed: { label: "Failed", color: "bg-red-500" }, stopped: { label: "Stopped", color: "bg-slate-500" }, ignored: { label: "Ignored", color: "bg-slate-400" },
6262
};
63-
export function RunStatusDot({ state, failureSource, decorative = false }: { state: string; failureSource?: string | null; decorative?: boolean }) {
63+
function runStatusDetails(state: string, failureSource?: string | null) {
6464
const base = runStatusStyles[state] ?? { label: state || "Unknown", color: "bg-slate-400" };
65-
const status = state === "failed" && failureSource ? { ...base, label: failureSource === "agent" ? "Agent failed" : "System failed" } : base;
65+
return state === "failed" && failureSource ? { ...base, label: failureSource === "agent" ? "Agent failed" : "System failed" } : base;
66+
}
67+
export function RunStatusDot({ state, failureSource, decorative = false }: { state: string; failureSource?: string | null; decorative?: boolean }) {
68+
const status = runStatusDetails(state, failureSource);
6669
return <span role={decorative ? undefined : "img"} aria-label={decorative ? undefined : `Status: ${status.label}`} aria-hidden={decorative || undefined} title={status.label} className={`inline-block size-2.5 rounded-full ${status.color} ${status.pulse ? "motion-safe:animate-pulse" : ""}`} />;
6770
}
71+
export function RunStatusLabel({ state, failureSource, className = "" }: { state: string; failureSource?: string | null; className?: string }) {
72+
const status = runStatusDetails(state, failureSource);
73+
const text = state === "failed" && failureSource ? status.label : state || "Unknown";
74+
return <span role="img" aria-label={`Status: ${status.label}`} className={`inline-flex items-center gap-2 ${className}`}><RunStatusDot state={state} failureSource={failureSource} decorative /><span className="first-letter:uppercase">{text}</span></span>;
75+
}
6876
export function Button({ variant = "secondary", className = "", ...props }: ComponentProps<"button"> & { variant?: keyof typeof buttonClasses }) {
6977
return <button {...props} className={`inline-flex min-h-10 shrink-0 items-center justify-center gap-2 rounded-lg border px-3 py-2 text-sm font-semibold transition disabled:cursor-not-allowed disabled:opacity-50 ${buttonClasses[variant]} ${className}`} />;
7078
}

0 commit comments

Comments
 (0)