From b5916a8aed08843c0570b20037172981cbd915e8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 16 Nov 2026 15:45:25 +1100 Subject: [PATCH 01/10] fix(web): remove redundant usage labels below quota bars --- .../components/usage/UsageLimitsPooled.tsx | 196 ++++++------------ 1 file changed, 61 insertions(+), 135 deletions(-) diff --git a/apps/web/src/components/usage/UsageLimitsPooled.tsx b/apps/web/src/components/usage/UsageLimitsPooled.tsx index 8ec1c7a02afcd..4e3e3afca0330 100644 --- a/apps/web/src/components/usage/UsageLimitsPooled.tsx +++ b/apps/web/src/components/usage/UsageLimitsPooled.tsx @@ -351,145 +351,74 @@ function SegmentTriggers({ const resetsIn = formatResetsIn(window, now); const credits = account.limits.resetCredits?.availableCount ?? 0; return ( - <> - + } + > +
+ {/* Clipped inside the rounded clip so the bar's own corners keep their antialiasing. */} +
+
- } - > -
- {/* Clipped inside the rounded clip so the bar's own corners keep their antialiasing. */} -
+ {remaining < 100 && reset && refillPercent > 0 ? (
- {remaining < 100 && reset && refillPercent > 0 ? ( -
- ) : null} -
-
- {paceMark ? ( - - ) : null} - - {index} - -
- {showAccountName ? ( - ) : null} - {/* A single-account bar repeats the headline percentage. */} - {showAccountName ? ( - - {remaining}% - - ) : null} - {resetsIn || credits ? ( - - {resetsIn?.replace("resets in ", "↻ ") ?? ""} - {credits ? ( - <> - {resetsIn ? ( - - · - - ) : null} - - - {credits} - - - ) : null} - - ) : null}
- - - - ); -} - -function LegendRow({ - payload, - color, - now, - index, -}: { - readonly payload: SegmentPayload; - readonly color: string; - readonly now: number; - readonly index: number; -}) { - const popover = use(SegmentPopoverContext) ?? undefined; - const { account, window } = payload; - const remaining = remainingPercent(window); - const resetsIn = formatResetsIn(window, now); - const credits = account.limits.resetCredits?.availableCount ?? 0; - return ( - } - className="min-w-0 @2xl/pool:hidden" - > - +
+ {paceMark ? ( - Segment - {index} - - - {remaining}% - - {resetsIn?.replace("resets in ", "↻ ") ?? ""} - {credits ? ( - <> - {resetsIn ? · : null} - - - {credits} - - - {credits} reset {credits === 1 ? "credit" : "credits"} banked - - + ) : null} +
+ {showAccountName ? ( + ) : null} - + {/* A single-account bar repeats the headline percentage. */} + {showAccountName ? ( + {remaining}% + ) : null} + {resetsIn || credits ? ( + + {resetsIn?.replace("resets in ", "↻ ") ?? ""} + {credits ? ( + <> + {resetsIn ? ( + + · + + ) : null} + + + {credits} + + + ) : null} + + ) : null} +
); } @@ -505,7 +434,7 @@ function PoolBar({ }) { const restores = new Map(pool.resets.map((reset) => [reset.member.account.key, reset])); return ( -
+
- + $0 cap
) : null, From 655dc6887a5101ad9201a420957b6e8af0bc4abb Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 16 Nov 2026 15:48:51 +1100 Subject: [PATCH 02/10] feat(web): arrange, hide, and collapse usage limits inline --- .../usage/UsageLimitLayoutControls.tsx | 60 ++++ .../usage/UsageLimitsPooled.browser.test.tsx | 164 ++++++++- .../components/usage/UsageLimitsPooled.tsx | 339 +++++++++++++++--- .../components/usage/usageLimitLayout.test.ts | 53 +++ .../src/components/usage/usageLimitLayout.ts | 52 +++ docs/user/usage.md | 5 + 6 files changed, 620 insertions(+), 53 deletions(-) create mode 100644 apps/web/src/components/usage/UsageLimitLayoutControls.tsx create mode 100644 apps/web/src/components/usage/usageLimitLayout.test.ts create mode 100644 apps/web/src/components/usage/usageLimitLayout.ts diff --git a/apps/web/src/components/usage/UsageLimitLayoutControls.tsx b/apps/web/src/components/usage/UsageLimitLayoutControls.tsx new file mode 100644 index 0000000000000..52b30d63ff8e8 --- /dev/null +++ b/apps/web/src/components/usage/UsageLimitLayoutControls.tsx @@ -0,0 +1,60 @@ +import { ArrowDownIcon, ArrowUpIcon } from "lucide-react"; + +import { Button } from "../ui/button"; + +export function UsageLimitLayoutControls({ + label, + index, + count, + hidden, + onMove, + onToggleVisibility, +}: { + readonly label: string; + readonly index: number; + readonly count: number; + readonly hidden: boolean; + readonly onMove: (direction: -1 | 1) => void; + readonly onToggleVisibility: () => void; +}) { + const visibilityLabel = `${hidden ? "Show" : "Hide"} ${label}`; + return ( +
+
+ + +
+ +
+ ); +} diff --git a/apps/web/src/components/usage/UsageLimitsPooled.browser.test.tsx b/apps/web/src/components/usage/UsageLimitsPooled.browser.test.tsx index ab114fbbd6f21..f4e9290b35e8e 100644 --- a/apps/web/src/components/usage/UsageLimitsPooled.browser.test.tsx +++ b/apps/web/src/components/usage/UsageLimitsPooled.browser.test.tsx @@ -2,13 +2,19 @@ import { EnvironmentId, ProviderDriverKind, ProviderInstanceId, + UsageLimitSourceId, + type ServerProviderUsageWindow, type ServerProvider, } from "@t3tools/contracts"; import { CHATGPT_USAGE_URL } from "@t3tools/shared/usageLimits"; import { describe, expect, it } from "vite-plus/test"; +import { commands, userEvent } from "vite-plus/test/browser"; + +import "../../index.css"; import { render } from "../../../test/render"; import { UsageLimitsPooled } from "./UsageLimitsPooled"; +import { USAGE_LIMIT_LAYOUT_KEY } from "./usageLimitLayout"; const checkedAt = "2026-10-25T16:00:00.000Z"; @@ -35,7 +41,163 @@ function managedChatGpt(instanceId: string, displayName: string): ServerProvider }; } -describe("UsageLimitsPooled ChatGPT usage card", () => { +function isolatedLayoutStorage() { + const saved = window.localStorage.getItem(USAGE_LIMIT_LAYOUT_KEY); + window.localStorage.removeItem(USAGE_LIMIT_LAYOUT_KEY); + return { + [Symbol.dispose]() { + if (saved === null) window.localStorage.removeItem(USAGE_LIMIT_LAYOUT_KEY); + else window.localStorage.setItem(USAGE_LIMIT_LAYOUT_KEY, saved); + }, + }; +} + +describe("UsageLimitsPooled", () => { + it("arranges limits inline and restores hidden providers without losing collapsed state", async () => { + using _storage = isolatedLayoutStorage(); + const weekly: ServerProviderUsageWindow = { + id: "weekly", + kind: "weekly", + label: "Weekly", + usedPercent: 40, + }; + const presentations = new Map([ + [ + EnvironmentId.make("desk"), + { + entry: { target: { label: "Desk" } }, + serverConfig: { + providers: [], + usageLimitSources: [ + { + id: UsageLimitSourceId.make("test-hub"), + kind: "cliproxy" as const, + label: "Hub", + checkedAt, + accounts: [ + { + id: "codex", + driver: ProviderDriverKind.make("codex"), + usageLimits: { + checkedAt, + windows: [ + weekly, + { ...weekly, id: "session", kind: "session" as const, label: "Session" }, + ], + }, + }, + { + id: "gemini", + driver: ProviderDriverKind.make("antigravity"), + usageLimits: { + checkedAt, + windows: [{ ...weekly, id: "gemini-weekly", label: "Gemini · Weekly" }], + }, + }, + ], + }, + ], + }, + }, + ], + ]); + await using screen = await render( + , + ); + expect(screen.getByRole("button", { name: "Customize limits" }).elements()).toHaveLength(0); + const collapse = screen.getByRole("button", { name: "Collapse Codex limits" }); + const collapseIndicator = collapse + .element() + .querySelector(".lucide-chevron-right")!; + await expect.element(collapseIndicator).toHaveStyle({ opacity: "0" }); + collapse.element().focus(); + await expect.element(collapse).toHaveFocus(); + await expect.element(collapseIndicator).toHaveStyle({ opacity: "1" }); + collapse.element().blur(); + await expect.element(collapseIndicator).toHaveStyle({ opacity: "0" }); + await collapse.hover(); + await expect.element(collapseIndicator).toHaveStyle({ opacity: "1" }); + await screen.getByRole("button", { name: "Collapse Codex limits" }).click(); + await expect.element(screen.getByText("Session", { exact: true })).not.toBeInTheDocument(); + + await screen.getByRole("button", { name: "Expand Codex limits" }).click(); + screen.getByRole("button", { name: "Collapse Codex limits" }).element().blur(); + await commands.resetPointer(); + expect(screen.getByRole("dialog").elements()).toHaveLength(0); + const providerReorder = screen + .getByRole("button", { name: "Move Codex down", exact: true }) + .element().parentElement!.parentElement!; + const windowReorder = screen + .getByRole("button", { name: "Move Codex Weekly up", exact: true }) + .element().parentElement!.parentElement!; + await expect.element(providerReorder).toHaveStyle({ opacity: "0" }); + await expect.element(windowReorder).toHaveStyle({ opacity: "0" }); + await screen.getByRole("heading", { name: /Codex/ }).hover(); + await expect.element(providerReorder).toHaveStyle({ opacity: "1" }); + await expect.element(windowReorder).toHaveStyle({ opacity: "0" }); + await screen.getByText("Weekly", { exact: true }).hover(); + await expect.element(windowReorder).toHaveStyle({ opacity: "1" }); + await expect.element(providerReorder).toHaveStyle({ opacity: "0" }); + await commands.resetPointer(); + await expect.element(providerReorder).toHaveStyle({ opacity: "0" }); + await expect.element(screen.getByText("Session", { exact: true })).toBeVisible(); + await screen.getByRole("button", { name: "Hide Codex Weekly", exact: true }).click(); + await expect.element(screen.getByText("Weekly", { exact: true })).not.toBeInTheDocument(); + await expect.element(screen.getByRole("button", { name: "Show hidden limits" })).toHaveFocus(); + await screen.getByRole("button", { name: "Show hidden limits" }).click(); + await screen.getByRole("button", { name: "Show Codex Weekly", exact: true }).click(); + await screen.getByRole("button", { name: "Hide hidden limits" }).click(); + await expect + .element(screen.getByRole("button", { name: "Collapse Codex limits" })) + .toHaveFocus(); + const moveProviderDown = screen.getByRole("button", { name: "Move Codex down", exact: true }); + moveProviderDown.element().focus(); + await expect.element(providerReorder).toHaveStyle({ opacity: "1" }); + await userEvent.keyboard("{Enter}"); + await expect.element(moveProviderDown).toHaveFocus(); + await expect.element(moveProviderDown).toHaveAttribute("aria-disabled", "true"); + await userEvent.keyboard("{Enter}"); + await expect + .element(screen.getByRole("heading", { level: 2 }).first()) + .toHaveTextContent("Antigravity"); + const moveWeeklyUp = screen.getByRole("button", { name: "Move Codex Weekly up", exact: true }); + moveWeeklyUp.element().focus(); + await userEvent.keyboard("{Enter}"); + await expect.element(moveWeeklyUp).toHaveFocus(); + await expect.element(moveWeeklyUp).toHaveAttribute("aria-disabled", "true"); + await userEvent.keyboard("{Enter}"); + await screen.getByRole("button", { name: "Collapse Codex limits" }).click(); + await screen.getByRole("button", { name: "Hide Codex", exact: true }).click(); + await expect.element(screen.getByRole("heading", { name: /Codex/ })).not.toBeInTheDocument(); + + await screen.getByRole("button", { name: "Show hidden limits" }).click(); + await screen.getByRole("button", { name: "Show Codex", exact: true }).click(); + await screen.getByRole("button", { name: "Hide hidden limits" }).click(); + await expect + .element(screen.getByRole("button", { name: "Expand Codex limits" })) + .toHaveAttribute("aria-expanded", "false"); + await screen.rerender( + , + ); + await expect + .element(screen.getByRole("button", { name: "Expand Codex limits" })) + .toHaveAttribute("aria-expanded", "false"); + await screen.getByRole("button", { name: "Expand Codex limits" }).click(); + await expect.element(screen.getByText("Session", { exact: true })).toBeVisible(); + + await screen.getByRole("button", { name: "Reset layout" }).click(); + await expect + .element(screen.getByRole("button", { name: "Collapse Codex limits" })) + .toHaveFocus(); + await expect + .element(screen.getByRole("heading", { level: 2 }).first()) + .toHaveTextContent("Codex"); + }); + it("names the managed connections it covers", async () => { const presentations = new Map([ [ diff --git a/apps/web/src/components/usage/UsageLimitsPooled.tsx b/apps/web/src/components/usage/UsageLimitsPooled.tsx index 4e3e3afca0330..f32574a2cdf73 100644 --- a/apps/web/src/components/usage/UsageLimitsPooled.tsx +++ b/apps/web/src/components/usage/UsageLimitsPooled.tsx @@ -18,7 +18,7 @@ import { } from "@t3tools/shared/usageLimits"; import type { Popover as PopoverPrimitive } from "@base-ui/react/popover"; import { normalizeProviderAccentColor } from "@t3tools/client-runtime/state/provider-instance-display"; -import { AlertTriangleIcon, ExternalLinkIcon, TicketIcon } from "lucide-react"; +import { AlertTriangleIcon, ChevronRightIcon, ExternalLinkIcon, TicketIcon } from "lucide-react"; import { createContext, Fragment, @@ -31,6 +31,7 @@ import { } from "react"; import { ensureLocalApi } from "../../localApi"; +import { useLocalStorage } from "../../hooks/useLocalStorage"; import { usePrimarySettings } from "../../hooks/useSettings"; import { cn } from "../../lib/utils"; import { formatUpcomingTimestamp } from "../../timestampFormat"; @@ -38,10 +39,21 @@ import { ProviderInstanceIcon } from "../chat/ProviderInstanceIcon"; import { providerClients } from "../settings/providerDriverMeta"; import { RedactedSensitiveText } from "../settings/RedactedSensitiveText"; import { Button } from "../ui/button"; +import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../ui/collapsible"; import { OpenAI } from "../Icons"; import { Alert, AlertTitle } from "../ui/alert"; import { Popover, PopoverCreateHandle, PopoverPopup, PopoverTrigger } from "../ui/popover"; import { PaceIcon, ResetCreditDialog, barColor, usePaceMark, useResetCredit } from "./UsageLimits"; +import { UsageLimitLayoutControls } from "./UsageLimitLayoutControls"; +import { + DEFAULT_LIMIT_LAYOUT, + limitWindowKey, + moveLimitItem, + orderLimitItems, + USAGE_LIMIT_LAYOUT_KEY, + UsageLimitLayoutSchema, + type UsageLimitLayout, +} from "./usageLimitLayout"; function accountInitials(email: string): string { const [local = "", domain = ""] = email.split("@"); @@ -474,74 +486,210 @@ function PoolWindowCard({ now, label, description, + controls, + hidden = false, }: { readonly pool: LimitPoolWindow; readonly color: string; readonly now: number; readonly label?: string | null | undefined; readonly description?: string | undefined; + readonly controls?: ReactNode; + readonly hidden?: boolean; }) { const nextRefill = pool.resets.find((reset) => reset.restoresPercent > 0); return ( -
-
- {label !== null ? ( - {label ?? pool.label} - ) : null} - - - {pool.remainingPercent}% - - - left - {pool.pace ? : null} - - - {nextRefill && pool.columns.length > 1 ? ( - - ↻ +{nextRefill.restoresPercent}% +
+
+ {hidden || label !== null ? ( + ) : null} + {!hidden ? ( + <> + + + {pool.remainingPercent}% + + + left + {pool.pace ? : null} + + + {nextRefill && pool.columns.length > 1 ? ( + + ↻ +{nextRefill.restoresPercent}% + + ) : null} + + ) : null}
- - {description ? ( -

{description}

+ {controls ? ( +
{controls}
+ ) : null} + {!hidden ? ( + <> +
+ +
+ {description ? ( +

{description}

+ ) : null} + ) : null}
); } -function PoolSection({ pool, now }: { readonly pool: LimitPool; readonly now: number }) { +function PoolSection({ + pool, + windows, + now, + providerKeys, + layout, + onChange, +}: { + readonly pool: LimitPool; + readonly windows: readonly LimitPoolWindow[]; + readonly now: number; + readonly providerKeys: readonly string[]; + readonly layout: UsageLimitLayout; + readonly onChange: (update: (current: UsageLimitLayout) => UsageLimitLayout) => void; +}) { const color = barColor(pool.driver); const label = providerClients.get(pool.driver)?.label ?? String(pool.driver); - const windows = displayLimitWindows(pool); + const hidden = layout.hiddenProviders.includes(pool.driver); + const collapsed = layout.collapsedProviders.includes(pool.driver); return ( -
-

- + onChange((current) => ({ + ...current, + collapsedProviders: open + ? current.collapsedProviders.filter((driver) => driver !== pool.driver) + : [...current.collapsedProviders, pool.driver], + })) + } + render={
} + > +
+

+ + {label} + {hidden ? ( + Hidden + ) : null} +

+

- {windows.map((window) => { - const details = - pool.driver === "cursor" ? cursorUsageWindowDetails(window.id, pool) : undefined; - return ( - + } + > + - ); - })} -
+ +
+ +
+ {windows.map((window, index) => { + const details = + pool.driver === "cursor" ? cursorUsageWindowDetails(window.id, pool) : undefined; + const key = limitWindowKey(pool.driver, window); + const windowHidden = layout.hiddenWindows.includes(key); + const controls = ( +
+
+ ); } @@ -553,24 +701,109 @@ export function UsageLimitsPooled({ readonly now: number; }) { const [segmentPopover] = useState(() => PopoverCreateHandle()); + const [showHidden, setShowHidden] = useState(false); + const restoreButton = useRef(null); + const limitsRoot = useRef(null); + const focusedBeforeChange = useRef(null); + const [layout, setLayout] = useLocalStorage( + USAGE_LIMIT_LAYOUT_KEY, + DEFAULT_LIMIT_LAYOUT, + UsageLimitLayoutSchema, + ); const segmentPopoverActions = useRef(null); - const pools = collectLimitPools(collectLimitAccounts(presentations), now); + const pools = orderLimitItems( + collectLimitPools(collectLimitAccounts(presentations), now), + layout.providerOrder, + (pool) => pool.driver, + ); + const arrangedPools = pools.map((pool) => ({ + pool, + windows: orderLimitItems(displayLimitWindows(pool), layout.windowOrder, (window) => + limitWindowKey(pool.driver, window), + ), + })); + const visiblePools = arrangedPools + .map(({ pool, windows }) => ({ + pool, + windows: windows.filter( + (window) => !layout.hiddenWindows.includes(limitWindowKey(pool.driver, window)), + ), + })) + .filter( + ({ pool, windows }) => !layout.hiddenProviders.includes(pool.driver) && windows.length > 0, + ); + const hasHidden = layout.hiddenProviders.length > 0 || layout.hiddenWindows.length > 0; + const hasLayout = Object.values(layout).some((items) => items.length > 0); + const shownPools = showHidden ? arrangedPools : visiblePools; const notices = collectLimitNotices(presentations); const externalLinks = collectExternalUsageLinks(presentations); + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- Hand off focus after an action removes its control. + useLayoutEffect(() => { + if (focusedBeforeChange.current && !focusedBeforeChange.current.isConnected) { + const target = + restoreButton.current ?? + limitsRoot.current?.querySelector("button[aria-expanded]") ?? + limitsRoot.current; + target?.focus(); + } + focusedBeforeChange.current = null; + }); return ( -
+
+ {pools.length > 0 && visiblePools.length === 0 && !showHidden ? ( +

All limits are hidden.

+ ) : null} {pools.length === 0 && notices.length === 0 && externalLinks.length === 0 ? (

No provider on the selected environments reports subscription limits.

) : null} - {pools.map((pool) => ( + {shownPools.map(({ pool, windows }) => ( - + item.driver)} + layout={layout} + onChange={(update) => { + focusedBeforeChange.current = document.activeElement; + setLayout(update); + }} + /> ))} + {hasLayout || showHidden ? ( +
+ {hasHidden || showHidden ? ( + + ) : null} + +
+ ) : null} {({ payload }) => payload ? ( @@ -578,7 +811,9 @@ export function UsageLimitsPooled({ handle={segmentPopover} actions={segmentPopoverActions} payload={payload} - pools={pools} + pools={visiblePools + .filter(({ pool }) => !layout.collapsedProviders.includes(pool.driver)) + .map(({ pool, windows }) => ({ ...pool, windows }))} now={now} /> ) : null diff --git a/apps/web/src/components/usage/usageLimitLayout.test.ts b/apps/web/src/components/usage/usageLimitLayout.test.ts new file mode 100644 index 0000000000000..66db8ce73ae35 --- /dev/null +++ b/apps/web/src/components/usage/usageLimitLayout.test.ts @@ -0,0 +1,53 @@ +import { describe, expect, it } from "vite-plus/test"; +import * as Schema from "effect/Schema"; + +import { + limitWindowKey, + moveLimitItem, + orderLimitItems, + UsageLimitLayoutSchema, +} from "./usageLimitLayout"; + +const decodeLayout = Schema.decodeUnknownSync(UsageLimitLayoutSchema); +const encodeLayout = Schema.encodeSync(UsageLimitLayoutSchema); + +describe("usage limit layout", () => { + it("preserves saved ordering and hidden windows when provider preferences are added", () => { + const saved = { + providerOrder: ["claudeAgent"], + windowOrder: ["weekly"], + hiddenWindows: ["session"], + }; + const decoded = decodeLayout(saved); + expect(decoded).toEqual({ ...saved, hiddenProviders: [], collapsedProviders: [] }); + const updated = { + ...decoded, + hiddenProviders: ["cursor"], + collapsedProviders: ["claudeAgent"], + }; + expect(decodeLayout(encodeLayout(updated))).toEqual(updated); + }); + + it("orders saved cards first and appends new cards in their default order", () => { + expect( + orderLimitItems(["new", "weekly", "session", "other"], ["session", "weekly"], (id) => id), + ).toEqual(["session", "weekly", "new", "other"]); + expect(limitWindowKey("claude", { kind: "weekly", id: "shared" })).not.toBe( + limitWindowKey("antigravity", { kind: "weekly", id: "shared" }), + ); + }); + + it("moves available cards without forgetting temporarily unavailable preferences", () => { + const saved = ["offline", "weekly", "session"]; + const moved = moveLimitItem(saved, ["weekly", "session", "new"], "session", -1); + expect(moved).toEqual(["session", "weekly", "new", "offline"]); + expect(orderLimitItems(["offline", "new", "weekly", "session"], moved, (id) => id)).toEqual([ + "session", + "weekly", + "new", + "offline", + ]); + expect(moveLimitItem(saved, ["weekly", "session"], "weekly", -1)).toBe(saved); + expect(moveLimitItem(saved, ["weekly", "session"], "session", 1)).toBe(saved); + }); +}); diff --git a/apps/web/src/components/usage/usageLimitLayout.ts b/apps/web/src/components/usage/usageLimitLayout.ts new file mode 100644 index 0000000000000..f7e8b45cc92e7 --- /dev/null +++ b/apps/web/src/components/usage/usageLimitLayout.ts @@ -0,0 +1,52 @@ +import type { LimitPoolWindow } from "@t3tools/shared/usageLimits"; +import * as Effect from "effect/Effect"; +import * as Schema from "effect/Schema"; + +export const USAGE_LIMIT_LAYOUT_KEY = "t3code:usage-limit-layout:v1"; +export const UsageLimitLayoutSchema = Schema.Struct({ + providerOrder: Schema.Array(Schema.String), + windowOrder: Schema.Array(Schema.String), + hiddenWindows: Schema.Array(Schema.String), + hiddenProviders: Schema.Array(Schema.String).pipe(Schema.withDecodingDefault(Effect.succeed([]))), + collapsedProviders: Schema.Array(Schema.String).pipe( + Schema.withDecodingDefault(Effect.succeed([])), + ), +}); +export type UsageLimitLayout = typeof UsageLimitLayoutSchema.Type; +export const DEFAULT_LIMIT_LAYOUT: UsageLimitLayout = { + providerOrder: [], + windowOrder: [], + hiddenWindows: [], + hiddenProviders: [], + collapsedProviders: [], +}; + +export function limitWindowKey(driver: string, window: Pick) { + return JSON.stringify([driver, window.kind, window.id]); +} + +export function orderLimitItems( + items: readonly T[], + order: readonly string[], + key: (item: T) => string, +): T[] { + const ranks = new Map(order.map((id, index) => [id, index])); + return [...items].sort( + (left, right) => (ranks.get(key(left)) ?? Infinity) - (ranks.get(key(right)) ?? Infinity), + ); +} + +export function moveLimitItem( + savedOrder: readonly string[], + currentKeys: readonly string[], + key: string, + direction: -1 | 1, +) { + const keys = [...currentKeys]; + const index = keys.indexOf(key); + const destination = index + direction; + if (index < 0 || destination < 0 || destination >= keys.length) return savedOrder; + [keys[index], keys[destination]] = [keys[destination]!, keys[index]!]; + const available = new Set(keys); + return [...keys, ...savedOrder.filter((id) => !available.has(id))]; +} diff --git a/docs/user/usage.md b/docs/user/usage.md index e6b3a46d5a14e..c5d36d0d061f4 100644 --- a/docs/user/usage.md +++ b/docs/user/usage.md @@ -127,6 +127,11 @@ the bar show each account's quota, countdown, and credits. Tap a row to open its The same account signed in on more than one environment, or reported by a hub as well, counts once. Filter with the environment dropdown to see what a single machine has. +On web and desktop, use the arrow beside a provider heading to collapse or expand its limits. +Hover over a provider or window, or focus it with the keyboard, to reveal hide and reorder +controls. Touch devices always show these controls. Choose **Show hidden limits** below the +list to restore hidden items, or **Reset layout** to restore defaults. These preferences are +saved on this device. When a Claude or Codex account has no overall weekly quota left, its pooled session contribution shows 0% left. The next refill depends on both reset times: an exhausted session must also reset, From abf9d6888abf06da99fa70b6c7f966edfe4cd34a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 16 Nov 2026 16:15:47 +1100 Subject: [PATCH 03/10] feat(web): reorder usage limits with drag handles --- .../usage/UsageLimitLayoutControls.tsx | 127 +++++++--- .../usage/UsageLimitsPooled.browser.test.tsx | 106 ++++++-- .../components/usage/UsageLimitsPooled.tsx | 227 +++++++++++------- .../components/usage/usageLimitLayout.test.ts | 12 +- .../src/components/usage/usageLimitLayout.ts | 9 +- docs/user/usage.md | 7 +- 6 files changed, 338 insertions(+), 150 deletions(-) diff --git a/apps/web/src/components/usage/UsageLimitLayoutControls.tsx b/apps/web/src/components/usage/UsageLimitLayoutControls.tsx index 52b30d63ff8e8..bf0c58c0aa72b 100644 --- a/apps/web/src/components/usage/UsageLimitLayoutControls.tsx +++ b/apps/web/src/components/usage/UsageLimitLayoutControls.tsx @@ -1,51 +1,110 @@ -import { ArrowDownIcon, ArrowUpIcon } from "lucide-react"; +import { + DndContext, + KeyboardSensor, + PointerSensor, + closestCenter, + pointerWithin, + type CollisionDetection, + type KeyboardCoordinateGetter, + useSensor, + useSensors, +} from "@dnd-kit/core"; +import { restrictToVerticalAxis } from "@dnd-kit/modifiers"; +import { SortableContext, type useSortable, verticalListSortingStrategy } from "@dnd-kit/sortable"; +import { GripVerticalIcon } from "lucide-react"; +import type { ReactNode } from "react"; +import { cn } from "../../lib/utils"; import { Button } from "../ui/button"; +const limitCollisionDetection: CollisionDetection = (args) => { + const collisions = pointerWithin(args); + return collisions.length > 0 ? collisions : closestCenter(args); +}; + +export function UsageLimitSortableList({ + items, + onReorder, + children, +}: { + readonly items: string[]; + readonly onReorder: (active: string, over: string) => void; + readonly children: ReactNode; +}) { + const keyboardCoordinates: KeyboardCoordinateGetter = ( + event, + { context, currentCoordinates }, + ) => { + if (event.code !== "ArrowUp" && event.code !== "ArrowDown") return; + event.preventDefault(); + const index = items.indexOf(String(context.over?.id ?? context.active?.id)); + const target = items[index + (event.code === "ArrowDown" ? 1 : -1)]; + const rect = target === undefined ? undefined : context.droppableRects.get(target); + if (!rect || !context.collisionRect) return; + return { + ...currentCoordinates, + y: + currentCoordinates.y + + rect.top + + rect.height / 2 - + (context.collisionRect.top + context.collisionRect.height / 2), + }; + }; + const sensors = useSensors( + useSensor(PointerSensor, { activationConstraint: { distance: 4 } }), + useSensor(KeyboardSensor, { coordinateGetter: keyboardCoordinates }), + ); + return ( + { + if (over && active.id !== over.id) onReorder(String(active.id), String(over.id)); + }} + > + + {children} + + + ); +} + export function UsageLimitLayoutControls({ label, - index, - count, hidden, - onMove, + attributes, + listeners, + handleRef, + isDragging, onToggleVisibility, }: { readonly label: string; - readonly index: number; - readonly count: number; readonly hidden: boolean; - readonly onMove: (direction: -1 | 1) => void; + readonly attributes: ReturnType["attributes"]; + readonly listeners: ReturnType["listeners"]; + readonly handleRef: ReturnType["setActivatorNodeRef"]; + readonly isDragging: boolean; readonly onToggleVisibility: () => void; }) { const visibilityLabel = `${hidden ? "Show" : "Hide"} ${label}`; return ( -
-
- - -
+
+ @@ -114,6 +120,7 @@ export function UsageLimitLayoutControls({ > {hidden ? "Show" : "Hide"} + {children}
); } diff --git a/apps/web/src/components/usage/UsageLimitsPooled.browser.test.tsx b/apps/web/src/components/usage/UsageLimitsPooled.browser.test.tsx index dae1d6499319f..1ca56099e0fb9 100644 --- a/apps/web/src/components/usage/UsageLimitsPooled.browser.test.tsx +++ b/apps/web/src/components/usage/UsageLimitsPooled.browser.test.tsx @@ -53,6 +53,7 @@ function isolatedLayoutStorage() { } async function dragHandle(source: HTMLElement | SVGElement, target: HTMLElement | SVGElement) { + await userEvent.hover(source.closest(".group\\/limit-row")!); await userEvent.hover(source); const from = source.getBoundingClientRect(); const to = target.getBoundingClientRect(); @@ -146,16 +147,14 @@ describe("UsageLimitsPooled", () => { ); expect(screen.getByRole("button", { name: "Customize limits" }).elements()).toHaveLength(0); const collapse = screen.getByRole("button", { name: "Collapse Codex limits" }); - const collapseIndicator = collapse - .element() - .querySelector(".lucide-chevron-right")!; + const collapseIndicator = collapse.element().parentElement!; await expect.element(collapseIndicator).toHaveStyle({ opacity: "0" }); collapse.element().focus(); await expect.element(collapse).toHaveFocus(); await expect.element(collapseIndicator).toHaveStyle({ opacity: "1" }); collapse.element().blur(); await expect.element(collapseIndicator).toHaveStyle({ opacity: "0" }); - await collapse.hover(); + await screen.getByRole("heading", { name: /Codex/ }).hover(); await expect.element(collapseIndicator).toHaveStyle({ opacity: "1" }); await screen.getByRole("button", { name: "Collapse Codex limits" }).click(); await expect.element(screen.getByText("Session", { exact: true })).not.toBeInTheDocument(); @@ -181,6 +180,7 @@ describe("UsageLimitsPooled", () => { await commands.resetPointer(); await expect.element(providerReorder).toHaveStyle({ opacity: "0" }); await expect.element(screen.getByText("Session", { exact: true })).toBeVisible(); + await screen.getByText("Weekly", { exact: true }).hover(); await screen.getByRole("button", { name: "Hide Codex Weekly", exact: true }).click(); await expect.element(screen.getByText("Weekly", { exact: true })).not.toBeInTheDocument(); await expect.element(screen.getByRole("button", { name: "Show hidden limits" })).toHaveFocus(); @@ -190,6 +190,7 @@ describe("UsageLimitsPooled", () => { await expect .element(screen.getByRole("button", { name: "Collapse Codex limits" })) .toHaveFocus(); + await screen.getByRole("heading", { name: /Antigravity/ }).hover(); await screen.getByRole("button", { name: "Collapse Antigravity limits" }).click(); const providerHandle = screen.getByRole("button", { name: "Reorder Codex", exact: true }); providerHandle.element().focus(); @@ -219,6 +220,7 @@ describe("UsageLimitsPooled", () => { await userEvent.keyboard("[ArrowDown]"); await userEvent.keyboard("[Escape]"); expect(JSON.parse(window.localStorage.getItem(USAGE_LIMIT_LAYOUT_KEY)!)).toEqual(saved); + await screen.getByRole("heading", { name: /Codex/ }).hover(); await screen.getByRole("button", { name: "Collapse Codex limits" }).click(); await screen.getByRole("button", { name: "Hide Codex", exact: true }).click(); await expect.element(screen.getByRole("heading", { name: /Codex/ })).not.toBeInTheDocument(); @@ -249,6 +251,7 @@ describe("UsageLimitsPooled", () => { await expect .element(screen.getByRole("heading", { level: 2 }).first()) .toHaveTextContent("Codex"); + await screen.getByRole("heading", { name: /Antigravity/ }).hover(); await screen.getByRole("button", { name: "Collapse Antigravity limits" }).click(); await dragHandle( screen.getByRole("button", { name: "Reorder Codex", exact: true }).element(), diff --git a/apps/web/src/components/usage/UsageLimitsPooled.tsx b/apps/web/src/components/usage/UsageLimitsPooled.tsx index b193c4141ef37..d761a5545690a 100644 --- a/apps/web/src/components/usage/UsageLimitsPooled.tsx +++ b/apps/web/src/components/usage/UsageLimitsPooled.tsx @@ -546,8 +546,8 @@ function PoolWindowCard({ ref={setNodeRef} style={style} className={cn( - "group/limit-row grid grid-cols-[minmax(0,1fr)_auto] items-start gap-x-4 gap-y-3 rounded-lg border border-border/60 bg-background p-4 @xl/limits:grid-cols-[9rem_minmax(0,1fr)_auto] @xl/limits:items-center", - isDragging && "relative z-10 shadow-md", + "group/limit-row relative grid items-center gap-x-6 gap-y-3 rounded-lg border border-border/60 bg-background p-4 md:grid-cols-[11rem_minmax(0,1fr)]", + isDragging && "z-10 shadow-md", )} >
@@ -569,13 +569,13 @@ function PoolWindowCard({ ) : null}
-
{controls}
-
+
{description ? ( -

{description}

+

{description}

) : null} +
{controls}
); } @@ -625,13 +625,13 @@ function PoolSection({ transition: transition, }} className={cn( - "@container/limits flex flex-col gap-3", + "flex flex-col gap-3", isDragging && "relative z-10 rounded-lg bg-background shadow-md", )} /> } > -
+

{label}

- +
Date: Tue, 17 Nov 2026 11:25:23 +1100 Subject: [PATCH 06/10] fix(web): count hidden usage limits where they were hidden Co-Authored-By: Claude Opus 5.5 --- .../usage/UsageLimitsPooled.browser.test.tsx | 16 +- .../components/usage/UsageLimitsPooled.tsx | 228 ++++++++++++------ docs/user/usage.md | 14 +- 3 files changed, 166 insertions(+), 92 deletions(-) diff --git a/apps/web/src/components/usage/UsageLimitsPooled.browser.test.tsx b/apps/web/src/components/usage/UsageLimitsPooled.browser.test.tsx index 1ca56099e0fb9..b1071bc082148 100644 --- a/apps/web/src/components/usage/UsageLimitsPooled.browser.test.tsx +++ b/apps/web/src/components/usage/UsageLimitsPooled.browser.test.tsx @@ -180,13 +180,16 @@ describe("UsageLimitsPooled", () => { await commands.resetPointer(); await expect.element(providerReorder).toHaveStyle({ opacity: "0" }); await expect.element(screen.getByText("Session", { exact: true })).toBeVisible(); + expect(screen.getByRole("button", { name: /Antigravity Gemini/ }).elements()).toHaveLength(0); await screen.getByText("Weekly", { exact: true }).hover(); await screen.getByRole("button", { name: "Hide Codex Weekly", exact: true }).click(); await expect.element(screen.getByText("Weekly", { exact: true })).not.toBeInTheDocument(); - await expect.element(screen.getByRole("button", { name: "Show hidden limits" })).toHaveFocus(); - await screen.getByRole("button", { name: "Show hidden limits" }).click(); + await expect.element(screen.getByRole("button", { name: "1 item hidden" })).toHaveFocus(); + await screen.getByRole("button", { name: "1 item hidden" }).click(); await screen.getByRole("button", { name: "Show Codex Weekly", exact: true }).click(); - await screen.getByRole("button", { name: "Hide hidden limits" }).click(); + await expect + .element(screen.getByRole("button", { name: "1 item hidden" })) + .not.toBeInTheDocument(); await expect .element(screen.getByRole("button", { name: "Collapse Codex limits" })) .toHaveFocus(); @@ -225,9 +228,12 @@ describe("UsageLimitsPooled", () => { await screen.getByRole("button", { name: "Hide Codex", exact: true }).click(); await expect.element(screen.getByRole("heading", { name: /Codex/ })).not.toBeInTheDocument(); - await screen.getByRole("button", { name: "Show hidden limits" }).click(); + await expect.element(screen.getByRole("button", { name: "1 item hidden" })).toHaveFocus(); + await screen.getByRole("button", { name: "1 item hidden" }).click(); await screen.getByRole("button", { name: "Show Codex", exact: true }).click(); - await screen.getByRole("button", { name: "Hide hidden limits" }).click(); + await expect + .element(screen.getByRole("button", { name: "1 item hidden" })) + .not.toBeInTheDocument(); await expect .element(screen.getByRole("button", { name: "Expand Codex limits" })) .toHaveAttribute("aria-expanded", "false"); diff --git a/apps/web/src/components/usage/UsageLimitsPooled.tsx b/apps/web/src/components/usage/UsageLimitsPooled.tsx index d761a5545690a..08bdb33a9b0b8 100644 --- a/apps/web/src/components/usage/UsageLimitsPooled.tsx +++ b/apps/web/src/components/usage/UsageLimitsPooled.tsx @@ -40,7 +40,6 @@ import { ProviderInstanceIcon } from "../chat/ProviderInstanceIcon"; import { providerClients } from "../settings/providerDriverMeta"; import { RedactedSensitiveText } from "../settings/RedactedSensitiveText"; import { Button } from "../ui/button"; -import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../ui/collapsible"; import { OpenAI } from "../Icons"; import { Alert, AlertTitle } from "../ui/alert"; import { Popover, PopoverCreateHandle, PopoverPopup, PopoverTrigger } from "../ui/popover"; @@ -489,6 +488,7 @@ function PoolWindowCard({ label, description, controlLabel, + arrangeable, onToggleVisibility, hidden, }: { @@ -499,6 +499,7 @@ function PoolWindowCard({ readonly description?: string | undefined; readonly id: string; readonly controlLabel: string; + readonly arrangeable: boolean; readonly onToggleVisibility: () => void; readonly hidden: boolean; }) { @@ -575,22 +576,58 @@ function PoolWindowCard({ {description ? (

{description}

) : null} -
{controls}
+ {arrangeable ? ( +
{controls}
+ ) : null}
); } +const PAGE_SCOPE = "page"; + +function HiddenLimitsToggle({ + scope, + count, + revealed, + onToggle, +}: { + readonly scope: string; + readonly count: number; + readonly revealed: boolean; + readonly onToggle: () => void; +}) { + if (count === 0) return null; + return ( + + ); +} + function PoolSection({ pool, windows, now, layout, + revealed, + onReveal, + onHide, onChange, }: { readonly pool: LimitPool; readonly windows: readonly LimitPoolWindow[]; readonly now: number; readonly layout: UsageLimitLayout; + readonly revealed: boolean; + readonly onReveal: (revealed: boolean) => void; + readonly onHide: () => void; readonly onChange: (update: (current: UsageLimitLayout) => UsageLimitLayout) => void; }) { const { @@ -606,35 +643,27 @@ function PoolSection({ const label = providerClients.get(pool.driver)?.label ?? String(pool.driver); const hidden = layout.hiddenProviders.includes(pool.driver); const collapsed = layout.collapsedProviders.includes(pool.driver); + const keys = windows.map((window) => limitWindowKey(pool.driver, window)); + const hiddenCount = keys.filter((key) => layout.hiddenWindows.includes(key)).length; + const shownWindows = revealed + ? windows + : windows.filter( + (window) => !layout.hiddenWindows.includes(limitWindowKey(pool.driver, window)), + ); return ( - - onChange((current) => ({ - ...current, - collapsedProviders: open - ? current.collapsedProviders.filter((driver) => driver !== pool.driver) - : [...current.collapsedProviders, pool.driver], - })) - } - render={ -
- } +
-
+
+ {hidden || collapsed ? null : ( + onReveal(!revealed)} + /> + )}
- + {hidden || collapsed || shownWindows.length === 0 ? null : ( limitWindowKey(pool.driver, window))} + items={shownWindows.map((window) => limitWindowKey(pool.driver, window))} onReorder={(active, over) => onChange((current) => ({ ...current, - windowOrder: moveLimitItem( - current.windowOrder, - windows.map((window) => limitWindowKey(pool.driver, window)), - active, - over, - ), + windowOrder: moveLimitItem(current.windowOrder, keys, active, over), })) } >
- {windows.map((window) => { + {shownWindows.map((window) => { const details = pool.driver === "cursor" ? cursorUsageWindowDetails(window.id, pool) : undefined; const key = limitWindowKey(pool.driver, window); @@ -709,22 +750,24 @@ function PoolSection({ label={details?.label} description={details?.description} controlLabel={`${label} ${details?.label ?? window.label}`} + arrangeable={windows.length > 1} hidden={windowHidden} - onToggleVisibility={() => + onToggleVisibility={() => { + if (!windowHidden) onReveal(false); onChange((current) => ({ ...current, hiddenWindows: windowHidden ? current.hiddenWindows.filter((id) => id !== key) : [...current.hiddenWindows, key], - })) - } + })); + }} /> ); })}
-
- + )} +
); } @@ -736,10 +779,9 @@ export function UsageLimitsPooled({ readonly now: number; }) { const [segmentPopover] = useState(() => PopoverCreateHandle()); - const [showHidden, setShowHidden] = useState(false); - const restoreButton = useRef(null); + const [revealed, setRevealed] = useState([]); const limitsRoot = useRef(null); - const focusedBeforeChange = useRef(null); + const focusedBeforeChange = useRef<{ element: Element; scope: string | null } | null>(null); const [layout, setLayout] = useLocalStorage( USAGE_LIMIT_LAYOUT_KEY, DEFAULT_LIMIT_LAYOUT, @@ -767,26 +809,60 @@ export function UsageLimitsPooled({ .filter( ({ pool, windows }) => !layout.hiddenProviders.includes(pool.driver) && windows.length > 0, ); - const hasHidden = layout.hiddenProviders.length > 0 || layout.hiddenWindows.length > 0; + const hiddenProviderCount = pools.filter((pool) => + layout.hiddenProviders.includes(pool.driver), + ).length; + const providersRevealed = revealed.includes(PAGE_SCOPE); + const shownPools = providersRevealed + ? arrangedPools + : arrangedPools.filter(({ pool }) => !layout.hiddenProviders.includes(pool.driver)); const hasLayout = Object.values(layout).some((items) => items.length > 0); - const shownPools = showHidden ? arrangedPools : visiblePools; const notices = collectLimitNotices(presentations); const externalLinks = collectExternalUsageLinks(presentations); + const reveal = (scope: string, next: boolean) => + setRevealed((current) => + next ? [...current, scope] : current.filter((revealedScope) => revealedScope !== scope), + ); + const rememberFocus = () => { + const element = document.activeElement; + focusedBeforeChange.current = element + ? { + element, + scope: element.closest("[data-limit-scope]")?.getAttribute("data-limit-scope") ?? null, + } + : null; + }; // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- Hand off focus after an action removes its control. useLayoutEffect(() => { - if (focusedBeforeChange.current && !focusedBeforeChange.current.isConnected) { - const target = - restoreButton.current ?? - limitsRoot.current?.querySelector("button[aria-expanded]") ?? - limitsRoot.current; - target?.focus(); - } + const before = focusedBeforeChange.current; focusedBeforeChange.current = null; + if (!before || before.element.isConnected) return; + const root = limitsRoot.current; + const section = before.scope + ? root?.querySelector(`[data-limit-scope="${globalThis.CSS.escape(before.scope)}"]`) + : null; + const target = + section?.querySelector("[data-hidden-toggle]") ?? + section?.querySelector("button[aria-expanded]") ?? + root?.querySelector(`[data-hidden-toggle="${PAGE_SCOPE}"]`) ?? + root?.querySelector("button[aria-expanded]") ?? + root; + target?.focus(); }); return (
- {pools.length > 0 && visiblePools.length === 0 && !showHidden ? ( -

All limits are hidden.

+ {hiddenProviderCount > 0 ? ( +
+ { + rememberFocus(); + reveal(PAGE_SCOPE, !providersRevealed); + }} + /> +
) : null} {pools.length === 0 && notices.length === 0 && externalLinks.length === 0 ? (

@@ -816,8 +892,14 @@ export function UsageLimitsPooled({ windows={windows} now={now} layout={layout} + revealed={revealed.includes(pool.driver)} + onReveal={(next) => { + rememberFocus(); + reveal(pool.driver, next); + }} + onHide={() => reveal(PAGE_SCOPE, false)} onChange={(update) => { - focusedBeforeChange.current = document.activeElement; + rememberFocus(); setLayout(update); }} /> @@ -825,29 +907,15 @@ export function UsageLimitsPooled({

- {hasLayout || showHidden ? ( + {hasLayout ? (
- {hasHidden || showHidden ? ( - - ) : null} +
+
+ > + +
+ {showHiddenCount ? ( + onReveal(!revealed)} + /> + ) : null}
{hidden || collapsed || shownWindows.length === 0 ? null : ( @@ -852,7 +863,7 @@ export function UsageLimitsPooled({ return (
{hiddenProviderCount > 0 ? ( -
+
Date: Tue, 17 Nov 2026 12:11:13 +1100 Subject: [PATCH 09/10] fix(web): revealed hidden providers show their usage limits Co-Authored-By: Claude Opus 5.5 --- .../usage/UsageLimitsPooled.browser.test.tsx | 6 ++++++ apps/web/src/components/usage/UsageLimitsPooled.tsx | 10 +++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/apps/web/src/components/usage/UsageLimitsPooled.browser.test.tsx b/apps/web/src/components/usage/UsageLimitsPooled.browser.test.tsx index e3bb4bd02c1f1..ca3ec25742506 100644 --- a/apps/web/src/components/usage/UsageLimitsPooled.browser.test.tsx +++ b/apps/web/src/components/usage/UsageLimitsPooled.browser.test.tsx @@ -194,6 +194,12 @@ describe("UsageLimitsPooled", () => { .element(screen.getByRole("button", { name: "Collapse Codex limits" })) .toHaveFocus(); await screen.getByRole("heading", { name: /Antigravity/ }).hover(); + await screen.getByRole("button", { name: "Hide Antigravity", exact: true }).click(); + await expect.element(screen.getByText("Gemini · Weekly")).not.toBeInTheDocument(); + await screen.getByRole("button", { name: "1 item hidden" }).click(); + await expect.element(screen.getByText("Gemini · Weekly")).toBeVisible(); + await screen.getByRole("button", { name: "Show Antigravity", exact: true }).click(); + await screen.getByRole("heading", { name: /Antigravity/ }).hover(); await screen.getByRole("button", { name: "Collapse Antigravity limits" }).click(); const providerHandle = screen.getByRole("button", { name: "Reorder Codex", exact: true }); await userEvent.keyboard("{Shift}"); diff --git a/apps/web/src/components/usage/UsageLimitsPooled.tsx b/apps/web/src/components/usage/UsageLimitsPooled.tsx index 78f61ad05a071..2ad9f479168a4 100644 --- a/apps/web/src/components/usage/UsageLimitsPooled.tsx +++ b/apps/web/src/components/usage/UsageLimitsPooled.tsx @@ -645,7 +645,7 @@ function PoolSection({ const collapsed = layout.collapsedProviders.includes(pool.driver); const keys = windows.map((window) => limitWindowKey(pool.driver, window)); const hiddenCount = keys.filter((key) => layout.hiddenWindows.includes(key)).length; - const showHiddenCount = !hidden && !collapsed && hiddenCount > 0; + const showHiddenCount = !collapsed && hiddenCount > 0; const shownWindows = revealed ? windows : windows.filter( @@ -702,7 +702,7 @@ function PoolSection({ })); }} > - {hidden ? null : ( + { - )} + }
{showHiddenCount ? ( @@ -735,7 +735,7 @@ function PoolSection({ ) : null}
- {hidden || collapsed || shownWindows.length === 0 ? null : ( + {collapsed || shownWindows.length === 0 ? null : ( limitWindowKey(pool.driver, window))} onReorder={(active, over) => @@ -745,7 +745,7 @@ function PoolSection({ })) } > -
+ - {collapsed || shownWindows.length === 0 ? null : ( + {shownWindows.length === 0 ? null : ( limitWindowKey(pool.driver, window))} onReorder={(active, over) => @@ -863,23 +858,23 @@ export function UsageLimitsPooled({ limitWindowKey(pool.driver, window), ), })); - const visiblePools = arrangedPools - .map(({ pool, windows }) => ({ - pool, - windows: windows.filter( - (window) => !layout.hiddenWindows.includes(limitWindowKey(pool.driver, window)), - ), - })) - .filter( - ({ pool, windows }) => !layout.hiddenProviders.includes(pool.driver) && windows.length > 0, - ); const hiddenProviderCount = pools.filter((pool) => layout.hiddenProviders.includes(pool.driver), ).length; const providersRevealed = revealed.includes(PAGE_SCOPE); - const shownPools = providersRevealed - ? arrangedPools - : arrangedPools.filter(({ pool }) => !layout.hiddenProviders.includes(pool.driver)); + const shownPools = arrangedPools + .filter(({ pool }) => providersRevealed || !layout.hiddenProviders.includes(pool.driver)) + .map(({ pool, windows }) => { + const windowsRevealed = revealed.includes(pool.driver); + const shownWindows = layout.collapsedProviders.includes(pool.driver) + ? [] + : windowsRevealed + ? windows + : windows.filter( + (window) => !layout.hiddenWindows.includes(limitWindowKey(pool.driver, window)), + ); + return { pool, windows, shownWindows, windowsRevealed }; + }); const hasLayout = Object.values(layout).some((items) => items.length > 0); const notices = collectLimitNotices(presentations, m); const externalLinks = collectExternalUsageLinks(presentations, m); @@ -949,14 +944,15 @@ export function UsageLimitsPooled({ } >
- {shownPools.map(({ pool, windows }) => ( + {shownPools.map(({ pool, windows, shownWindows, windowsRevealed }) => ( { rememberFocus(); reveal(pool.driver, next); @@ -993,9 +989,7 @@ export function UsageLimitsPooled({ handle={segmentPopover} actions={segmentPopoverActions} payload={payload} - pools={visiblePools - .filter(({ pool }) => !layout.collapsedProviders.includes(pool.driver)) - .map(({ pool, windows }) => ({ ...pool, windows }))} + windows={shownPools.flatMap(({ shownWindows }) => shownWindows)} now={now} /> ) : null