TypeScript
feat(web): add usage page keybinding (#9434)
Jake Leventhal3e2370fbbf1e
diff --git a/apps/web/src/components/CommandPalette.tsx b/apps/web/src/components/CommandPalette.tsxindex d216828eb3e..0825c5cb92c 100644--- a/apps/web/src/components/CommandPalette.tsx+++ b/apps/web/src/components/CommandPalette.tsx@@ -469,6 +469,7 @@ function overlayModeForCommand(command: string | null): SearchOverlayMode | null}export function CommandPalette({ children }: { children: ReactNode }) {+ const navigate = useNavigate();const [state, dispatch] = useReducer(reduceCommandPaletteUiState, {open: false,mode: "command",@@ -561,6 +562,13 @@ export function CommandPalette({ children }: { children: ReactNode }) {});return;}+ if (command === "usage.open") {+ event.preventDefault();+ event.stopPropagation();+ setOpen(false);+ void navigate({ to: "/usage" });+ return;+ }const mode = overlayModeForCommand(command);if (mode === null) {return;@@ -574,9 +582,11 @@ export function CommandPalette({ children }: { children: ReactNode }) {}, [appearanceMode,keybindings,+ navigate,previewOpen,resolvedTheme,setAppearanceMode,+ setOpen,terminalOpen,theme,themeHalves,@@ -2023,6 +2033,7 @@ function OpenCommandPaletteDialog(props: {searchTerms: ["usage", "use", "tokens", "cost", "spend", "limits", "stats", "analytics"],title: "Open usage",icon: <ChartNoAxesColumnIcon className={ITEM_ICON_CLASS} />,+ shortcutCommand: "usage.open",run: async () => {await navigate({ to: "/usage" });},diff --git a/apps/web/src/components/settings/KeybindingsSettings.logic.test.ts b/apps/web/src/components/settings/KeybindingsSettings.logic.test.tsindex 10fc154d5b0..05fa0943fba 100644--- a/apps/web/src/components/settings/KeybindingsSettings.logic.test.ts+++ b/apps/web/src/components/settings/KeybindingsSettings.logic.test.ts@@ -243,6 +243,7 @@ describe("KeybindingsSettings.logic", () => {"chat.new","rightPanel.toggleMaximized","thread.stop",+ "usage.open","script.setup-db.run",]),);diff --git a/docs/user/usage.md b/docs/user/usage.mdindex c28e392878b..5da542b26a2 100644--- a/docs/user/usage.md+++ b/docs/user/usage.md@@ -1,5 +1,9 @@# Usage and limits+Open **Usage** from the sidebar or the command palette, or press `mod+u` on web and+desktop when the terminal is not focused. Customize `usage.open` in+**Settings → Keybindings**.+## Understand your usage**Usage** combines Codex, Claude Code, and Grok Build session history from your connecteddiff --git a/packages/contracts/src/keybindings.test.ts b/packages/contracts/src/keybindings.test.tsindex 14579c74119..dee46551c22 100644--- a/packages/contracts/src/keybindings.test.ts+++ b/packages/contracts/src/keybindings.test.ts@@ -78,6 +78,12 @@ it.effect("parses keybinding rules", () =>});assert.strictEqual(parsedProjectSearch.command, "projectSearch.toggle");+ const parsedUsageOpen = yield* decode(KeybindingRule, {+ key: "mod+u",+ command: "usage.open",+ });+ assert.strictEqual(parsedUsageOpen.command, "usage.open");+const parsedThemeEditor = yield* decode(KeybindingRule, {key: "mod+alt+shift+t",command: "themeEditor.toggle",diff --git a/packages/contracts/src/keybindings.ts b/packages/contracts/src/keybindings.tsindex 75dc8919596..cb576842030 100644--- a/packages/contracts/src/keybindings.ts+++ b/packages/contracts/src/keybindings.ts@@ -78,6 +78,7 @@ export const STATIC_KEYBINDING_COMMANDS = ["commandPalette.toggle","filePicker.toggle","projectSearch.toggle",+ "usage.open","theme.select","appearance.cycle","themeEditor.toggle",diff --git a/packages/shared/src/keybindings.ts b/packages/shared/src/keybindings.tsindex 6f1071767ae..28fa05be85b 100644--- a/packages/shared/src/keybindings.ts+++ b/packages/shared/src/keybindings.ts@@ -40,6 +40,7 @@ export const DEFAULT_KEYBINDINGS: ReadonlyArray<KeybindingRule> = [{ key: "mod+k", command: "commandPalette.toggle", when: "!terminalFocus" },{ key: "mod+p", command: "filePicker.toggle", when: "!terminalFocus" },{ key: "mod+shift+f", command: "projectSearch.toggle", when: "!terminalFocus" },+ { key: "mod+u", command: "usage.open", when: "!terminalFocus" },{ key: "mod+alt+a", command: "theme.select", when: "!terminalFocus" },{ key: "mod+alt+shift+a", command: "appearance.cycle", when: "!terminalFocus" },{ key: "mod+alt+shift+t", command: "themeEditor.toggle" },