From 61c1742591c3b06161627bd24f1a53252edd1eec Mon Sep 17 00:00:00 2001 From: Tobias Pickel Date: Wed, 9 Jan 2019 14:59:35 +0100 Subject: [PATCH] fix(user): sort user by name --- src/store/reducers/__tests__/user.spec.ts | 6 +++--- src/store/reducers/user.ts | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/store/reducers/__tests__/user.spec.ts b/src/store/reducers/__tests__/user.spec.ts index 65437801..11ce98f0 100644 --- a/src/store/reducers/__tests__/user.spec.ts +++ b/src/store/reducers/__tests__/user.spec.ts @@ -184,12 +184,12 @@ describe('action creators', () => { describe('selectors', () => { describe('getUserArray', () => { - it('returns the current user map as an arry', () => { + it('returns the current user map as an array', () => { expect( getUserArray({ - user: { 1: { id: 1 }, 2: { id: 2 } }, + user: { 1: { id: 1, name: 'a' }, 2: { id: 2, name: 'b' } }, } as any) - ).toEqual([{ id: 1 }, { id: 2 }]); + ).toEqual([{ id: 1, name: 'a' }, { id: 2, name: 'b' }]); }); }); describe('getUser', () => { diff --git a/src/store/reducers/user.ts b/src/store/reducers/user.ts index 07361179..25fadf7e 100644 --- a/src/store/reducers/user.ts +++ b/src/store/reducers/user.ts @@ -206,7 +206,9 @@ export function getUserState(state: AppState): UsersState { } export function getUserArray(state: AppState): User[] { - return Object.values(getUserState(state)); + return Object.values(getUserState(state)).sort((a: User, b: User) => + a.name.localeCompare(b.name) + ); } export function getUser(state: AppState, userId: number): User | undefined {