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
20 changes: 11 additions & 9 deletions packages/app/src/features/jobs/list.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Card, buttonClasses, Page } from "../../shared/ui";
import { Card, Badge, buttonClasses, Page, tableCellClasses, tableClasses, tableHeadClasses, tableRowClasses, tableShellClasses } from "../../shared/ui";
import { Link, useNavigate, useSearch } from "@tanstack/react-router";
import { useQuery } from "@tanstack/react-query";
import { jobsQuery, type JobsOrder, type JobsSearch, type JobsSort } from "./queries";
Expand All @@ -19,15 +19,17 @@ export function JobsList() {
{query.error && <p role="alert">{query.error.message}</p>}
{query.data && <>
{!query.data.items.length && <Card className="py-12 text-center"><h2>No jobs found</h2><p className="text-sm text-slate-600 dark:text-slate-400">Create your first job or adjust your search.</p></Card>}
{!!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" 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>
{!!query.data.items.length && <div className={`${tableShellClasses} overflow-hidden`}>
<table className={`${tableClasses} table-fixed`} aria-label="Jobs">
<thead className={tableHeadClasses}><tr>
<th scope="col" className={`w-24 ${tableCellClasses}`}>Status</th>
<th scope="col" aria-sort={ariaSort("running")} className={`w-20 ${tableCellClasses}`}><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={tableCellClasses}><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 ${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="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>
<tbody>{query.data.items.map(job => <tr key={job.id} className={tableRowClasses}>
<td className={`whitespace-nowrap ${tableCellClasses}`}><Badge active={job.enabled}>{job.enabled ? "Enabled" : "Disabled"}</Badge></td>
<td className={`whitespace-nowrap ${tableCellClasses} font-mono tabular-nums ${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={tableCellClasses}><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>
</tr>)}</tbody>
</table>
</div>}
Expand Down
16 changes: 8 additions & 8 deletions packages/app/src/features/runs/history.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Badge, Button, buttonClasses } from "../../shared/ui";
import { Badge, Button, buttonClasses, tableCellClasses, tableClasses, tableHeadClasses, tableRowClasses, tableShellClasses } from "../../shared/ui";
import { Link, useNavigate, useSearch } from "@tanstack/react-router";
import { useQuery } from "@tanstack/react-query";
import { historyQuery } from "./queries";
Expand All @@ -18,13 +18,13 @@ export function RunHistory({ jobId }: { jobId: string }) {
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 && <><div role="region" aria-label="Runs table" tabIndex={0} className="overflow-x-auto rounded-lg border border-stone-200 dark:border-slate-700">
<table className="w-full text-left text-sm"><caption className="sr-only">Job runs{search.sort ? "" : ", newest first"}</caption>
<thead className="bg-stone-100 dark:bg-slate-800"><tr>{columns.map(([column, label]) => <th key={column} scope="col" aria-sort={search.sort === column ? (search.direction === "desc" ? "descending" : "ascending") : "none"} className="px-3 py-2"><Button className="min-h-8 border-0 bg-transparent px-0 py-0 text-left hover:bg-transparent dark:bg-transparent" aria-label={`${label}, ${sortLabel(column)}. Activate to sort ${search.sort === column && search.direction === "asc" ? "descending" : "ascending"}`} onClick={() => sortColumn(column)}>{label}{search.sort === column && <span aria-hidden="true"> {search.direction === "desc" ? "↓" : "↑"}</span>}</Button></th>)}</tr></thead>
<tbody>{runs.data.items.map(run => <tr className="border-t border-stone-200 dark:border-slate-700" key={run.id}>
<td className="min-w-40 max-w-sm break-words px-3 py-2"><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.issue_title || "Run"}</Link></td>
<td className="px-3 py-2"><Badge active={run.state === "running"}>{run.state}</Badge></td>
<td className="whitespace-nowrap px-3 py-2"><time dateTime={run.created_at}>{new Date(run.created_at).toLocaleString()}</time></td><td className="px-3 py-2">{run.agent_kind}</td>
{runs.data && <><div role="region" aria-label="Runs table" tabIndex={0} className={tableShellClasses}>
<table className={tableClasses}><caption className="sr-only">Job runs{search.sort ? "" : ", newest first"}</caption>
<thead className={tableHeadClasses}><tr>{columns.map(([column, label]) => <th key={column} scope="col" aria-sort={search.sort === column ? (search.direction === "desc" ? "descending" : "ascending") : "none"} className={tableCellClasses}><Button className="min-h-8 border-0 bg-transparent px-0 py-0 text-left hover:bg-transparent dark:bg-transparent" aria-label={`${label}, ${sortLabel(column)}. Activate to sort ${search.sort === column && search.direction === "asc" ? "descending" : "ascending"}`} onClick={() => sortColumn(column)}>{label}{search.sort === column && <span aria-hidden="true"> {search.direction === "desc" ? "↓" : "↑"}</span>}</Button></th>)}</tr></thead>
<tbody>{runs.data.items.map(run => <tr className={tableRowClasses} key={run.id}>
<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}`}><Badge active={run.state === "running"}>{run.state}</Badge></td>
<td className={`whitespace-nowrap ${tableCellClasses}`}><time dateTime={run.created_at}>{new Date(run.created_at).toLocaleString()}</time></td><td className={tableCellClasses}>{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>
</div></>}
Expand Down
5 changes: 5 additions & 0 deletions packages/app/src/shared/ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ export const buttonClasses = {
secondary: "bg-white text-slate-700 border-stone-200 hover:bg-stone-100 dark:bg-slate-900 dark:text-slate-200 dark:border-slate-700 dark:hover:bg-slate-800",
destructive: "bg-red-50 text-red-800 border-red-200 hover:bg-red-100 dark:bg-red-950 dark:text-red-200 dark:border-red-800",
};
export const tableShellClasses = "overflow-x-auto rounded-xl border border-stone-200 bg-white shadow-sm dark:border-slate-800 dark:bg-slate-900";
export const tableClasses = "w-full text-left text-sm";
export const tableHeadClasses = "bg-stone-100 text-xs font-semibold text-slate-600 dark:bg-slate-800 dark:text-slate-400";
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 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
24 changes: 12 additions & 12 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(), ["Running", "Title"]);
assert.deepEqual(await table.locator("thead th").allTextContents(), ["Status", "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.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.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 Down Expand Up @@ -80,23 +80,23 @@ test("jobs can sort running and title in both directions with accessible state",
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");
await page.waitForFunction(() => document.querySelector("thead th:nth-child(2)")?.getAttribute("aria-sort") === "ascending");
assert.equal(await table.locator("th").nth(1).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");
await page.waitForFunction(() => document.querySelector("thead th:nth-child(2)")?.getAttribute("aria-sort") === "descending");
assert.equal(await table.locator("th").nth(1).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");
await page.waitForFunction(() => document.querySelectorAll("thead th")[2]?.getAttribute("aria-sort") === "ascending");
assert.equal(await table.locator("th").nth(2).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");
assert.equal(await table.locator("th").nth(2).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");
await page.waitForFunction(() => document.querySelectorAll("thead th")[2]?.getAttribute("aria-sort") === "descending");
assert.equal(await table.locator("th").nth(2).getAttribute("aria-sort"), "descending");
assert.deepEqual(await table.locator("tbody a").allTextContents(), ["Zulu", "Idle", "Beta", "Alpha"]);
await context.close();
});
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/job-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/job-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.
Binary file modified packages/app/test/visual/baselines/long-job-mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading