Skip to content

Commit

Permalink
Merge pull request #56171 from FitseTLT/fix-self-dm-not-on-top-of-sea…
Browse files Browse the repository at this point in the history
…rch-result

Fix - Search - Self DM is removed from top of search list when email is fully typed out in query
  • Loading branch information
madmax330 authored Feb 4, 2025
2 parents 582a892 + be5f3ea commit 150e3d0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ function orderReportOptionsWithSearch(
}

if (option.isSelfDM) {
return 0;
return -1;
}
if (preferRecentExpenseReports && !!option?.lastIOUCreationDate) {
return 1;
Expand Down
39 changes: 39 additions & 0 deletions tests/unit/OptionsListUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,32 @@ describe('OptionsListUtils', () => {
},
};

const REPORTS_WITH_SELFDM: OnyxCollection<Report> = {
16: {
lastReadTime: '2021-01-14 11:25:39.302',
lastVisibleActionCreated: '2022-11-22 03:26:02.022',
isPinned: false,
reportID: '16',
participants: {
2: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS},
},
reportName: 'Expense Report',
type: CONST.REPORT.TYPE.EXPENSE,
},
17: {
lastReadTime: '2021-01-14 11:25:39.302',
lastVisibleActionCreated: '2022-11-22 03:26:02.022',
isPinned: false,
reportID: '17',
participants: {
2: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS},
},
reportName: '',
type: CONST.REPORT.TYPE.CHAT,
chatType: CONST.REPORT.CHAT_TYPE.SELF_DM,
},
};

const PERSONAL_DETAILS_WITH_CONCIERGE: PersonalDetailsList = {
...PERSONAL_DETAILS,
'999': {
Expand Down Expand Up @@ -1090,6 +1116,19 @@ describe('OptionsListUtils', () => {
expect(filteredOptions.personalDetails.length).toBe(2);
expect(matchingEntries.length).toBe(1);
});

it('should order self dm always on top if the search matches with the self dm login', () => {
const searchTerm = '[email protected]';

const OPTIONS_WITH_SELFDM = OptionsListUtils.createOptionList(PERSONAL_DETAILS, REPORTS_WITH_SELFDM);

// When search term matches with self dm login
const options = OptionsListUtils.getSearchOptions(OPTIONS_WITH_SELFDM, [CONST.BETAS.ALL]);
const filteredOptions = OptionsListUtils.filterAndOrderOptions(options, searchTerm);

// Then the self dm should be on top.
expect(filteredOptions.recentReports.at(0)?.isSelfDM).toBe(true);
});
});

describe('canCreateOptimisticPersonalDetailOption', () => {
Expand Down

0 comments on commit 150e3d0

Please sign in to comment.