Skip to content

Commit

Permalink
[Discover] replace primary time field for sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaanj committed Nov 17, 2021
1 parent 60dcfa8 commit 63252f6
Showing 1 changed file with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,16 @@ export function getSwitchIndexPatternAppState(
: currentColumns;
const columns = nextColumns.length ? nextColumns : [];

// remove prev time field sort
let nextSort = getSortArray(currentSort, nextIndexPattern).filter(
(value) => value[0] !== currentIndexPattern.timeFieldName
);

// append default sorting if indexPattern has time field
if (nextIndexPattern.timeFieldName) {
nextSort = [[nextIndexPattern.timeFieldName, sortDirection], ...nextSort];
let nextSort = getSortArray(currentSort, nextIndexPattern);
const [first, ...restSorting] = nextSort;
// replace primary timeFieldName if it was sorted
if (nextIndexPattern.timeFieldName && first && first[0] === currentIndexPattern.timeFieldName) {
nextSort = [[nextIndexPattern.timeFieldName, sortDirection], ...restSorting];
}

return {
index: nextIndexPattern.id,
columns,
sort: nextSort,
sort: !nextSort.length ? [[nextIndexPattern.timeFieldName, sortDirection]] : nextSort,
};
}

0 comments on commit 63252f6

Please sign in to comment.