forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Index Management] Add sorting for index columns added via extensions…
… service (elastic#176163) ## Summary Fixes elastic#175140 Follow up for elastic#174785 This PR fixes the sorting in the indices table for columns added via the extensions service. To test this change, add an ILM phase column as the example in this [commit](elastic@90bdf47) and follow the instructions in the ILM plugin [readme](https://github.com/elastic/kibana/blob/04415ce2fc3b302efdace7f391c07047839fb0f1/x-pack/plugins/index_lifecycle_management/README.md#quick-steps-for-testing-ilm-in-index-management). ### Screenshot <img width="1088" alt="Screenshot 2024-02-02 at 18 03 34" src="https://github.com/elastic/kibana/assets/6585477/9f8b9409-ea38-41ed-9e04-636b4f61e8dd"> ### Checklist Delete any items that are not applicable to this PR. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [ ] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [ ] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) - [ ] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers) ### Risk Matrix Delete this section if it is not applicable to this PR. Before closing this PR, invite QA, stakeholders, and other developers to identify risks that should be tested prior to the change/feature release. When forming the risk matrix, consider some of the following examples and how they may potentially impact the change: | Risk | Probability | Severity | Mitigation/Notes | |---------------------------|-------------|----------|-------------------------| | Multiple Spaces—unexpected behavior in non-default Kibana Space. | Low | High | Integration tests will verify that all features are still supported in non-default Kibana Space and when user switches between spaces. | | Multiple nodes—Elasticsearch polling might have race conditions when multiple Kibana nodes are polling for the same tasks. | High | Low | Tasks are idempotent, so executing them multiple times will not result in logical error, but will degrade performance. To test for this case we add plenty of unit tests around this logic and document manual testing procedure. | | Code should gracefully handle cases when feature X or plugin Y are disabled. | Medium | High | Unit tests will verify that any feature flag or plugin combination still results in our service operational. | | [See more potential risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) | ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
- Loading branch information
1 parent
a2628e7
commit 1763f04
Showing
4 changed files
with
264 additions
and
31 deletions.
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