disable concatenate aggregation type for visualizations other than table and metric

This commit is contained in:
Stéphane Campinas 2016-12-17 15:00:08 +00:00
parent 3d5fa029cd
commit 2a2fa67d2a
No known key found for this signature in database
GPG key ID: 8272664236A42C2F

View file

@ -65,40 +65,47 @@ export default function AggTypeMetricTopProvider(Private) {
{ {
display: 'Min', display: 'Min',
isCompatibleType: isNumber, isCompatibleType: isNumber,
isCompatibleVis: _.constant(true),
disabled: true, disabled: true,
val: 'min' val: 'min'
}, },
{ {
display: 'Max', display: 'Max',
isCompatibleType: isNumber, isCompatibleType: isNumber,
isCompatibleVis: _.constant(true),
disabled: true, disabled: true,
val: 'max' val: 'max'
}, },
{ {
display: 'Sum', display: 'Sum',
isCompatibleType: isNumber, isCompatibleType: isNumber,
isCompatibleVis: _.constant(true),
disabled: true, disabled: true,
val: 'sum' val: 'sum'
}, },
{ {
display: 'Average', display: 'Average',
isCompatibleType: isNumber, isCompatibleType: isNumber,
isCompatibleVis: _.constant(true),
disabled: true, disabled: true,
val: 'average' val: 'average'
}, },
{ {
display: 'Concatenate', display: 'Concatenate',
isCompatibleType: _.constant(true), isCompatibleType: _.constant(true),
isCompatibleVis: function (name) {
return name === 'metric' || name === 'table';
},
disabled: true, disabled: true,
val: 'concat' val: 'concat'
} }
], ],
controller: function ($scope) { controller: function ($scope) {
$scope.options = _.cloneDeep($scope.aggParam.options); $scope.options = _.cloneDeep($scope.aggParam.options);
$scope.$watch('agg.params.field.type', function (type) { $scope.$watchGroup([ 'agg.vis.type.name', 'agg.params.field.type' ], function ([ visName, fieldType ]) {
if (type) { if (fieldType && visName) {
_.each($scope.options, option => { _.each($scope.options, option => {
option.disabled = !option.isCompatibleType(type); option.disabled = !option.isCompatibleVis(visName) || !option.isCompatibleType(fieldType);
}); });
} }
}); });
@ -167,7 +174,7 @@ export default function AggTypeMetricTopProvider(Private) {
let values = []; let values = [];
for (const hit of hits) { for (const hit of hits) {
const hitValues = path === '_source' ? hit._source : agg.vis.indexPattern.flattenHit(hit, true)[path];; const hitValues = path === '_source' ? hit._source : agg.vis.indexPattern.flattenHit(hit, true)[path];
if (_.isArray(hitValues)) { if (_.isArray(hitValues)) {
values.push(...hitValues); values.push(...hitValues);
} else { } else {
@ -193,4 +200,4 @@ export default function AggTypeMetricTopProvider(Private) {
return values; return values;
} }
}); });
}; }