mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
parent
8ebcb3c65d
commit
3f9fee6017
2 changed files with 10 additions and 7 deletions
|
@ -5,7 +5,7 @@ import { IndexedArray } from 'ui/indexed_array';
|
|||
|
||||
// this is generally a data-structure that IndexedArray is good for managing
|
||||
const users = [
|
||||
{ name: 'John', id: 69, username: 'beast', group: 'admins' },
|
||||
{ name: 'John', id: 6, username: 'beast', group: 'admins' },
|
||||
{ name: 'Anon', id: 0, username: 'shhhh', group: 'secret' },
|
||||
{ name: 'Fern', id: 42, username: 'kitty', group: 'editor' },
|
||||
{ name: 'Mary', id: 55, username: 'sheep', group: 'editor' }
|
||||
|
@ -170,9 +170,9 @@ describe('IndexedArray', function () {
|
|||
|
||||
const ordered = reg.inIdOrder;
|
||||
expect(ordered[0].id).to.be(0);
|
||||
expect(ordered[1].id).to.be(42);
|
||||
expect(ordered[2].id).to.be(55);
|
||||
expect(ordered[3].id).to.be(69);
|
||||
expect(ordered[1].id).to.be(6);
|
||||
expect(ordered[2].id).to.be(42);
|
||||
expect(ordered[3].id).to.be(55);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -35,9 +35,12 @@ export class IndexedArray {
|
|||
this._setupIndex(config.index, inflectIndex, _.indexBy),
|
||||
this._setupIndex(config.order, inflectOrder, (raw, pluckValue) => {
|
||||
return [...raw].sort((itemA, itemB) => {
|
||||
const a = String(pluckValue(itemA));
|
||||
const b = String(pluckValue(itemB));
|
||||
return a.toLowerCase().localeCompare(b.toLowerCase());
|
||||
const a = pluckValue(itemA);
|
||||
const b = pluckValue(itemB);
|
||||
if (typeof a === 'number' && typeof b === 'number') {
|
||||
return a - b;
|
||||
}
|
||||
return String(a).toLowerCase().localeCompare(String(b).toLowerCase());
|
||||
});
|
||||
})
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue