diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 82714dbcbe11..4408185ccde2 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -974,6 +974,7 @@ function getOptions( tags = {}, recentlyUsedTags = [], canInviteUser = true, + includeSelectedOptions = false, }, ) { if (includeCategories) { @@ -1110,8 +1111,15 @@ function getOptions( allPersonalDetailsOptions = lodashOrderBy(allPersonalDetailsOptions, [(personalDetail) => personalDetail.text && personalDetail.text.toLowerCase()], 'asc'); } - // Always exclude already selected options and the currently logged in user - const optionsToExclude = [...selectedOptions, {login: currentUserLogin}]; + // Exclude the current user from the personal details list + const optionsToExclude = [{login: currentUserLogin}]; + + // If we're including selected options from the search results, we only want to exclude them if the search input is empty + // This is because on certain pages, we show the selected options at the top when the search input is empty + // This prevents the issue of seeing the selected option twice if you have them as a recent chat and select them + if (!includeSelectedOptions || searchInputValue === '') { + optionsToExclude.push(...selectedOptions); + } _.each(excludeLogins, (login) => { optionsToExclude.push({login}); @@ -1357,6 +1365,7 @@ function getIOUConfirmationOptionsFromParticipants(participants, amountText) { * @param {Object} [tags] * @param {Array} [recentlyUsedTags] * @param {boolean} [canInviteUser] + * @param {boolean} [includeSelectedOptions] * @returns {Object} */ function getFilteredOptions( @@ -1375,6 +1384,7 @@ function getFilteredOptions( tags = {}, recentlyUsedTags = [], canInviteUser = true, + includeSelectedOptions = false, ) { return getOptions(reports, personalDetails, { betas, @@ -1393,6 +1403,7 @@ function getFilteredOptions( tags, recentlyUsedTags, canInviteUser, + includeSelectedOptions, }); } diff --git a/src/pages/NewChatPage.js b/src/pages/NewChatPage.js index 64bff8655403..a9401bce684e 100755 --- a/src/pages/NewChatPage.js +++ b/src/pages/NewChatPage.js @@ -71,13 +71,16 @@ function NewChatPage({betas, isGroupChat, personalDetails, reports, translate, i const sectionsList = []; let indexOffset = 0; - sectionsList.push({ - title: undefined, - data: selectedOptions, - shouldShow: !_.isEmpty(selectedOptions), - indexOffset, - }); - indexOffset += selectedOptions.length; + // Only show the selected participants if the search is empty + if (searchTerm === '') { + sectionsList.push({ + title: undefined, + data: selectedOptions, + shouldShow: !_.isEmpty(selectedOptions), + indexOffset, + }); + indexOffset += selectedOptions.length; + } if (maxParticipantsReached) { return sectionsList; @@ -109,7 +112,7 @@ function NewChatPage({betas, isGroupChat, personalDetails, reports, translate, i } return sectionsList; - }, [translate, filteredPersonalDetails, filteredRecentReports, filteredUserToInvite, maxParticipantsReached, selectedOptions]); + }, [translate, filteredPersonalDetails, filteredRecentReports, filteredUserToInvite, maxParticipantsReached, selectedOptions, searchTerm]); /** * Removes a selected option from list if already selected. If not already selected add this option to the list. @@ -130,7 +133,24 @@ function NewChatPage({betas, isGroupChat, personalDetails, reports, translate, i recentReports, personalDetails: newChatPersonalDetails, userToInvite, - } = OptionsListUtils.getFilteredOptions(reports, personalDetails, betas, searchTerm, newSelectedOptions, excludedGroupEmails); + } = OptionsListUtils.getFilteredOptions( + reports, + personalDetails, + betas, + searchTerm, + newSelectedOptions, + isGroupChat ? excludedGroupEmails : [], + false, + true, + false, + {}, + [], + false, + {}, + [], + true, + true, + ); setSelectedOptions(newSelectedOptions); setFilteredRecentReports(recentReports); @@ -165,7 +185,24 @@ function NewChatPage({betas, isGroupChat, personalDetails, reports, translate, i recentReports, personalDetails: newChatPersonalDetails, userToInvite, - } = OptionsListUtils.getFilteredOptions(reports, personalDetails, betas, searchTerm, selectedOptions, isGroupChat ? excludedGroupEmails : []); + } = OptionsListUtils.getFilteredOptions( + reports, + personalDetails, + betas, + searchTerm, + selectedOptions, + isGroupChat ? excludedGroupEmails : [], + false, + true, + false, + {}, + [], + false, + {}, + [], + true, + true, + ); setFilteredRecentReports(recentReports); setFilteredPersonalDetails(newChatPersonalDetails); setFilteredUserToInvite(userToInvite); diff --git a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js index 4571af34ddee..1263dd5db2b9 100755 --- a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js +++ b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js @@ -104,16 +104,19 @@ function MoneyRequestParticipantsSelector({ const newSections = []; let indexOffset = 0; - newSections.push({ - title: undefined, - data: _.map(participants, (participant) => { - const isPolicyExpenseChat = lodashGet(participant, 'isPolicyExpenseChat', false); - return isPolicyExpenseChat ? OptionsListUtils.getPolicyExpenseReportOption(participant) : OptionsListUtils.getParticipantsOption(participant, personalDetails); - }), - shouldShow: true, - indexOffset, - }); - indexOffset += participants.length; + // Only show the selected participants if the search is empty + if (searchTerm === '') { + newSections.push({ + title: undefined, + data: _.map(participants, (participant) => { + const isPolicyExpenseChat = lodashGet(participant, 'isPolicyExpenseChat', false); + return isPolicyExpenseChat ? OptionsListUtils.getPolicyExpenseReportOption(participant) : OptionsListUtils.getParticipantsOption(participant, personalDetails); + }), + shouldShow: true, + indexOffset, + }); + indexOffset += participants.length; + } if (maxParticipantsReached) { return newSections; @@ -148,7 +151,7 @@ function MoneyRequestParticipantsSelector({ } return newSections; - }, [maxParticipantsReached, newChatOptions, participants, personalDetails, translate]); + }, [maxParticipantsReached, newChatOptions, participants, personalDetails, translate, searchTerm]); /** * Adds a single participant to the request @@ -227,6 +230,14 @@ function MoneyRequestParticipantsSelector({ // We don't want to include any P2P options like personal details or reports that are not workspace chats for certain features. !isDistanceRequest, + false, + {}, + [], + false, + {}, + [], + true, + true, ); setNewChatOptions({ recentReports: chatOptions.recentReports,