Skip to content

Commit 9b55434

Browse files
bilalabbadclaude
andcommitted
fix(frontend): keep the current branch when opening tasks from the header
The header task-status link derived its `branch` query param from window.location via constructPath, but nuqs writes the branch into the URL one render after the branch context updates, so the memoized href carried the previous branch (none at all on the first switch). Navigating there dropped the branch and BranchesProvider fell back to the default one. Derive the param from currentBranch instead, excluding it on the default branch. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 7d3fca3 commit 9b55434

3 files changed

Lines changed: 50 additions & 2 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed the task status button in the header sending you to the tasks page on the default branch instead of the branch you were working on.

frontend/app/src/entities/tasks/ui/task-status.test.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,44 @@ describe("TaskStatus", () => {
6767
expect(component.getByTestId("pulse").query()).toBeNull();
6868
});
6969

70+
test("links to the tasks page with the current branch, not the branch in the URL", async () => {
71+
// GIVEN
72+
useCurrentBranchMock.mockReturnValue({
73+
currentBranch: generateBranch({ name: "branch1", is_default: false }),
74+
setCurrentBranch: () => {},
75+
});
76+
getBranchTaskStatusFromApiMock.mockResolvedValue({
77+
data: { InfrahubTaskBranchStatus: { count: 0 } },
78+
} as Awaited<ReturnType<typeof getBranchTaskStatusFromApi>>);
79+
80+
// WHEN
81+
const component = await render(<TaskStatus />);
82+
83+
// THEN
84+
await expect
85+
.element(component.getByRole("link", { name: "View branch tasks" }))
86+
.toHaveAttribute("href", expect.stringContaining("branch=branch1"));
87+
});
88+
89+
test("omits the branch query param when the current branch is the default one", async () => {
90+
// GIVEN
91+
useCurrentBranchMock.mockReturnValue({
92+
currentBranch: generateBranch({ name: "main", is_default: true }),
93+
setCurrentBranch: () => {},
94+
});
95+
getBranchTaskStatusFromApiMock.mockResolvedValue({
96+
data: { InfrahubTaskBranchStatus: { count: 0 } },
97+
} as Awaited<ReturnType<typeof getBranchTaskStatusFromApi>>);
98+
99+
// WHEN
100+
const component = await render(<TaskStatus />);
101+
102+
// THEN
103+
await expect
104+
.element(component.getByRole("link", { name: "View branch tasks" }))
105+
.toHaveAttribute("href", expect.not.stringContaining("branch="));
106+
});
107+
70108
test("renders error icon with tooltip when query fails", async () => {
71109
// GIVEN
72110
useCurrentBranchMock.mockReturnValue({

frontend/app/src/entities/tasks/ui/task-status.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useQuery } from "@tanstack/react-query";
44

55
import TasksStatusIcon from "@/assets/icons/tasks-status.svg?react";
66

7-
import { constructPath } from "@/shared/api/rest/fetch";
7+
import { constructPath, type overrideQueryParams } from "@/shared/api/rest/fetch";
88
import { Pulse } from "@/shared/components/ui/pulse";
99
import { QSP } from "@/shared/config/qsp";
1010

@@ -28,11 +28,20 @@ export function TaskStatus() {
2828
value: currentBranch.name,
2929
};
3030

31+
// constructPath reads window.location, which nuqs updates one render later than the branch
32+
// context, so the branch has to come from currentBranch to avoid linking to the previous one.
33+
const branchParam: overrideQueryParams = currentBranch.is_default
34+
? { name: QSP.BRANCH, exclude: true }
35+
: { name: QSP.BRANCH, value: currentBranch.name };
36+
3137
const commonButtonProps: LinkButtonProps = {
3238
shape: "square",
3339
variant: "outline",
3440
size: "sm",
35-
href: constructPath("/tasks", [{ name: QSP.FILTER, value: JSON.stringify([filter]) }]),
41+
href: constructPath("/tasks", [
42+
branchParam,
43+
{ name: QSP.FILTER, value: JSON.stringify([filter]) },
44+
]),
3645
};
3746

3847
if (error) {

0 commit comments

Comments
 (0)