From 30c08c869e4d017574a685f47bab226f467754dd Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Wed, 12 Jun 2024 16:53:39 -0700 Subject: [PATCH 01/38] allow displaying default rooms with empty participants when searching for reports --- src/libs/OptionsListUtils.ts | 4 ++++ src/libs/ReportUtils.ts | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 9b30764b065d..e2d959ce4945 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -175,6 +175,7 @@ type GetOptionsConfig = { recentlyUsedPolicyReportFieldOptions?: string[]; transactionViolations?: OnyxCollection; includeInvoiceRooms?: boolean; + isSearchingForReports?: boolean; }; type GetUserToInviteConfig = { @@ -1749,6 +1750,7 @@ function getOptions( policyReportFieldOptions = [], recentlyUsedPolicyReportFieldOptions = [], includeInvoiceRooms = false, + isSearchingForReports = false, }: GetOptionsConfig, ): Options { if (includeCategories) { @@ -1831,6 +1833,7 @@ function getOptions( isInFocusMode: false, excludeEmptyChats: false, includeSelfDM, + isSearchingForReports }); }); @@ -2082,6 +2085,7 @@ function getSearchOptions(options: OptionList, searchValue = '', betas: Beta[] = includeMoneyRequests: true, includeTasks: true, includeSelfDM: true, + isSearchingForReports: true, }); Timing.end(CONST.TIMING.LOAD_SEARCH_OPTIONS); Performance.markEnd(CONST.TIMING.LOAD_SEARCH_OPTIONS); diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 914c653b6f91..a65749a2fa1b 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5334,6 +5334,7 @@ function shouldReportBeInOptionList({ excludeEmptyChats, doesReportHaveViolations, includeSelfDM = false, + isSearchingForReports = false, }: { report: OnyxEntry; currentReportId: string; @@ -5343,6 +5344,7 @@ function shouldReportBeInOptionList({ excludeEmptyChats: boolean; doesReportHaveViolations: boolean; includeSelfDM?: boolean; + isSearchingForReports?: boolean; }) { const isInDefaultMode = !isInFocusMode; // Exclude reports that have no data because there wouldn't be anything to show in the option item. @@ -5370,7 +5372,8 @@ function shouldReportBeInOptionList({ !isSelfDM(report) && !isSystemChat(report) && !isGroupChat(report) && - !isInvoiceRoom(report)) + !isInvoiceRoom(report) && + (!isSearchingForReports && isDefaultRoom(report))) ) { return false; } From 72e3f6d3d887521c8ed69f80a0735bd8f7882faf Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 17 Jun 2024 12:32:24 -0700 Subject: [PATCH 02/38] add comment --- src/libs/ReportUtils.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index c6ba5fb2734a..bfc8cf5b4e04 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5370,6 +5370,10 @@ function shouldReportBeInOptionList({ !isSystemChat(report) && !isGroupChat(report) && !isInvoiceRoom(report) && + + // We omit sending back participants for default rooms when searching for reports since they aren't needed to display the results and can get very large. + // So we allow showing default rooms with no participants when searching for reports. + // In any other circumstances we should never have default rooms with no participants in Onyx. (!isSearchingForReports && isDefaultRoom(report))) ) { return false; From 76b6469092860356cf64107d5b68b43d007cb53d Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 17 Jun 2024 12:41:03 -0700 Subject: [PATCH 03/38] style --- src/libs/OptionsListUtils.ts | 2 +- src/libs/ReportUtils.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index cd78d6740996..09f6c8c90b18 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1833,7 +1833,7 @@ function getOptions( isInFocusMode: false, excludeEmptyChats: false, includeSelfDM, - isSearchingForReports + isSearchingForReports, }); }); diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index bfc8cf5b4e04..75f4e08973df 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5370,11 +5370,11 @@ function shouldReportBeInOptionList({ !isSystemChat(report) && !isGroupChat(report) && !isInvoiceRoom(report) && - // We omit sending back participants for default rooms when searching for reports since they aren't needed to display the results and can get very large. // So we allow showing default rooms with no participants when searching for reports. // In any other circumstances we should never have default rooms with no participants in Onyx. - (!isSearchingForReports && isDefaultRoom(report))) + !isSearchingForReports && + isDefaultRoom(report)) ) { return false; } From 57d33566d9fa86aeaa36a7bc1112f36859156f12 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 17 Jun 2024 13:36:49 -0700 Subject: [PATCH 04/38] prevent rooms from getting filtered out during participantLogins/display names check --- src/libs/OptionsListUtils.ts | 7 +++++++ src/libs/ReportUtils.ts | 1 + 2 files changed, 8 insertions(+) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 09f6c8c90b18..03a0754a5028 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -2420,6 +2420,13 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt }); } + // If the item is a chat room, then we just include all the search terms as the keys. + // Since we don't send back participants with chat rooms in SearchForReports, this ensures they don't get filtered out during this check. + // Note that the back-end already handles including rooms that have participants matching the search term. + if (item.isChatRoom) { + keys.concat(searchTerms); + } + return keys; }; const matchResults = searchTerms.reduceRight((items, term) => { diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 75f4e08973df..c51d917992a3 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5370,6 +5370,7 @@ function shouldReportBeInOptionList({ !isSystemChat(report) && !isGroupChat(report) && !isInvoiceRoom(report) && + // We omit sending back participants for default rooms when searching for reports since they aren't needed to display the results and can get very large. // So we allow showing default rooms with no participants when searching for reports. // In any other circumstances we should never have default rooms with no participants in Onyx. From 932b8ce9388a6ba0a53cd8e11858c89e99f8830a Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 17 Jun 2024 14:44:20 -0700 Subject: [PATCH 05/38] style --- src/libs/ReportUtils.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index c51d917992a3..75f4e08973df 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5370,7 +5370,6 @@ function shouldReportBeInOptionList({ !isSystemChat(report) && !isGroupChat(report) && !isInvoiceRoom(report) && - // We omit sending back participants for default rooms when searching for reports since they aren't needed to display the results and can get very large. // So we allow showing default rooms with no participants when searching for reports. // In any other circumstances we should never have default rooms with no participants in Onyx. From 1464ba19c124723faf6d0572190c555abd2cda0a Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 17 Jun 2024 16:26:49 -0700 Subject: [PATCH 06/38] ensure chat rooms don't get filtered out in the front-end if they don't have participants in Onyx --- src/libs/OptionsListUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 03a0754a5028..de7f814799da 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -2424,7 +2424,7 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt // Since we don't send back participants with chat rooms in SearchForReports, this ensures they don't get filtered out during this check. // Note that the back-end already handles including rooms that have participants matching the search term. if (item.isChatRoom) { - keys.concat(searchTerms); + keys.push(...searchTerms); } return keys; From e8cae103e43cc725ee15a0d5455cc5fb2d02f172 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 17 Jun 2024 16:29:50 -0700 Subject: [PATCH 07/38] update comment --- src/libs/OptionsListUtils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index de7f814799da..b7da700d7b53 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -2423,6 +2423,7 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt // If the item is a chat room, then we just include all the search terms as the keys. // Since we don't send back participants with chat rooms in SearchForReports, this ensures they don't get filtered out during this check. // Note that the back-end already handles including rooms that have participants matching the search term. + // This effectively means that only the back-end logic is used for filtering chat rooms. if (item.isChatRoom) { keys.push(...searchTerms); } From acc477f17da78c6f5a8c56284132bd1c2b8ab5d3 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 17 Jun 2024 16:38:54 -0700 Subject: [PATCH 08/38] remove unused --- src/libs/OptionsListUtils.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index b7da700d7b53..09f6c8c90b18 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -2420,14 +2420,6 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt }); } - // If the item is a chat room, then we just include all the search terms as the keys. - // Since we don't send back participants with chat rooms in SearchForReports, this ensures they don't get filtered out during this check. - // Note that the back-end already handles including rooms that have participants matching the search term. - // This effectively means that only the back-end logic is used for filtering chat rooms. - if (item.isChatRoom) { - keys.push(...searchTerms); - } - return keys; }; const matchResults = searchTerms.reduceRight((items, term) => { From 978ad3b9605e10af9da0e1883ae58e2cf8884bce Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Fri, 21 Jun 2024 12:52:35 -0700 Subject: [PATCH 09/38] prevent all chat rooms from being searchable by participant --- src/libs/OptionsListUtils.ts | 12 ++++++++++++ src/libs/ReportUtils.ts | 1 + 2 files changed, 13 insertions(+) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index f937eb9df8de..868171ea1d3a 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -769,6 +769,7 @@ function createOption( isPolicyExpenseChat: false, isOwnPolicyExpenseChat: false, isExpenseReport: false, + isTripRoom: false, policyID: undefined, isOptimisticPersonalDetail: false, lastMessageText: '', @@ -806,6 +807,7 @@ function createOption( result.isWaitingOnBankAccount = report.isWaitingOnBankAccount; result.policyID = report.policyID; result.isSelfDM = ReportUtils.isSelfDM(report); + result.isTripRoom = ReportUtils.isTripRoom(report); const visibleParticipantAccountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(report, true); @@ -2494,6 +2496,16 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt values = values.concat(getParticipantsLoginsArray(item)); } + // We don't want the following to be searchable by participant: + // - Default rooms + // - Policy rooms + // - Policy expense chats + // - Invoice rooms + // - Trip rooms + if (!item.isChatRoom && !item.isPolicyExpenseChat && !item.isTripRoom) { + values = values.concat(getParticipantsLoginsArray(item)); + } + return uniqFast(values); }); const personalDetails = filterArrayByMatch(items.personalDetails, term, (item) => diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 96cb8d79de56..3c37e0a034f5 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -411,6 +411,7 @@ type OptionData = { displayNamesWithTooltips?: DisplayNameWithTooltips | null; isDefaultRoom?: boolean; isInvoiceRoom?: boolean; + isTripRoom?: boolean; isExpenseReport?: boolean; isOptimisticPersonalDetail?: boolean; selected?: boolean; From 3e6b24ec35020c2247ee1ace15a59dc870594c3a Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Fri, 21 Jun 2024 15:25:36 -0700 Subject: [PATCH 10/38] Allow empty rooms to show up when searching --- src/libs/OptionsListUtils.ts | 24 +++++++++++++++++++++--- src/libs/ReportUtils.ts | 16 ++++++++++++---- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 868171ea1d3a..504c6c8ac8d0 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -773,6 +773,7 @@ function createOption( policyID: undefined, isOptimisticPersonalDetail: false, lastMessageText: '', + isUnsearchableViaParticipants: false, }; const personalDetailMap = getPersonalDetailsForAccountIDs(accountIDs, personalDetails); @@ -808,6 +809,8 @@ function createOption( result.policyID = report.policyID; result.isSelfDM = ReportUtils.isSelfDM(report); result.isTripRoom = ReportUtils.isTripRoom(report); + result.policyName = ReportUtils.getPolicyName(report); + result.isUnsearchableViaParticipants = ReportUtils.isUnsearchableViaParticipants(report); const visibleParticipantAccountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(report, true); @@ -1872,6 +1875,8 @@ function getOptions( }); }); + console.log(">>>> filtered", filteredReportOptions); + // Sorting the reports works like this: // - Order everything by the last message timestamp (descending) // - When searching, self DM is put at the top @@ -1935,13 +1940,23 @@ function getOptions( return; } - if ((!accountIDs || accountIDs.length === 0) && !isChatRoom) { - return; + if (!accountIDs || accountIDs.length === 0) { + if (!isSearchingForReports) { + if (!isChatRoom) { + return; + } + } + + if (!ReportUtils.isUnsearchableViaParticipants(report)) { + return; + } } return option; }); + console.log(">>>> allReportOptions", allReportOptions); + const havingLoginPersonalDetails = includeP2P ? options.personalDetails.filter((detail) => !!detail?.login && !!detail.accountID && !detail?.isOptimisticPersonalDetail) : []; let allPersonalDetailsOptions = havingLoginPersonalDetails; @@ -2022,6 +2037,7 @@ function getOptions( const isSearchMatch = isSearchStringMatch(searchValue, searchText, participantNames, isChatRoom); if (!isReportIdSearch && !isSearchMatch) { + console.log(">>> filtering out", reportOption); continue; } } @@ -2446,6 +2462,8 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt optionsToExclude.push({login}); }); + console.log(">>>> options", options); + const getParticipantsLoginsArray = (item: ReportUtils.OptionData) => { const keys: string[] = []; const visibleChatMemberAccountIDs = item.participantsList ?? []; @@ -2502,7 +2520,7 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt // - Policy expense chats // - Invoice rooms // - Trip rooms - if (!item.isChatRoom && !item.isPolicyExpenseChat && !item.isTripRoom) { + if (!item.isUnsearchableViaParticipants) { values = values.concat(getParticipantsLoginsArray(item)); } diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 3c37e0a034f5..c17af5cbedb0 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -430,6 +430,7 @@ type OptionData = { shouldShowAmountInput?: boolean; amountInputProps?: MoneyRequestAmountInputProps; tabIndex?: 0 | -1; + isUnsearchableViaParticipants?: boolean; } & Report; type OnyxDataTaskAssigneeChat = { @@ -972,6 +973,13 @@ function isChatRoom(report: OnyxEntry): boolean { return isUserCreatedPolicyRoom(report) || isDefaultRoom(report) || isInvoiceRoom(report); } +/** + * Whether the provided report is not searchable via participant + */ +function isUnsearchableViaParticipants(report: OnyxEntry): boolean { + return isUserCreatedPolicyRoom(report) || isDefaultRoom(report) || isInvoiceRoom(report) || isInvoiceRoom(report) || isTripRoom(report); +} + /** * Whether the provided report is a public room */ @@ -5403,11 +5411,10 @@ function shouldReportBeInOptionList({ !isSystemChat(report) && !isGroupChat(report) && !isInvoiceRoom(report) && - // We omit sending back participants for default rooms when searching for reports since they aren't needed to display the results and can get very large. - // So we allow showing default rooms with no participants when searching for reports. + // We omit sending back participants for chat rooms when searching for reports since they aren't needed to display the results and can get very large. + // So we allow showing rooms with no participants when searching for reports. // In any other circumstances we should never have default rooms with no participants in Onyx. - !isSearchingForReports && - isDefaultRoom(report)) + (!isSearchingForReports && isUnsearchableViaParticipants(report))) ) { return false; } @@ -7290,6 +7297,7 @@ export { createDraftWorkspaceAndNavigateToConfirmationScreen, isChatUsedForOnboarding, getChatUsedForOnboarding, + isUnsearchableViaParticipants }; export type { From 6aebea173837c6fcc67b12b3ebda125ac69b334d Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 24 Jun 2024 12:52:40 -0700 Subject: [PATCH 11/38] remove debug logs --- src/libs/OptionsListUtils.ts | 7 +------ src/libs/ReportUtils.ts | 5 +++-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 504c6c8ac8d0..b47583f3469e 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1875,8 +1875,6 @@ function getOptions( }); }); - console.log(">>>> filtered", filteredReportOptions); - // Sorting the reports works like this: // - Order everything by the last message timestamp (descending) // - When searching, self DM is put at the top @@ -1955,7 +1953,7 @@ function getOptions( return option; }); - console.log(">>>> allReportOptions", allReportOptions); + console.log('>>>> allReportOptions', allReportOptions); const havingLoginPersonalDetails = includeP2P ? options.personalDetails.filter((detail) => !!detail?.login && !!detail.accountID && !detail?.isOptimisticPersonalDetail) : []; let allPersonalDetailsOptions = havingLoginPersonalDetails; @@ -2037,7 +2035,6 @@ function getOptions( const isSearchMatch = isSearchStringMatch(searchValue, searchText, participantNames, isChatRoom); if (!isReportIdSearch && !isSearchMatch) { - console.log(">>> filtering out", reportOption); continue; } } @@ -2462,8 +2459,6 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt optionsToExclude.push({login}); }); - console.log(">>>> options", options); - const getParticipantsLoginsArray = (item: ReportUtils.OptionData) => { const keys: string[] = []; const visibleChatMemberAccountIDs = item.participantsList ?? []; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index c17af5cbedb0..b7560a096cf5 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5414,7 +5414,8 @@ function shouldReportBeInOptionList({ // We omit sending back participants for chat rooms when searching for reports since they aren't needed to display the results and can get very large. // So we allow showing rooms with no participants when searching for reports. // In any other circumstances we should never have default rooms with no participants in Onyx. - (!isSearchingForReports && isUnsearchableViaParticipants(report))) + !isSearchingForReports && + isUnsearchableViaParticipants(report)) ) { return false; } @@ -7297,7 +7298,7 @@ export { createDraftWorkspaceAndNavigateToConfirmationScreen, isChatUsedForOnboarding, getChatUsedForOnboarding, - isUnsearchableViaParticipants + isUnsearchableViaParticipants, }; export type { From d0fb81dbf1ed47bbf1788c95f795fc87044a89e9 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 24 Jun 2024 12:53:18 -0700 Subject: [PATCH 12/38] remove debug logs --- src/libs/OptionsListUtils.ts | 2 -- src/libs/ReportUtils.ts | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index b47583f3469e..137f01ed1c7d 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1953,8 +1953,6 @@ function getOptions( return option; }); - console.log('>>>> allReportOptions', allReportOptions); - const havingLoginPersonalDetails = includeP2P ? options.personalDetails.filter((detail) => !!detail?.login && !!detail.accountID && !detail?.isOptimisticPersonalDetail) : []; let allPersonalDetailsOptions = havingLoginPersonalDetails; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index b7560a096cf5..b350eaaeb3e8 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -977,7 +977,7 @@ function isChatRoom(report: OnyxEntry): boolean { * Whether the provided report is not searchable via participant */ function isUnsearchableViaParticipants(report: OnyxEntry): boolean { - return isUserCreatedPolicyRoom(report) || isDefaultRoom(report) || isInvoiceRoom(report) || isInvoiceRoom(report) || isTripRoom(report); + return isUserCreatedPolicyRoom(report) || isDefaultRoom(report) || isInvoiceRoom(report) || isTripRoom(report); } /** From 76f675ddcb6e13ce03f495de3327a640344e33cd Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 24 Jun 2024 12:53:47 -0700 Subject: [PATCH 13/38] update comment --- src/libs/OptionsListUtils.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 137f01ed1c7d..56a892d70020 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -2510,7 +2510,6 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt // We don't want the following to be searchable by participant: // - Default rooms // - Policy rooms - // - Policy expense chats // - Invoice rooms // - Trip rooms if (!item.isUnsearchableViaParticipants) { From a5b70cc4451261c3947f9dc0fa2cbc8537e95ce6 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Wed, 26 Jun 2024 15:05:45 -0700 Subject: [PATCH 14/38] Flip searchable via participants conditions --- src/libs/OptionsListUtils.ts | 8 ++++---- src/libs/ReportUtils.ts | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 664c15642627..9f0e1aa832b5 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -774,7 +774,7 @@ function createOption( policyID: undefined, isOptimisticPersonalDetail: false, lastMessageText: '', - isUnsearchableViaParticipants: false, + isSearchableViaParticipants: false, }; const personalDetailMap = getPersonalDetailsForAccountIDs(accountIDs, personalDetails); @@ -811,7 +811,7 @@ function createOption( result.isSelfDM = ReportUtils.isSelfDM(report); result.isTripRoom = ReportUtils.isTripRoom(report); result.policyName = ReportUtils.getPolicyName(report); - result.isUnsearchableViaParticipants = ReportUtils.isUnsearchableViaParticipants(report); + result.isSearchableViaParticipants = ReportUtils.isSearchableViaParticipants(report); const visibleParticipantAccountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(report, true); @@ -1946,7 +1946,7 @@ function getOptions( } } - if (!ReportUtils.isUnsearchableViaParticipants(report)) { + if (ReportUtils.isSearchableViaParticipants(report)) { return; } } @@ -2513,7 +2513,7 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt // - Policy rooms // - Invoice rooms // - Trip rooms - if (!item.isUnsearchableViaParticipants) { + if (item.isSearchableViaParticipants) { values = values.concat(getParticipantsLoginsArray(item)); } diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 07543a420575..fd1409e81c02 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -431,7 +431,7 @@ type OptionData = { shouldShowAmountInput?: boolean; amountInputProps?: MoneyRequestAmountInputProps; tabIndex?: 0 | -1; - isUnsearchableViaParticipants?: boolean; + isSearchableViaParticipants?: boolean; } & Report; type OnyxDataTaskAssigneeChat = { @@ -975,10 +975,10 @@ function isChatRoom(report: OnyxEntry): boolean { } /** - * Whether the provided report is not searchable via participant + * Whether the provided report is searchable via participant */ -function isUnsearchableViaParticipants(report: OnyxEntry): boolean { - return isUserCreatedPolicyRoom(report) || isDefaultRoom(report) || isInvoiceRoom(report) || isTripRoom(report); +function isSearchableViaParticipants(report: OnyxEntry): boolean { + return !isChatReport(report) || isDM(report) || isGroupChat(report) || isPolicyExpenseChat(report) || isSystemChat(report) || isSelfDM(report); } /** @@ -5427,11 +5427,11 @@ function shouldReportBeInOptionList({ !isSystemChat(report) && !isGroupChat(report) && !isInvoiceRoom(report) && - // We omit sending back participants for chat rooms when searching for reports since they aren't needed to display the results and can get very large. + // We omit sending back participants for certain reports when searching for reports since they aren't needed to display the results and can get very large. // So we allow showing rooms with no participants when searching for reports. - // In any other circumstances we should never have default rooms with no participants in Onyx. + // In any other circumstances we should never have these reports with no participants in Onyx. !isSearchingForReports && - isUnsearchableViaParticipants(report)) + !isSearchableViaParticipants(report)) ) { return false; } @@ -7325,7 +7325,7 @@ export { createDraftWorkspaceAndNavigateToConfirmationScreen, isChatUsedForOnboarding, getChatUsedForOnboarding, - isUnsearchableViaParticipants, + isSearchableViaParticipants, findPolicyExpenseChatByPolicyID, }; From baad6f926ceed772bfe9ab9f2073ee09011e3a5a Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Wed, 26 Jun 2024 15:20:46 -0700 Subject: [PATCH 15/38] Add comment for confusing section --- src/libs/OptionsListUtils.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 9f0e1aa832b5..9def94e98991 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1946,6 +1946,10 @@ function getOptions( } } + // Rooms that aren't searchable via participant won't have any participants returned with SearchForReports + // so we have to let their options pass through this check. + // Rooms that are searchable via participant should always have participants returned with SearchForReports, + // so we block any that don't have participants with this check. if (ReportUtils.isSearchableViaParticipants(report)) { return; } From 0237f81c9ff35fc9e203334d291d3620c5b2d32c Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Thu, 27 Jun 2024 12:47:39 -0700 Subject: [PATCH 16/38] calculate isSearchingForReports from searchInputValue --- src/libs/OptionsListUtils.ts | 10 +++++++--- src/libs/ReportUtils.ts | 1 - 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 9def94e98991..df6b8b3ac024 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -176,7 +176,6 @@ type GetOptionsConfig = { recentlyUsedPolicyReportFieldOptions?: string[]; transactionViolations?: OnyxCollection; includeInvoiceRooms?: boolean; - isSearchingForReports?: boolean; }; type GetUserToInviteConfig = { @@ -1789,7 +1788,6 @@ function getOptions( policyReportFieldOptions = [], recentlyUsedPolicyReportFieldOptions = [], includeInvoiceRooms = false, - isSearchingForReports = false, }: GetOptionsConfig, ): Options { if (includeCategories) { @@ -1852,6 +1850,8 @@ function getOptions( const searchValue = parsedPhoneNumber.possible ? parsedPhoneNumber.number?.e164 ?? '' : searchInputValue.toLowerCase(); const topmostReportId = Navigation.getTopmostReportId() ?? '-1'; + const isSearchingForReports = !!searchInputValue.length; + // Filter out all the reports that shouldn't be displayed const filteredReportOptions = options.reports.filter((option) => { const report = option.item; @@ -2517,7 +2517,11 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt // - Policy rooms // - Invoice rooms // - Trip rooms - if (item.isSearchableViaParticipants) { + if (ReportUtils.isSearchableViaParticipants({ + reportID: item.reportID, + type: item.type, + chatType: item.chatType + })) { values = values.concat(getParticipantsLoginsArray(item)); } diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index fd1409e81c02..a1f31b69d093 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5390,7 +5390,6 @@ function shouldReportBeInOptionList({ excludeEmptyChats, doesReportHaveViolations, includeSelfDM = false, - isSearchingForReports = false, }: { report: OnyxEntry; currentReportId: string; From a842879a3f98673bc7ec7e233262ee2900f038b5 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Thu, 27 Jun 2024 13:03:15 -0700 Subject: [PATCH 17/38] simplify logic and improve comment --- src/libs/OptionsListUtils.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index df6b8b3ac024..b0646f548a17 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1939,20 +1939,18 @@ function getOptions( return; } + // Rooms that aren't searchable via participant won't have any participants returned with SearchForReports + // so we don't need to check if their participants exist in order for them to qualify as a valid option. + if (isSearchingForReports && !ReportUtils.isSearchableViaParticipants(report)) { + return option; + } + if (!accountIDs || accountIDs.length === 0) { if (!isSearchingForReports) { if (!isChatRoom) { return; } } - - // Rooms that aren't searchable via participant won't have any participants returned with SearchForReports - // so we have to let their options pass through this check. - // Rooms that are searchable via participant should always have participants returned with SearchForReports, - // so we block any that don't have participants with this check. - if (ReportUtils.isSearchableViaParticipants(report)) { - return; - } } return option; From 128a3ce7c40ffa44c33c1ddbb54b573e88a14d6d Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Thu, 27 Jun 2024 13:04:27 -0700 Subject: [PATCH 18/38] update comment --- src/libs/OptionsListUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index b0646f548a17..f834ac5bb68e 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1939,7 +1939,7 @@ function getOptions( return; } - // Rooms that aren't searchable via participant won't have any participants returned with SearchForReports + // Reports that aren't searchable via participant won't have any participants returned with SearchForReports // so we don't need to check if their participants exist in order for them to qualify as a valid option. if (isSearchingForReports && !ReportUtils.isSearchableViaParticipants(report)) { return option; From dfead132355c111260ee10b5361384caba6d8e3b Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Thu, 27 Jun 2024 18:50:11 -0700 Subject: [PATCH 19/38] style --- src/libs/OptionsListUtils.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index f834ac5bb68e..8a9639078a34 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -2515,11 +2515,13 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt // - Policy rooms // - Invoice rooms // - Trip rooms - if (ReportUtils.isSearchableViaParticipants({ - reportID: item.reportID, - type: item.type, - chatType: item.chatType - })) { + if ( + ReportUtils.isSearchableViaParticipants({ + reportID: item.reportID, + type: item.type, + chatType: item.chatType, + }) + ) { values = values.concat(getParticipantsLoginsArray(item)); } From 01c993f812d2a3ece567159ec2bf1d8bc28ae86a Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Thu, 27 Jun 2024 19:13:00 -0700 Subject: [PATCH 20/38] remove unused --- src/libs/OptionsListUtils.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 8a9639078a34..1f7f73e9442a 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -2132,7 +2132,6 @@ function getSearchOptions(options: OptionList, searchValue = '', betas: Beta[] = includeMoneyRequests: true, includeTasks: true, includeSelfDM: true, - isSearchingForReports: true, }); Timing.end(CONST.TIMING.LOAD_SEARCH_OPTIONS); Performance.markEnd(CONST.TIMING.LOAD_SEARCH_OPTIONS); From d42b35bc75f4a6585d48e1a44adc713f6fd1cbd3 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Thu, 27 Jun 2024 19:14:16 -0700 Subject: [PATCH 21/38] add back missing variable --- src/libs/ReportUtils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index a1f31b69d093..fd1409e81c02 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5390,6 +5390,7 @@ function shouldReportBeInOptionList({ excludeEmptyChats, doesReportHaveViolations, includeSelfDM = false, + isSearchingForReports = false, }: { report: OnyxEntry; currentReportId: string; From ecf4bfe3b73eddd8edbef5328385066733760cae Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Fri, 28 Jun 2024 10:59:06 -0700 Subject: [PATCH 22/38] remove unused logic --- src/libs/OptionsListUtils.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 1f7f73e9442a..a7de63aa7eeb 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1945,12 +1945,8 @@ function getOptions( return option; } - if (!accountIDs || accountIDs.length === 0) { - if (!isSearchingForReports) { - if (!isChatRoom) { - return; - } - } + if ((!accountIDs || accountIDs.length === 0) && !isChatRoom) { + return; } return option; @@ -2603,7 +2599,7 @@ export { sortCategories, sortTags, getCategoryOptionTree, - hasEnabledTags, + hasEnabledTags formatMemberForList, formatSectionsFromSearchTerm, getShareLogOptions, From 1835257c6df8013555c7f6d421c588f2c367c765 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Fri, 28 Jun 2024 11:05:55 -0700 Subject: [PATCH 23/38] improve comment --- src/libs/OptionsListUtils.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index a7de63aa7eeb..b463ef8ebd72 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1941,6 +1941,10 @@ function getOptions( // Reports that aren't searchable via participant won't have any participants returned with SearchForReports // so we don't need to check if their participants exist in order for them to qualify as a valid option. + // This doesn't necessarily mean these reports are empty, we just do this because: + // - they don't need participants to be displayed as an option, and we'll load all the participant data again if the user selects the report from the option list + // - it improves query performance in SearchForReports + // - it drastically reduces response size if (isSearchingForReports && !ReportUtils.isSearchableViaParticipants(report)) { return option; } From edcb7ef509e98efdf0edaa7d8f41c98d100b88d4 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Fri, 28 Jun 2024 11:06:19 -0700 Subject: [PATCH 24/38] remove unused comment --- src/libs/OptionsListUtils.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index b463ef8ebd72..d67bf29ed1a8 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -2509,11 +2509,6 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt values = values.concat(getParticipantsLoginsArray(item)); } - // We don't want the following to be searchable by participant: - // - Default rooms - // - Policy rooms - // - Invoice rooms - // - Trip rooms if ( ReportUtils.isSearchableViaParticipants({ reportID: item.reportID, From 131ae678c7c523267334474d4767de6522eede50 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Fri, 28 Jun 2024 11:53:55 -0700 Subject: [PATCH 25/38] Use isChatRoom to decide whether to display reports with empty participants --- src/libs/OptionsListUtils.ts | 16 ++-------------- src/libs/ReportUtils.ts | 2 +- src/pages/ChatFinderPage/index.tsx | 2 +- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index d67bf29ed1a8..932dc53b03df 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1850,8 +1850,6 @@ function getOptions( const searchValue = parsedPhoneNumber.possible ? parsedPhoneNumber.number?.e164 ?? '' : searchInputValue.toLowerCase(); const topmostReportId = Navigation.getTopmostReportId() ?? '-1'; - const isSearchingForReports = !!searchInputValue.length; - // Filter out all the reports that shouldn't be displayed const filteredReportOptions = options.reports.filter((option) => { const report = option.item; @@ -1872,7 +1870,7 @@ function getOptions( isInFocusMode: false, excludeEmptyChats: false, includeSelfDM, - isSearchingForReports, + isSearchingForReports: !!searchInputValue.length, }); }); @@ -1939,16 +1937,6 @@ function getOptions( return; } - // Reports that aren't searchable via participant won't have any participants returned with SearchForReports - // so we don't need to check if their participants exist in order for them to qualify as a valid option. - // This doesn't necessarily mean these reports are empty, we just do this because: - // - they don't need participants to be displayed as an option, and we'll load all the participant data again if the user selects the report from the option list - // - it improves query performance in SearchForReports - // - it drastically reduces response size - if (isSearchingForReports && !ReportUtils.isSearchableViaParticipants(report)) { - return option; - } - if ((!accountIDs || accountIDs.length === 0) && !isChatRoom) { return; } @@ -2598,7 +2586,7 @@ export { sortCategories, sortTags, getCategoryOptionTree, - hasEnabledTags + hasEnabledTags, formatMemberForList, formatSectionsFromSearchTerm, getShareLogOptions, diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index fd1409e81c02..3e3af2d706d1 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -971,7 +971,7 @@ function isOpenInvoiceReport(report: OnyxEntry | EmptyObject): boolean { * Whether the provided report is a chat room */ function isChatRoom(report: OnyxEntry): boolean { - return isUserCreatedPolicyRoom(report) || isDefaultRoom(report) || isInvoiceRoom(report); + return isUserCreatedPolicyRoom(report) || isDefaultRoom(report) || isInvoiceRoom(report) || isTripRoom(report); } /** diff --git a/src/pages/ChatFinderPage/index.tsx b/src/pages/ChatFinderPage/index.tsx index cb3d0b1eafd9..3b6e5a0d822c 100644 --- a/src/pages/ChatFinderPage/index.tsx +++ b/src/pages/ChatFinderPage/index.tsx @@ -93,7 +93,7 @@ function ChatFinderPage({betas, isSearchingForReports, navigation}: ChatFinderPa headerMessage: '', }; } - const optionList = OptionsListUtils.getSearchOptions(options, '', betas ?? []); + const optionList = OptionsListUtils.getSearchOptions(options, debouncedSearchValueInServer.trim(), betas ?? []); const header = OptionsListUtils.getHeaderMessage(optionList.recentReports.length + optionList.personalDetails.length !== 0, !!optionList.userToInvite, ''); return {...optionList, headerMessage: header}; }, [areOptionsInitialized, betas, isScreenTransitionEnd, options]); From a133dde688cf38525c31ccf9917374eccefc5bd2 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Fri, 28 Jun 2024 11:56:09 -0700 Subject: [PATCH 26/38] remove unused --- src/libs/OptionsListUtils.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 932dc53b03df..f1402fabc88a 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -808,9 +808,6 @@ function createOption( result.isWaitingOnBankAccount = report.isWaitingOnBankAccount; result.policyID = report.policyID; result.isSelfDM = ReportUtils.isSelfDM(report); - result.isTripRoom = ReportUtils.isTripRoom(report); - result.policyName = ReportUtils.getPolicyName(report); - result.isSearchableViaParticipants = ReportUtils.isSearchableViaParticipants(report); const visibleParticipantAccountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(report, true); From 8e0ca9009ab3c7d09a7b5f9f5d45051a45b0e800 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Fri, 28 Jun 2024 11:58:23 -0700 Subject: [PATCH 27/38] remove unused --- src/libs/OptionsListUtils.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index f1402fabc88a..fb6d4a5f7de9 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -769,11 +769,9 @@ function createOption( isPolicyExpenseChat: false, isOwnPolicyExpenseChat: false, isExpenseReport: false, - isTripRoom: false, policyID: undefined, isOptimisticPersonalDetail: false, lastMessageText: '', - isSearchableViaParticipants: false, }; const personalDetailMap = getPersonalDetailsForAccountIDs(accountIDs, personalDetails); From 09870fc75cadd1933275d7694bd2fb045729fd9e Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Fri, 28 Jun 2024 11:59:32 -0700 Subject: [PATCH 28/38] remove unused --- src/libs/ReportUtils.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 3e3af2d706d1..16196876920e 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -412,7 +412,6 @@ type OptionData = { displayNamesWithTooltips?: DisplayNameWithTooltips | null; isDefaultRoom?: boolean; isInvoiceRoom?: boolean; - isTripRoom?: boolean; isExpenseReport?: boolean; isOptimisticPersonalDetail?: boolean; selected?: boolean; @@ -431,7 +430,6 @@ type OptionData = { shouldShowAmountInput?: boolean; amountInputProps?: MoneyRequestAmountInputProps; tabIndex?: 0 | -1; - isSearchableViaParticipants?: boolean; } & Report; type OnyxDataTaskAssigneeChat = { From 7c124837f1cb3272908ebceedfd47498787326a5 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Fri, 28 Jun 2024 12:05:52 -0700 Subject: [PATCH 29/38] simplify logic --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 16196876920e..ca8f8b9c202b 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -976,7 +976,7 @@ function isChatRoom(report: OnyxEntry): boolean { * Whether the provided report is searchable via participant */ function isSearchableViaParticipants(report: OnyxEntry): boolean { - return !isChatReport(report) || isDM(report) || isGroupChat(report) || isPolicyExpenseChat(report) || isSystemChat(report) || isSelfDM(report); + return !isChatReport(report) || !isChatRoom(report); } /** From cae1a80349767471783b3d17556a6d7399d19545 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Fri, 28 Jun 2024 15:29:30 -0700 Subject: [PATCH 30/38] remove isSearchableViaParticipants --- src/libs/OptionsListUtils.ts | 9 ++------- src/libs/ReportUtils.ts | 12 ++---------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index fb6d4a5f7de9..f02c1fe4bfff 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -2492,13 +2492,8 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt values = values.concat(getParticipantsLoginsArray(item)); } - if ( - ReportUtils.isSearchableViaParticipants({ - reportID: item.reportID, - type: item.type, - chatType: item.chatType, - }) - ) { + const partialReport = {reportID: item.reportID, type: item.type, chatType: item.chatType}; + if (!ReportUtils.isChatReport(partialReport) || !ReportUtils.isChatRoom(partialReport)) { values = values.concat(getParticipantsLoginsArray(item)); } diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index ca8f8b9c202b..93c2bd251d34 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -972,13 +972,6 @@ function isChatRoom(report: OnyxEntry): boolean { return isUserCreatedPolicyRoom(report) || isDefaultRoom(report) || isInvoiceRoom(report) || isTripRoom(report); } -/** - * Whether the provided report is searchable via participant - */ -function isSearchableViaParticipants(report: OnyxEntry): boolean { - return !isChatReport(report) || !isChatRoom(report); -} - /** * Whether the provided report is a public room */ @@ -5425,11 +5418,11 @@ function shouldReportBeInOptionList({ !isSystemChat(report) && !isGroupChat(report) && !isInvoiceRoom(report) && - // We omit sending back participants for certain reports when searching for reports since they aren't needed to display the results and can get very large. + // We omit sending back participants for chat rooms when searching for reports since they aren't needed to display the results and can get very large. // So we allow showing rooms with no participants when searching for reports. // In any other circumstances we should never have these reports with no participants in Onyx. !isSearchingForReports && - !isSearchableViaParticipants(report)) + !isChatRoom(report)) ) { return false; } @@ -7323,7 +7316,6 @@ export { createDraftWorkspaceAndNavigateToConfirmationScreen, isChatUsedForOnboarding, getChatUsedForOnboarding, - isSearchableViaParticipants, findPolicyExpenseChatByPolicyID, }; From a202b1eb81ca12c156328d6933bb36b379da955f Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Fri, 28 Jun 2024 15:32:18 -0700 Subject: [PATCH 31/38] remove unused --- src/libs/ReportUtils.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 93c2bd251d34..75a32fe55916 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5381,7 +5381,6 @@ function shouldReportBeInOptionList({ excludeEmptyChats, doesReportHaveViolations, includeSelfDM = false, - isSearchingForReports = false, }: { report: OnyxEntry; currentReportId: string; @@ -5391,7 +5390,6 @@ function shouldReportBeInOptionList({ excludeEmptyChats: boolean; doesReportHaveViolations: boolean; includeSelfDM?: boolean; - isSearchingForReports?: boolean; }) { const isInDefaultMode = !isInFocusMode; // Exclude reports that have no data because there wouldn't be anything to show in the option item. @@ -5419,9 +5417,7 @@ function shouldReportBeInOptionList({ !isGroupChat(report) && !isInvoiceRoom(report) && // We omit sending back participants for chat rooms when searching for reports since they aren't needed to display the results and can get very large. - // So we allow showing rooms with no participants when searching for reports. - // In any other circumstances we should never have these reports with no participants in Onyx. - !isSearchingForReports && + // So we allow showing rooms with no participants–in any other circumstances we should never have these reports with no participants in Onyx. !isChatRoom(report)) ) { return false; From 88a6564bee46724abf1ea3fbd690061ba9239662 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Fri, 28 Jun 2024 16:02:45 -0700 Subject: [PATCH 32/38] add missing hook dependency --- src/pages/ChatFinderPage/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/ChatFinderPage/index.tsx b/src/pages/ChatFinderPage/index.tsx index 3b6e5a0d822c..75b11990742e 100644 --- a/src/pages/ChatFinderPage/index.tsx +++ b/src/pages/ChatFinderPage/index.tsx @@ -96,7 +96,7 @@ function ChatFinderPage({betas, isSearchingForReports, navigation}: ChatFinderPa const optionList = OptionsListUtils.getSearchOptions(options, debouncedSearchValueInServer.trim(), betas ?? []); const header = OptionsListUtils.getHeaderMessage(optionList.recentReports.length + optionList.personalDetails.length !== 0, !!optionList.userToInvite, ''); return {...optionList, headerMessage: header}; - }, [areOptionsInitialized, betas, isScreenTransitionEnd, options]); + }, [areOptionsInitialized, betas, isScreenTransitionEnd, options, debouncedSearchValueInServer]); const filteredOptions = useMemo(() => { if (debouncedSearchValue.trim() === '') { From 802a3d0680a99df640715324992283850e3aa92d Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Fri, 28 Jun 2024 16:03:12 -0700 Subject: [PATCH 33/38] remove unused param --- src/libs/OptionsListUtils.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index f02c1fe4bfff..fadb47f5c72a 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -1865,7 +1865,6 @@ function getOptions( isInFocusMode: false, excludeEmptyChats: false, includeSelfDM, - isSearchingForReports: !!searchInputValue.length, }); }); From 9ca7cea01fa5cf2df13b94cd3ee3c248269d14e7 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 1 Jul 2024 11:43:22 -0700 Subject: [PATCH 34/38] remove duplicate checks --- src/libs/ReportUtils.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 75a32fe55916..dc5e7ccd148e 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5406,19 +5406,16 @@ function shouldReportBeInOptionList({ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing report?.isHidden || (participantAccountIDs.length === 0 && + // We omit sending back participants for chat rooms when searching for reports since they aren't needed to display the results and can get very large. + // So we allow showing rooms with no participants–in any other circumstances we should never have these reports with no participants in Onyx. + !isChatRoom(report) && !isChatThread(report) && - !isPublicRoom(report) && - !isUserCreatedPolicyRoom(report) && !isArchivedRoom(report) && !isMoneyRequestReport(report) && !isTaskReport(report) && !isSelfDM(report) && !isSystemChat(report) && - !isGroupChat(report) && - !isInvoiceRoom(report) && - // We omit sending back participants for chat rooms when searching for reports since they aren't needed to display the results and can get very large. - // So we allow showing rooms with no participants–in any other circumstances we should never have these reports with no participants in Onyx. - !isChatRoom(report)) + !isGroupChat(report)) ) { return false; } From d1c6c0072fe71278e2b68922d5d280bde34e3473 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 1 Jul 2024 12:03:06 -0700 Subject: [PATCH 35/38] condense logic and add comment --- src/libs/OptionsListUtils.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index fadb47f5c72a..f7083d8c2426 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -2473,11 +2473,6 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt values.push(item.login.replace(emailRegex, '')); } - if (!item.isChatRoom) { - const participantNames = getParticipantNames(item.participantsList ?? []); - values = values.concat(Array.from(participantNames)); - } - if (item.isThread) { if (item.alternateText) { values.push(item.alternateText); @@ -2491,8 +2486,12 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt values = values.concat(getParticipantsLoginsArray(item)); } + // We don't want chat rooms to be searchable via participants, so we only add participant logins/display + // if the report in question isn't a chat room. const partialReport = {reportID: item.reportID, type: item.type, chatType: item.chatType}; if (!ReportUtils.isChatReport(partialReport) || !ReportUtils.isChatRoom(partialReport)) { + const participantNames = getParticipantNames(item.participantsList ?? []); + values = values.concat(Array.from(participantNames)); values = values.concat(getParticipantsLoginsArray(item)); } From f5dc4f700e3b230179ed8e061f3e51a9750d5e48 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Mon, 1 Jul 2024 13:43:11 -0700 Subject: [PATCH 36/38] remove unused --- src/pages/ChatFinderPage/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/ChatFinderPage/index.tsx b/src/pages/ChatFinderPage/index.tsx index 75b11990742e..cb3d0b1eafd9 100644 --- a/src/pages/ChatFinderPage/index.tsx +++ b/src/pages/ChatFinderPage/index.tsx @@ -93,10 +93,10 @@ function ChatFinderPage({betas, isSearchingForReports, navigation}: ChatFinderPa headerMessage: '', }; } - const optionList = OptionsListUtils.getSearchOptions(options, debouncedSearchValueInServer.trim(), betas ?? []); + const optionList = OptionsListUtils.getSearchOptions(options, '', betas ?? []); const header = OptionsListUtils.getHeaderMessage(optionList.recentReports.length + optionList.personalDetails.length !== 0, !!optionList.userToInvite, ''); return {...optionList, headerMessage: header}; - }, [areOptionsInitialized, betas, isScreenTransitionEnd, options, debouncedSearchValueInServer]); + }, [areOptionsInitialized, betas, isScreenTransitionEnd, options]); const filteredOptions = useMemo(() => { if (debouncedSearchValue.trim() === '') { From 505e31a47337b2cc2dbc361cfc54ec4359dee2f4 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Wed, 3 Jul 2024 16:22:35 -0700 Subject: [PATCH 37/38] consolidate logic --- src/libs/OptionsListUtils.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 9bf0ef46ec13..f65a1accb763 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -2501,14 +2501,7 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt if (item.subtitle) { values.push(item.subtitle); } - } else { - values = values.concat(getParticipantsLoginsArray(item)); - } - - // We don't want chat rooms to be searchable via participants, so we only add participant logins/display - // if the report in question isn't a chat room. - const partialReport = {reportID: item.reportID, type: item.type, chatType: item.chatType}; - if (!ReportUtils.isChatReport(partialReport) || !ReportUtils.isChatRoom(partialReport)) { + } else if (!item.isChatRoom) { const participantNames = getParticipantNames(item.participantsList ?? []); values = values.concat(Array.from(participantNames)); values = values.concat(getParticipantsLoginsArray(item)); From 86735ab68ac55181fb3edb616e8de47185590451 Mon Sep 17 00:00:00 2001 From: Jasper Huang Date: Wed, 3 Jul 2024 16:25:48 -0700 Subject: [PATCH 38/38] consolidate logic --- src/libs/OptionsListUtils.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index f65a1accb763..763ab0ccd48b 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -2501,7 +2501,9 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt if (item.subtitle) { values.push(item.subtitle); } - } else if (!item.isChatRoom) { + } + + if (!item.isChatRoom) { const participantNames = getParticipantNames(item.participantsList ?? []); values = values.concat(Array.from(participantNames)); values = values.concat(getParticipantsLoginsArray(item));