refactor(ui): give each Cost Optimization tab its own route - #34424
refactor(ui): give each Cost Optimization tab its own route#34424ryan-crabbe-berri wants to merge 3 commits into
Conversation
Greptile SummaryRefactors Cost Optimization into independently routable tabs.
Confidence Score: 5/5The PR appears safe to merge. No blocking failures remain.
|
| Filename | Overview |
|---|---|
| ui/litellm-dashboard/src/app/(dashboard)/components/TabRouteBar.tsx | Adds reusable anchor-backed tabs with client-side navigation and native modifier-click behavior. |
| ui/litellm-dashboard/src/app/(dashboard)/cost-optimization/layout.tsx | Introduces the shared Cost Optimization header, banner, route-derived tab selection, and nested-page layout. |
| ui/litellm-dashboard/src/app/(dashboard)/cost-optimization/tabRoutes.ts | Defines the Cost Optimization route slugs through the shared tab-routing utility. |
| ui/litellm-dashboard/src/utils/migratedPages.ts | Resolves nested migrated routes by their first route segment so the dashboard shell retains the parent sidebar selection. |
Reviews (2): Last reviewed commit: "refactor(ui): adopt shared tab-routing h..." | Re-trigger Greptile
Split the Cost Optimization page's four tabs (Usage, Prompt Compression, Autorouter, Prompt Caching) into their own prerendered paths under /cost-optimization, mirroring the Models + Endpoints and Caching per-tab routing. A shared layout renders the header, the experimental banner and the tab bar, deriving the active tab from the pathname; each tab is its own page.tsx that pulls only the props it needs, so deep links and hard-loads to /cost-optimization/compression, /autorouter and /caching resolve to real static HTML with no nginx change. The former CostOptimizationView is removed. The tab bar is rebuilt on the shadcn Tabs primitive and the antd Alert becomes a plain banner, so the page adds no new antd usage.
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.
…n Cost Optimization Replace the page's hand-written tabRoutes.ts and layout routing engine with createTabRoutes + useTabRouting + the shared <TabRouteBar>, keeping the header and experimental banner inline. Rebasing onto staging also picked up the new shared useDailyActivityRange hook: the Usage and Prompt Caching tabs now take an `activity` prop, so each of those routes calls the hook itself and passes it through (each tab route mounts alone, so per-route data is correct). The per-page tabRoutes.test.ts is dropped in favor of the central factory test.
8c3125d to
5fad308
Compare
|
Rebased onto staging now that the shared tab-routing helpers (#34435) are merged. This branch now uses Also folded in staging drift: Cost Optimization gained a shared |
|
@greptileai re review |
QA (Devin) — before/after after the shared tab-routing helper refactorRe-QA'd the Cost Optimization per-tab routing locally ( AFTER results (this PR): each tab has its own URL — clicking a tab and deep-linking / hard-refreshing both land on the exact nested tab (e.g.
Two things to flag (shared across all 4 routing PRs):
Full report + recording: https://app.devin.ai/sessions/f98c3131bcf746c88756b609bae3e724 |
TLDR
Problem this solves:
How it solves it:
Relevant issues
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
UI-only change; steps to verify against a live proxy (captured at commit 8c3125d).
out/cost-optimization/index.html,out/cost-optimization/compression/index.html,out/cost-optimization/autorouter/index.html,out/cost-optimization/caching/index.htmlScreenshots of each tab and of a hard-refresh deep link to be attached.
Type
🧹 Refactoring
Changes
Cost Optimization moves from a single tabbed wrapper to path-based routing, the same pattern used for Models + Endpoints (#34327) and Caching (#34415).
tabRoutes.tsis the source of truth: the tab slugs pluscostOptimizationTabHrefandslugFromPathname, which map a slug to a trailing-slash URL and read the active slug back off the pathname.layout.tsxrenders the shared header, the experimental banner and the tab bar, derives the active tab fromusePathname()so no tab state is stored, and pushes to a tab's path on click; an unknown slug redirects to the base route. Each tab is its ownpage.tsx(Usage at the index, thencompression,autorouter,caching) that pulls only the props it needs. Build-time-known tab paths prerender to static HTML, so deep links and hard-loads work with no nginx change; there is no runtime-unknown id here, so nothing needs query params.The old
CostOptimizationViewwrapper is deleted, the tab bar is rebuilt on the shadcnTabsprimitive, and the antdAlertbecomes a plain banner, so the page adds no new antd usage.A second commit fixes a shared shell helper that every nested tab route depends on:
legacyKeyForPathnamematched the full relative path against a single route segment, so a path like/cost-optimization/compressionresolved to no key and the shell fell back to the default page, leaving the sidebar item unhighlighted. It now matches on the first path segment, which fixes highlighting for every migrated page with nested routes. This is the same one-line shell fix that is also in #34415; the two edits are byte-identical, so they merge cleanly whichever lands first.Tests:
tabRoutes.test.tslocks the slug/href mapping,layout.test.tsxcovers rendering the tab bar, the active base tab, routing on click and the unknown-slug redirect, andmigratedPages.test.tsgains a regression for nested-route sidebar resolution.Final Attestation