Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/9170.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Visualization chart not expanded after legend toggle ([#9170](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9170))
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
unmountComponentAtNode(domNode);
});

if (vis.getUiState() !== uiState) {
vis.setUiState(uiState);

Check warning on line 61 in src/plugins/visualizations/public/expressions/visualization_renderer.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/visualizations/public/expressions/visualization_renderer.tsx#L61

Added line #L61 was not covered by tests
Copy link
Collaborator

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.

Copy link
Contributor Author

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);
}

Copy link
Member

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?

Copy link
Contributor Author

@wanglam wanglam Jan 15, 2025

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.

}

const listenOnChange = params ? params.listenOnChange : false;
render(
<Visualization
Expand Down
Loading