Skip to content

Commit

Permalink
Merge pull request #52168 from margelo/perf/cleanup-optionslistutils
Browse files Browse the repository at this point in the history
perf: cleanup option list
  • Loading branch information
marcaaron authored Nov 15, 2024
2 parents 4cc54ab + 1465c8a commit b2b6e2d
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2187,6 +2187,15 @@ function getPersonalDetailSearchTerms(item: Partial<ReportUtils.OptionData>) {
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
*/
Expand All @@ -2200,11 +2209,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);
Expand Down Expand Up @@ -2264,13 +2268,15 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt
};
}, options);

let {recentReports, personalDetails} = matchResults;
const {recentReports, personalDetails} = matchResults;

const personalDetailsWithoutDMs = filteredPersonalDetailsOfRecentReports(recentReports, personalDetails);

let filteredPersonalDetails: ReportUtils.OptionData[] = personalDetailsWithoutDMs;
let filteredRecentReports: ReportUtils.OptionData[] = recentReports;
if (sortByReportTypeInSearch) {
personalDetails = filteredPersonalDetailsOfRecentReports(recentReports, personalDetails);
recentReports = recentReports.concat(personalDetails);
personalDetails = [];
recentReports = orderOptions(recentReports, searchValue);
filteredRecentReports = recentReports.concat(personalDetailsWithoutDMs);
filteredPersonalDetails = [];
}

let userToInvite = null;
Expand All @@ -2287,11 +2293,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: [],
Expand Down Expand Up @@ -2349,6 +2355,7 @@ export {
formatSectionsFromSearchTerm,
getShareLogOptions,
filterOptions,
filteredPersonalDetailsOfRecentReports,
createOptionList,
createOptionFromReport,
getReportOption,
Expand Down

0 comments on commit b2b6e2d

Please sign in to comment.