fix(web): persist usage page environment selection - #10920
Conversation
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — This is a focused Usage-page fix that persists an already user-selected environment subset in the existing localStorage record while preserving the prior all-environments default and legacy preferences. The production change is isolated and covered by compatibility and round-trip tests, with no API, deployment, security, billing, or static-analysis configuration changes. You can add or adjust custom eligibility rules. Learn more. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe usage page now persists selected environment IDs in usage preferences. Preferences support normalized environment selections, legacy data, defaults, and storage failures. The page restores saved selections and saves changes from environment, metric, and time-window controls. ChangesUsage preference persistence
Priority: ⬇️ Low Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to The Usage page now restores and saves environment filters alongside existing preferences, including all-environments and empty selections. Existing saved preferences remain compatible, with no concrete merge-blocking risk identified. Sequence Diagram(s)sequenceDiagram
participant UsagePage
participant PreferenceHelpers
participant PreferenceStorage
UsagePage->>PreferenceStorage: Read saved usage preferences
PreferenceStorage-->>UsagePage: Return selectedEnvironmentIds
UsagePage->>PreferenceHelpers: Convert stored IDs to a selection set
PreferenceHelpers-->>UsagePage: Return selected environments
UsagePage->>PreferenceHelpers: Convert selection set to stored IDs
PreferenceHelpers-->>UsagePage: Return normalized IDs
UsagePage->>PreferenceStorage: Save updated usage preferences
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
What Changed
The Usage page already remembered the last metric and time window between visits. This PR extends the same
t3code:usage-page-preferences:v1localStorage record with the environment selection, so a custom set of selected environments is restored on the next visit.usagePagePreferences.ts: the preferences schema gains an optionalselectedEnvironmentIdsfield.null(the default) means "all environments", including ones connected later; an array is an explicit subset, an empty array means nothing is selected. Two small helpers convert between the stored shape and theReadonlySetthe page uses.UsagePage.tsx: the initial selection is restored from preferences, and every selection change (including switching back to all environments) is saved. Changing metric or window preserves the selection instead of dropping it.Why
The environment picker was the only Usage page state not persisted. Users with the same providers connected on multiple machines see duplicated provider rows across environments, and deselecting the duplicates on every visit was tedious. This follows the existing pattern the page uses for metric/window persistence, with no new storage keys and graceful decoding of preferences saved before this field existed.
UI Changes
None. No visible element changed; only which environments are pre-selected when the page opens.
Checklist
Model: openrouter/z-ai/glm-5.3-flash. Harness: OpenCode (T3 Code).
Summary by CodeRabbit
New Features
Bug Fixes