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

[Discover][Visualize] Fix visualizing a selected field in discover search #61226

Merged
merged 5 commits into from
Mar 26, 2020

Conversation

sulemanof
Copy link
Contributor

@sulemanof sulemanof commented Mar 25, 2020

Summary

Fixes #61213
Fixes #61103

Data should be deep cloned since the object is freezed on mutations.
The mutation was occurred in AggConfig.ensureIds while creating new AggConfigs object .

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@sulemanof sulemanof requested a review from a team March 25, 2020 09:36
@sulemanof sulemanof added release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.7.0 v8.0.0 labels Mar 25, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

@sulemanof sulemanof added Feature:Discover Discover Application Feature:Vis Editor Visualization editor issues labels Mar 25, 2020
@timroes
Copy link
Contributor

timroes commented Mar 25, 2020

I would suggest fixing it instead inside the Vis.setState method (the one that earlier also did the cloneDeep, which got removed when refactoring it to TypeScript in #59958):

diff --git a/src/legacy/core_plugins/visualizations/public/np_ready/public/vis.ts b/src/legacy/core_plugins/visualizations/public/np_ready/public/vis.ts
index 0ba936c9f6..91b6a2368f 100644
--- a/src/legacy/core_plugins/visualizations/public/np_ready/public/vis.ts
+++ b/src/legacy/core_plugins/visualizations/public/np_ready/public/vis.ts
@@ -132,8 +132,10 @@ export class Vis {
       this.data.savedSearchId = state.data.savedSearchId;
     }
     if (state.data && state.data.aggs) {
-      let configStates = state.data.aggs;
-      configStates = this.initializeDefaultsFromSchemas(configStates, this.type.schemas.all || []);
+      const configStates = this.initializeDefaultsFromSchemas(
+        cloneDeep(state.data.aggs),
+        this.type.schemas.all || []
+      );
       if (!this.data.indexPattern) {
         if (state.data.aggs.length) {
           throw new Error('trying to initialize aggs without index pattern');

@sulemanof
Copy link
Contributor Author

I would suggest fixing it instead inside the Vis.setState method (the one that earlier also did the cloneDeep, which got removed when refactoring it to TypeScript):

Agree!
I did not take into account other possible cases

@sulemanof sulemanof requested a review from a team as a code owner March 25, 2020 10:19
Copy link
Member

@kertal kertal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx for fixing this so quickly! Could you add a functional test for that, the maps team recently added one for linking geo point fields to maps. Would be nice to catch this kinds of errors in the future.

describe('discover visualize button', () => {

@sulemanof
Copy link
Contributor Author

functional/apps/maps/discover.js

Good call @kertal !
I've added a functional test for it.
This also helped to reveal one more issue:
if an app filter or query are configured in discover, they are not applied in visualize!
I'm going to create an issue for that with additional details, and an appropriate fix could also be prepared with additional tests in test/functional/apps/discover/_field_visualize.ts.

I'd kindly ask @dmlemeshko to take a look at functional tests changes! 🙂

@lukeelmers lukeelmers self-requested a review March 25, 2020 16:19
@timroes timroes added the v7.8.0 label Mar 25, 2020
@sulemanof sulemanof requested a review from dmlemeshko March 25, 2020 20:51
@sulemanof
Copy link
Contributor Author

As @timroes suggested, fixing the issue with filters is moved into a separate PR #61392

@kertal kertal self-requested a review March 26, 2020 06:51
Copy link
Member

@kertal kertal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM, tested locally in chrome, thx a lot for the functional test!

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Member

@dmlemeshko dmlemeshko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I ran broken scripted fields and the newly added tests against Istanbul-instrumented Kibana and both are passing. Thank you for the fix!

@sulemanof sulemanof merged commit 1d278d4 into elastic:master Mar 26, 2020
@sulemanof sulemanof deleted the fix/visualize_discover_search branch March 26, 2020 07:53
sulemanof added a commit to sulemanof/kibana that referenced this pull request Mar 26, 2020
…arch (elastic#61226)

* Fix visualize a discover search

* Move deep clone into vis.ts

* Add functional tests

* Fix passing filters to visualize

* Revert fixing filters
sulemanof added a commit to sulemanof/kibana that referenced this pull request Mar 26, 2020
…arch (elastic#61226)

* Fix visualize a discover search

* Move deep clone into vis.ts

* Add functional tests

* Fix passing filters to visualize

* Revert fixing filters
sulemanof added a commit that referenced this pull request Mar 26, 2020
…arch (#61226) (#61407)

* Fix visualize a discover search

* Move deep clone into vis.ts

* Add functional tests

* Fix passing filters to visualize

* Revert fixing filters
sulemanof added a commit that referenced this pull request Mar 26, 2020
…arch (#61226) (#61406)

* Fix visualize a discover search

* Move deep clone into vis.ts

* Add functional tests

* Fix passing filters to visualize

* Revert fixing filters

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported Feature:Discover Discover Application Feature:Vis Editor Visualization editor issues release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.7.0 v7.8.0 v8.0.0
Projects
None yet
7 participants