Fix blank index pattern selector in Discover (#13715)

ui-select-match's expression was expecting an IndexPattern object, but
the indexPatternList passed to ui-select-choices contained SavedObject
instances due to the [SavedObjectsClient refactor][1]. This wasn't a
problem most of the time because switching index patterns caused the
entire directive to get destroyed and re-created. However, when the
directive didn't get re-created (for example, when clicking the already
selected pattern) it would result in a blank select box.

Fixes https://github.com/elastic/kibana/issues/13080

[1]: https://github.com/elastic/kibana/pull/12719
This commit is contained in:
Matt Bargar 2017-08-28 10:59:01 -04:00 committed by Matthew Bargar
parent a93ee59b5a
commit c11cd4963b
2 changed files with 4 additions and 2 deletions

View file

@ -4,10 +4,9 @@
class="index-pattern-selection"
ng-model="selectedIndexPattern"
on-select="setIndexPattern($item)"
ng-init="selectedIndexPattern = indexPattern"
>
<ui-select-match>
{{$select.selected.title}}
{{$select.selected.get('title')}}
</ui-select-match>
<ui-select-choices repeat="pattern in indexPatternList | filter:$select.search">
<div ng-bind-html="pattern.get('title') | highlight: $select.search"></div>

View file

@ -30,6 +30,9 @@ app.directive('discFieldChooser', function ($location, globalState, config, $rou
},
template: fieldChooserTemplate,
link: function ($scope) {
$scope.selectedIndexPattern = $scope.indexPatternList.find(
(pattern) => pattern.id === $scope.indexPattern.id
);
$scope.indexPatternList = _.sortBy($scope.indexPatternList, o => o.get('title'));
$scope.setIndexPattern = function (pattern) {
$scope.state.index = pattern.id;