diff --git a/packages/api/test/static-slice.e2e.test.ts b/packages/api/test/static-slice.e2e.test.ts index 39e4abd7..561909c3 100644 --- a/packages/api/test/static-slice.e2e.test.ts +++ b/packages/api/test/static-slice.e2e.test.ts @@ -63,7 +63,8 @@ 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", exact: true }).waitFor(); + await page.getByRole("button", { name: "Your account", exact: true }).waitFor(); + expect(await page.getByRole("link", { name: "owner", exact: true }).count()).toBe(0); 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(); diff --git a/packages/app/src/features/auth/account-bar.tsx b/packages/app/src/features/auth/account-bar.tsx index f4b06449..adb2c63d 100644 --- a/packages/app/src/features/auth/account-bar.tsx +++ b/packages/app/src/features/auth/account-bar.tsx @@ -1,4 +1,4 @@ -import { useEffect, useMemo, useRef, useState } from "react"; +import { useEffect, useRef, useState } from "react"; import { Button } from "../../shared/ui"; import { SearchLauncher } from "../search/launcher"; import { ThemeToggle } from "../../shared/theme"; @@ -7,7 +7,9 @@ import { useMutation, useQuery } from "@tanstack/react-query"; import { api } from "factorize-api-client"; import { messageOf, refreshIdentity, sessionQuery } from "./session"; import { projectQuery, projectsQuery } from "../projects/queries"; -import { jobQuery } from "../jobs/queries"; +import { jobQuery, jobsQuery } from "../jobs/queries"; +import { runStatusQuery } from "../runs/queries"; +import { ResourceSwitcher } from "../../shared/resource-switcher"; import beeMark from "../../assets/bee-mark-monochrome.png"; export function AccountBar() { @@ -19,10 +21,15 @@ export function AccountBar() { const routeProjectId = projectMatch && projectMatch[1] !== "new" ? decodeURIComponent(projectMatch[1]) : undefined; const jobMatch = pathname.match(/^\/jobs\/([^/]+)/); const routeJobId = jobMatch && jobMatch[1] !== "new" ? decodeURIComponent(jobMatch[1]) : undefined; - const routeJob = useQuery({ ...jobQuery(routeJobId ?? ""), enabled: !!authenticated && !!routeJobId, retry: false }); + const runMatch = pathname.match(/^\/job-runs\/([^/]+)/); + const routeRunId = runMatch && runMatch[1] !== "new" ? decodeURIComponent(runMatch[1]) : undefined; + const routeRun = useQuery({ ...runStatusQuery(routeRunId ?? ""), enabled: !!authenticated && !!routeRunId }); + const currentJobId = routeJobId ?? routeRun.data?.job_id; + const routeJob = useQuery({ ...jobQuery(currentJobId ?? ""), enabled: !!authenticated && !!currentJobId, retry: false }); const currentProjectId = routeProjectId ?? routeJob.data?.projectId; const routeProject = useQuery({ ...projectQuery(currentProjectId ?? ""), enabled: !!authenticated && !!currentProjectId, retry: false }); const currentProject = projects.data?.find(project => project.id === currentProjectId) ?? routeProject.data; + const projectJobs = useQuery({ ...jobsQuery({ projectId: currentProjectId, sort: "title" }), enabled: !!authenticated && !!currentJobId && !!currentProjectId }); const navigate = useNavigate(); const logout = useMutation({ retry: false, @@ -32,31 +39,19 @@ export function AccountBar() { await refreshIdentity(); }, }); - const [open, setOpen] = useState(false), [search, setSearch] = useState(""), [active, setActive] = useState(0); const [accountOpen, setAccountOpen] = useState(false), [mobileAccountOpen, setMobileAccountOpen] = useState(false); - const menu = useRef(null), trigger = useRef(null), searchInput = useRef(null), accountMenu = useRef(null), accountTrigger = useRef(null), mobileAccountMenu = useRef(null), mobileAccountTrigger = useRef(null); - const options = useMemo(() => (projects.data ?? []).filter(project => project.name.toLocaleLowerCase().includes(search.trim().toLocaleLowerCase())), [projects.data, search]); + const accountMenu = useRef(null), accountTrigger = useRef(null), mobileAccountMenu = useRef(null), mobileAccountTrigger = useRef(null); useEffect(() => { - 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) && !mobileAccountMenu.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); (mobileAccountOpen ? mobileAccountTrigger : accountTrigger).current?.focus(); } - } - }; + if (!accountOpen) return; + const click = (event: PointerEvent) => { if (!accountMenu.current?.contains(event.target as Node) && !mobileAccountMenu.current?.contains(event.target as Node)) setAccountOpen(false); }; + const key = (event: KeyboardEvent) => { if (event.key === "Escape") { setAccountOpen(false); (mobileAccountOpen ? mobileAccountTrigger : accountTrigger).current?.focus(); } }; document.addEventListener("pointerdown", click); document.addEventListener("keydown", key); return () => { document.removeEventListener("pointerdown", click); document.removeEventListener("keydown", key); }; - }, [open, accountOpen, mobileAccountOpen]); - const choose = (id: string) => { setOpen(false); setSearch(""); void navigate({ to: "/projects/$projectId", params: { projectId: id } }); }; + }, [accountOpen, mobileAccountOpen]); + const chooseProject = (id: string) => { void navigate({ to: "/projects/$projectId", params: { projectId: id } }); }; + const chooseJob = (id: string) => { void navigate({ to: "/jobs/$jobId", params: { jobId: 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
Skip to content