Skip to content

fix(web): persist usage page environment selection - #10920

Open
AmoonPod wants to merge 1 commit into
pingdotgg:mainfrom
AmoonPod:fix/usage-persist-env-selection
Open

fix(web): persist usage page environment selection#10920
AmoonPod wants to merge 1 commit into
pingdotgg:mainfrom
AmoonPod:fix/usage-persist-env-selection

Conversation

@AmoonPod

@AmoonPod AmoonPod commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

What Changed

The Usage page already remembered the last metric and time window between visits. This PR extends the same t3code:usage-page-preferences:v1 localStorage 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 optional selectedEnvironmentIds field. 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 the ReadonlySet the 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

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes (not applicable - no visual change)
  • I included a video for animation/interaction changes (not applicable)

Model: openrouter/z-ai/glm-5.3-flash. Harness: OpenCode (T3 Code).

Summary by CodeRabbit

  • New Features

    • Usage page environment filter selections are now saved and restored across visits.
    • Explicit environment selections, deselections, and the all-environments option are remembered.
  • Bug Fixes

    • Improved handling of saved usage preferences, including older, invalid, or incomplete preference data.
    • Environment selections are cleaned up to prevent duplicate or blank entries.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Sep 9, 2026
@macroscopeapp

macroscopeapp Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at cd35c6a

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.

@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 19d4c8e4-551c-4cf6-943a-34beaec1cee3

📥 Commits

Reviewing files that changed from the base of the PR and between 6c58362 and cd35c6a.

📒 Files selected for processing (3)
  • apps/web/src/components/usage/UsagePage.tsx
  • apps/web/src/components/usage/usagePagePreferences.test.ts
  • apps/web/src/components/usage/usagePagePreferences.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The 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.

Changes

Usage preference persistence

Layer / File(s) Summary
Preference schema and conversions
apps/web/src/components/usage/usagePagePreferences.ts, apps/web/src/components/usage/usagePagePreferences.test.ts
Preferences now store optional environment IDs. Conversion helpers trim, filter, deduplicate, and preserve null for all environments. Tests cover defaults, legacy data, invalid data, conversion behavior, and storage failures.
Usage page environment persistence
apps/web/src/components/usage/UsagePage.tsx
The page restores saved environment selections and persists changes made through environment, metric, and time-window controls.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to cd35c

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
Loading

Suggested reviewers: extoci

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: persisting the Usage page environment selection.
Description check ✅ Passed The description includes complete What Changed, Why, UI Changes, and Checklist sections. It explains the storage behavior, compatibility, scope, and testing-related considerations.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant