feat(charts): replace Chart group props with ChartGroupProvider#3507
feat(charts): replace Chart group props with ChartGroupProvider#3507
Conversation
🦋 Changeset detectedLatest commit: 8aeac39 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Pull request overview
Refactors chart grouping by introducing a ChartGroup container (React Context-driven) to replace groupId / enableGroupTooltipSync props on Chart, improving synced-tooltip visibility behavior and fixing lingering tooltip rendering after unhover.
Changes:
- Added
ChartGroupcomponent + context to manage group-level tooltip sync and hover state - Updated
Chart,useChart,useTooltipVisibility, andChartTooltipto consume group state via context - Updated stories, README docs, tests, and added a major-version changeset with migration guidance
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| charts/core/src/index.ts | Exposes ChartGroup from the core entrypoint |
| charts/core/src/ChartTooltip/ChartTooltip.tsx | Reworks tooltip visibility logic around group-level hover + sync |
| charts/core/src/ChartTooltip/ChartTooltip.spec.tsx | Updates mock chart instance shape for new tooltip sync fields |
| charts/core/src/ChartGroup/index.ts | Adds public exports for ChartGroup and related context/types |
| charts/core/src/ChartGroup/ChartGroupContext.types.ts | Defines group context contract (groupId, sync flag, hover state) |
| charts/core/src/ChartGroup/ChartGroupContext.tsx | Implements ChartGroupContext + useChartGroupContext hook |
| charts/core/src/ChartGroup/ChartGroup.types.ts | Defines ChartGroupProps / base props |
| charts/core/src/ChartGroup/ChartGroup.tsx | Implements ChartGroup provider + container |
| charts/core/src/ChartGroup/ChartGroup.styles.ts | Adds base container styles helper |
| charts/core/src/ChartGroup/ChartGroup.spec.tsx | Adds unit tests for ChartGroup + context hook |
| charts/core/src/ChartContext/ChartContext.spec.tsx | Updates chart instance expectations for renamed fields |
| charts/core/src/Chart/hooks/useTooltipVisibility.ts | Adds group hover callbacks + fixes event listener cleanup |
| charts/core/src/Chart/hooks/useTooltipVisibility.spec.tsx | Updates hook invocation shape for new args |
| charts/core/src/Chart/hooks/useChart.types.ts | Replaces old group props with ChartGroupContextType-based shape |
| charts/core/src/Chart/hooks/useChart.ts | Wires group context fields into chart instance |
| charts/core/src/Chart/hooks/useChart.spec.ts | Updates tests to remove obsolete props and adjust expectations |
| charts/core/src/Chart/Chart.types.ts | Removes groupId / enableGroupTooltipSync props |
| charts/core/src/Chart/Chart.tsx | Consumes ChartGroup context and forwards it into useChart |
| charts/core/src/Chart.stories.tsx | Migrates grouped stories to ChartGroup |
| charts/core/README.md | Documents ChartGroup usage and removes Chart group prop docs |
| .changeset/chart-group-tooltip-sync.md | Declares a major bump + migration guide |
|
Size Change: +260 B (+0.01%) Total Size: 1.85 MB
ℹ️ View Unchanged
|
5f34dec to
dc29b3a
Compare
…pContext for grouping ChartCard and Chart instances
…text, and fix synced unhover behavior for ChartTooltip
dc29b3a to
b8d6993
Compare
|
Coverage after merging steph/oc-charts-sync into main will be
Coverage Report for Changed Files
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
tsck
left a comment
There was a problem hiding this comment.
LGTM! Thanks for doing your due diligence on this!
✍️ Proposed changes
Replaced
groupIdandenableGroupTooltipSyncprops on theChartcomponent with a newChartGroupProvider. This refactoring fixes a bug where tooltips continued to render after unhovering a grouped chart instance when tooltip sync was enabled. The newChartGroupProvideruses React Context to manage group-level state, providing better separation of concerns and more reliable tooltip visibility management across grouped charts.Bugged when unhovering chart: https://storybook.mongodb.design/?path=/story/composition-charts-core--synced-by-group-id-with-tooltip-sync
Note: I made a couple attempts to solve the issue without making a major change but no dice. This API is objectively better, and migration is minimal. MMS and internal tools have been consulted on the API change.
✅ Checklist
pnpm changesetand documented my changes🧪 How to test changes
Verify
SyncedByGroupIDWithTooltipSyncstory works as expectedVerify
SyncedByGroupIDWithoutTooltipSyncstory works as expectedSpot-check and verify standalone chart stories work as expected