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] Fix timefield sorting when switching similar index patterns #116145

Merged
merged 14 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,12 @@ describe('Discover getSwitchIndexPatternAppState', () => {
expect(result.columns).toEqual([]);
expect(result.sort).toEqual([['timeFieldA', 'desc']]);
});
test('should change sorting for similar index patterns', async () => {
const current = getIndexPattern('timebased', 'timefield', ['timefield']);
const next = getIndexPattern('timebased2', 'timefield2', ['timefield', 'timefield2']);

const result = getSwitchIndexPatternAppState(current, next, [], [['timefield', 'desc']]);
expect(result.columns).toEqual([]);
expect(result.sort).toEqual([['timefield2', 'desc']]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ export function getSwitchIndexPatternAppState(
return {
index: nextIndexPattern.id,
columns,
sort:
nextIndexPattern.timeFieldName && !nextSort.length
? [[nextIndexPattern.timeFieldName, sortDirection]]
: nextSort,
sort: nextIndexPattern.timeFieldName
? [[nextIndexPattern.timeFieldName, sortDirection]]
: nextSort,
kertal marked this conversation as resolved.
Show resolved Hide resolved
};
}