Skip to content

Commit

Permalink
Merge pull request #42411 from callstack-internal/prefer-chatrooms-ov…
Browse files Browse the repository at this point in the history
…er-threads

chore: update search results ordering
  • Loading branch information
roryabraham authored May 29, 2024
2 parents 06146fb + d3af5e2 commit 23232b4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ type Options = {

type PreviewConfig = {showChatPreviewLine?: boolean; forcePolicyNamePreview?: boolean; showPersonalDetails?: boolean};

type FilterOptionsConfig = Pick<GetOptionsConfig, 'betas'> & {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
Expand Down Expand Up @@ -1566,11 +1568,14 @@ function createOptionFromReport(report: Report, personalDetails: OnyxEntry<Perso
* @param searchValue - search string
* @returns a sorted list of options
*/
function orderOptions(options: ReportUtils.OptionData[], searchValue: string | undefined) {
function orderOptions(options: ReportUtils.OptionData[], searchValue: string | undefined, {preferChatroomsOverThreads = false} = {}) {
return lodashOrderBy(
options,
[
(option) => {
if (preferChatroomsOverThreads && option.isThread) {
return 4;
}
if (!!option.isChatRoom || option.isArchivedRoom) {
return 3;
}
Expand Down Expand Up @@ -1985,7 +1990,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 {
Expand Down Expand Up @@ -2328,7 +2333,8 @@ function getFirstKeyForList(data?: Option[] | null) {
/**
* Filters options based on the search input value
*/
function filterOptions(options: Options, searchInputValue: string, betas: OnyxEntry<Beta[]> = []): Options {
function filterOptions(options: Options, searchInputValue: string, config?: FilterOptionsConfig): Options {
const {betas = [], preferChatroomsOverThreads = false} = config ?? {};
const searchValue = getSearchValueForPhoneOrEmail(searchInputValue);
const searchTerms = searchValue ? searchValue.split(' ') : [];

Expand Down Expand Up @@ -2407,7 +2413,7 @@ function filterOptions(options: Options, searchInputValue: string, betas: OnyxEn

return {
personalDetails: [],
recentReports: orderOptions(recentReports, searchValue),
recentReports: orderOptions(recentReports, searchValue, {preferChatroomsOverThreads}),
userToInvite,
currentUserOption: null,
categoryOptions: [],
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ChatFinderPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,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,
Expand Down

0 comments on commit 23232b4

Please sign in to comment.