-
Notifications
You must be signed in to change notification settings - Fork 924
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
Fix visualization chart not expanded after legend toggle #9170
base: main
Are you sure you want to change the base?
Fix visualization chart not expanded after legend toggle #9170
Conversation
Signed-off-by: Lin Wang <[email protected]>
❌ Empty Changelog SectionThe Changelog section in your PR description is empty. Please add a valid changelog entry or entries. If you did add a changelog entry, check to make sure that it was not accidentally included inside the comment block in the Changelog section. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #9170 +/- ##
==========================================
+ Coverage 61.01% 61.05% +0.03%
==========================================
Files 3813 3813
Lines 91401 91403 +2
Branches 14443 14444 +1
==========================================
+ Hits 55772 55805 +33
+ Misses 32067 32028 -39
- Partials 3562 3570 +8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
Nice! Thanks :)
@@ -57,6 +57,10 @@ export const visualization = (): ExpressionRenderDefinition<VisRenderValue> => ( | |||
unmountComponentAtNode(domNode); | |||
}); | |||
|
|||
if (vis.getUiState() !== uiState) { | |||
vis.setUiState(uiState); |
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 am concerned that handlers.uiState
has a type of any
while vis.setUiState
is expecting PersistedState
.
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.
You're right, but I think it's not a big issue. According the implementation in the Visualization component, the uiState
has already been assigned to the vis object. The vis.uiState
always be an empty since vis
object recreated in every render. To address this any
concern, how about add a type assertment in the compare condition. Refactor code like below:
if (uiState instanceof PersistedState && vis.getUiState() !== uiState) {
vis.setUiState(uiState);
}
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.
Nit: Should we do a deep compare?
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.
vis.getUiState()
should always be an empty object in this place. Since we construct a new ExpVis
object above. The uiState
of this object should be empty too.
Description
This PR fixes an issue where the chart was not expanding after hiding the legend. The root cause was that the
VisLegend
component was usingvis.getUiState()
as theuiState
in the vis_controller, which was different from theuiState
in theVisualizationChart
component. According to the code in visualization_chart, it was usingthis.props.uiState
. Therefore, changes tovis.legendOpen
were not triggering a re-render inVisualizationChart
.To resolve this issue, I added a
uiState
synchronization logic insrc/plugins/visualizations/public/expressions/visualization_renderer.tsx
. This logic compares thevisState
invis
and callssetState
to ensure that the twouiState
instances are the same. As a result, the chart will be resized correctly.Issues Resolved
#9143
Testing the changes
Changelog
Check List
yarn test:jest
yarn test:jest_integration