[Discover] Reimplement $route.reload when index pattern changes (#59877) (#60021)

This commit is contained in:
Matthias Wilhelm 2020-03-12 18:36:09 +01:00 committed by GitHub
parent 13ba5e2231
commit 67934ca23b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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();
@ -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