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
22 changes: 13 additions & 9 deletions packages/app/src/features/search/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ export default function SearchDialog({ close }: { close: () => void }) {
const items = results.data?.items ?? [];
useEffect(() => { dialog.current?.querySelector(`#search-result-${selected}`)?.scrollIntoView({ block: "nearest" }); }, [selected, results.data]);
const choose = (index: number) => { const item = items[index]; if (!item) return; close(); if (item.kind === "job") void navigate({ to: "/jobs/$jobId", params: { jobId: item.id } }); else void navigate({ to: "/job-runs/$runId", params: { runId: item.id }, search: { after: 0 } }); };
return <dialog ref={dialog} aria-label="Search jobs and runs" onClose={close} onClick={e => { if (e.target === e.currentTarget) close(); }} className="w-[min(92vw,42rem)] max-h-[80vh] overflow-auto">
<div className="mb-4 flex items-start justify-between gap-3"><h2>Search</h2><Button onClick={close}>Close search</Button></div><Label>Search jobs and runs <Input autoFocus role="combobox" aria-expanded={items.length > 0} aria-autocomplete="list" value={text} maxLength={500} aria-controls="search-results" aria-activedescendant={items.length ? `search-result-${selected}` : undefined} onChange={e => setText(e.target.value)} onKeyDown={e => {
if (e.key === "ArrowDown" && items.length) { e.preventDefault(); setSelected(index => (index + 1) % items.length); }
if (e.key === "ArrowUp" && items.length) { e.preventDefault(); setSelected(index => (index - 1 + items.length) % items.length); }
if (e.key === "Enter") { e.preventDefault(); choose(selected); }
}} /></Label>
{!q && <p className="my-4 text-sm text-slate-600 dark:text-slate-400">Find jobs and runs by name, prompt, or context. Use ↑ ↓ to select and Enter to open.</p>}
{results.isFetching && <p role="status">Searching…</p>}{results.error && <p role="alert">{results.error.message}</p>}{q && !results.isPending && !items.length && <p>No results found.</p>}
<ul id="search-results" role="listbox" aria-label="Search results">{items.map((item, index) => <li key={`${item.kind}:${item.id}:${index}`} role="presentation"><Button role="option" id={`search-result-${index}`} aria-selected={selected === index} tabIndex={-1} className="my-2 w-full flex-col items-start text-left aria-selected:border-factorize-500 aria-selected:bg-factorize-50 dark:aria-selected:bg-factorize-500/10" onClick={() => choose(index)}>{item.title}<span className="block text-sm">{item.kind} · {item.subtitle}</span></Button></li>)}</ul>
return <dialog ref={dialog} aria-label="Search jobs and runs" onClose={close} onClick={e => { if (e.target === e.currentTarget) close(); }} className="w-[min(92vw,42rem)] h-[min(36rem,80dvh)] overflow-hidden">
<div className="flex h-full min-h-0 flex-col">
<div className="mb-4 flex shrink-0 items-start justify-between gap-3"><h2>Search</h2><Button onClick={close}>Close search</Button></div><Label className="shrink-0">Search jobs and runs <Input autoFocus role="combobox" aria-expanded={items.length > 0} aria-autocomplete="list" value={text} maxLength={500} aria-controls="search-results" aria-activedescendant={items.length ? `search-result-${selected}` : undefined} onChange={e => setText(e.target.value)} onKeyDown={e => {
if (e.key === "ArrowDown" && items.length) { e.preventDefault(); setSelected(index => (index + 1) % items.length); }
if (e.key === "ArrowUp" && items.length) { e.preventDefault(); setSelected(index => (index - 1 + items.length) % items.length); }
if (e.key === "Enter") { e.preventDefault(); choose(selected); }
}} /></Label>
<div className="mt-4 min-h-0 flex-1 overflow-y-auto overscroll-contain [scrollbar-gutter:stable]">
{!q && <p className="my-4 text-sm text-slate-600 dark:text-slate-400">Find jobs and runs by name, prompt, or context. Use ↑ ↓ to select and Enter to open.</p>}
{results.isFetching && <p role="status">Searching…</p>}{results.error && <p role="alert">{results.error.message}</p>}{q && !results.isPending && !items.length && <p>No results found.</p>}
<ul id="search-results" role="listbox" aria-label="Search results">{items.map((item, index) => <li key={`${item.kind}:${item.id}:${index}`} role="presentation"><Button role="option" id={`search-result-${index}`} aria-selected={selected === index} tabIndex={-1} className="my-2 w-full flex-col items-start text-left aria-selected:border-factorize-500 aria-selected:bg-factorize-50 dark:aria-selected:bg-factorize-500/10" onClick={() => choose(index)}>{item.title}<span className="block text-sm">{item.kind} · {item.subtitle}</span></Button></li>)}</ul>
</div>
</div>
</dialog>;
}
Binary file modified packages/app/test/visual/baselines/search-empty-mobile.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/search-error-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/search-error-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/search-loading-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/search-loading-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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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/search-results-mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 56 additions & 0 deletions packages/app/test/visual/design.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,59 @@ for (const theme of ["light", "dark"]) test(`search loading, error and no result
await expect(page).toHaveScreenshot(`search-no-results-${theme}-390.png`);
expect((await new AxeBuilder({ page }).withTags(["wcag2a", "wcag2aa", "wcag21aa"]).analyze()).violations).toEqual([]);
});

for (const viewport of [{ width: 1280, height: 900 }, { width: 390, height: 844 }, { width: 390, height: 400 }]) test(`search geometry stays stable through asynchronous query changes ${viewport.width}x${viewport.height}`, async ({ page }) => {
await page.setViewportSize(viewport); await mockApi(page);
let pending;
await page.route("**/api/v1/search?**", route => { pending = route; });
await page.goto(origin + "/jobs");
const opener = page.getByRole("button", { name: "Search jobs and runs", exact: true });
await opener.click();
const dialog = page.getByRole("dialog"), input = dialog.getByRole("combobox");
await expect(input).toBeFocused();
const geometry = async () => ({ panel: await dialog.boundingBox(), input: await input.boundingBox() });
const initial = await geometry();
expect(initial.panel.y).toBeGreaterThanOrEqual(0);
expect(initial.panel.y + initial.panel.height).toBeLessThanOrEqual(viewport.height);
const items = count => Array.from({ length: count }, (_, index) => ({ kind: "job", id: jobId, title: `Result ${index + 1}`, subtitle: "Matching job " + "long text ".repeat(8) }));
for (const [query, count] of [["missing", 0], ["few", 2], ["many", 30], ["changed", 1], ["empty again", 0]]) {
pending = undefined;
await input.fill(query);
await expect(dialog.getByRole("status")).toHaveText("Searching…");
expect(await geometry()).toEqual(initial);
await expect.poll(() => pending && new URL(pending.request().url()).searchParams.get("q")).toBe(query);
await pending.fulfill({ json: { items: items(count) } });
await expect(dialog.getByRole("option")).toHaveCount(count);
await expect(dialog.getByRole("status")).toHaveCount(0);
if (!count) await expect(dialog.getByText("No results found.", { exact: true })).toBeVisible();
expect(await geometry()).toEqual(initial);
await expect(input).toBeFocused();
if (count === 30) {
await input.press("ArrowUp");
await expect(input).toHaveAttribute("aria-activedescendant", "search-result-29");
await expect(dialog.getByRole("option").last()).toHaveAttribute("aria-selected", "true");
const last = await dialog.getByRole("option").last().boundingBox();
expect(last.y + last.height).toBeLessThanOrEqual(initial.panel.y + initial.panel.height);
expect(await dialog.locator("#search-results").evaluate(list => list.parentElement.scrollTop)).toBeGreaterThan(0);
expect(await geometry()).toEqual(initial);
await input.press("ArrowDown");
await expect(input).toHaveAttribute("aria-activedescendant", "search-result-0");
}
}
await input.fill("");
await expect(dialog.getByText("Find jobs and runs", { exact: false })).toBeVisible();
expect(await geometry()).toEqual(initial);
await input.fill("select");
await expect(dialog.getByRole("status")).toHaveText("Searching…");
await expect.poll(() => pending && new URL(pending.request().url()).searchParams.get("q")).toBe("select");
await pending.fulfill({ json: { items: items(2) } });
await expect(dialog.getByRole("option")).toHaveCount(2);
await input.press("ArrowDown"); await input.press("Enter");
await expect(dialog).toHaveCount(0); await expect(page).toHaveURL(origin + "/jobs/" + jobId);
await opener.click(); await input.fill("click");
await expect(dialog.getByRole("status")).toHaveText("Searching…");
await expect.poll(() => pending && new URL(pending.request().url()).searchParams.get("q")).toBe("click");
await pending.fulfill({ json: { items: items(1) } });
await dialog.getByRole("option").click(); await expect(dialog).toHaveCount(0);
await opener.click(); await page.keyboard.press("Escape"); await expect(opener).toBeFocused();
});
Loading