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
10 changes: 5 additions & 5 deletions packages/app/src/features/runs/history.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ export function RunHistory({ jobId }: { jobId: string }) {
const runs = useQuery(historyQuery(jobId, search.cursor, search.sort, search.direction));
const previous = search.previous === undefined ? [] : search.previous.split(",");
const pageClasses = `inline-flex min-h-10 items-center rounded-lg border px-3 py-2 text-sm font-semibold ${buttonClasses.secondary}`;
const columns: Array<[HistorySort, string]> = [["status", "Status"], ["run", "Run"], ["created", "Created"]];
const columns: Array<[HistorySort, string]> = [["run", "Run"], ["status", "Status"], ["created", "Created"], ["agent", "Agent"]];
const sortColumn = (column: HistorySort) => {
const direction = search.sort === column && search.direction === "asc" ? "desc" : "asc";
void navigate({ to: "/jobs/$jobId", params: { jobId }, search: { sort: column, direction, cursor: undefined, previous: undefined } });
};
const sortLabel = (column: HistorySort) => search.sort === column ? (search.direction === "desc" ? "sorted descending" : "sorted ascending") : "not sorted";
return <section aria-label="Runs" className="my-6 min-w-0">
{runs.isPending && <p role="status">Loading run history…</p>}{runs.error && <p role="alert">{runs.error.message} <Button onClick={() => void runs.refetch()}>Retry</Button></p>}
{runs.data && <><Table shellProps={{ role: "region", "aria-label": "Runs table", tabIndex: 0 }}><caption className="sr-only">Job runs{search.sort ? "" : ", newest first"}</caption>
{runs.data && <><Table className="min-w-[36rem] table-fixed" shellProps={{ role: "region", "aria-label": "Runs table", tabIndex: 0 }}><caption className="sr-only">Job runs{search.sort ? "" : ", newest first"}</caption><colgroup><col className="w-[38%] sm:w-[42%]" /><col className="w-16 sm:w-20" /><col className="w-[30%] sm:w-[26%]" /><col className="w-[20%] sm:w-[16%]" /></colgroup>
<thead className={tableHeadClasses}><tr>{columns.map(([column, label]) => <SortableHeader key={column} label={label} active={search.sort === column} direction={search.direction} ariaLabel={`${label}, ${sortLabel(column)}`} onSort={() => sortColumn(column)} />)}</tr></thead>
<tbody>{runs.data.items.map(run => <tr className={tableRowClasses} key={run.id}>
<td className={tableCellClasses}><Link to="/job-runs/$runId" params={{ runId: run.id }} search={{ after: 0 }} title={run.run_name || run.issue_title || "Run"} className="block truncate font-semibold hover:text-factorize-700 focus-visible:rounded-sm dark:hover:text-factorize-500">{run.run_name || run.issue_title || "Run"}</Link></td>
<td className={`whitespace-nowrap ${tableCellClasses}`}><RunStatusDot state={run.state} /></td>
<td className={`min-w-40 max-w-sm break-words ${tableCellClasses}`}><Link to="/job-runs/$runId" params={{ runId: run.id }} search={{ after: 0 }} className="font-semibold hover:text-factorize-700 focus-visible:rounded-sm dark:hover:text-factorize-500">{run.run_name || run.issue_title || "Run"}</Link></td>
<td className={`whitespace-nowrap ${tableCellClasses}`}><time dateTime={run.created_at}>{new Date(run.created_at).toLocaleString()}</time></td>
</tr>)}{runs.data.items.length === 0 && <tr><td colSpan={3} className="px-3 py-6 text-center">No runs found.</td></tr>}</tbody>
<td className={`whitespace-nowrap ${tableCellClasses}`}><time dateTime={run.created_at}>{new Date(run.created_at).toLocaleString()}</time></td><td className={`${tableCellClasses} truncate`} title={run.agent_kind}>{run.agent_kind}</td>
</tr>)}{runs.data.items.length === 0 && <tr><td colSpan={4} className="px-3 py-6 text-center">No runs found.</td></tr>}</tbody>
</Table></>}
<nav aria-label="Run pages" className="mt-4 flex flex-wrap items-center gap-2">
{search.cursor && <Link className={pageClasses} to="/jobs/$jobId" params={{ jobId }} search={{ sort: search.sort, direction: search.direction }}>First page</Link>}
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/features/runs/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function RunList({ jobId, limit = 30 }: { jobId?: string; limit?: number
</nav>;
return <section aria-label="Runs" className="my-6 min-w-0">
{runs.isPending && <p role="status">Loading runs…</p>}{runs.error && <p role="alert">{runs.error.message} <Button onClick={() => void runs.refetch()}>Retry</Button></p>}
{runs.data && <>{runs.data.items.length === 0 && jobId ? <Table shellProps={{ role: "region", "aria-label": "Runs table", tabIndex: 0 }}><tbody><tr><td colSpan={4} className={tableCellClasses + " py-6 text-center"}>No runs found.</td></tr></tbody></Table> : runs.data.items.length === 0 ? <p className="py-8 text-center text-sm text-slate-600 dark:text-slate-400">No runs yet</p> : <Table shellProps={{ role: "region", "aria-label": "Runs table", tabIndex: 0 }}><caption className="sr-only">Runs{search.sort ? "" : ", newest first"}</caption><thead className={tableHeadClasses}><tr>{sortableHeader("status", "Status")}{sortableHeader("job", "Job name")}{sortableHeader("run", "Run")}{sortableHeader("created", "Created")}</tr></thead><tbody>{runs.data.items.map(run => <tr className={tableRowClasses} key={run.id}><td className={`whitespace-nowrap ${tableCellClasses}`}><RunStatusDot state={run.state} /></td><td className={`min-w-40 max-w-sm break-words ${tableCellClasses}`}><Link to="/jobs/$jobId" params={{ jobId: run.job_id }} className="font-semibold hover:text-factorize-700 dark:hover:text-factorize-500">{run.job_name}</Link></td><td className={`min-w-40 max-w-sm break-words ${tableCellClasses}`}><Link to="/job-runs/$runId" params={{ runId: run.id }} search={{ after: 0 }} className="font-semibold hover:text-factorize-700 dark:hover:text-factorize-500">{run.run_name || "Run"}</Link></td><td className={`whitespace-nowrap ${tableCellClasses}`}><time dateTime={run.created_at}>{new Date(run.created_at).toLocaleString()}</time></td></tr>)}</tbody></Table>}</>}
{runs.data && <>{runs.data.items.length === 0 && jobId ? <Table className="min-w-[36rem] table-fixed" shellProps={{ role: "region", "aria-label": "Runs table", tabIndex: 0 }}><tbody><tr><td colSpan={4} className={tableCellClasses + " py-6 text-center"}>No runs found.</td></tr></tbody></Table> : runs.data.items.length === 0 ? <p className="py-8 text-center text-sm text-slate-600 dark:text-slate-400">No runs yet</p> : <Table className="min-w-[36rem] table-fixed" shellProps={{ role: "region", "aria-label": "Runs table", tabIndex: 0 }}><caption className="sr-only">Runs{search.sort ? "" : ", newest first"}</caption><colgroup><col className="w-14 sm:w-16" /><col className="w-[30%] sm:w-[32%]" /><col className="w-[35%] sm:w-[34%]" /><col className="w-[25%] sm:w-[22%]" /></colgroup><thead className={tableHeadClasses}><tr>{sortableHeader("status", "Status")}{sortableHeader("job", "Job name")}{sortableHeader("run", "Run")}{sortableHeader("created", "Created")}</tr></thead><tbody>{runs.data.items.map(run => <tr className={tableRowClasses} key={run.id}><td className={`whitespace-nowrap ${tableCellClasses}`}><RunStatusDot state={run.state} /></td><td className={tableCellClasses}><Link to="/jobs/$jobId" params={{ jobId: run.job_id }} title={run.job_name} className="block truncate font-semibold hover:text-factorize-700 dark:hover:text-factorize-500">{run.job_name}</Link></td><td className={tableCellClasses}><Link to="/job-runs/$runId" params={{ runId: run.id }} search={{ after: 0 }} title={run.run_name || "Run"} className="block truncate font-semibold hover:text-factorize-700 dark:hover:text-factorize-500">{run.run_name || "Run"}</Link></td><td className={`whitespace-nowrap ${tableCellClasses}`}><time dateTime={run.created_at}>{new Date(run.created_at).toLocaleString()}</time></td></tr>)}</tbody></Table>}</>}
{pagination}
</section>;
}
2 changes: 1 addition & 1 deletion packages/app/src/shared/ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const tableHeadClasses = "bg-stone-100 text-xs font-semibold text-slate-6
export const tableRowClasses = "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";
export const tableCellClasses = "px-2 py-2 sm:px-3";
export function Table({ className = "", children, shellProps, ...props }: ComponentProps<"table"> & { shellProps?: ComponentProps<"div"> }) {
return <div {...shellProps} className={`${tableShellClasses} overflow-hidden ${shellProps?.className ?? ""}`}><table {...props} className={`${tableClasses} ${className}`}>{children}</table></div>;
return <div {...shellProps} className={`${tableShellClasses} ${shellProps?.className ?? ""}`}><table {...props} className={`${tableClasses} ${className}`}>{children}</table></div>;
}
export function SortableHeader({ label, active = false, direction = "asc", onSort, className = "", ariaLabel = label }: { label: string; active?: boolean; direction?: "asc" | "desc"; onSort: () => void; className?: string; ariaLabel?: string }) {
const order = active ? (direction === "desc" ? "descending" : "ascending") : "none";
Expand Down
8 changes: 5 additions & 3 deletions packages/app/test/jobs.browser.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -301,15 +301,17 @@ test("run table headers sort every column accessibly and persist in the URL", as
await page.goto(origin + `/jobs/${jobId}`);
const table = page.getByRole("table");
await table.getByRole("columnheader").nth(0).getByRole("button").waitFor();
assert.deepEqual(await table.locator("thead th").allTextContents(), ["Status", "Run", "Created"]);
assert.equal(await table.getByRole("columnheader", { name: /Agent/ }).count(), 0);
for (const index of [0, 1, 2]) assert.equal(await table.getByRole("columnheader").nth(index).getByRole("button").count(), 1);
assert.deepEqual(await table.locator("thead th").allTextContents(), ["Run", "Status", "Created", "Agent"]);
assert.equal(await table.getByRole("columnheader", { name: /Agent/ }).count(), 1);
for (const index of [0, 1, 2, 3]) assert.equal(await table.getByRole("columnheader").nth(index).getByRole("button").count(), 1);
const runButton = page.getByRole("button", { name: "Run job", exact: true }), optionsButton = page.getByRole("button", { name: "More run options", exact: true });
const runBox = await runButton.boundingBox(), optionsBox = await optionsButton.boundingBox();
assert.equal(runBox.x + runBox.width, optionsBox.x);
const runHeader = table.getByRole("button", { name: /Run, not sorted/ });
const widths = await table.locator("thead th").evaluateAll(cells => cells.map(cell => Math.round(cell.getBoundingClientRect().width)));
await runHeader.focus(); await page.keyboard.press("Enter"); await page.waitForURL(`**/jobs/${jobId}?sort=run&direction=asc`);
assert.equal(await table.getByRole("columnheader", { name: /Run/ }).getAttribute("aria-sort"), "ascending");
assert.deepEqual(await table.locator("thead th").evaluateAll(cells => cells.map(cell => Math.round(cell.getBoundingClientRect().width))), widths);
await table.getByRole("button", { name: /Run, sorted ascending/ }).click(); await page.waitForURL(`**/jobs/${jobId}?sort=run&direction=desc`);
assert.equal(requests.at(-1).searchParams.get("direction"), "desc");
await context.close();
Expand Down
19 changes: 19 additions & 0 deletions packages/app/test/runs.browser.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,25 @@ test("all-runs table sorts its data columns with accessible headers", async () =
assert.equal(await table.getByRole("columnheader", { name: /Created/ }).getAttribute("aria-sort"), "descending");
await context.close();
});
test("all-runs columns keep their widths when sorting changes content", async () => {
const { context, page } = await setup();
const shortRuns = [{ id: runId, run_name: "Run", state: "succeeded", created_at: time, updated_at: time, started_at: null, agent_kind: "codex" }];
const longRuns = [{ id: runId, run_name: "A very long run name that should stay inside its assigned column", state: "succeeded", created_at: time, updated_at: time, started_at: null, agent_kind: "codex" }];
await page.route("**/api/v1/runs?**", route => {
const url = new URL(route.request().url());
return route.fulfill({ json: { items: url.searchParams.get("sort") === "run" ? longRuns : shortRuns, nextCursor: null } });
});
for (const viewport of [{ width: 1280, height: 800 }, { width: 390, height: 844 }]) {
await page.setViewportSize(viewport); await page.goto(origin + "/job-runs");
const table = page.getByRole("table");
await table.getByRole("columnheader", { name: /Run/ }).waitFor();
const widths = await table.locator("thead th").evaluateAll(cells => cells.map(cell => Math.round(cell.getBoundingClientRect().width)));
await table.getByRole("button", { name: /Run, not sorted/ }).click(); await page.waitForURL("**/job-runs?sort=run&direction=asc");
const sortedWidths = await table.locator("thead th").evaluateAll(cells => cells.map(cell => Math.round(cell.getBoundingClientRect().width)));
assert.deepEqual(sortedWidths, widths); assert.equal(await table.locator("a").first().evaluate(link => getComputedStyle(link).textOverflow), "ellipsis");
}
await context.close();
});
test("shared run status dots show running transitions in both tables", async () => {
const { context, page } = await setup(); let state = "running";
await page.route(`**/api/v1/jobs/${jobId}`, route => route.fulfill({ json: { id: jobId, name: "Job", enabled: true, model: "", agentKind: "codex", concurrencyLimit: 1, runningCount: state === "running" ? 1 : 0, promptTemplate: "Prompt", triggers: [] } }));
Expand Down
Loading