-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Index Management] Add sorting for index columns added via extensions service #176163
Merged
yuliacech
merged 5 commits into
elastic:main
from
yuliacech:im/indices_list/fix_columns_sorting
Feb 5, 2024
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f2bd00f
[Index Management] Add sorting to the columns added via extensions se…
yuliacech 3a527cc
[Index Management] Add sorting for any index values
yuliacech 90bdf47
TESTING: add ilm phase column
yuliacech 04415ce
Revert "TESTING: add ilm phase column"
yuliacech ee7d613
Merge branch 'main' into im/indices_list/fix_columns_sorting
yuliacech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
210 changes: 210 additions & 0 deletions
210
x-pack/plugins/index_management/public/application/services/sort_table.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,210 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { Index } from '../../../common'; | ||
import { ExtensionsService } from '../../services/extensions_service'; | ||
import { sortTable } from './sort_table'; | ||
describe('sortTable', () => { | ||
describe('sorts by name', () => { | ||
const indices = [{ name: 'test1' }, { name: 'test2' }] as Index[]; | ||
it('ascending', () => { | ||
const sorted = sortTable(indices, 'name', true); | ||
expect(sorted).toEqual([{ name: 'test1' }, { name: 'test2' }]); | ||
}); | ||
it('descending', () => { | ||
const sorted = sortTable(indices, 'name', false); | ||
expect(sorted).toEqual([{ name: 'test2' }, { name: 'test1' }]); | ||
}); | ||
}); | ||
|
||
describe('sorts by status', () => { | ||
const indices = [{ status: 'open' }, { status: 'close' }] as Index[]; | ||
it('ascending', () => { | ||
const sorted = sortTable(indices, 'status', true); | ||
expect(sorted).toEqual([{ status: 'close' }, { status: 'open' }]); | ||
}); | ||
it('descending', () => { | ||
const sorted = sortTable(indices, 'status', false); | ||
expect(sorted).toEqual([{ status: 'open' }, { status: 'close' }]); | ||
}); | ||
}); | ||
|
||
describe('sorts by health', () => { | ||
const indices = [{ health: 'green' }, { health: 'yellow' }, { health: 'red' }] as Index[]; | ||
it('ascending', () => { | ||
const sorted = sortTable(indices, 'health', true); | ||
expect(sorted).toEqual([{ health: 'green' }, { health: 'red' }, { health: 'yellow' }]); | ||
}); | ||
it('descending', () => { | ||
const sorted = sortTable(indices, 'health', false); | ||
expect(sorted).toEqual([{ health: 'yellow' }, { health: 'red' }, { health: 'green' }]); | ||
}); | ||
}); | ||
|
||
describe('sorts by primary', () => { | ||
const indices = [{ primary: '1' }, { primary: '12' }, { primary: '2' }] as Index[]; | ||
it('ascending', () => { | ||
const sorted = sortTable(indices, 'primary', true); | ||
expect(sorted).toEqual([{ primary: '1' }, { primary: '2' }, { primary: '12' }]); | ||
}); | ||
it('descending', () => { | ||
const sorted = sortTable(indices, 'primary', false); | ||
expect(sorted).toEqual([{ primary: '12' }, { primary: '2' }, { primary: '1' }]); | ||
}); | ||
}); | ||
|
||
describe('sorts by replica', () => { | ||
const indices = [{ replica: '1' }, { replica: '12' }, { replica: '2' }] as Index[]; | ||
it('ascending', () => { | ||
const sorted = sortTable(indices, 'replica', true); | ||
expect(sorted).toEqual([{ replica: '1' }, { replica: '2' }, { replica: '12' }]); | ||
}); | ||
it('descending', () => { | ||
const sorted = sortTable(indices, 'replica', false); | ||
expect(sorted).toEqual([{ replica: '12' }, { replica: '2' }, { replica: '1' }]); | ||
}); | ||
}); | ||
|
||
describe('sorts by documents', () => { | ||
const indices = [{ documents: 1 }, { documents: 12 }, { documents: 2 }] as Index[]; | ||
it('ascending', () => { | ||
const sorted = sortTable(indices, 'documents', true); | ||
expect(sorted).toEqual([{ documents: 1 }, { documents: 2 }, { documents: 12 }]); | ||
}); | ||
it('descending', () => { | ||
const sorted = sortTable(indices, 'documents', false); | ||
expect(sorted).toEqual([{ documents: 12 }, { documents: 2 }, { documents: 1 }]); | ||
}); | ||
}); | ||
|
||
describe('sorts by size', () => { | ||
const indices = [{ size: '248b' }, { size: '2.35mb' }, { size: '6.36kb' }] as Index[]; | ||
it('ascending', () => { | ||
const sorted = sortTable(indices, 'size', true); | ||
expect(sorted).toEqual([{ size: '248b' }, { size: '6.36kb' }, { size: '2.35mb' }]); | ||
}); | ||
it('descending', () => { | ||
const sorted = sortTable(indices, 'size', false); | ||
expect(sorted).toEqual([{ size: '2.35mb' }, { size: '6.36kb' }, { size: '248b' }]); | ||
}); | ||
}); | ||
|
||
describe('sorts by primary_size', () => { | ||
const indices = [ | ||
{ primary_size: '248b' }, | ||
{ primary_size: '2.35mb' }, | ||
{ primary_size: '6.36kb' }, | ||
] as Index[]; | ||
it('ascending', () => { | ||
const sorted = sortTable(indices, 'primary_size', true); | ||
expect(sorted).toEqual([ | ||
{ primary_size: '248b' }, | ||
{ primary_size: '6.36kb' }, | ||
{ primary_size: '2.35mb' }, | ||
]); | ||
}); | ||
it('descending', () => { | ||
const sorted = sortTable(indices, 'primary_size', false); | ||
expect(sorted).toEqual([ | ||
{ primary_size: '2.35mb' }, | ||
{ primary_size: '6.36kb' }, | ||
{ primary_size: '248b' }, | ||
]); | ||
}); | ||
}); | ||
|
||
describe('sorts by data_stream', () => { | ||
const indices = [ | ||
{ data_stream: 'test1' }, | ||
{ data_stream: undefined }, | ||
{ data_stream: 'test2' }, | ||
] as Index[]; | ||
it('ascending', () => { | ||
const sorted = sortTable(indices, 'data_stream', true); | ||
expect(sorted).toEqual([ | ||
{ data_stream: 'test1' }, | ||
{ data_stream: 'test2' }, | ||
{ data_stream: undefined }, | ||
]); | ||
}); | ||
it('descending', () => { | ||
const sorted = sortTable(indices, 'data_stream', false); | ||
expect(sorted).toEqual([ | ||
{ data_stream: undefined }, | ||
{ data_stream: 'test2' }, | ||
{ data_stream: 'test1' }, | ||
]); | ||
}); | ||
}); | ||
|
||
describe('sorts by a column added via extensions service', () => { | ||
const indices = [ | ||
{ ilm: { phase: 'hot' } }, | ||
{ ilm: { phase: 'warm' } }, | ||
{ ilm: { phase: undefined } }, | ||
] as Index[]; | ||
const extensionsService = { | ||
columns: [ | ||
{ | ||
fieldName: 'ilm.phase', | ||
label: 'ILM phase', | ||
order: 10, | ||
render: (index: Index) => (index.ilm?.managed ? index.ilm.phase : ''), | ||
sort: (index: Index) => (index.ilm?.managed ? index.ilm.phase : ''), | ||
}, | ||
], | ||
} as ExtensionsService; | ||
it('ascending', () => { | ||
const sorted = sortTable(indices, 'ilm.phase', true, extensionsService); | ||
expect(sorted).toEqual([ | ||
{ ilm: { phase: 'hot' } }, | ||
{ ilm: { phase: 'warm' } }, | ||
{ ilm: { phase: undefined } }, | ||
]); | ||
}); | ||
it('descending', () => { | ||
const sorted = sortTable(indices, 'ilm.phase', false, extensionsService); | ||
expect(sorted).toEqual([ | ||
{ ilm: { phase: undefined } }, | ||
{ ilm: { phase: 'warm' } }, | ||
{ ilm: { phase: 'hot' } }, | ||
]); | ||
}); | ||
}); | ||
describe('sorting by a column without a sorter', () => { | ||
const indices = [ | ||
{ test: 'test1' }, | ||
{ test: 'test2' }, | ||
{ test: undefined }, | ||
{ test: 'test5' }, | ||
{ test: 'test3' }, | ||
{ test: undefined }, | ||
] as unknown as Index[]; | ||
it('ascending', () => { | ||
const sorted = sortTable(indices, 'test', true); | ||
expect(sorted).toEqual([ | ||
{ test: 'test1' }, | ||
{ test: 'test2' }, | ||
{ test: 'test3' }, | ||
{ test: 'test5' }, | ||
{ test: undefined }, | ||
{ test: undefined }, | ||
]); | ||
}); | ||
it('descending', () => { | ||
const sorted = sortTable(indices, 'test', false); | ||
expect(sorted).toEqual([ | ||
{ test: undefined }, | ||
{ test: undefined }, | ||
{ test: 'test5' }, | ||
{ test: 'test3' }, | ||
{ test: 'test2' }, | ||
{ test: 'test1' }, | ||
]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering why we need an additional
sort
property since we could use the already existingrender
property for sorting? After all, the user would expect the column to be sorted by the values that are rendered in this column.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is just to keep the extensions service flexible: there might a property used for render and a property used for sorting, for example
display_size: '58kb'
andsize_in_bytes: 59392