diff --git a/packages/app/src/features/auth/account-bar.tsx b/packages/app/src/features/auth/account-bar.tsx
index 2eac0c44..06847946 100644
--- a/packages/app/src/features/auth/account-bar.tsx
+++ b/packages/app/src/features/auth/account-bar.tsx
@@ -7,6 +7,7 @@ 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 beeMark from "../../assets/bee-mark-monochrome.png";
export function AccountBar() {
@@ -14,10 +15,14 @@ export function AccountBar() {
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 projectMatch = pathname.match(/^\/projects\/([^/]+)/);
+ 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 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 navigate = useNavigate();
const logout = useMutation({
retry: false,
@@ -68,7 +73,7 @@ export function AccountBar() {
}
- {routeProjectId && <>/
+ {currentProjectId && <>
/
{currentProject ?
{currentProject.name} :
{routeProject.isPending ? "Loading project…" : routeProject.error ? "Project unavailable" : "Project"}}
{open &&
@@ -79,7 +84,7 @@ export function AccountBar() {
{projects.error &&
{projects.error.message}}
{projects.data?.length === 0 && No projects yet.}
{projects.data && !projects.error && options.length === 0 && projects.data.length > 0 && No matching projects.}
- {options.map((project, index) => setActive(index)} onMouseDown={event => event.preventDefault()} onClick={() => choose(project.id)}>{project.name}{project.id === routeProjectId && Current})}
+ {options.map((project, index) => setActive(index)} onMouseDown={event => event.preventDefault()} onClick={() => choose(project.id)}>{project.name}{project.id === currentProjectId && Current})}
}
>}
diff --git a/packages/app/test/jobs.browser.test.mjs b/packages/app/test/jobs.browser.test.mjs
index 5de55e49..a04f535e 100644
--- a/packages/app/test/jobs.browser.test.mjs
+++ b/packages/app/test/jobs.browser.test.mjs
@@ -303,9 +303,10 @@ test("project tabs omit redundant headings while job detail selects project jobs
assert.equal(await page.getByText("Job", { exact: true }).count(), 1);
await context.close();
});
-test("main navigation shows the project switcher only inside a project", async () => {
+test("main navigation shows the current project switcher inside a project and its jobs", async () => {
const { page, context } = await contextFor({ viewport: { width: 1280, height: 844 } });
await page.route("**/api/v1/projects", route => route.fulfill({ json: [{ id: projectId, name: "Release project", description: "Project jobs", jobCount: 1 }] }));
+ await page.route(`**/api/v1/jobs/${jobId}`, route => route.fulfill({ json: { ...summary, promptTemplate: "Template", executionConfigId: "local", triggers: [] } }));
await page.route("**/api/v1/job-summaries?**", route => route.fulfill({ json: { items: [], nextCursor: null } }));
const mainNav = page.getByRole("navigation", { name: "Main navigation" });
await page.goto(origin + "/");
@@ -318,6 +319,13 @@ test("main navigation shows the project switcher only inside a project", async (
assert.equal(await switcher.count(), 1);
await switcher.click();
await page.getByRole("option", { name: /Release project/ }).waitFor();
+ await page.goto(origin + `/jobs/${jobId}`);
+ await mainNav.getByRole("link", { name: "Release project", exact: true }).waitFor();
+ const jobSwitcher = mainNav.getByRole("button", { name: "Switch project" });
+ assert.equal(await jobSwitcher.count(), 1);
+ await jobSwitcher.click();
+ const currentProject = page.getByRole("option", { name: /Release project.*Current/ });
+ await currentProject.waitFor();
await context.close();
});
test("mobile main navigation truncates the account and project names without the logo divider", async () => {