feat: add configurable usage display order setting#4126
Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c225450259
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| onChange={(order) => | ||
| handleAutoSave({ usageDisplayOrder: order }) |
There was a problem hiding this comment.
Persist usage display order before exposing the toggle
When a user chooses Used First, this autosave payload is sent to the Tauri save_settings(settings: AppSettings) command, but the persisted backend AppSettings model does not define a usageDisplayOrder field and get_settings_for_frontend also returns that same model. In the desktop app this unknown JSON field is dropped during save/refresh, so reopening settings (or using the modal after refetch) falls back to remaining-first and the new preference cannot actually stick. Add the field to the backend settings model and frontend Settings type before wiring the control.
Useful? React with 👍 / 👎.
|
Hey @farion1231 👋, hope you're doing well! I submitted this PR a little while ago and just wanted to gently check in to see if you've had a chance to take a look. No rush at all — I know you have a lot on your plate maintaining this project! The CI checks are all green ✅, and I'm happy to make any changes or clarifications if needed. Thanks so much for your time and for maintaining cc-switch! 🙏 |
|
Thanks for the contribution! I really like the direction 👍 That said, this version is missing a key piece — put together, you'll find the setting doesn't actually persist. Two things to fix:
Once these two are addressed it should be good to go. Thanks again! |
|
Thanks for the detailed and spot-on review, @farion1231! 🙏 You were absolutely right on both counts. I've pushed a fix ( 1. Backend wiring 2. Scope One note: the tray menu only renders utilization percentages (no used/remaining ordering), so I left it untouched — happy to revisit if you'd prefer it reflect the setting some other way. Also added unit tests covering both display orders. All checks pass locally (typecheck, format, |
|
Followed up to make the setting truly global ( Tray menu ( Subscription quota badges ( I left the transient test toasts in All green locally: typecheck, format, |
Add a new user setting to control whether remaining quota or used quota is displayed first in usage summaries. Changes: - Add 'usageDisplayOrder' field to settings schema with options: 'remaining-first' (default) and 'used-first' - Create UsageDisplaySettings component for the settings UI - Update formatUsageDataSummary to accept optional displayOrder parameter - Add setting to General tab in SettingsPage - Add i18n translations for en, zh, zh-TW, ja Fixes user feedback that 'used first' display order is unintuitive. Default behavior now shows remaining quota first, with an option to switch to the old behavior if preferred.
Address review feedback from @farion1231: 1. Backend wiring: add usage_display_order field to AppSettings (src-tauri/src/settings.rs) so serde no longer silently drops it on save_settings. Includes Default and normalize() validation (only accepts 'remaining-first' / 'used-first'). Without this the setting reverted to default as soon as the query refetched. 2. Scope: apply the setting to the main usage display (UsageFooter.tsx) in both inline mode and the UsagePlanItem rows, so toggling the switch visibly reorders used/remaining in the footer — not just the usage script test toast. Total always stays first; separators are computed so reordering never produces a dangling divider. The tray menu only renders utilization percentages (no used/remaining ordering), so it needs no change. Also add unit tests covering both display orders.
Make the usage display order preference global, not just the script-test toast and the main usage footer. Tray menu (src-tauri/src/tray.rs): - format_script_summary / format_subscription_summary / format_usage_suffix now take a UsageLabelOpts (remaining_first + localized labels). When remaining-first is active the tray shows the complement (100 - util) with a 'remaining' label; otherwise it shows utilization with a 'used' label. The color emoji ALWAYS reflects utilization (closeness to the cap), regardless of which number is displayed. - TrayTexts gains localized used/remaining labels (en/zh/zh-TW/ja). - Reads the preference via settings::usage_display_remaining_first(). Subscription quota badges (SubscriptionQuotaFooter.tsx): - TierBadge and TierBar now respect displayOrder. The numeric value follows the preference; the progress bar fill and the color stay based on utilization. SubscriptionQuotaView reads the setting and threads it down, so CLI-credential and self-managed OAuth quota footers both honor it. UsageFooter's token_plan inline branch passes displayOrder too. - Add subscription.usedShort / remainingShort i18n keys (en/zh/zh-TW/ja). Add Rust unit tests for remaining-first rendering, including the invariant that the emoji still tracks utilization when showing remaining.
2c09b47 to
e2a10cf
Compare
|
Hey @farion1231 👋, just a gentle check-in on this one — no rush at all! Since your last review I've addressed both points: the setting now persists through the backend Whenever you have a moment to take another look, I'd really appreciate it. Happy to make any further changes if needed. Thanks again for your time and for maintaining this project! 🙏 |
Summary
Add a new user setting to control whether remaining quota or used quota is displayed first in usage summaries.
Motivation
Current behavior always shows "used" first, then "remaining". Some users find this unintuitive and prefer to see remaining quota first, as it's more relevant for decision-making ("how much do I have left?" rather than "how much did I use?").
Changes
Settings Schema: Add
usageDisplayOrderfield with options:remaining-first(default) - shows remaining quota firstused-first- shows used quota first (old behavior)UI Component: New
UsageDisplaySettingscomponent in General tabDisplay Logic: Update
formatUsageDataSummaryto accept optionaldisplayOrderparameterremaining-first)Internationalization: Add translations for:
Screenshots
N/A (settings UI follows existing patterns)
Testing
pnpm typecheck)pnpm format:check)Breaking Changes
None. Default behavior now shows remaining first, which is more intuitive. Users who prefer the old behavior can switch to "Used First" in settings.