diff --git a/src/core_plugins/kibana/public/visualize/editor/editor.js b/src/core_plugins/kibana/public/visualize/editor/editor.js index c24e133c5a4c2..736d71e9cb401 100644 --- a/src/core_plugins/kibana/public/visualize/editor/editor.js +++ b/src/core_plugins/kibana/public/visualize/editor/editor.js @@ -5,7 +5,6 @@ import 'plugins/kibana/visualize/editor/agg_filter'; import 'ui/visualize'; import 'ui/collapsible_sidebar'; import 'ui/share'; -import getVisLibOptions from 'ui/utils/get_vislib_options'; import angular from 'angular'; import Notifier from 'ui/notify/notifier'; import RegistryVisTypesProvider from 'ui/registry/vis_types'; @@ -295,8 +294,8 @@ uiModules function transferVisState(fromVis, toVis, stage) { return function () { - const fromVisLib = getVisLibOptions(fromVis); - const toVisLib = getVisLibOptions(toVis); + //verify this before we copy the "new" state + const aggregationChanges = !fromVis.aggs.jsonDataEquals(toVis.aggs); const view = fromVis.getEnabledState(); const full = fromVis.getState(); @@ -304,7 +303,11 @@ uiModules editableVis.dirty = false; $state.vis = full; - if (stage && _.isEqual(toVisLib, fromVisLib)) {//only requery ES when the query changed. vislib params are irrelevant + /** + * Only fetch (full ES round trip), if the play-button has been pressed (ie. 'stage' variable) and if there + * has been changes in the Data-tab. + */ + if (stage && aggregationChanges) { $scope.fetch(); } else { $state.save(); diff --git a/src/ui/public/utils/get_vislib_options.js b/src/ui/public/utils/get_vislib_options.js deleted file mode 100644 index 2af6fb21389bd..0000000000000 --- a/src/ui/public/utils/get_vislib_options.js +++ /dev/null @@ -1,14 +0,0 @@ -import _ from 'lodash'; - -export default function getVislibOptions(vis) { - return _.assign( - {}, - vis.type.params.defaults, - { - type: vis.type.name, - // Add attribute which determines whether an index is time based or not. - hasTimeField: vis.indexPattern && vis.indexPattern.hasTimeField() - }, - vis.params - ); -} diff --git a/src/ui/public/vis/agg_configs.js b/src/ui/public/vis/agg_configs.js index 08f6798b7b2e5..29458d14c4030 100644 --- a/src/ui/public/vis/agg_configs.js +++ b/src/ui/public/vis/agg_configs.js @@ -47,6 +47,23 @@ export default function AggConfigsFactory(Private) { } } + /** + * Data-by-data comparison of this Aggregation + * Ignores the non-array indexes + * @param aggConfigs an AggConfigs instance + */ + AggConfigs.prototype.jsonDataEquals = function (aggConfigs) { + if (aggConfigs.length !== this.length) { + return false; + } + for (let i = 0; i < this.length; i += 1) { + if (!_.isEqual(aggConfigs[i].toJSON(),this[i].toJSON())) { + return false; + } + } + return true; + }; + AggConfigs.prototype.toDsl = function () { let dslTopLvl = {}; let dslLvlCursor; diff --git a/src/ui/public/vislib_vis_type/vislib_renderbot.js b/src/ui/public/vislib_vis_type/vislib_renderbot.js index 3059ff48092db..1cbbf1a424c21 100644 --- a/src/ui/public/vislib_vis_type/vislib_renderbot.js +++ b/src/ui/public/vislib_vis_type/vislib_renderbot.js @@ -1,5 +1,4 @@ import _ from 'lodash'; -import getVislibOptions from 'ui/utils/get_vislib_options'; import VislibProvider from 'ui/vislib'; import VisRenderbotProvider from 'ui/vis/renderbot'; import VislibVisTypeBuildChartDataProvider from 'ui/vislib_vis_type/build_chart_data'; @@ -30,7 +29,18 @@ module.exports = function VislibRenderbotFactory(Private) { }; VislibRenderbot.prototype._getVislibParams = function () { - return getVislibOptions(this.vis); + let self = this; + + return _.assign( + {}, + self.vis.type.params.defaults, + { + type: self.vis.type.name, + // Add attribute which determines whether an index is time based or not. + hasTimeField: self.vis.indexPattern && self.vis.indexPattern.hasTimeField() + }, + self.vis.params + ); }; VislibRenderbot.prototype.buildChartData = buildChartData;