feat: improve Amount formatting capabilities - #871
Conversation
- Add notation prop for compact formatting ($1.2M) in dashboards - Add narrowSymbol option to currencyDisplay - Add signDisplay prop for gains/losses (+/- sign control) - Add tabularNums prop (default true) to toggle fixed-width figures - Memoize Intl.NumberFormat instances module-wide; resolve currency validity and decimals in one cached lookup
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reached
Next review available in: 21 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe Sequence Diagram(s)sequenceDiagram
participant Amount
participant getCurrencyInfo
participant getFormatter
participant IntlNumberFormat
Amount->>getCurrencyInfo: Validate currency and read decimal count
getCurrencyInfo->>getFormatter: Request cached currency formatter
getFormatter->>IntlNumberFormat: Create or reuse formatter
Amount->>getFormatter: Format with notation and signDisplay
getFormatter->>IntlNumberFormat: Create or reuse formatter
Amount->>Amount: Render value with optional tabular styling
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/raystack/components/amount/amount.tsx`:
- Around line 142-163: Bound currencyInfoCache before inserting entries in
getCurrencyInfo, using the same 64-entry limit as formatterCache; alternatively,
skip caching when the currency code is invalid. Preserve cached lookups for
valid currencies while ensuring unlimited distinct invalid inputs cannot cause
persistent module-level growth.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d73b795e-3e56-4627-9a51-35c6ad4032e4
📒 Files selected for processing (6)
apps/www/src/components/playground/amount-examples.tsxapps/www/src/content/docs/components/amount/demo.tsapps/www/src/content/docs/components/amount/index.mdxpackages/raystack/components/amount/__tests__/amount.test.tsxpackages/raystack/components/amount/amount.module.csspackages/raystack/components/amount/amount.tsx
Summary
Implements the remaining items from #595, plus a
tabularNumsprop.New props
notation('standard' | 'compact', default'standard') — compact formatting like$1.2M/$13Kfor dashboards and summary views. Note: compact rounds aggressively by design (Intl behavior), so small values like$12.99render as$13.currencyDisplay: 'narrowSymbol'— always shows the narrow symbol ($instead ofUS$in non-US locales).signDisplay('auto' | 'always' | 'exceptZero' | 'never', default'auto') — controls the+/-sign, useful for gains/losses.tabularNums(defaulttrue) — fixed-width figures so digits align across table rows. Previously this was always on via CSS; it is now a prop so running text can opt out for proportional figures. Default behavior is unchanged.Performance
Intl.NumberFormatinstances are now memoized in a module-level cache (keyed by locale + options, capped at 64 entries). Previously every render created 3 formatter instances, which adds up fast when Amount renders in table rows.isValidCurrency()andgetCurrencyDecimals()are merged into a single cachedgetCurrencyInfo()lookup. Decimals now come fromresolvedOptions().maximumFractionDigitsinstead of regex-matching formatted output.Not included
padStartconversion handles short strings correctly ("5"→$0.05).Docs
notation,signDisplay, andtabularNumsexample sections.Test plan
Closes #595