From dc92b0e8e0f1b2267f4ec1ab9a6f76d71805ecdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hanno=20J=2E=20G=C3=B6decke?= Date: Thu, 7 Nov 2024 10:47:26 +0100 Subject: [PATCH 1/3] cleanup option list --- src/libs/OptionsListUtils.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 497a2d33cf56..059034035a00 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -2555,13 +2555,15 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt }; }, options); - let {recentReports, personalDetails} = matchResults; + const {recentReports, personalDetails} = matchResults; + const noneReportPersonalDetails = filteredPersonalDetailsOfRecentReports(recentReports, personalDetails); + + let filteredPersonalDetails: ReportUtils.OptionData[] = noneReportPersonalDetails; + let filteredRecentReports: ReportUtils.OptionData[] = recentReports; if (sortByReportTypeInSearch) { - personalDetails = filteredPersonalDetailsOfRecentReports(recentReports, personalDetails); - recentReports = recentReports.concat(personalDetails); - personalDetails = []; - recentReports = orderOptions(recentReports, searchValue); + filteredRecentReports = recentReports.concat(noneReportPersonalDetails); + filteredPersonalDetails = []; } let userToInvite = null; @@ -2578,11 +2580,11 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt if (maxRecentReportsToShow > 0 && recentReports.length > maxRecentReportsToShow) { recentReports.splice(maxRecentReportsToShow); } - const filteredPersonalDetails = filteredPersonalDetailsOfRecentReports(recentReports, personalDetails); + const sortedRecentReports = orderOptions(filteredRecentReports, searchValue, {preferChatroomsOverThreads, preferPolicyExpenseChat, preferRecentExpenseReports}); return { personalDetails: filteredPersonalDetails, - recentReports: orderOptions(recentReports, searchValue, {preferChatroomsOverThreads, preferPolicyExpenseChat, preferRecentExpenseReports}), + recentReports: sortedRecentReports, userToInvite, currentUserOption: matchResults.currentUserOption, categoryOptions: [], From 63565408632e7f70a9e70c747048af3a29e09197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hanno=20J=2E=20G=C3=B6decke?= Date: Thu, 7 Nov 2024 10:54:28 +0100 Subject: [PATCH 2/3] export filteredPersonalDetailsOfRecentReports --- src/libs/OptionsListUtils.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 059034035a00..2d366e45f5a0 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -2477,6 +2477,15 @@ function getPersonalDetailSearchTerms(item: Partial) { function getCurrentUserSearchTerms(item: ReportUtils.OptionData) { return [item.text ?? '', item.login ?? '', item.login?.replace(CONST.EMAIL_SEARCH_REGEX, '') ?? '']; } + +/** + * Remove the personal details for the DMs that are already in the recent reports so that we don't show duplicates. + */ +function filteredPersonalDetailsOfRecentReports(recentReports: ReportUtils.OptionData[], personalDetails: ReportUtils.OptionData[]) { + const excludedLogins = new Set(recentReports.map((report) => report.login)); + return personalDetails.filter((personalDetail) => !excludedLogins.has(personalDetail.login)); +} + /** * Filters options based on the search input value */ @@ -2490,11 +2499,6 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt preferPolicyExpenseChat = false, preferRecentExpenseReports = false, } = config ?? {}; - // Remove the personal details for the DMs that are already in the recent reports so that we don't show duplicates - function filteredPersonalDetailsOfRecentReports(recentReports: ReportUtils.OptionData[], personalDetails: ReportUtils.OptionData[]) { - const excludedLogins = new Set(recentReports.map((report) => report.login)); - return personalDetails.filter((personalDetail) => !excludedLogins.has(personalDetail.login)); - } if (searchInputValue.trim() === '' && maxRecentReportsToShow > 0) { const recentReports = options.recentReports.slice(0, maxRecentReportsToShow); const personalDetails = filteredPersonalDetailsOfRecentReports(recentReports, options.personalDetails); @@ -2646,6 +2650,7 @@ export { formatSectionsFromSearchTerm, getShareLogOptions, filterOptions, + filteredPersonalDetailsOfRecentReports, createOptionList, createOptionFromReport, getReportOption, From 1465c8a6225c4ce07a88a420d387d299ac949e1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hanno=20J=2E=20G=C3=B6decke?= Date: Thu, 7 Nov 2024 14:44:39 +0100 Subject: [PATCH 3/3] rename to personalDetailsWithoutDMs --- src/libs/OptionsListUtils.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 2d366e45f5a0..da61c43504f2 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -2561,12 +2561,12 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt const {recentReports, personalDetails} = matchResults; - const noneReportPersonalDetails = filteredPersonalDetailsOfRecentReports(recentReports, personalDetails); + const personalDetailsWithoutDMs = filteredPersonalDetailsOfRecentReports(recentReports, personalDetails); - let filteredPersonalDetails: ReportUtils.OptionData[] = noneReportPersonalDetails; + let filteredPersonalDetails: ReportUtils.OptionData[] = personalDetailsWithoutDMs; let filteredRecentReports: ReportUtils.OptionData[] = recentReports; if (sortByReportTypeInSearch) { - filteredRecentReports = recentReports.concat(noneReportPersonalDetails); + filteredRecentReports = recentReports.concat(personalDetailsWithoutDMs); filteredPersonalDetails = []; }