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
15 changes: 7 additions & 8 deletions packages/app/src/features/jobs/detail.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { Breadcrumb, Page, ResourceHeader } from "../../shared/ui";
import { JobHeader } from "./header";
import { Page } from "../../shared/ui";
import { JobActions } from "./header";
import { RunHistory } from "../runs/history";
import { useParams, Link } from "@tanstack/react-router";
import { useParams } from "@tanstack/react-router";
import { useQuery } from "@tanstack/react-query";
import { jobQuery } from "./queries";
import { JobNav } from "./job-nav";
export function JobDetail() {
const { jobId } = useParams({ strict: false });
const query = useQuery(jobQuery(jobId!));
const job = query.data;
const content = <>
{query.isPending && <><ResourceHeader type="Job" title="Job" /><p role="status">Loading job…</p></>}{query.error && <p role="alert">{query.error.message}</p>}
{job && <><JobHeader job={job} /><div className="mb-6"><RunHistory jobId={job.id} /></div></>}
</>;
return <>{job?.projectId && <JobNav jobId={job.id} tab="runs" />}<Page className="pt-6 sm:pt-8">{!job?.projectId && <Breadcrumb><Link to="/projects">Projects</Link></Breadcrumb>}{content}</Page></>;
return <>{job?.projectId && <JobNav jobId={job.id} tab="runs" />}<Page className="pt-6 sm:pt-8">
{query.isPending && <p role="status">Loading job…</p>}{query.error && <p role="alert">{query.error.message}</p>}
{job && <><JobActions job={job} /><div className="mb-6"><RunHistory jobId={job.id} /></div></>}
</Page></>;
}
18 changes: 9 additions & 9 deletions packages/app/src/features/jobs/header.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { api } from "factorize-api-client";
import { Button, ResourceHeader } from "../../shared/ui";
import { ActionBar, Button, ResourceHeader } from "../../shared/ui";
import { messageOf } from "../auth/session";
import { InvokeJob } from "./invoke";
import { JobTabs } from "./tabs";
Expand All @@ -10,7 +10,7 @@ type JobHeaderProps = {
job: Pick<Job, "id" | "name" | "enabled">;
};

