Skip to content

Commit

Permalink
Only refresh when Data-tab has changed
Browse files Browse the repository at this point in the history
The below is a more clear way to express what needs to happen.
This also avoids a bug when there is no re-fetch when there are both
changes in the Options and Data tab.
  • Loading branch information
thomasneirynck committed Aug 10, 2016
1 parent 3f59e38 commit 433c842
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 20 deletions.
11 changes: 7 additions & 4 deletions src/core_plugins/kibana/public/visualize/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -295,16 +294,20 @@ 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();
toVis.setState(view);
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();
Expand Down
14 changes: 0 additions & 14 deletions src/ui/public/utils/get_vislib_options.js

This file was deleted.

17 changes: 17 additions & 0 deletions src/ui/public/vis/agg_configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 12 additions & 2 deletions src/ui/public/vislib_vis_type/vislib_renderbot.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 433c842

Please sign in to comment.