Skip to content

Commit edc7ea3

Browse files
committed
fix(webapp): read the agent's page label from the left of the path
A preview branch named `env` put a second `env` segment in the path and `lastIndexOf` picked it, shifting every index derived from it.
1 parent 243c0d0 commit edc7ea3

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

apps/webapp/app/components/dashboard-agent/page-label.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ describe("pageLabelFromPath", () => {
2626
expect(pageLabelFromPath(`${envRoot}/some-new-thing`)).toBe("Some new thing");
2727
});
2828

29+
it("reads the section past a preview branch named like a path marker", () => {
30+
const branchRoot = "/orgs/acme-1234/projects/hello-world-ab12/env";
31+
32+
expect(pageLabelFromPath(`${branchRoot}/env/runs`)).toBe("Runs");
33+
expect(pageLabelFromPath(`${branchRoot}/env/runs/run_abc123`)).toBe("Runs");
34+
expect(pageLabelFromPath(`${branchRoot}/env/environment-variables`)).toBe(
35+
"Environment variables"
36+
);
37+
expect(pageLabelFromPath(`${branchRoot}/env`)).toBe("Overview");
38+
expect(pageLabelFromPath(`${branchRoot}/projects/queues`)).toBe("Queues");
39+
});
40+
2941
it("falls back to the last segment outside an env path", () => {
3042
expect(pageLabelFromPath("/orgs/acme-1234/settings/members")).toBe("Members");
3143
expect(pageLabelFromPath("/account/security")).toBe("Security");

apps/webapp/app/components/dashboard-agent/page-label.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,23 @@ function prettifySegment(segment: string): string {
8080
return words.charAt(0).toUpperCase() + words.slice(1);
8181
}
8282

83+
// An env path is always `/orgs/{org}/projects/{project}/env/{slug}/{section}`, so both
84+
// markers sit at fixed indexes. A branch slug is index 5 and can never be read as the marker.
85+
const ENV_MARKER_INDEX = 4;
86+
const ENV_SECTION_INDEX = 6;
87+
8388
// Env-scoped paths label off the section after `env/{slug}`; anything else falls
8489
// back to its last segment.
8590
export function pageLabelFromPath(pathname: string): string {
8691
const segments = pathname.split("/").filter(Boolean);
8792
if (segments.length === 0) return FALLBACK_LABEL;
8893

89-
const envIndex = segments.lastIndexOf("env");
90-
if (envIndex !== -1) {
91-
// `env` is followed by the env slug, then the section (if any).
92-
const section = segments[envIndex + 2];
94+
if (
95+
segments[0] === "orgs" &&
96+
segments[2] === "projects" &&
97+
segments[ENV_MARKER_INDEX] === "env"
98+
) {
99+
const section = segments[ENV_SECTION_INDEX];
93100
if (!section) return "Overview";
94101
return SECTION_LABELS[section] ?? prettifySegment(section);
95102
}

0 commit comments

Comments
 (0)