Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/app/src/features/runs/detail.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Badge, Button, Breadcrumb, Page, ResourceHeader } from "../../shared/ui";
import { Button, Breadcrumb, Page, ResourceHeader, RunStatusLabel } from "../../shared/ui";
import { ContinuousTrace } from "./continuous-trace";
import { ExpandedRunDetail } from "./expanded-detail";
import { ReplayTrace } from "./replay";
Expand Down Expand Up @@ -58,7 +58,7 @@ export function RunDetail() {
{status.isPending && <p role="status">Loading run…</p>}{status.error && <p role="alert">{status.error.message}</p>}
<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>
{status.data && <>
<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>
<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>
</>}
{!status.data && <ResourceHeader type="Run" title="Run" />}
{stop.error && <p role="alert">{stop.error.message}</p>}
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Badge, Card, Page, RunStatusDot } from "../shared/ui";
import { Card, Page, RunStatusLabel } from "../shared/ui";
import { Link } from "@tanstack/react-router";
import { useQuery } from "@tanstack/react-query";
import { sessionQuery } from "../features/auth/session";
Expand All @@ -14,7 +14,7 @@ function RecentSection({ title, children, empty }: { title: string; children: Re
function RecentDashboard() {
const projects = useQuery(recentProjectsQuery), jobs = useQuery(recentJobsQuery), runs = useQuery(runPageQuery({ limit: 5 }));
const error = projects.error || jobs.error || runs.error;
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>;
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>;
}
export function MigrationIndex() {
const session = useQuery(sessionQuery);
Expand Down
12 changes: 10 additions & 2 deletions packages/app/src/shared/ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,19 @@ const runStatusStyles: Record<string, { label: string; color: string; pulse?: bo
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" },
failed: { label: "Failed", color: "bg-red-500" }, stopped: { label: "Stopped", color: "bg-slate-500" }, ignored: { label: "Ignored", color: "bg-slate-400" },
};
export function RunStatusDot({ state, failureSource, decorative = false }: { state: string; failureSource?: string | null; decorative?: boolean }) {
function runStatusDetails(state: string, failureSource?: string | null) {
const base = runStatusStyles[state] ?? { label: state || "Unknown", color: "bg-slate-400" };
const status = state === "failed" && failureSource ? { ...base, label: failureSource === "agent" ? "Agent failed" : "System failed" } : base;
return state === "failed" && failureSource ? { ...base, label: failureSource === "agent" ? "Agent failed" : "System failed" } : base;
}
export function RunStatusDot({ state, failureSource, decorative = false }: { state: string; failureSource?: string | null; decorative?: boolean }) {
const status = runStatusDetails(state, failureSource);
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" : ""}`} />;
}
export function RunStatusLabel({ state, failureSource, className = "" }: { state: string; failureSource?: string | null; className?: string }) {
const status = runStatusDetails(state, failureSource);
const text = state === "failed" && failureSource ? status.label : state || "Unknown";
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>;
}
export function Button({ variant = "secondary", className = "", ...props }: ComponentProps<"button"> & { variant?: keyof typeof buttonClasses }) {
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}`} />;
}
Expand Down
Loading