From d3af5e2e2841ff8df299c4c35c60dc691b667d12 Mon Sep 17 00:00:00 2001 From: Tomasz Misiukiewicz Date: Tue, 21 May 2024 11:29:07 +0200 Subject: [PATCH] chore: update search results ordering --- src/libs/OptionsListUtils.ts | 14 ++++++++++---- src/pages/ChatFinderPage/index.tsx | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 544ced533e82..61149ea14505 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -212,6 +212,8 @@ type Options = { type PreviewConfig = {showChatPreviewLine?: boolean; forcePolicyNamePreview?: boolean; showPersonalDetails?: boolean}; +type FilterOptionsConfig = Pick & {preferChatroomsOverThreads: boolean}; + /** * OptionsListUtils is used to build a list options passed to the OptionsList component. Several different UI views can * be configured to display different results based on the options passed to the private getOptions() method. Public @@ -1545,11 +1547,14 @@ function createOptionFromReport(report: Report, personalDetails: OnyxEntry { + if (preferChatroomsOverThreads && option.isThread) { + return 4; + } if (!!option.isChatRoom || option.isArchivedRoom) { return 3; } @@ -1962,7 +1967,7 @@ function getOptions( // When sortByReportTypeInSearch is true, recentReports will be returned with all the reports including personalDetailsOptions in the correct Order. recentReportOptions.push(...personalDetailsOptions); personalDetailsOptions = []; - recentReportOptions = orderOptions(recentReportOptions, searchValue); + recentReportOptions = orderOptions(recentReportOptions, searchValue, {preferChatroomsOverThreads: true}); } return { @@ -2305,7 +2310,8 @@ function getFirstKeyForList(data?: Option[] | null) { /** * Filters options based on the search input value */ -function filterOptions(options: Options, searchInputValue: string, betas: OnyxEntry = []): Options { +function filterOptions(options: Options, searchInputValue: string, config?: FilterOptionsConfig): Options { + const {betas = [], preferChatroomsOverThreads = false} = config ?? {}; const searchValue = getSearchValueForPhoneOrEmail(searchInputValue); const searchTerms = searchValue ? searchValue.split(' ') : []; @@ -2384,7 +2390,7 @@ function filterOptions(options: Options, searchInputValue: string, betas: OnyxEn return { personalDetails: [], - recentReports: orderOptions(recentReports, searchValue), + recentReports: orderOptions(recentReports, searchValue, {preferChatroomsOverThreads}), userToInvite, currentUserOption: null, categoryOptions: [], diff --git a/src/pages/ChatFinderPage/index.tsx b/src/pages/ChatFinderPage/index.tsx index d4b856e6955e..b7711856b343 100644 --- a/src/pages/ChatFinderPage/index.tsx +++ b/src/pages/ChatFinderPage/index.tsx @@ -99,7 +99,7 @@ function ChatFinderPage({betas, isSearchingForReports, navigation}: ChatFinderPa }; } - const newOptions = OptionsListUtils.filterOptions(searchOptions, debouncedSearchValue, betas); + const newOptions = OptionsListUtils.filterOptions(searchOptions, debouncedSearchValue, {betas, preferChatroomsOverThreads: true}); const header = OptionsListUtils.getHeaderMessage(newOptions.recentReports.length + Number(!!newOptions.userToInvite) > 0, false, debouncedSearchValue); return { recentReports: newOptions.recentReports,