-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat(explore-attr-breakdowns): Using new useChartXRangeSelection hook #103814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(explore-attr-breakdowns): Using new useChartXRangeSelection hook #103814
Conversation
| ); | ||
| boxSelectOptions.clearSelection(); | ||
| }, [boxSelectOptions, router]); | ||
| clearSelection(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Falsy check fails for zero timestamp values
The condition checks if startTimestamp or endTimestamp are falsy, but since these are numeric timestamps, a value of 0 (Unix epoch) is valid yet falsy in JavaScript. This causes the function to incorrectly return early when the selection includes timestamp 0, preventing zoom functionality for that edge case. The check needs to explicitly test for null or undefined rather than relying on falsy evaluation.
| saveOnZoom: true, | ||
| }); | ||
|
|
||
| const {groupName} = useWidgetSyncContext(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useWidgetSyncContext gets called on line 141. Can we just get the groupName from there? Unless there's a reason we need to create another context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Laser eyes 👁️🗨️
| boxSelectOptions={boxSelectOptions} | ||
| triggerWrapperRef={triggerWrapperRef} | ||
| /> | ||
| {index === 0 ? <AttributeComparisonCTA>{widget}</AttributeComparisonCTA> : widget} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Chart clicks clear selection unexpectedly
The ChartWrapper no longer prevents selection clearing when clicked. The old useChartBoxSelect hook checked if clicks were inside chartWrapperRef before clearing selection, but the new useChartXRangeSelection hook uses data-explore-chart-selection-region attributes instead. The ChartWrapper lacks this attribute, causing clicks on the chart to clear the selection, breaking the previous behavior where users could interact with the chart without losing their selection.
| const {brush, onBrushEnd, onBrushStart, toolBox, ActionMenu} = useChartXRangeSelection({ | ||
| chartRef, | ||
| deps: [props.plottables], | ||
| disabled: true, | ||
| chartsGroupName: groupName, | ||
| ...props.chartXRangeSelection, | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I missed this in the original PR, but it looks like useChartXRangeSelection accepts a actionMenuRenderer, and then returns the rendered component (ActionMenu) using some states within the hook.
This feels unconventional to me because the hook now handles rendering components outside of echarts as well as brush logic in echarts. I don't think this is a blocker, but would it make more sense for the hook to just return the states necessary for rendering instead? And then the parent can handle the rendering using those states? Unless there is some limitation that forces us to do it this way. Feel free to address in a follow up if necessary!
useChartXRangeSelectionto enable range selection only in explore chartsuseBoxChartSelectionhook