fix(sparklines): Guard against nil trend when series has no data#2797
fix(sparklines): Guard against nil trend when series has no data#2797sentry[bot] wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c4c6c443cc
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| style: "color: #{@sparkline_series.trend.color}", | ||
| class: "font-mono text-right text-xs font-medium text-primary" %> | ||
| <% else %> | ||
| <%= tag.p "–", class: "font-mono text-right text-xs font-medium text-primary" %> |
There was a problem hiding this comment.
Extract the repeated empty-trend shape into DS
When no trend exists, this branch duplicates the identical hand-rolled trend/empty-state paragraph added to accountable_sparklines/show.html.erb, while the existing app/components/DS/ inventory has no equivalent. The repository UI rules require introducing a DS::* primitive before landing a second copy, so centralize this rendering instead of maintaining two independent versions.
AGENTS.md reference: AGENTS.md:L57-L57
Useful? React with 👍 / 👎.
| style: "color: #{@series.trend.color}", | ||
| class: "font-mono text-right text-xs font-medium text-primary" %> | ||
| <% else %> | ||
| <%= tag.p "–", class: "font-mono text-right text-xs font-medium text-primary" %> |
There was a problem hiding this comment.
Localize the empty-trend label
When an accountable series has no data, this literal becomes user-visible content but bypasses t(), so non-English locales cannot select their own no-data representation and translation tooling will not discover it; the same literal in accounts/sparkline.html.erb should be moved to translations as part of the same fix.
AGENTS.md reference: AGENTS.md:L58-L58
Useful? React with 👍 / 👎.
|
Automated review of this bot-generated fix. The fix itself is a narrow, non-swallowing nil-check — However, a few concerns before merging: 1. The stated root cause doesn't match how the series is actually built. Given that, it's worth confirming from the Sentry event (breadcrumbs/params) what actually produced 2. No regression test added. The diff only touches the two 3. Inconsistent with the existing convention for this exact situation. The codebase already has an established pattern for "no trend data yet": Recommend addressing 2 and 3 (and getting a straight answer on 1) before merging. Generated by Claude Code |
This PR addresses the
ActionView::Template::Error: undefined method 'percent_formatted' for niloccurring inAccountableSparklinesController#showandaccounts/sparkline.html.erb.Root Cause:
Series#trendreturnsnilwhen the underlying seriesvaluesare blank (i.e., no data points exist for an account's balance history). The affected views were attempting to call methods like.percent_formattedand.colordirectly on thisnilobject, leading to aNoMethodError.Solution:
Instead of modifying
Series#trendto always return aTrendobject (which would fail due toTrend'scurrentpresence validation), the most pragmatic fix is to add nil-guarding in the views. This PR introducesif @series.trend(or@sparkline_series.trend) checks in bothapp/views/accountable_sparklines/show.html.erbandapp/views/accounts/sparkline.html.erb. Whentrendisnil, a neutral–placeholder is rendered instead of attempting to display a formatted percentage or color.Fixes SURE-APP-A2