fix: preserve valid falsy custom names (0, "") in tooltips#7175
Conversation
WalkthroughThe PR updates the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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.
🧹 Nitpick comments (1)
test/util/ChartUtils.spec.tsx (1)
439-467: Nice regression coverage; add explicitnullcase for completeness.The suite is strong for
0/''preservation and fallback paths. Consider adding anullinput assertion to fully lock in the nullish contract introduced in Line [705].Suggested test addition
describe('getTooltipNameProp', () => { @@ it('should fall back to string dataKey when name is undefined', () => { expect(getTooltipNameProp(undefined, 'revenue')).toBe('revenue'); }); + + it('should fall back to string dataKey when name is null', () => { + expect(getTooltipNameProp(null, 'revenue')).toBe('revenue'); + }); @@ });As per coding guidelines:
test/**/*.{test,spec}.{ts,tsx}: Aim for 100% unit test code coverage when writing new code.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/util/ChartUtils.spec.tsx` around lines 439 - 467, Add explicit tests covering name === null for getTooltipNameProp: verify that getTooltipNameProp(null, 'revenue') falls back to the string dataKey ('revenue'), getTooltipNameProp(null, (e) => e) returns undefined when dataKey is a function, and getTooltipNameProp(null, null) returns undefined; add these assertions to the existing describe('getTooltipNameProp') block in ChartUtils.spec.tsx so the null branch of the nullish contract (introduced around line 705) is exercised.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@test/util/ChartUtils.spec.tsx`:
- Around line 439-467: Add explicit tests covering name === null for
getTooltipNameProp: verify that getTooltipNameProp(null, 'revenue') falls back
to the string dataKey ('revenue'), getTooltipNameProp(null, (e) => e) returns
undefined when dataKey is a function, and getTooltipNameProp(null, null) returns
undefined; add these assertions to the existing describe('getTooltipNameProp')
block in ChartUtils.spec.tsx so the null branch of the nullish contract
(introduced around line 705) is exercised.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ec916c43-7f60-4678-961a-e46b57e9c9fe
📒 Files selected for processing (2)
src/util/ChartUtils.tstest/util/ChartUtils.spec.tsx
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7175 +/- ##
=======================================
Coverage 89.68% 89.68%
=======================================
Files 537 537
Lines 40674 40674
Branches 5547 5548 +1
=======================================
Hits 36477 36477
Misses 4189 4189
Partials 8 8 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Bundle ReportChanges will increase total bundle size by 38 bytes (0.0%) ⬆️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: recharts/bundle-treeshaking-polarAssets Changed:
view changes for bundle: recharts/bundle-cjsAssets Changed:
view changes for bundle: recharts/bundle-umdAssets Changed:
view changes for bundle: recharts/bundle-treeshaking-cartesianAssets Changed:
view changes for bundle: recharts/bundle-es6Assets Changed:
|
Description
Fixes a bug where providing
name={0}orname=""to a graphical component (like<Bar>,<Line>, etc.) would be silently ignored, causing the tooltip and legend to fall back to thedataKeyinstead.This occurred because
getTooltipNamePropinsrc/util/ChartUtils.tsused a falsy check (if (nameFromItem)) which incorrectly drops the number0and empty strings. Changed this to a nullish check (!= null).Proposed Changes
!= nullcheck ingetTooltipNameProp.getTooltipNameProp.Checklist
Summary by CodeRabbit
Bug Fixes
Tests