From b35b213a14e56af87a37374cebce18423370b470 Mon Sep 17 00:00:00 2001 From: Petr Jasek Date: Tue, 8 Oct 2024 18:34:21 +0200 Subject: [PATCH 1/2] fix SelectUser component when there is no deskId SDESK-7411 --- scripts/api/user.ts | 6 ++++++ scripts/core/ui/components/SelectUser.tsx | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/api/user.ts b/scripts/api/user.ts index 1f2eff49ed..4fabb669e7 100644 --- a/scripts/api/user.ts +++ b/scripts/api/user.ts @@ -1,4 +1,5 @@ import ng from 'core/services/ng'; +import {IUser} from 'superdesk-api'; function hasPrivilege(privilege: string): boolean { const privileges = ng.get('privileges'); @@ -18,8 +19,13 @@ function isLoggedIn() { return session?.identity?._id != null; } +function getAll(): Array { + return ng.get('desks').users._items; +} + export const user = { hasPrivilege, isLoggedIn, getCurrentUserId, + getAll, }; diff --git a/scripts/core/ui/components/SelectUser.tsx b/scripts/core/ui/components/SelectUser.tsx index 31011ba37d..fab6d5ed08 100644 --- a/scripts/core/ui/components/SelectUser.tsx +++ b/scripts/core/ui/components/SelectUser.tsx @@ -117,9 +117,11 @@ export class SelectUser extends SuperdeskReactComponent { - const deskMembers = sdApi.desks.getDeskMembers(this.props.deskId); + const users = this.props.deskId + ? sdApi.desks.getDeskMembers(this.props.deskId) + : sdApi.user.getAll(); - return Promise.resolve(searchUsers(deskMembers, searchString)); + return Promise.resolve(searchUsers(users, searchString)); }} value={this.state.selectedUser} onChange={(user) => { From 83f3a5b9c5d6e37c6ea50733a33f47d552eab028 Mon Sep 17 00:00:00 2001 From: Petr Jasek Date: Wed, 9 Oct 2024 10:38:04 +0200 Subject: [PATCH 2/2] use OrderedMap --- scripts/api/user.ts | 5 +++-- scripts/core/ui/components/SelectUser.tsx | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/api/user.ts b/scripts/api/user.ts index 4fabb669e7..d512eda2a9 100644 --- a/scripts/api/user.ts +++ b/scripts/api/user.ts @@ -1,5 +1,6 @@ import ng from 'core/services/ng'; import {IUser} from 'superdesk-api'; +import {OrderedMap} from 'immutable'; function hasPrivilege(privilege: string): boolean { const privileges = ng.get('privileges'); @@ -19,8 +20,8 @@ function isLoggedIn() { return session?.identity?._id != null; } -function getAll(): Array { - return ng.get('desks').users._items; +function getAll(): OrderedMap { + return OrderedMap(ng.get('desks').users._items.map((user) => [user._id, user])); } export const user = { diff --git a/scripts/core/ui/components/SelectUser.tsx b/scripts/core/ui/components/SelectUser.tsx index fab6d5ed08..d76527ad07 100644 --- a/scripts/core/ui/components/SelectUser.tsx +++ b/scripts/core/ui/components/SelectUser.tsx @@ -119,7 +119,7 @@ export class SelectUser extends SuperdeskReactComponent { const users = this.props.deskId ? sdApi.desks.getDeskMembers(this.props.deskId) - : sdApi.user.getAll(); + : sdApi.user.getAll().toArray(); return Promise.resolve(searchUsers(users, searchString)); }}