Skip to content
TypeScript

fix(web): usage tabs no longer jump when switching to Limits (#25336)

Theo Browne32507803daba
diff --git a/apps/web/src/components/usage/UsagePage.tsx b/apps/web/src/components/usage/UsagePage.tsx
index e7e36a6963e..b5c12b148fe 100644
--- a/apps/web/src/components/usage/UsagePage.tsx
+++ b/apps/web/src/components/usage/UsagePage.tsx
@@ -392,34 +392,35 @@ export function UsagePage() {
) : null}
<div className="ms-auto hidden shrink-0 items-center justify-end gap-2 @4xl/usage-header:flex">
<ToggleGroup
- aria-label="Usage metric"
+ aria-label="Usage period"
variant="segmented"
- value={[metric]}
+ value={[String(windowDays)]}
+ disabled={showingLimits}
+ // Limits are always current; the New design hides the period instead of greying it.
+ // It sits before the metric tabs so hiding it never moves them.
+ className={showingLimits ? "redesign:hidden" : undefined}
onValueChange={(next) => {
const value = next[0];
- if (isUsageMetric(value)) selectMetric(value);
+ if (value) selectWindow(Number(value));
}}
>
- {METRIC_OPTIONS.map((option) => (
- <Toggle key={option.value} value={option.value} title={shortcutTitle(option)}>
+ {WINDOW_OPTIONS.map((option) => (
+ <Toggle key={option.days} value={String(option.days)} title={shortcutTitle(option)}>
{option.label}
</Toggle>
))}
</ToggleGroup>
<ToggleGroup
- aria-label="Usage period"
+ aria-label="Usage metric"
variant="segmented"
- value={[String(windowDays)]}
- disabled={showingLimits}
- // Limits are always current; the New design hides the period instead of greying it.
- className={showingLimits ? "redesign:hidden" : undefined}
+ value={[metric]}
onValueChange={(next) => {
const value = next[0];
- if (value) selectWindow(Number(value));
+ if (isUsageMetric(value)) selectMetric(value);
}}
>
- {WINDOW_OPTIONS.map((option) => (
- <Toggle key={option.days} value={String(option.days)} title={shortcutTitle(option)}>
+ {METRIC_OPTIONS.map((option) => (
+ <Toggle key={option.value} value={option.value} title={shortcutTitle(option)}>
{option.label}
</Toggle>
))}
@@ -437,51 +438,51 @@ export function UsagePage() {
</div>
<div className="ms-auto flex shrink-0 items-center justify-end gap-1 @4xl/usage-header:hidden">
<Select
- value={metric}
- onValueChange={(value) => {
- if (isUsageMetric(value)) selectMetric(value);
- }}
+ value={String(windowDays)}
+ disabled={showingLimits}
+ onValueChange={(value) => selectWindow(Number(value))}
>
<SelectTrigger
- aria-label="Usage metric"
+ aria-label="Usage period"
size="compact"
variant="ghost"
- className="w-auto min-w-0"
+ className={cn("w-auto min-w-0", showingLimits && "redesign:hidden")}
>
<SelectValue>
- {METRIC_OPTIONS.find((option) => option.value === metric)?.label}
+ {WINDOW_OPTIONS.find((option) => option.days === windowDays)?.label}
</SelectValue>
</SelectTrigger>
<SelectPopup align="end" alignItemWithTrigger={false}>
- {METRIC_OPTIONS.map((option) => (
- <SelectItem key={option.value} value={option.value} title={shortcutTitle(option)}>
+ {WINDOW_OPTIONS.map((option) => (
+ <SelectItem
+ key={option.days}
+ value={String(option.days)}
+ title={shortcutTitle(option)}
+ >
{option.label}
</SelectItem>
))}
</SelectPopup>
</Select>
<Select
- value={String(windowDays)}
- disabled={showingLimits}
- onValueChange={(value) => selectWindow(Number(value))}
+ value={metric}
+ onValueChange={(value) => {
+ if (isUsageMetric(value)) selectMetric(value);
+ }}
>
<SelectTrigger
- aria-label="Usage period"
+ aria-label="Usage metric"
size="compact"
variant="ghost"
- className={cn("w-auto min-w-0", showingLimits && "redesign:hidden")}
+ className="w-auto min-w-0"
>
<SelectValue>
- {WINDOW_OPTIONS.find((option) => option.days === windowDays)?.label}
+ {METRIC_OPTIONS.find((option) => option.value === metric)?.label}
</SelectValue>
</SelectTrigger>
<SelectPopup align="end" alignItemWithTrigger={false}>
- {WINDOW_OPTIONS.map((option) => (
- <SelectItem
- key={option.days}
- value={String(option.days)}
- title={shortcutTitle(option)}
- >
+ {METRIC_OPTIONS.map((option) => (
+ <SelectItem key={option.value} value={option.value} title={shortcutTitle(option)}>
{option.label}
</SelectItem>
))}