-
-
Notifications
You must be signed in to change notification settings - Fork 330
feat(leaderboard): regroup tabs by primary and secondary views #1067
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/app/[locale]/dashboard/leaderboard/_components/leaderboard-primary-tabs.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| "use client"; | ||
|
|
||
| import type { LeaderboardPrimaryTab } from "@/app/[locale]/dashboard/leaderboard/_components/leaderboard-tab-groups"; | ||
| import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs"; | ||
|
|
||
| interface LeaderboardPrimaryTabLabels { | ||
| user: string; | ||
| provider: string; | ||
| model: string; | ||
| } | ||
|
|
||
| interface LeaderboardPrimaryTabsProps { | ||
| isAdmin: boolean; | ||
| activePrimaryTab: LeaderboardPrimaryTab; | ||
| onPrimaryChange: (tab: LeaderboardPrimaryTab) => void; | ||
| labels: LeaderboardPrimaryTabLabels; | ||
| } | ||
|
|
||
| export function LeaderboardPrimaryTabs({ | ||
| isAdmin, | ||
| activePrimaryTab, | ||
| onPrimaryChange, | ||
| labels, | ||
| }: LeaderboardPrimaryTabsProps) { | ||
| return ( | ||
| <Tabs | ||
| value={activePrimaryTab} | ||
| onValueChange={(value) => onPrimaryChange(value as LeaderboardPrimaryTab)} | ||
| > | ||
| <TabsList | ||
| data-testid="leaderboard-primary-tabs" | ||
| className={isAdmin ? "grid w-full grid-cols-3" : "w-full"} | ||
| > | ||
| <TabsTrigger data-testid="leaderboard-primary-tab-user" value="user"> | ||
| {labels.user} | ||
| </TabsTrigger> | ||
| {isAdmin ? ( | ||
| <TabsTrigger data-testid="leaderboard-primary-tab-provider" value="provider"> | ||
| {labels.provider} | ||
| </TabsTrigger> | ||
| ) : null} | ||
| {isAdmin ? ( | ||
| <TabsTrigger data-testid="leaderboard-primary-tab-model" value="model"> | ||
| {labels.model} | ||
| </TabsTrigger> | ||
| ) : null} | ||
| </TabsList> | ||
| </Tabs> | ||
| ); | ||
| } |
46 changes: 46 additions & 0 deletions
46
src/app/[locale]/dashboard/leaderboard/_components/leaderboard-secondary-tabs.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| "use client"; | ||
|
|
||
| import type { | ||
| LeaderboardPrimaryTab, | ||
| LeaderboardSecondaryTab, | ||
| } from "@/app/[locale]/dashboard/leaderboard/_components/leaderboard-tab-groups"; | ||
| import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs"; | ||
|
|
||
| interface LeaderboardSecondaryTabLabels { | ||
| cost: string; | ||
| cacheHit: string; | ||
| } | ||
|
|
||
| interface LeaderboardSecondaryTabsProps { | ||
| activePrimaryTab: LeaderboardPrimaryTab; | ||
| activeSecondaryTab: LeaderboardSecondaryTab | null; | ||
| onSecondaryChange: (tab: LeaderboardSecondaryTab) => void; | ||
| labels: LeaderboardSecondaryTabLabels; | ||
| } | ||
|
|
||
| export function LeaderboardSecondaryTabs({ | ||
| activePrimaryTab, | ||
| activeSecondaryTab, | ||
| onSecondaryChange, | ||
| labels, | ||
| }: LeaderboardSecondaryTabsProps) { | ||
| if (activePrimaryTab === "model") { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <Tabs | ||
| value={activeSecondaryTab ?? "cost"} | ||
| onValueChange={(value) => onSecondaryChange(value as LeaderboardSecondaryTab)} | ||
| > | ||
| <TabsList data-testid="leaderboard-secondary-tabs" className="grid w-full grid-cols-2"> | ||
| <TabsTrigger data-testid="leaderboard-secondary-tab-cost" value="cost"> | ||
| {labels.cost} | ||
| </TabsTrigger> | ||
| <TabsTrigger data-testid="leaderboard-secondary-tab-cache-hit" value="cacheHit"> | ||
| {labels.cacheHit} | ||
| </TabsTrigger> | ||
| </TabsList> | ||
| </Tabs> | ||
| ); | ||
| } | ||
84 changes: 84 additions & 0 deletions
84
src/app/[locale]/dashboard/leaderboard/_components/leaderboard-tab-groups.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| export type LeaderboardLeafScope = | ||
| | "user" | ||
| | "userCacheHitRate" | ||
| | "provider" | ||
| | "providerCacheHitRate" | ||
| | "model"; | ||
|
|
||
| export type LeaderboardPrimaryTab = "user" | "provider" | "model"; | ||
| export type LeaderboardPrimaryTabWithSecondary = Exclude<LeaderboardPrimaryTab, "model">; | ||
| export type LeaderboardSecondaryTab = "cost" | "cacheHit"; | ||
|
|
||
| export function normalizeScopeFromUrl( | ||
| scope: string | null | undefined, | ||
| isAdmin: boolean | ||
| ): LeaderboardLeafScope { | ||
| if (scope === "user") { | ||
| return "user"; | ||
| } | ||
|
|
||
| if ( | ||
| isAdmin && | ||
| (scope === "userCacheHitRate" || | ||
| scope === "provider" || | ||
| scope === "providerCacheHitRate" || | ||
| scope === "model") | ||
| ) { | ||
| return scope; | ||
| } | ||
|
|
||
| return "user"; | ||
| } | ||
|
|
||
| export function getPrimaryTabFromScope(scope: LeaderboardLeafScope): LeaderboardPrimaryTab { | ||
| if (scope === "provider" || scope === "providerCacheHitRate") { | ||
| return "provider"; | ||
| } | ||
|
|
||
| if (scope === "model") { | ||
| return "model"; | ||
| } | ||
|
|
||
| return "user"; | ||
| } | ||
|
|
||
| export function isUserFamilyScope(scope: LeaderboardLeafScope): boolean { | ||
| return getPrimaryTabFromScope(scope) === "user"; | ||
| } | ||
|
|
||
| export function isProviderFamilyScope(scope: LeaderboardLeafScope): boolean { | ||
| return getPrimaryTabFromScope(scope) === "provider"; | ||
| } | ||
|
|
||
| export function getSecondaryTabFromScope( | ||
| scope: LeaderboardLeafScope | ||
| ): LeaderboardSecondaryTab | null { | ||
| if (scope === "model") { | ||
| return null; | ||
| } | ||
|
|
||
| return scope === "userCacheHitRate" || scope === "providerCacheHitRate" ? "cacheHit" : "cost"; | ||
| } | ||
|
|
||
| export function getScopeForPrimaryTab(tab: LeaderboardPrimaryTab): LeaderboardLeafScope { | ||
| if (tab === "provider") { | ||
| return "provider"; | ||
| } | ||
|
|
||
| if (tab === "model") { | ||
| return "model"; | ||
| } | ||
|
|
||
| return "user"; | ||
| } | ||
|
|
||
| export function getScopeForSecondaryTab( | ||
| primaryTab: LeaderboardPrimaryTabWithSecondary, | ||
| secondaryTab: LeaderboardSecondaryTab | ||
| ): LeaderboardLeafScope { | ||
| if (primaryTab === "provider") { | ||
| return secondaryTab === "cacheHit" ? "providerCacheHitRate" : "provider"; | ||
| } | ||
|
|
||
| return secondaryTab === "cacheHit" ? "userCacheHitRate" : "user"; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modelguard inside componentThe
activePrimaryTab === "model"early return is unreachable in practice: the parent already gates rendering withshowSecondaryTabs = isAdmin && activePrimaryTab !== "model", so this component is never mounted when the primary tab is"model". The same applies to the?? "cost"fallback on line 30 —activeSecondaryTabis onlynullfor the"model"scope, which is already excluded by the parent guard. Both are harmless but add noise.Prompt To Fix With AI