Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Discover] Modify columns and sort when switching index pattern #74336

Merged
21 changes: 19 additions & 2 deletions src/plugins/discover/public/application/angular/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ function discoverController($element, $route, $scope, $timeout, $window, Promise

if (!_.isEqual(newStatePartial, oldStatePartial)) {
$scope.$evalAsync(async () => {
if (oldStatePartial.index !== newStatePartial.index) {
//in case of index switch the route has currently to be reloaded, legacy
return;
}

$scope.state = { ...newState };

// detect changes that should trigger fetching of new data
Expand All @@ -277,8 +282,20 @@ function discoverController($element, $route, $scope, $timeout, $window, Promise
});

$scope.setIndexPattern = async (id) => {
await replaceUrlAppState({ index: id });
$route.reload();
const nextIndexPattern = await indexPatterns.get(id);
if (nextIndexPattern) {
const nextColumns = $scope.state.columns.filter((column) =>
nextIndexPattern.fields.getByName(column)
);
kertal marked this conversation as resolved.
Show resolved Hide resolved
const nextSort = getSortArray($scope.state.sort, nextIndexPattern);
const nextState = {
index: id,
columns: nextColumns.length ? nextColumns : ['_source'],
sort: nextSort,
};
await replaceUrlAppState(nextState);
$route.reload();
}
};

// update data source when filters update
Expand Down