From b42952185686f6dff831caf39e93f606b70c7d6b Mon Sep 17 00:00:00 2001 From: sulemanof Date: Wed, 25 Mar 2020 12:32:01 +0300 Subject: [PATCH 1/5] Fix visualize a discover search --- .../kibana/public/visualize/np_ready/editor/editor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/editor.js b/src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/editor.js index c5325ca3108b4..6770b53000861 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/editor.js +++ b/src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/editor.js @@ -332,7 +332,7 @@ function VisualizeAppController($scope, $route, $injector, $timeout, kbnUrlState if (!_.isEqual(stateContainer.getState().vis, stateDefaults.vis)) { try { const { aggs, ...visState } = stateContainer.getState().vis; - vis.setState({ ...visState, data: { aggs } }); + vis.setState({ ...visState, data: { aggs: _.cloneDeep(aggs) } }); } catch (error) { // stop syncing url updtes with the state to prevent extra syncing stopAllSyncing(); From 873a19f23502d986161037353d0afd06f78c2556 Mon Sep 17 00:00:00 2001 From: sulemanof Date: Wed, 25 Mar 2020 13:19:12 +0300 Subject: [PATCH 2/5] Move deep clone into vis.ts --- .../kibana/public/visualize/np_ready/editor/editor.js | 2 +- .../visualizations/public/np_ready/public/vis.ts | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/editor.js b/src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/editor.js index 6770b53000861..c5325ca3108b4 100644 --- a/src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/editor.js +++ b/src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/editor.js @@ -332,7 +332,7 @@ function VisualizeAppController($scope, $route, $injector, $timeout, kbnUrlState if (!_.isEqual(stateContainer.getState().vis, stateDefaults.vis)) { try { const { aggs, ...visState } = stateContainer.getState().vis; - vis.setState({ ...visState, data: { aggs: _.cloneDeep(aggs) } }); + vis.setState({ ...visState, data: { aggs } }); } catch (error) { // stop syncing url updtes with the state to prevent extra syncing stopAllSyncing(); 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 0ba936c9f6567..91b6a2368f5ef 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'); From 3f396eefc8bbabbb5ac648fc30e04866faf47bd5 Mon Sep 17 00:00:00 2001 From: sulemanof Date: Wed, 25 Mar 2020 17:37:13 +0300 Subject: [PATCH 3/5] Add functional tests --- .../apps/discover/_field_visualize.ts | 80 +++++++++++++++++++ test/functional/apps/discover/index.js | 1 + 2 files changed, 81 insertions(+) create mode 100644 test/functional/apps/discover/_field_visualize.ts diff --git a/test/functional/apps/discover/_field_visualize.ts b/test/functional/apps/discover/_field_visualize.ts new file mode 100644 index 0000000000000..4a72d5bb34716 --- /dev/null +++ b/test/functional/apps/discover/_field_visualize.ts @@ -0,0 +1,80 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { FtrProviderContext } from '../../ftr_provider_context'; + +export default function({ getService, getPageObjects }: FtrProviderContext) { + const esArchiver = getService('esArchiver'); + const inspector = getService('inspector'); + const kibanaServer = getService('kibanaServer'); + const log = getService('log'); + const PageObjects = getPageObjects(['common', 'discover', 'header', 'timePicker']); + const defaultSettings = { + defaultIndex: 'logstash-*', + }; + + describe('discover field visualize button', () => { + before(async function() { + log.debug('load kibana index with default index pattern'); + await esArchiver.load('discover'); + + // and load a set of makelogs data + await esArchiver.loadIfNeeded('logstash_functional'); + await kibanaServer.uiSettings.replace(defaultSettings); + }); + + beforeEach(async () => { + log.debug('go to discover'); + await PageObjects.common.navigateToApp('discover'); + await PageObjects.timePicker.setDefaultAbsoluteRange(); + }); + + it('should visualize a field in area chart', async () => { + await PageObjects.discover.clickFieldListItem('phpmemory'); + log.debug('visualize a phpmemory field'); + await PageObjects.discover.clickFieldListItemVisualize('phpmemory'); + await PageObjects.header.waitUntilLoadingHasFinished(); + const expectedTableData = [ + ['0', '10'], + ['58,320', '2'], + ['171,080', '2'], + ['3,240', '1'], + ['3,520', '1'], + ['3,880', '1'], + ['4,120', '1'], + ['4,640', '1'], + ['4,760', '1'], + ['5,680', '1'], + ['7,160', '1'], + ['7,400', '1'], + ['8,400', '1'], + ['8,800', '1'], + ['8,960', '1'], + ['9,400', '1'], + ['10,280', '1'], + ['10,840', '1'], + ['13,080', '1'], + ['13,360', '1'], + ]; + await inspector.open(); + await inspector.expectTableData(expectedTableData); + await inspector.close(); + }); + }); +} diff --git a/test/functional/apps/discover/index.js b/test/functional/apps/discover/index.js index 64a5a61335365..582c979a194f4 100644 --- a/test/functional/apps/discover/index.js +++ b/test/functional/apps/discover/index.js @@ -35,6 +35,7 @@ export default function({ getService, loadTestFile }) { loadTestFile(require.resolve('./_saved_queries')); loadTestFile(require.resolve('./_discover')); loadTestFile(require.resolve('./_discover_histogram')); + loadTestFile(require.resolve('./_field_visualize')); loadTestFile(require.resolve('./_filter_editor')); loadTestFile(require.resolve('./_errors')); loadTestFile(require.resolve('./_field_data')); From de3bd58ad3326477b64f1a051dc78544abc1edc6 Mon Sep 17 00:00:00 2001 From: sulemanof Date: Wed, 25 Mar 2020 19:11:57 +0300 Subject: [PATCH 4/5] Fix passing filters to visualize --- .../kibana/public/discover/np_ready/angular/discover.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/discover.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/discover.js index 8e4e77b2d18a6..90e55f517e45e 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/discover.js +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/discover.js @@ -275,6 +275,7 @@ function discoverController( filterManager.getUpdates$(), { next: () => { + $scope.state.filters = filterManager.getAppFilters(); $scope.updateDataSource(); }, }, From b7dd1cc984add14f06bb38d0cc0caf5a45042ae2 Mon Sep 17 00:00:00 2001 From: sulemanof Date: Thu, 26 Mar 2020 08:13:52 +0300 Subject: [PATCH 5/5] Revert fixing filters --- .../kibana/public/discover/np_ready/angular/discover.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/discover.js b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/discover.js index 90e55f517e45e..8e4e77b2d18a6 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/discover.js +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/discover.js @@ -275,7 +275,6 @@ function discoverController( filterManager.getUpdates$(), { next: () => { - $scope.state.filters = filterManager.getAppFilters(); $scope.updateDataSource(); }, },