Skip to content

Commit

Permalink
filter out incompatble aggregate options and auto select the option i…
Browse files Browse the repository at this point in the history
…f there is only one
  • Loading branch information
scampi committed Dec 28, 2016
1 parent 66d3b31 commit 1bd4727
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
required
name="aggregate"
ng-model="agg.params.aggregate"
ng-options="opt as opt.display disable when opt.disabled for opt in options| orderBy: 'display' track by opt.val"
ng-options="opt as opt.display for opt in options| orderBy: 'display' track by opt.val"
class="form-control"
></select>
</div>
Expand Down
9 changes: 6 additions & 3 deletions src/ui/public/agg_types/metrics/top_hit.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,15 @@ export default function AggTypeMetricTopProvider(Private) {
}
],
controller: function ($scope) {
$scope.options = _.cloneDeep($scope.aggParam.options);
$scope.options = [];
$scope.$watchGroup([ 'agg.vis.type.name', 'agg.params.field.type' ], function ([ visName, fieldType ]) {
if (fieldType && visName) {
_.each($scope.options, option => {
option.disabled = !option.isCompatibleVis(visName) || !option.isCompatibleType(fieldType);
$scope.options = _.filter($scope.aggParam.options, option => {
return option.isCompatibleVis(visName) && option.isCompatibleType(fieldType);
});
if ($scope.options.length === 1) {
$scope.agg.params.aggregate = $scope.options[0];
}
}
});
},
Expand Down

0 comments on commit 1bd4727

Please sign in to comment.