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
21 changes: 12 additions & 9 deletions packages/app/src/features/jobs/list.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { Card, Badge, buttonClasses, Page } from "../../shared/ui";
import { Link, useSearch } from "@tanstack/react-router";
import { Card, buttonClasses, Page } from "../../shared/ui";
import { Link, useNavigate, useSearch } from "@tanstack/react-router";
import { useQuery } from "@tanstack/react-query";
import { jobsQuery, type JobsSearch } from "./queries";
import { jobsQuery, type JobsOrder, type JobsSearch, type JobsSort } from "./queries";
export function JobsList() {
const search = useSearch({ strict: false }) as JobsSearch;
const navigate = useNavigate({ from: "/jobs" });
const query = useQuery(jobsQuery(search));
const sortLabel = (sort: JobsSort) => sort === "running" ? "Running" : "Title";
const sortOrder = (sort: JobsSort): JobsOrder => search.sort === sort && search.order === "asc" ? "desc" : "asc";
const chooseSort = (sort: JobsSort) => void navigate({ search: { ...search, cursor: undefined, sort, order: sortOrder(sort) } });
const ariaSort = (sort: JobsSort) => search.sort !== sort ? "none" : search.order === "desc" ? "descending" : "ascending";
return <Page >
<div className="mb-5 flex min-w-0 items-center justify-between gap-3">
<h1 className="text-3xl font-bold tracking-tight">Jobs</h1>
Expand All @@ -17,14 +22,12 @@ export function JobsList() {
{!!query.data.items.length && <div className="overflow-hidden rounded-xl border border-stone-200 bg-white shadow-sm dark:border-slate-800 dark:bg-slate-900">
<table className="w-full table-fixed text-left text-sm" aria-label="Jobs">
<thead className="bg-stone-100 text-xs text-slate-600 dark:bg-slate-800 dark:text-slate-400"><tr>
<th scope="col" className="w-24 px-2 py-2 sm:px-3">Status</th>
<th scope="col" className="w-20 px-2 py-2 sm:px-3">Running</th>
<th scope="col" className="px-2 py-2 sm:px-3">Title</th>
<th scope="col" aria-sort={ariaSort("running")} className="w-20 px-2 py-2 sm:px-3"><button type="button" className="font-semibold underline decoration-transparent underline-offset-4 hover:decoration-current focus-visible:rounded-sm focus-visible:decoration-current focus-visible:outline-none" onClick={() => chooseSort("running")} aria-label={`${sortLabel("running")} sort, ${search.sort === "running" ? search.order : "not active"}`}>Running{search.sort === "running" && <span aria-hidden="true"> {search.order === "desc" ? "↓" : "↑"}</span>}</button></th>
<th scope="col" aria-sort={ariaSort("title")} className="px-2 py-2 sm:px-3"><button type="button" className="font-semibold underline decoration-transparent underline-offset-4 hover:decoration-current focus-visible:rounded-sm focus-visible:decoration-current focus-visible:outline-none" onClick={() => chooseSort("title")} aria-label={`${sortLabel("title")} sort, ${search.sort === "title" ? search.order : "not active"}`}>Title{search.sort === "title" && <span aria-hidden="true"> {search.order === "desc" ? "↓" : "↑"}</span>}</button></th>
</tr></thead>
<tbody>{query.data.items.map(job => <tr key={job.id} className="group relative border-t border-stone-200 transition-colors hover:bg-factorize-50 focus-within:bg-factorize-50 focus-within:shadow-[inset_3px_0_0_var(--color-factorize-500)] dark:border-slate-800 dark:hover:bg-factorize-500/10 dark:focus-within:bg-factorize-500/10">
<td className="whitespace-nowrap px-2 py-2 sm:px-3"><Badge active={job.enabled}>{job.enabled ? "Enabled" : "Disabled"}</Badge></td>
<tbody>{query.data.items.map(job => <tr key={job.id} className={`group relative border-t border-stone-200 transition-colors hover:bg-factorize-50 focus-within:bg-factorize-50 focus-within:shadow-[inset_3px_0_0_var(--color-factorize-500)] dark:border-slate-800 dark:hover:bg-factorize-500/10 dark:focus-within:bg-factorize-500/10 ${job.enabled ? "" : "text-slate-500 dark:text-slate-400"}`}>
<td className={`whitespace-nowrap px-2 py-2 font-mono tabular-nums sm:px-3 ${job.runningCount > 0 ? "font-semibold text-factorize-700 dark:text-factorize-500" : "text-slate-600 dark:text-slate-400"}`}>{job.runningCount}/{job.concurrencyLimit}</td>
<td className="px-2 py-2 sm:px-3"><Link to="/jobs/$jobId" params={{ jobId: job.id }} title={job.name} className="block truncate font-semibold outline-none after:absolute after:inset-0 focus-visible:after:rounded-sm focus-visible:after:ring-2 focus-visible:after:ring-inset focus-visible:after:ring-factorize-500">{job.name}</Link></td>
<td className="min-w-0 px-2 py-2 sm:px-3"><div className="flex min-w-0 items-center gap-2"><Link to="/jobs/$jobId" params={{ jobId: job.id }} title={job.name} className="min-w-0 truncate font-semibold outline-none after:absolute after:inset-0 focus-visible:after:rounded-sm focus-visible:after:ring-2 focus-visible:after:ring-inset focus-visible:after:ring-factorize-500">{job.name}</Link>{!job.enabled && <span className="shrink-0 rounded-full border border-stone-300 bg-stone-100 px-1.5 py-0.5 text-[10px] font-semibold leading-tight text-slate-600 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-300">Disabled</span>}</div></td>
</tr>)}</tbody>
</table>
</div>}
Expand Down
15 changes: 12 additions & 3 deletions packages/app/src/features/jobs/queries.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { api } from "factorize-api-client";
import { queryOptions } from "@tanstack/react-query";
import { messageOf } from "../auth/session";
export type JobsSearch = { q: string; cursor?: string; enabled?: "true" | "false" };
export type JobsSort = "running" | "title";
export type JobsOrder = "asc" | "desc";
export type JobsSearch = { q: string; cursor?: string; enabled?: "true" | "false"; sort?: JobsSort; order?: JobsOrder };
export const jobsQuery = (search: JobsSearch) => queryOptions({
queryKey: ["jobs", "summaries", { q: search.q, enabled: search.enabled }],
queryKey: ["jobs", "summaries", { q: search.q, enabled: search.enabled, sort: search.sort, order: search.order }],
queryFn: async ({ signal }) => {
// The API's UUID pages do not reflect running/title order. Collect lightweight
// summaries before paginating so active jobs on later API pages come first.
Expand All @@ -15,7 +17,14 @@ export const jobsQuery = (search: JobsSearch) => queryOptions({
items.push(...data.items);
cursor = data.nextCursor ?? undefined;
} while (cursor);
items.sort((a, b) => Number(b.runningCount > 0) - Number(a.runningCount > 0) || a.name.localeCompare(b.name) || a.id.localeCompare(b.id));
items.sort((a, b) => {
if (!search.sort) return Number(b.runningCount > 0) - Number(a.runningCount > 0) || a.name.localeCompare(b.name) || a.id.localeCompare(b.id);
const direction = search.order === "desc" ? -1 : 1;
const comparison = search.sort === "running"
? a.runningCount - b.runningCount
: a.name.localeCompare(b.name);
return direction * comparison || a.name.localeCompare(b.name) || a.id.localeCompare(b.id);
});
return items;
},
select: items => {
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/features/jobs/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function jobsRoutes(root: AnyRootRoute) {
if (!(await queryClient.ensureQueryData(sessionQuery)).authenticated) throw redirect({ to: "/auth/login", search: { returnTo: location.href, token: undefined } });
};
const jobs = createRoute({ getParentRoute: () => root, path: "/jobs", beforeLoad: guard,
validateSearch: (s: Record<string, unknown>): JobsSearch => ({ q: typeof s.q === "string" ? s.q.slice(0, 120) : "", cursor: typeof s.cursor === "string" ? s.cursor : undefined, enabled: s.enabled === "true" || s.enabled === "false" ? s.enabled : undefined }),
validateSearch: (s: Record<string, unknown>): JobsSearch => ({ q: typeof s.q === "string" ? s.q.slice(0, 120) : "", cursor: typeof s.cursor === "string" ? s.cursor : undefined, enabled: s.enabled === "true" || s.enabled === "false" ? s.enabled : undefined, sort: s.sort === "running" || s.sort === "title" ? s.sort : undefined, order: s.order === "asc" || s.order === "desc" ? s.order : undefined }),
loaderDeps: ({ search }) => search,
loader: ({ deps }) => queryClient.ensureQueryData(jobsQuery(deps)),
component: lazyRouteComponent(() => import("./list"), "JobsList"),
Expand Down
43 changes: 39 additions & 4 deletions packages/app/test/jobs.browser.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ for (const width of [1280, 390, 320]) for (const theme of ["light", "dark"]) tes
await page.goto(origin + "/jobs?q=Review");
const table = page.getByRole("table", { name: "Jobs", exact: true });
await table.getByRole("link", { name: "Alpha running", exact: true }).waitFor();
assert.deepEqual(await table.locator("thead th").allTextContents(), ["Status", "Running", "Title"]);
assert.deepEqual(await table.locator("tbody td:last-child").allTextContents(), ["Alpha running", longTitle, ...fixtures.slice(1, 29).map(job => job.name)]);
assert.deepEqual(await table.locator("tbody tr").first().locator("td").allTextContents(), ["Disabled", "2/10", "Alpha running"]);
assert.deepEqual(await table.locator("tbody tr").nth(2).locator("td").allTextContents(), ["Disabled", "0/2", "Idle 01"]);
assert.deepEqual(await table.locator("thead th").allTextContents(), ["Running", "Title"]);
assert.deepEqual(await table.locator("tbody td:last-child a").allTextContents(), ["Alpha running", longTitle, ...fixtures.slice(1, 29).map(job => job.name)]);
assert.deepEqual(await table.locator("tbody tr").first().locator("td").allTextContents(), ["2/10", "Alpha runningDisabled"]);
assert.deepEqual(await table.locator("tbody tr").nth(2).locator("td").allTextContents(), ["0/2", "Idle 01Disabled"]);
assert.equal(await page.getByLabel("Search jobs", { exact: true }).count(), 0);
assert.equal(await page.getByText("Your software factory. Configure prompts, connect triggers, and follow every run.").count(), 0);
const heading = await page.getByRole("heading", { name: "Jobs", exact: true }).boundingBox(), create = await page.getByRole("link", { name: "Create job", exact: true }).boundingBox();
Expand All @@ -65,6 +65,41 @@ for (const width of [1280, 390, 320]) for (const theme of ["light", "dark"]) tes
await page.getByRole("heading", { name: "Alpha running", exact: true }).waitFor();
await context.close();
});
test("jobs can sort running and title in both directions with accessible state", async () => {
const { page, context } = await contextFor();
const fixtures = [
{ ...summary, id: "job-z", name: "Zulu", runningCount: 1 },
{ ...summary, id: "job-a", name: "Alpha", runningCount: 3, enabled: false },
{ ...summary, id: "job-b", name: "Beta", runningCount: 3 },
{ ...summary, id: "job-i", name: "Idle", runningCount: 0 },
];
await page.route("**/api/v1/job-summaries?**", route => route.fulfill({ json: { items: fixtures, nextCursor: null } }));
await page.goto(origin + "/jobs");
const table = page.getByRole("table", { name: "Jobs", exact: true });
await table.getByRole("link", { name: "Zulu", exact: true }).waitFor();
assert.deepEqual(await table.locator("tbody a").allTextContents(), ["Alpha", "Beta", "Zulu", "Idle"]);
const running = table.getByRole("button", { name: /Running sort/ });
await running.click();
await page.waitForFunction(() => document.querySelector("thead th")?.getAttribute("aria-sort") === "ascending");
assert.equal(await table.locator("th").nth(0).getAttribute("aria-sort"), "ascending");
assert.deepEqual(await table.locator("tbody a").allTextContents(), ["Idle", "Zulu", "Alpha", "Beta"]);
await running.click();
await page.waitForFunction(() => document.querySelector("thead th")?.getAttribute("aria-sort") === "descending");
assert.equal(await table.locator("th").nth(0).getAttribute("aria-sort"), "descending");
assert.deepEqual(await table.locator("tbody a").allTextContents(), ["Alpha", "Beta", "Zulu", "Idle"]);
const title = table.getByRole("button", { name: /Title sort/ });
await title.click();
await page.waitForFunction(() => document.querySelectorAll("thead th")[1]?.getAttribute("aria-sort") === "ascending");
assert.equal(await table.locator("th").nth(1).getAttribute("aria-sort"), "ascending");
assert.deepEqual(await table.locator("tbody a").allTextContents(), ["Alpha", "Beta", "Idle", "Zulu"]);
await page.reload(); await table.getByRole("link", { name: "Alpha", exact: true }).waitFor();
assert.equal(await table.locator("th").nth(1).getAttribute("aria-sort"), "ascending");
await title.click();
await page.waitForFunction(() => document.querySelectorAll("thead th")[1]?.getAttribute("aria-sort") === "descending");
assert.equal(await table.locator("th").nth(1).getAttribute("aria-sort"), "descending");
assert.deepEqual(await table.locator("tbody a").allTextContents(), ["Zulu", "Idle", "Beta", "Alpha"]);
await context.close();
});
test("invocation validates JSON, preserves retry idempotency and navigates to lightweight run/trace", async () => {
const { page, context } = await contextFor();
await page.route(`**/api/v1/jobs/${jobId}`, route => route.fulfill({ json: { ...summary, promptTemplate: "Template", runNameTemplate: "", executionTargetId: "local", executionTarget: { connectionId: "local", workspace: "ephemeral", cwd: "/home/exedev/workspace", agentKind: "codex" }, triggers: [], currentRuns: 0, maxConcurrency: 2 } }));
Expand Down
Binary file modified packages/app/test/visual/baselines/chunk-recovery-dark-390.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/app/test/visual/baselines/chunk-recovery-light-390.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/app/test/visual/baselines/jobs-dark-1280.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/app/test/visual/baselines/jobs-dark-390.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/app/test/visual/baselines/jobs-light-1280.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/app/test/visual/baselines/jobs-light-390.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading