From 9c6dc85da3c0f95427b940fe594a311b7d1da9de Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Wed, 18 Oct 2023 12:24:15 -0700 Subject: [PATCH 1/8] Update getOptions to exclude selected options --- src/libs/OptionsListUtils.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 82714dbcbe11..73283a52c190 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,12 @@ 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 (!includeSelectedOptions) { + optionsToExclude.push(...selectedOptions); + } _.each(excludeLogins, (login) => { optionsToExclude.push({login}); @@ -1357,6 +1362,7 @@ function getIOUConfirmationOptionsFromParticipants(participants, amountText) { * @param {Object} [tags] * @param {Array} [recentlyUsedTags] * @param {boolean} [canInviteUser] + * @param {boolean} [includeSelectedOptions] * @returns {Object} */ function getFilteredOptions( @@ -1375,6 +1381,7 @@ function getFilteredOptions( tags = {}, recentlyUsedTags = [], canInviteUser = true, + includeSelectedOptions = false, ) { return getOptions(reports, personalDetails, { betas, @@ -1393,6 +1400,7 @@ function getFilteredOptions( tags, recentlyUsedTags, canInviteUser, + includeSelectedOptions }); } From ea1b33747e03be34fedde7d01b26d787866308ee Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Wed, 18 Oct 2023 12:41:01 -0700 Subject: [PATCH 2/8] Add handling for searchInput value --- src/libs/OptionsListUtils.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 73283a52c190..157d29153dee 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -1114,7 +1114,10 @@ function getOptions( // Exclude the current user from the personal details list const optionsToExclude = [{login: currentUserLogin}]; - if (!includeSelectedOptions) { + // 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 when the search input is empty + // 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); } From 66d16ab178a76f555b4c230e6781018fe8aeedc1 Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Wed, 18 Oct 2023 12:41:24 -0700 Subject: [PATCH 3/8] Update the participants in the money request participants page --- .../MoneyRequestParticipantsSelector.js | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js index 4571af34ddee..624973b95662 100755 --- a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js +++ b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js @@ -104,16 +104,18 @@ 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; + 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; @@ -227,6 +229,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, From 8fb4f8c8e962f8aef71415c65da6509b113b8a37 Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Wed, 18 Oct 2023 12:50:05 -0700 Subject: [PATCH 4/8] Update OptionsListUtils.js --- src/libs/OptionsListUtils.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 157d29153dee..ef8b3d2710c3 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -1115,9 +1115,9 @@ function getOptions( 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 when the search input is empty - // Prevents the issue of seeing the selected option twice if you have them as a recent chat and select them - if (includeSelectedOptions && searchInputValue === '') { + // 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); } From e60f8be1f7aeeee7a008451e7453be4350ce29c9 Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Wed, 18 Oct 2023 12:54:09 -0700 Subject: [PATCH 5/8] Update the new chat participants --- src/pages/NewChatPage.js | 19 +++++++++++-------- .../MoneyRequestParticipantsSelector.js | 1 + 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/pages/NewChatPage.js b/src/pages/NewChatPage.js index 64bff8655403..c9508a1c8de3 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; @@ -130,7 +133,7 @@ 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, excludedGroupEmails, false, true, false, {}, [], false, {}, [], true, true); setSelectedOptions(newSelectedOptions); setFilteredRecentReports(recentReports); diff --git a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js index 624973b95662..eb92246a03ee 100755 --- a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js +++ b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js @@ -104,6 +104,7 @@ function MoneyRequestParticipantsSelector({ const newSections = []; let indexOffset = 0; + // Only show the selected participants if the search is empty if (searchTerm === '') { newSections.push({ title: undefined, From fb1d1b6ebad3a41af706a75f21aa43ed312bf138 Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Wed, 18 Oct 2023 13:04:12 -0700 Subject: [PATCH 6/8] Add search term to memo / prettier --- src/libs/OptionsListUtils.js | 2 +- src/pages/NewChatPage.js | 2 +- .../MoneyRequestParticipantsSelector.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index ef8b3d2710c3..4408185ccde2 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -1403,7 +1403,7 @@ function getFilteredOptions( tags, recentlyUsedTags, canInviteUser, - includeSelectedOptions + includeSelectedOptions, }); } diff --git a/src/pages/NewChatPage.js b/src/pages/NewChatPage.js index c9508a1c8de3..37b8f0d30174 100755 --- a/src/pages/NewChatPage.js +++ b/src/pages/NewChatPage.js @@ -112,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. diff --git a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js index eb92246a03ee..1263dd5db2b9 100755 --- a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js +++ b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js @@ -151,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 From 5b94b25f977e81b1418524fdd21e0925d5bd9150 Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Wed, 18 Oct 2023 13:35:47 -0700 Subject: [PATCH 7/8] fix issue with new chat page --- src/pages/NewChatPage.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/pages/NewChatPage.js b/src/pages/NewChatPage.js index 37b8f0d30174..42b774179235 100755 --- a/src/pages/NewChatPage.js +++ b/src/pages/NewChatPage.js @@ -133,7 +133,7 @@ function NewChatPage({betas, isGroupChat, personalDetails, reports, translate, i recentReports, personalDetails: newChatPersonalDetails, userToInvite, - } = OptionsListUtils.getFilteredOptions(reports, personalDetails, betas, searchTerm, newSelectedOptions, excludedGroupEmails, false, true, false, {}, [], false, {}, [], true, true); + } = OptionsListUtils.getFilteredOptions(reports, personalDetails, betas, searchTerm, newSelectedOptions, excludedGroupEmails); setSelectedOptions(newSelectedOptions); setFilteredRecentReports(recentReports); @@ -168,7 +168,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); From ccd2f3c858e67672e373cdadc8ec66ab14df910d Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Wed, 18 Oct 2023 13:52:02 -0700 Subject: [PATCH 8/8] fix the issue where the name dissapears --- src/pages/NewChatPage.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/pages/NewChatPage.js b/src/pages/NewChatPage.js index 42b774179235..a9401bce684e 100755 --- a/src/pages/NewChatPage.js +++ b/src/pages/NewChatPage.js @@ -133,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);