export function JobHeader({ job }: JobHeaderProps) {
export function JobActions({ job }: JobHeaderProps) {
const cache = useQueryClient();
const enabled = useMutation({
retry: false,
Expand All @@ -26,11 +26,11 @@ export function JobHeader({ job }: JobHeaderProps) {
},
});

return <>
<ResourceHeader type="Job" title={job.name}><div className="flex max-w-full shrink-0 flex-wrap items-center gap-2"><InvokeJob jobId={job.id} enabled={job.enabled} />
<Button className="min-h-9 px-2.5 py-1.5 text-xs" disabled={enabled.isPending} onClick={() => enabled.mutate(!job.enabled)}>{job.enabled ? "Disable job" : "Enable job"}</Button>
</div></ResourceHeader>
<JobTabs jobId={job.id} />
{enabled.error && <p role="alert">{enabled.error.message}</p>}
</>;
return <ActionBar><div role="group" aria-label="Job actions" className="flex max-w-full shrink-0 flex-wrap items-center gap-2"><InvokeJob jobId={job.id} enabled={job.enabled} />
<Button disabled={enabled.isPending} onClick={() => enabled.mutate(!job.enabled)}>{job.enabled ? "Disable job" : "Enable job"}</Button>
</div>{enabled.error && <p role="alert" className="basis-full">{enabled.error.message}</p>}</ActionBar>;
}

export function JobHeader({ job }: JobHeaderProps) {
return <><ResourceHeader type="Job" title={job.name}><JobActions job={job} /></ResourceHeader><JobTabs jobId={job.id} /></>;
}
4 changes: 2 additions & 2 deletions packages/app/src/features/jobs/invoke.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export function InvokeJob({ jobId, enabled }: { jobId: string; enabled: boolean
} catch { setValidation("JSON data must be an object."); return; }
invoke({ prompt: String(form.get("prompt") ?? ""), data, ...(String(form.get("name") ?? "").trim() ? { name: String(form.get("name")).trim() } : {}) });
}
return <div className="relative my-4 flex items-stretch">
<Button className="min-h-9 rounded-r-none px-2.5 py-1.5 text-xs" variant="primary" disabled={!enabled || mutation.isPending} onClick={() => invoke({ prompt: "" })}>{mutation.isPending ? "Running…" : "Run job"}</Button>
return <div className="relative flex items-stretch">
<Button className="rounded-r-none" variant="primary" disabled={!enabled || mutation.isPending} onClick={() => invoke({ prompt: "" })}>{mutation.isPending ? "Running…" : "Run job"}</Button>
<Button ref={menuButton} variant="primary" disabled={!enabled || mutation.isPending} aria-label="More run options" aria-haspopup="menu" aria-expanded={menuOpen} aria-controls="run-job-menu" className="rounded-l-none px-2" onClick={() => { mutation.reset(); setMenuOpen(value => !value); }}>▾</Button>
{menuOpen && <div id="run-job-menu" role="menu" aria-label="Run options" className="absolute left-0 top-full z-10 mt-2 min-w-44 rounded-lg border border-stone-200 bg-white p-1 shadow-lg dark:border-slate-700 dark:bg-slate-900">
<button role="menuitem" className="block w-full rounded-md px-3 py-2 text-left text-sm hover:bg-stone-100 dark:hover:bg-slate-800" onClick={() => { setMenuOpen(false); mutation.reset(); menuButton.current?.focus(); setOpen(true); }}>Run with prompt</button>
Expand Down
6 changes: 3 additions & 3 deletions packages/app/src/features/projects/detail.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Link, useParams } from "@tanstack/react-router";
import { useQuery } from "@tanstack/react-query";
import { Button } from "../../shared/ui";
import { ActionBar, Button } from "../../shared/ui";
import { JobsTable } from "../jobs/list";
import { ProjectGraph } from "./graph";
import { projectQuery } from "./queries";
Expand All @@ -11,11 +11,11 @@ export function ProjectDetail() {
const { projectId } = useParams({ from: "/projects/$projectId" });
const project = useQuery(projectQuery(projectId));
const [view, setView] = useState<"list" | "graph">("list");
return <ProjectNav tab="jobs">{project.data && <div className="mb-5 flex flex-wrap items-center justify-between gap-3">
return <ProjectNav tab="jobs">{project.data && <ActionBar>
<div role="group" aria-label="Project jobs view" className="inline-flex rounded-lg border border-stone-200 bg-white p-0.5 dark:border-slate-700 dark:bg-slate-900">
<Button className={`min-h-9 rounded-md border-0 px-3 py-1.5 ${view === "list" ? "bg-stone-100 text-slate-950 shadow-sm dark:bg-slate-800 dark:text-white" : "bg-transparent text-slate-600 hover:bg-stone-50 dark:text-slate-300 dark:hover:bg-slate-800"}`} aria-pressed={view === "list"} onClick={() => setView("list")}>List</Button>
<Button className={`min-h-9 rounded-md border-0 px-3 py-1.5 ${view === "graph" ? "bg-stone-100 text-slate-950 shadow-sm dark:bg-slate-800 dark:text-white" : "bg-transparent text-slate-600 hover:bg-stone-50 dark:text-slate-300 dark:hover:bg-slate-800"}`} aria-pressed={view === "graph"} onClick={() => setView("graph")}>Graph</Button>
</div>
<Link to="/jobs/new" search={{ projectId }}><Button variant="primary">Create job</Button></Link>
</div>}{view === "list" ? <JobsTable projectId={projectId} /> : <ProjectGraph projectId={projectId} />}</ProjectNav>;
</ActionBar>}{view === "list" ? <JobsTable projectId={projectId} /> : <ProjectGraph projectId={projectId} />}</ProjectNav>;
}
1 change: 1 addition & 0 deletions packages/app/src/shared/ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export function Textarea({ className = "", ...props }: ComponentProps<"textarea"
export function Select({ className = "", ...props }: ComponentProps<"select">) { return <select {...props} className={`${fieldClasses} ${className}`} />; }
export function Label({ className = "", ...props }: ComponentProps<"label">) { return <label {...props} className={`block min-w-0 text-sm font-medium text-slate-700 dark:text-slate-300 ${className}`} />; }
export function Page({ className = "", ...props }: ComponentProps<"main">) { return <main {...props} id="main-content" className={`mx-auto w-full min-w-0 max-w-6xl flex-1 px-4 py-8 sm:px-6 sm:py-12 lg:px-8 ${className}`} />; }
export function ActionBar({ className = "", ...props }: ComponentProps<"div">) { return <div {...props} className={`mb-5 flex flex-wrap items-center justify-between gap-3 ${className}`} />; }
export function Breadcrumb({ children }: { children?: ReactNode }) { return <nav aria-label="Breadcrumb" className="mb-4 flex min-h-6 min-w-0 flex-wrap items-center gap-2 text-sm">{children}</nav>; }
export function ResourceHeader({ type, title, titleActions, description, children }: { type: "Project" | "Job" | "Run"; title: string; titleActions?: ReactNode; description?: ReactNode; children?: ReactNode }) {
return <div className="mb-6 min-w-0">
Expand Down
2 changes: 1 addition & 1 deletion packages/app/test/editor.browser.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ test("Settings edits and saves repeatedly, preserves revision, protects dirty ta
return route.fulfill({ json: current });
});
await page.route("**/api/v1/job-summaries?**", route => route.fulfill({ json: { items: [], nextCursor: null } }));
await page.goto(origin + `/jobs/${id}`);
await page.goto(origin + `/jobs/${id}/settings`);
const tabs = page.getByRole("navigation", { name: "Job views" });
await tabs.getByRole("link", { name: "Settings", exact: true }).focus(); await page.keyboard.press("Enter");
await page.waitForURL(`**/jobs/${id}/settings`);
Expand Down
6 changes: 4 additions & 2 deletions packages/app/test/functional/critical.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ test("project and job child requests start after session but do not wait for the
expect(historySearch).toContain("state=failed");
releaseJob();
await jobNavigation;
await expect(page.getByRole("heading", { name: job.name, exact: true })).toBeVisible();
await expect(page.getByRole("heading", { name: job.name, exact: true })).toHaveCount(0);
await expect(page.getByRole("group", { name: "Job actions" }).getByRole("button", { name: "Run job", exact: true })).toBeVisible();
expect(await page.getByRole("status").filter({ hasText: "Loading run history…" }).isVisible()).toBe(true);
releaseHistory();
await expect(page.getByRole("status").filter({ hasText: "Loading run history…" })).toHaveCount(0);
Expand Down Expand Up @@ -155,7 +156,8 @@ test("intent preloading reuses project detail and jobs queries on click", async
await expect.poll(() => requestCounts.get(`/api/v1/jobs/${jobId}`) ?? 0).toBe(1);
await expect.poll(() => requestCounts.get("/api/v1/runs") ?? 0).toBe(1);
await jobLink.click();
await expect(page.getByRole("heading", { name: job.name, exact: true })).toBeVisible();
await expect(page.getByRole("heading", { name: job.name, exact: true })).toHaveCount(0);
await expect(page.getByRole("group", { name: "Job actions" }).getByRole("button", { name: "Run job", exact: true })).toBeVisible();
expect(requestCounts.get(`/api/v1/jobs/${jobId}`)).toBe(1);
expect(requestCounts.get("/api/v1/runs")).toBe(1);
});
Expand Down
32 changes: 19 additions & 13 deletions packages/app/test/jobs.browser.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ test("project tabs stay on projects while job detail gets Runs and Settings navi
const projectNavigation = page.getByRole("navigation", { name: "Project navigation" });
assert.equal(await projectNavigation.getByRole("link", { name: "Jobs", exact: true }).getAttribute("aria-current"), "page");
await page.goto(origin + `/jobs/${jobId}`);
await page.getByRole("heading", { name: "Review builds", exact: true }).waitFor();
assert.equal(await page.getByRole("navigation", { name: "Breadcrumb" }).count(), 0);
assert.equal(await page.getByRole("heading", { name: "Review builds", exact: true }).count(), 0);
assert.equal(await page.getByRole("navigation", { name: "Job navigation" }).getByRole("link", { name: "Runs", exact: true }).getAttribute("aria-current"), "page");
await page.getByRole("navigation", { name: "Job navigation" }).getByRole("link", { name: "Settings", exact: true }).click();
assert.equal(await page.getByRole("navigation", { name: "Job navigation" }).getByRole("link", { name: "Settings", exact: true }).getAttribute("aria-current"), "page");
Expand Down Expand Up @@ -442,7 +442,8 @@ for (const width of [1280, 390, 320]) for (const theme of ["light", "dark"]) tes
assert.ok(requests.every(url => url.searchParams.get("limit") === "30" && url.searchParams.get("q") === "Review" && url.searchParams.get("sort") === "active"));
await table.getByRole("link", { name: "Alpha running", exact: true }).focus(); await page.keyboard.press("Enter");
await page.waitForURL(`**/jobs/${fixtures[30].id}`);
await page.getByRole("heading", { name: "Alpha running", exact: true }).waitFor();
assert.equal(await page.getByRole("heading", { name: "Alpha running", exact: true }).count(), 0);
await page.getByRole("group", { name: "Job actions" }).getByRole("button", { name: "Run job", exact: true }).waitFor();
await context.close();
});
test("mobile jobs list only navigates when a job title is tapped", async () => {
Expand Down Expand Up @@ -573,19 +574,22 @@ for (const width of [1280, 390]) test(`job header actions and status remain usab
const longTitle = "Production deployment " + "with a deliberately long title ".repeat(12);
await page.route(`**/api/v1/jobs/${jobId}`, route => route.fulfill({ json: { ...summary, name: longTitle, enabled, runningCount: 1, concurrencyLimit: 3, promptTemplate: "Template", executionConfigId: "local", triggers: [] } }));
await page.goto(origin + "/jobs/" + jobId);
const heading = page.getByRole("heading", { name: longTitle, exact: true });
await heading.waitFor();
assert.equal(await page.getByRole("heading", { name: longTitle, exact: true }).count(), 0);
assert.equal(await page.getByText("codex · Default model · 1/3 running", { exact: true }).count(), 0);
assert.equal(await page.getByText("Enabled", { exact: true }).count(), 0);
assert.equal(await page.getByRole("button", { name: "Run job", exact: true }).isEnabled(), true);
assert.equal(await page.getByRole("button", { name: "Disable job", exact: true }).count(), 1);
const actions = page.getByRole("group", { name: "Job actions" });
const runButton = actions.getByRole("button", { name: "Run job", exact: true });
const disableButton = actions.getByRole("button", { name: "Disable job", exact: true });
assert.equal(await runButton.isEnabled(), true);
assert.equal(await disableButton.count(), 1);
assert.equal((await runButton.boundingBox()).height, (await disableButton.boundingBox()).height);
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true);
enabled = false;
await page.reload();
await page.getByRole("heading", { name: longTitle, exact: true }).waitFor();
assert.equal(await page.getByRole("button", { name: "Run job", exact: true }).isDisabled(), true);
assert.equal(await page.getByRole("button", { name: "Enable job", exact: true }).count(), 1);
assert.equal(await heading.evaluate(element => getComputedStyle(element).color !== "rgb(15, 23, 42)"), true);
assert.equal(await page.getByRole("heading", { name: longTitle, exact: true }).count(), 0);
assert.equal(await actions.getByRole("button", { name: "Run job", exact: true }).isDisabled(), true);
assert.equal(await actions.getByRole("button", { name: "Enable job", exact: true }).count(), 1);
assert.equal((await actions.getByRole("button", { name: "Run job", exact: true }).boundingBox()).height, (await actions.getByRole("button", { name: "Enable job", exact: true }).boundingBox()).height);
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true);
await context.close();
});
Expand Down Expand Up @@ -652,9 +656,11 @@ test("job Runs tab paginates distinct records, supports refresh/back and keeps c
});
await page.goto(origin + `/jobs/${jobId}?state=failed&contextQuery=old`);
await page.getByRole("link", { name: "Record 0", exact: true }).waitFor();
assert.equal(await page.getByRole("navigation", { name: "Job views" }).getByRole("link", { name: "Runs", exact: true }).getAttribute("aria-current"), "page");
const activeTab = page.getByRole("navigation", { name: "Job views" }).getByRole("link", { name: "Runs", exact: true });
assert.deepEqual(await activeTab.evaluate(el => { const css = getComputedStyle(el); return [css.borderBottomWidth, css.borderBottomStyle, css.borderBottomColor]; }), ["2px", "solid", "rgb(253, 201, 1)"]);
assert.equal(await page.getByRole("navigation", { name: "Job views" }).count(), 0);
assert.equal(await page.getByRole("heading", { name: "Review builds", exact: true }).count(), 0);
const actions = page.getByRole("group", { name: "Job actions" });
assert.equal(await actions.getByRole("button", { name: "Run job", exact: true }).count(), 1);
assert.equal(await actions.getByRole("button", { name: "Disable job", exact: true }).count(), 1);
assert.equal(await page.getByRole("table").locator("tbody tr").count(), 30);
assert.equal(await page.getByText("Prompt template", { exact: true }).count(), 0);
assert.equal(await page.getByText("Triggers", { exact: true }).count(), 0);
Expand Down
Loading