mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-05 02:41:56 +00:00
fix(ui): resolve nested tab routes to their sidebar item
legacyKeyForPathname matched the full relative path against a single route segment, so a nested tab route like /cost-optimization/compression resolved to no key and the shell fell back to the default page, leaving the Cost Optimization nav item unhighlighted. Match on the first path segment instead, which fixes every migrated page with nested tab routes.
This commit is contained in:
parent
d7e31e73c0
commit
971958a36a
2 changed files with 12 additions and 1 deletions
|
|
@ -236,4 +236,13 @@ describe("legacyKeyForPathname", () => {
|
|||
expect(legacyKeyForPathname("/team-x/ui/api-reference")).toBe("api_ref");
|
||||
expect(legacyKeyForPathname("/ui/api-reference")).toBeNull();
|
||||
});
|
||||
|
||||
it("resolves a nested tab route to its sidebar key via the first path segment", async () => {
|
||||
vi.doMock("@/components/networking", () => ({ serverRootPath: "/" }));
|
||||
const { legacyKeyForPathname } = await import("./migratedPages");
|
||||
|
||||
expect(legacyKeyForPathname("/ui/cost-optimization/compression")).toBe("cost-optimization");
|
||||
expect(legacyKeyForPathname("/ui/cost-optimization/caching/")).toBe("cost-optimization");
|
||||
expect(legacyKeyForPathname("/ui/some-legacy-page/nested")).toBeNull();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -76,8 +76,10 @@ export function legacyPageHref(pageKey: string): string {
|
|||
export function legacyKeyForPathname(pathname: string): string | null {
|
||||
const base = uiBase();
|
||||
const rel = (pathname.startsWith(base) ? pathname.slice(base.length) : pathname).replace(/^\/+|\/+$/g, "");
|
||||
const firstSegment = rel.split("/")[0] ?? "";
|
||||
if (!firstSegment) return null;
|
||||
for (const [key, segment] of Object.entries(MIGRATED_PAGES)) {
|
||||
if (rel === segment) return key;
|
||||
if (firstSegment === segment) return key;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue