Skip to content

Commit

Permalink
Merge pull request elastic#2865 from spenceralger/conditionalKeepField
Browse files Browse the repository at this point in the history
Only keep the field if it matches the field type filter
  • Loading branch information
w33ble committed Feb 3, 2015
2 parents 7b1bca7 + 4a88640 commit 2cd85bc
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/kibana/components/vis/_agg_config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
define(function (require) {
return function AggConfigFactory(Private) {
return function AggConfigFactory(Private, fieldTypeFilter) {
var _ = require('lodash');
var fieldFormats = Private(require('components/index_patterns/_field_formats'));

Expand Down Expand Up @@ -110,8 +110,16 @@ define(function (require) {
* @return {object} the new params object
*/
AggConfig.prototype.resetParams = function () {
// We need to ensure that row and field don't get overriden.
return this.fillDefaults(_.pick(this.params, 'row', 'field'));
var fieldParam = this.type && this.type.params.byName.field;
var field;

if (fieldParam) {
var prevField = this.params.field;
var fieldOpts = fieldTypeFilter(this.vis.indexPattern.fields, fieldParam.filterFieldTypes);
field = _.contains(fieldOpts, prevField) ? prevField : null;
}

return this.fillDefaults({ row: this.params.row, field: field });
};

AggConfig.prototype.write = function () {
Expand Down

0 comments on commit 2cd85bc

Please sign in to comment.