Skip to content

Commit

Permalink
[Discover] Reimplement $route.reload when index pattern changes (#59877
Browse files Browse the repository at this point in the history
…) (#60021)
  • Loading branch information
kertal authored Mar 12, 2020
1 parent 13ba5e2 commit 67934ca
Showing 1 changed file with 4 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,28 +237,9 @@ function discoverController(
$scope.state = { ...newState };

// detect changes that should trigger fetching of new data
const changes = ['interval', 'sort', 'index', 'query'].filter(
const changes = ['interval', 'sort', 'query'].filter(
prop => !_.isEqual(newStatePartial[prop], oldStatePartial[prop])
);
if (changes.indexOf('index') !== -1) {
try {
$scope.indexPattern = await indexPatterns.get(newStatePartial.index);
$scope.opts.timefield = getTimeField();
$scope.enableTimeRangeSelector = !!$scope.opts.timefield;
// is needed to rerender the histogram
$scope.vis = undefined;

// Taking care of sort when switching index pattern:
// Old indexPattern: sort by A
// If A is not available in the new index pattern, sort has to be adapted and propagated to URL
const sort = getSortArray(newStatePartial.sort, $scope.indexPattern);
if (newStatePartial.sort && !_.isEqual(sort, newStatePartial.sort)) {
return await replaceUrlAppState({ sort });
}
} catch (e) {
toastNotifications.addWarning({ text: getIndexPatternWarning(newStatePartial.index) });
}
}

if (changes.length) {
$fetchObservable.next();
Expand All @@ -267,8 +248,9 @@ function discoverController(
}
});

$scope.setIndexPattern = id => {
setAppState({ index: id });
$scope.setIndexPattern = async id => {
await replaceUrlAppState({ index: id });
$route.reload();
};

// update data source when filters update
Expand Down

0 comments on commit 67934ca

Please sign in to comment.