feat: add context to register and trigger bank chart controls#258
feat: add context to register and trigger bank chart controls#258amliu-jumptrading wants to merge 5 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a context-based control system to enable interaction between distribution bar charts and bank chart filters. When users click on a distribution bar (specifically the Bundle/Other bars in Income Distribution), the corresponding filter in the bank chart controls is automatically triggered and focused, with visual feedback via tooltips.
Changes:
- Implemented ChartControlsContext with a ref-based callback registry pattern for registering and triggering chart controls
- Made distribution bars interactive with click handlers, tooltips, and hover effects
- Converted ToggleGroupControl from uncontrolled to controlled component with ref forwarding for programmatic focus
- Added visual feedback (tooltip with highlight, focus states, scroll-into-view) when controls are triggered externally
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| src/features/SlotDetails/index.tsx | Wraps SlotDetails components with ChartControlsProvider |
| src/features/SlotDetails/ChartControlsContext.tsx | Defines types and creates context for chart controls system |
| src/features/SlotDetails/ChartControlsProvider.tsx | Implements provider with ref-based callback registry |
| src/features/SlotDetails/DetailedSlotStats/FeeSection/IncomeByBundle.tsx | Adds click handler to trigger bundle filter control |
| src/features/SlotDetails/DetailedSlotStats/FeeSection/DistributionBars.tsx | Makes bars interactive with click support, tooltips, and conditional styling |
| src/features/SlotDetails/DetailedSlotStats/FeeSection/distributionBars.module.css | Adds clickable styles with hover effects, removes overflow:hidden |
| src/features/Overview/SlotPerformance/TransactionBarsCard/ChartControls/useChartControl.ts | Custom hook for registering controls and managing tooltip state |
| src/features/Overview/SlotPerformance/TransactionBarsCard/ChartControls/index.tsx | Implements bundle control registration, focus handling, and scroll behavior |
| src/features/Overview/SlotPerformance/TransactionBarsCard/ChartControls/ToggleGroupControl.tsx | Converts to controlled component with ref forwarding and tooltip support |
| src/features/Overview/SlotPerformance/TransactionBarsCard/ChartControls/toggleGroupControl.module.css | Adds tooltip-triggered state styling and improves focus states |
| src/features/Overview/SlotPerformance/TransactionBarsCard/ChartControls/chartControl.module.css | Adds tooltip styling for chart controls |
| src/colors.ts | Adds slotDetailsChartControlsTriggered color for visual feedback |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/features/SlotDetails/DetailedSlotStats/FeeSection/distributionBars.module.css
Show resolved
Hide resolved
src/features/SlotDetails/DetailedSlotStats/FeeSection/DistributionBars.tsx
Outdated
Show resolved
Hide resolved
src/features/Overview/SlotPerformance/TransactionBarsCard/ChartControls/useChartControl.ts
Outdated
Show resolved
Hide resolved
src/features/Overview/SlotPerformance/TransactionBarsCard/ChartControls/index.tsx
Show resolved
Hide resolved
src/features/Overview/SlotPerformance/TransactionBarsCard/ChartControls/ToggleGroupControl.tsx
Show resolved
Hide resolved
src/features/Overview/SlotPerformance/TransactionBarsCard/ChartControls/index.tsx
Show resolved
Hide resolved
src/features/Overview/SlotPerformance/TransactionBarsCard/ChartControls/useChartControl.ts
Show resolved
Hide resolved
src/features/SlotDetails/DetailedSlotStats/FeeSection/distributionBars.module.css
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/features/SlotDetails/DetailedSlotStats/FeeSection/DistributionBars.tsx
Outdated
Show resolved
Hide resolved
src/features/SlotDetails/DetailedSlotStats/FeeSection/distributionBars.module.css
Show resolved
Hide resolved
asuzuki-jumptrading
left a comment
There was a problem hiding this comment.
This is a very clever way to not keep the filter values in the context! Nice work :D
src/features/Overview/SlotPerformance/TransactionBarsCard/ChartControls/useChartControl.ts
Outdated
Show resolved
Hide resolved
src/features/SlotDetails/DetailedSlotStats/FeeSection/DistributionBars.tsx
Outdated
Show resolved
Hide resolved
src/features/Overview/SlotPerformance/TransactionBarsCard/ChartControls/ToggleGroupControl.tsx
Outdated
Show resolved
Hide resolved
src/features/Overview/SlotPerformance/TransactionBarsCard/ChartControls/useChartControl.ts
Show resolved
Hide resolved
a31e0cc to
03bafb0
Compare
atsai-jumptrading
left a comment
There was a problem hiding this comment.
much cleaner! 🧼
| {onItemClick ? ( | ||
| <Flex | ||
| asChild | ||
| className={styles.clickable} |
There was a problem hiding this comment.
why do we need to make our own clickable styling? Can we not use radix button with ghost variant or the reset component?
| const closeTooltip = useCallback(() => setIsTooltipOpen(false), []); | ||
|
|
||
| useEffect(() => { | ||
| const cleanup = registerControl(key, (value) => { |
There was a problem hiding this comment.
could just return registerControl
| ) { | ||
| const { registerControl } = useContext(ChartControlsContext); | ||
| const updateRef = useRef(update); | ||
| useEffect(() => { |
There was a problem hiding this comment.
can just do this in the render without the useEffect, actually slower updating within the useEffect
| hasMinTextWidth, | ||
| }: ToggleGroupControlProps<T>) { | ||
| const [value, setValue] = useState(defaultValue); | ||
| export interface ToggleGroupControlHandle<T extends string> { |
There was a problem hiding this comment.
i think convention is to just call it by componentRef, as in ToggleGroupControlRef
Uh oh!
There was an error while loading. Please reload this page.