From b6da975829f930ef0229e45e612e26251fd99149 Mon Sep 17 00:00:00 2001 From: Spencer Alger Date: Tue, 30 Sep 2014 16:20:28 -0700 Subject: [PATCH] [vis] Reset the aggParams on agg change, fixes #350 --- src/kibana/apps/visualize/editor/agg.js | 9 +++++++-- src/kibana/components/vis/_agg_config.js | 9 +++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/kibana/apps/visualize/editor/agg.js b/src/kibana/apps/visualize/editor/agg.js index c9c481d0bf286..f39493c4f5375 100644 --- a/src/kibana/apps/visualize/editor/agg.js +++ b/src/kibana/apps/visualize/editor/agg.js @@ -48,7 +48,7 @@ define(function (require) { var $aggParamEditors; var $aggParamEditorsScope; - $scope.$watch('agg.type', function updateAggParamEditor() { + $scope.$watch('agg.type', function updateAggParamEditor(newType, oldType) { if ($aggParamEditors) { $aggParamEditors.remove(); $aggParamEditorsScope.$destroy(); @@ -59,7 +59,12 @@ define(function (require) { var type = $scope.agg.type; if (!agg) return; - agg.fillDefaults(); + + if (newType !== oldType) { + // don't reset on initial load, the + // saved params should persist + agg.resetParams(); + } if (!type) return; diff --git a/src/kibana/components/vis/_agg_config.js b/src/kibana/components/vis/_agg_config.js index fa0bfbc135168..ec21355d76d05 100644 --- a/src/kibana/components/vis/_agg_config.js +++ b/src/kibana/components/vis/_agg_config.js @@ -60,6 +60,15 @@ define(function (require) { }); }; + /** + * Clear the parameters for this aggConfig + * + * @return {object} the new params object + */ + AggConfig.prototype.resetParams = function () { + return this.fillDefaults({}); + }; + AggConfig.prototype.write = function () { return this.type.params.write(this); };