Skip to content

Commit

Permalink
[Discover] replace time fields when switching between time based data…
Browse files Browse the repository at this point in the history
… views
  • Loading branch information
dimaanj committed Nov 22, 2021
1 parent 366a28e commit c3512b9
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ export function getSwitchIndexPatternAppState(
});

if (nextIndexPattern.isTimeBased() && !nextSort.length) {
// set default timefield sorting when there was no new sorting
// set default sorting if it was not set
nextSort = [[nextIndexPattern.timeFieldName, sortDirection]];
} else if (
nextIndexPattern.isTimeBased() &&
nextSort.length !== 0 &&
nextSort[0][0] === currentIndexPattern.timeFieldName
) {
// replace previous data view timeFieldName with new one
nextSort = [[nextIndexPattern.timeFieldName, sortDirection], ...nextSort.slice(1)];
} else if (nextIndexPattern.isTimeBased() && currentIndexPattern.isTimeBased()) {
// switch time fields
nextSort = nextSort.map((cur) =>
cur[0] === currentIndexPattern.timeFieldName
? [nextIndexPattern.timeFieldName, sortDirection]
: cur
);
}

return {
Expand Down

0 comments on commit c3512b9

Please sign in to comment.