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
Binary file added docs/pr-evidence/gen-2821-header-desktop.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 added docs/pr-evidence/gen-2821-header-mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions packages/api/test/static-slice.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ describe.skipIf(!url)("compiled React + actual Worker API + PostgreSQL", () => {
await page.getByRole("img", { name: "Status: Succeeded", exact: true }).waitFor();
}
await page.goto(`https://factorize.test/projects/${f.projectId}`);
await page.getByRole("link", { name: "owner@example.test", exact: true }).waitFor();
await page.locator("#project-switcher").waitFor();
await page.getByRole("link", { name: "owner", exact: true }).waitFor();
await page.getByRole("link", { name: "Default", exact: true }).waitFor();
await page.getByRole("button", { name: "Switch project", exact: true }).click();
await page.getByRole("combobox", { name: "Search projects", exact: true }).waitFor();
expect(await page.getByRole("link", { name: "Factorize", exact: true }).count()).toBe(0);
expect(await page.locator("html").getAttribute("data-theme")).toBe("light");
expect(await page.locator("body").evaluate((element: any) => (globalThis as any).getComputedStyle(element).backgroundColor)).toBe("rgb(252, 251, 246)");
Expand Down
83 changes: 63 additions & 20 deletions packages/app/src/features/auth/account-bar.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { useEffect, useRef, useState } from "react";
import { useEffect, useMemo, useRef, useState } from "react";
import { Button } from "../../shared/ui";
import { SearchLauncher } from "../search/launcher";
import { ThemeToggle } from "../../shared/theme";
import { Link } from "@tanstack/react-router";
import { Link, useNavigate, useRouterState } from "@tanstack/react-router";
import { useMutation, useQuery } from "@tanstack/react-query";
import { api } from "factorize-api-client";
import { messageOf, refreshIdentity, sessionQuery } from "./session";
import { projectsQuery } from "../projects/queries";
import { useNavigate } from "@tanstack/react-router";
import { projectQuery, projectsQuery } from "../projects/queries";
import beeMark from "../../assets/bee-mark-monochrome.png";

export function AccountBar() {
const session = useQuery(sessionQuery);
const projects = useQuery({ ...projectsQuery, enabled: !!session.data?.authenticated });
const authenticated = session.data?.authenticated;
const projects = useQuery({ ...projectsQuery, enabled: !!authenticated });
const pathname = useRouterState({ select: state => state.location.pathname });
const match = pathname.match(/^\/projects\/([^/]+)/);
const routeProjectId = match && match[1] !== "new" ? decodeURIComponent(match[1]) : undefined;
const routeProject = useQuery({ ...projectQuery(routeProjectId ?? ""), enabled: !!authenticated && !!routeProjectId, retry: false });
const currentProject = projects.data?.find(project => project.id === routeProjectId) ?? routeProject.data;
const navigate = useNavigate();
const logout = useMutation({
retry: false,
Expand All @@ -21,28 +27,65 @@ export function AccountBar() {
await refreshIdentity();
},
});
const [open, setOpen] = useState(false);
const menu = useRef<HTMLDivElement>(null), trigger = useRef<HTMLButtonElement>(null);
const [open, setOpen] = useState(false), [search, setSearch] = useState(""), [active, setActive] = useState(0);
const [accountOpen, setAccountOpen] = useState(false);
const menu = useRef<HTMLDivElement>(null), trigger = useRef<HTMLButtonElement>(null), searchInput = useRef<HTMLInputElement>(null), accountMenu = useRef<HTMLDivElement>(null), accountTrigger = useRef<HTMLButtonElement>(null);
const options = useMemo(() => (projects.data ?? []).filter(project => project.name.toLocaleLowerCase().includes(search.trim().toLocaleLowerCase())), [projects.data, search]);
useEffect(() => {
if (!open) return;
const click = (event: PointerEvent) => { if (!menu.current?.contains(event.target as Node)) setOpen(false); };
const key = (event: KeyboardEvent) => { if (event.key === "Escape") { setOpen(false); trigger.current?.focus(); } };
if (!open && !accountOpen) return;
const click = (event: PointerEvent) => {
if (open && !menu.current?.contains(event.target as Node)) setOpen(false);
if (accountOpen && !accountMenu.current?.contains(event.target as Node)) setAccountOpen(false);
};
const key = (event: KeyboardEvent) => {
if (event.key === "Escape") {
if (open) { setOpen(false); trigger.current?.focus(); }
if (accountOpen) { setAccountOpen(false); accountTrigger.current?.focus(); }
}
};
document.addEventListener("pointerdown", click); document.addEventListener("keydown", key);
return () => { document.removeEventListener("pointerdown", click); document.removeEventListener("keydown", key); };
}, [open]);
const authenticated = session.data?.authenticated;
}, [open, accountOpen]);
const choose = (id: string) => { setOpen(false); setSearch(""); void navigate({ to: "/projects/$projectId", params: { projectId: id } }); };
const email = session.data?.authenticated ? session.data.user.email ?? "" : "";
const initials = (email || "?").split("@")[0].split(/[._-]/).filter(Boolean).slice(0, 2).map((part: string) => part[0]).join("").toUpperCase() || "?";
// The current session contract exposes email only. Use its local part as a readable
// display identity and retain the full address in the account menu.
const displayName = email.split("@")[0] || "Account";
return <header className="border-b border-stone-200 bg-white dark:border-slate-800 dark:bg-slate-950">
<a href="#main-content" className="sr-only focus:not-sr-only focus:absolute focus:z-50 focus:bg-factorize-500 focus:p-3 focus:text-slate-950">Skip to content</a>
<nav aria-label="Main navigation" className="mx-auto flex min-h-16 max-w-6xl flex-wrap items-center justify-between gap-3 px-4 py-3 sm:px-6 lg:px-8">
{authenticated ? <Link to="/" className="truncate text-sm font-semibold text-slate-700 hover:text-factorize-700 dark:text-slate-200 dark:hover:text-factorize-500" title={session.data?.user.email}>{session.data?.user.email}</Link> : <Link to="/" className="text-sm font-semibold">Dashboard</Link>}
<div className="flex flex-wrap items-center gap-2 sm:gap-4">
{authenticated && <><label className="sr-only" htmlFor="project-switcher">Project</label><input id="project-switcher" list="project-options" placeholder="Select project…" className="h-10 w-36 rounded-lg border border-stone-300 bg-white px-3 text-sm dark:border-slate-700 dark:bg-slate-900 sm:w-52" onChange={event => { const project = projects.data?.find(item => item.name === event.currentTarget.value); if (project) void navigate({ to: "/projects/$projectId", params: { projectId: project.id } }); }} /><datalist id="project-options">{projects.data?.map(project => <option key={project.id} value={project.name} />)}</datalist><SearchLauncher /></>}
<nav aria-label="Main navigation" className="mx-auto flex min-h-16 max-w-6xl flex-wrap items-center justify-between gap-x-5 gap-y-3 px-4 py-3 sm:px-6 lg:px-8">
<div className="flex min-w-0 flex-1 items-center gap-3 sm:gap-4">
<Link to="/" aria-label="Factorize dashboard" className="flex shrink-0 items-center"><img src={beeMark} alt="" className="size-8 object-contain" /></Link>
<span aria-hidden="true" className="h-8 w-px shrink-0 bg-stone-300 dark:bg-slate-700" />
{authenticated ? <div className="flex min-w-0 items-center gap-2 text-sm font-semibold">
<Link to="/" title={session.data?.user.email} className="max-w-[38vw] truncate text-slate-700 hover:text-factorize-700 dark:text-slate-200 dark:hover:text-factorize-500 sm:max-w-56">{displayName}</Link>
<span aria-hidden="true" className="text-slate-400">/</span>
<div ref={menu} className="relative flex min-w-0 items-center">
{currentProject ? <Link to="/projects/$projectId" params={{ projectId: currentProject.id }} className="max-w-[35vw] truncate text-slate-700 hover:text-factorize-700 dark:text-slate-200 sm:max-w-64">{currentProject.name}</Link> : routeProjectId ? <span className="truncate text-slate-600 dark:text-slate-300">{routeProject.isPending ? "Loading project…" : routeProject.error ? "Project unavailable" : "Project"}</span> : <Link to="/projects" className="truncate text-slate-600 hover:text-factorize-700 dark:text-slate-300 dark:hover:text-factorize-500">Projects</Link>}
<button ref={trigger} type="button" aria-label="Switch project" aria-haspopup="listbox" aria-expanded={open} className="ml-1 flex size-8 shrink-0 items-center justify-center rounded-md text-slate-600 hover:bg-stone-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-factorize-500 dark:text-slate-300 dark:hover:bg-slate-800" onClick={() => { setOpen(value => !value); setSearch(""); setActive(0); requestAnimationFrame(() => searchInput.current?.focus()); }}><svg aria-hidden="true" viewBox="0 0 20 20" className="size-4 fill-current"><path d="m5 7 5 5 5-5" /></svg></button>
{open && <div className="absolute left-0 top-full z-40 mt-2 w-[min(19rem,calc(100vw-2rem))] rounded-xl border border-stone-200 bg-white p-2 shadow-xl dark:border-slate-700 dark:bg-slate-900">
<label className="sr-only" htmlFor="project-switcher-search">Search projects</label>
<input ref={searchInput} id="project-switcher-search" role="combobox" aria-autocomplete="list" aria-controls="project-switcher-options" aria-expanded="true" aria-activedescendant={options[active] ? `project-option-${options[active].id}` : undefined} value={search} onChange={event => { setSearch(event.target.value); setActive(0); }} onKeyDown={event => { if (event.key === "ArrowDown") { event.preventDefault(); setActive(index => Math.min(index + 1, options.length - 1)); } else if (event.key === "ArrowUp") { event.preventDefault(); setActive(index => Math.max(index - 1, 0)); } else if (event.key === "Enter" && options[active]) { event.preventDefault(); choose(options[active].id); } }} placeholder="Search projects…" className="h-10 w-full rounded-lg border border-stone-300 bg-white px-3 text-sm outline-none focus:border-factorize-500 focus:ring-2 focus:ring-factorize-500/30 dark:border-slate-700 dark:bg-slate-950" />
<ul id="project-switcher-options" role="listbox" aria-label="Projects" className="mt-2 max-h-64 overflow-y-auto">
{projects.isPending && <li role="status" className="px-3 py-2 text-sm text-slate-500">Loading projects…</li>}
{projects.error && <li role="alert" className="px-3 py-2 text-sm text-red-700">{projects.error.message}</li>}
{projects.data?.length === 0 && <li className="px-3 py-2 text-sm text-slate-500">No projects yet.</li>}
{projects.data && !projects.error && options.length === 0 && projects.data.length > 0 && <li className="px-3 py-2 text-sm text-slate-500">No matching projects.</li>}
{options.map((project, index) => <li key={project.id} id={`project-option-${project.id}`} role="option" aria-selected={project.id === routeProjectId} className={`cursor-pointer rounded-lg px-3 py-2 text-sm ${index === active ? "bg-factorize-50 text-slate-950 dark:bg-slate-800 dark:text-white" : "text-slate-700 dark:text-slate-200"}`} onMouseEnter={() => setActive(index)} onMouseDown={event => event.preventDefault()} onClick={() => choose(project.id)}>{project.name}{project.id === routeProjectId && <span className="ml-2 text-xs text-slate-500">Current</span>}</li>)}
</ul>
</div>}
</div>
</div> : <Link to="/" className="text-sm font-semibold">Dashboard</Link>}
</div>
<div className="flex shrink-0 items-center gap-2 sm:gap-4">
{authenticated && <SearchLauncher />}
<ThemeToggle />
{authenticated ? <div ref={menu} className="relative">
<Button ref={trigger} aria-expanded={open} aria-controls="profile-menu" onClick={() => setOpen(!open)} aria-label="Your account" className="!size-10 !min-h-10 !rounded-full !p-1"><span className="flex size-7 items-center justify-center rounded-full bg-factorize-100 text-xs font-semibold text-slate-950">{(session.data?.user.email ?? "").slice(0, 1).toUpperCase()}</span></Button>
{open && <div id="profile-menu" className="absolute right-0 z-30 mt-2 w-64 rounded-xl border border-stone-200 bg-white p-3 shadow-lg dark:border-slate-700 dark:bg-slate-900">
{authenticated ? <div ref={accountMenu} className="relative">
<Button ref={accountTrigger} aria-expanded={accountOpen} aria-controls="profile-menu" onClick={() => setAccountOpen(!accountOpen)} aria-label="Your account" className="!size-10 !min-h-10 !rounded-full !border-0 !bg-factorize-500 !p-0 text-sm font-semibold text-slate-950">{initials}</Button>
{accountOpen && <div id="profile-menu" className="absolute right-0 z-30 mt-2 w-64 rounded-xl border border-stone-200 bg-white p-3 shadow-lg dark:border-slate-700 dark:bg-slate-900">
<p className="mb-3 break-all px-2 text-xs text-slate-600 dark:text-slate-300">{session.data?.user.email ?? ""}</p>
<Link to="/settings" onClick={() => setOpen(false)} className="block rounded-lg px-3 py-3 text-sm hover:bg-stone-100 dark:hover:bg-slate-800">Settings</Link>
<Link to="/settings" onClick={() => setAccountOpen(false)} className="block rounded-lg px-3 py-3 text-sm hover:bg-stone-100 dark:hover:bg-slate-800">Settings</Link>
<Button className="mt-2 w-full" onClick={() => logout.mutate()} disabled={logout.isPending}>{logout.isPending ? "Signing out…" : "Sign out"}</Button>
</div>}
</div> : <Link to="/auth/login" className="rounded-lg px-3 py-2 text-sm font-semibold">Account</Link>}
Expand Down
2 changes: 1 addition & 1 deletion packages/app/test/jobs.browser.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ test("project tabs omit redundant headings while job detail keeps its project br
await page.goto(origin + `/projects/${projectId}`);
await page.getByRole("heading", { name: "Release project jobs", exact: true }).waitFor();
assert.equal(await page.getByRole("navigation", { name: "Breadcrumb" }).count(), 0);
assert.equal(await page.getByRole("heading", { name: "Release project", exact: true }).count(), 0);
assert.equal(await page.getByRole("navigation", { name: "Main navigation" }).getByRole("link", { name: "Release project", exact: true }).count(), 1);
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}`);
Expand Down
8 changes: 5 additions & 3 deletions packages/app/test/runs.browser.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ test("run page errors back off for ten seconds and recover", async () => {
for (let elapsed = 0; count < 4 && elapsed < 2000; elapsed++) await page.clock.runFor(1);
await recoveredResponse; await page.getByRole("link", { name: "Polling run", exact: true }).waitFor(); await page.getByRole("alert").waitFor({ state: "detached" }); assert.equal(count, 4, "the ten-second error interval should retry and recover");
await page.clock.runFor(12_000); assert.equal(count, 4, "a successful response should return to the 15-second idle interval");
await page.clock.runFor(5_000); assert.equal(count, 5, "the idle interval should refresh after about 15 seconds");
const idleRefetch = page.waitForResponse(response => new URL(response.url()).pathname === "/api/v1/runs");
await page.clock.runFor(10_000); await idleRefetch; assert.equal(count, 5, "the idle interval should refresh after about 15 seconds");
await context.close();
});
test("all-jobs runs index uses a tenant-scoped page, navigation, refresh, and created time", async () => {
Expand Down Expand Up @@ -106,9 +107,10 @@ test("all-runs status header supports multi-select filtering, independent sortin
await dialog.waitFor({ state: "hidden" });
await page.getByRole("button", { name: /Status, 2 statuses selected/ }).click();
const requestCountBeforeClear = requests.length;
await page.getByRole("dialog", { name: "Status filter and sort" }).getByRole("button", { name: "Clear filters and reset sort" }).click(); await page.waitForFunction(() => { const params = new URLSearchParams(location.search); return location.pathname === "/job-runs" && !params.has("state") && !params.has("states"); });
await page.getByRole("dialog", { name: "Status filter and sort" }).getByRole("button", { name: "Clear filters and reset sort" }).click(); await page.waitForFunction(() => { const params = new URLSearchParams(location.search); return location.pathname === "/job-runs" && !params.has("state") && !params.has("states") && !params.has("sort") && !params.has("direction"); });
await page.getByRole("link", { name: "Run", exact: true }).waitFor();
assert.ok(requests.slice(requestCountBeforeClear).every(url => !url.searchParams.has("state")), "clearing statuses must not issue a request with stale status filters"); await context.close();
assert.ok(requests.slice(requestCountBeforeClear).every(url => !url.searchParams.has("state") && !url.searchParams.has("states")), "clearing filters must not issue a request with stale status filters");
assert.ok(requests.some(url => url.pathname === "/api/v1/runs" && !url.searchParams.has("state") && !url.searchParams.has("states")), "clearing filters should fetch the unfiltered run list"); await context.close();
});
test("all-runs combines independent project and job filters, preserves them through pagination, and toggles row filters", async () => {
const { context, page } = await setup(); const requests = [], projectA = "00000000-0000-4000-8000-000000000003", jobA = "00000000-0000-4000-8000-000000000001";
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/clients-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/clients-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/consent-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/consent-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/device-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/device-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/editor-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/index-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/index-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-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/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-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/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-error-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/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/jobs-loading-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/keys-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/keys-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/login-dark-390.png
Binary file modified packages/app/test/visual/baselines/login-light-390.png
Binary file modified packages/app/test/visual/baselines/long-job-mobile.png
Binary file modified packages/app/test/visual/baselines/not-found-dark-390.png
Binary file modified packages/app/test/visual/baselines/not-found-light-390.png
Binary file modified packages/app/test/visual/baselines/password-dark-390.png
Binary file modified packages/app/test/visual/baselines/password-light-390.png
Binary file modified packages/app/test/visual/baselines/project-jobs-desktop.png
Binary file modified packages/app/test/visual/baselines/project-jobs-mobile.png
Binary file modified packages/app/test/visual/baselines/run-context-dark-390.png
Binary file modified packages/app/test/visual/baselines/run-context-light-390.png
Binary file modified packages/app/test/visual/baselines/search-empty-mobile.png
Binary file modified packages/app/test/visual/baselines/search-error-dark-390.png
Binary file modified packages/app/test/visual/baselines/search-error-light-390.png
Binary file modified packages/app/test/visual/baselines/search-loading-dark-390.png
Binary file modified packages/app/test/visual/baselines/search-loading-light-390.png
Binary file modified packages/app/test/visual/baselines/search-no-results-light-390.png
Binary file modified packages/app/test/visual/baselines/search-results-mobile.png
Binary file modified packages/app/test/visual/baselines/settings-dark-1280.png
Binary file modified packages/app/test/visual/baselines/settings-dark-390.png
Binary file modified packages/app/test/visual/baselines/settings-light-1280.png
Binary file modified packages/app/test/visual/baselines/settings-light-390.png
Binary file modified packages/app/test/visual/baselines/signup-mobile.png
Loading