Skip to content

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

Merged
sulemanof merged 5 commits intoelastic:masterfrom
sulemanof:fix/visualize_discover_search
Mar 26, 2020
Merged

[Discover][Visualize] Fix visualizing a selected field in discover search#61226
sulemanof merged 5 commits intoelastic:masterfrom
sulemanof:fix/visualize_discover_search

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 Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) t// 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
Contributor

@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 Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) t// v7.7.0 v7.8.0 v8.0.0

Projects

None yet

7 participants