-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Datatable] Sorts null values last (#172691)
## Summary Closes #169126 We were using the orderBy which sorts the null values at the beginning on descending order lodash/lodash#4169 I created my own function. Now they are sorted always last like Lens does. <img width="1820" alt="image" src="https://github.com/elastic/kibana/assets/17003240/d6fbd6b9-96fe-4e71-b90f-63a030902cca"> ### Checklist - [ ] [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 (cherry picked from commit 6be8e5e)
- Loading branch information
Showing
3 changed files
with
90 additions
and
10 deletions.
There are no files selected for viewing
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
52 changes: 52 additions & 0 deletions
52
src/plugins/vis_types/table/public/components/utils.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,52 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { sortNullsLast } from './utils'; | ||
|
||
describe('sortNullsLast', () => { | ||
const rows = [ | ||
{ | ||
col1: null, | ||
}, | ||
{ | ||
col1: 'meow', | ||
}, | ||
{ | ||
col1: 'woof', | ||
}, | ||
]; | ||
test('should sort correctly in ascending order', async () => { | ||
const sortedRows = sortNullsLast(rows, 'asc', 'col1'); | ||
expect(sortedRows).toStrictEqual([ | ||
{ | ||
col1: 'meow', | ||
}, | ||
{ | ||
col1: 'woof', | ||
}, | ||
{ | ||
col1: null, | ||
}, | ||
]); | ||
}); | ||
|
||
test('should sort correctly in descending order', async () => { | ||
const sortedRows = sortNullsLast(rows, 'desc', 'col1'); | ||
expect(sortedRows).toStrictEqual([ | ||
{ | ||
col1: 'woof', | ||
}, | ||
{ | ||
col1: 'meow', | ||
}, | ||
{ | ||
col1: null, | ||
}, | ||
]); | ||
}); | ||
}); |
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