From 023c69cb95f40e1ada792bcc2635ac48b278e946 Mon Sep 17 00:00:00 2001 From: Akmal Isomadinov Date: Thu, 26 Jan 2023 14:09:31 +0500 Subject: [PATCH] Web:Client:Components:PeopleSelector Fixed bug 60771 --- .../src/components/PeopleSelector/index.js | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/client/src/components/PeopleSelector/index.js b/packages/client/src/components/PeopleSelector/index.js index 3f202b6c6b..82f7f6c957 100644 --- a/packages/client/src/components/PeopleSelector/index.js +++ b/packages/client/src/components/PeopleSelector/index.js @@ -50,6 +50,7 @@ const PeopleSelector = ({ withSelectAll, filter, excludeItems, + currentUserId, }) => { const [itemsList, setItemsList] = useState(items); const [searchValue, setSearchValue] = useState(""); @@ -100,6 +101,21 @@ const PeopleSelector = ({ }; }; + const moveCurrentUserToTopOfList = (listUser) => { + const currentUserIndex = listUser.findIndex( + (user) => user.id === currentUserId + ); + + // return if the current user is already at the top of the list or not found + if (currentUserIndex < 1) return listUser; + + const [currentUser] = listUser.splice(currentUserIndex, 1); + + listUser.splice(0, 0, currentUser); + + return listUser; + }; + const loadNextPage = (startIndex, search = searchValue) => { const pageCount = 100; @@ -132,7 +148,7 @@ const PeopleSelector = ({ }) .map((item) => toListItem(item)); - newItems = [...newItems, ...items]; + newItems = moveCurrentUserToTopOfList([...newItems, ...items]); const newTotal = response.total - totalDifferent; @@ -216,7 +232,10 @@ PeopleSelector.defaultProps = { }; const ExtendedPeopleSelector = inject(({ auth }) => { - return { theme: auth.settingsStore.theme }; + return { + theme: auth.settingsStore.theme, + currentUserId: auth.userStore.user.id, + }; })( observer( withTranslation(["PeopleSelector", "PeopleTranslations", "Common"])(