Skip to content

Commit

Permalink
Merge pull request #55698 from nyomanjyotisa/issue-53671-2
Browse files Browse the repository at this point in the history
User's name containing accent not shown in results if no accent in search query
  • Loading branch information
MonilBhavsar authored Jan 27, 2025
2 parents 08cf4a9 + 2c7998d commit ba27d00
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ import {
shouldReportShowSubscript,
} from './ReportUtils';
import type {OptionData} from './ReportUtils';
import StringUtils from './StringUtils';
import {getTaskCreatedMessage, getTaskReportActionMessage} from './TaskUtils';
import {generateAccountID} from './UserUtils';

Expand Down Expand Up @@ -1839,29 +1840,31 @@ function filteredPersonalDetailsOfRecentReports(recentReports: OptionData[], per
* Filters options based on the search input value
*/
function filterReports(reports: OptionData[], searchTerms: string[]): OptionData[] {
const normalizedSearchTerms = searchTerms.map((term) => StringUtils.normalizeAccents(term));
// We search eventually for multiple whitespace separated search terms.
// We start with the search term at the end, and then narrow down those filtered search results with the next search term.
// We repeat (reduce) this until all search terms have been used:
const filteredReports = searchTerms.reduceRight(
const filteredReports = normalizedSearchTerms.reduceRight(
(items, term) =>
filterArrayByMatch(items, term, (item) => {
const values: string[] = [];
if (item.text) {
values.push(item.text);
values.push(StringUtils.normalizeAccents(item.text));
values.push(StringUtils.normalizeAccents(item.text).replace(/['-]/g, ''));
}

if (item.login) {
values.push(item.login);
values.push(item.login.replace(CONST.EMAIL_SEARCH_REGEX, ''));
values.push(StringUtils.normalizeAccents(item.login));
values.push(StringUtils.normalizeAccents(item.login.replace(CONST.EMAIL_SEARCH_REGEX, '')));
}

if (item.isThread) {
if (item.alternateText) {
values.push(item.alternateText);
values.push(StringUtils.normalizeAccents(item.alternateText));
}
} else if (!!item.isChatRoom || !!item.isPolicyExpenseChat) {
if (item.subtitle) {
values.push(item.subtitle);
values.push(StringUtils.normalizeAccents(item.subtitle));
}
}

Expand Down Expand Up @@ -2125,6 +2128,7 @@ export {
filterWorkspaceChats,
orderWorkspaceOptions,
filterSelfDMChat,
filterReports,
};

export type {Section, SectionBase, MemberForList, Options, OptionList, SearchOption, PayeePersonalDetails, Option, OptionTree, ReportAndPersonalDetailOptions, GetUserToInviteConfig};
10 changes: 10 additions & 0 deletions tests/unit/OptionsListUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1251,4 +1251,14 @@ describe('OptionsListUtils', () => {
expect(result?.reportID).toEqual(REPORT.reportID);
});
});

describe('filterReports', () => {
it('should match a user with an accented name when searching using non-accented characters', () => {
const reports = [{text: "Álex Timón D'artagnan Zo-e"} as ReportUtils.OptionData];
const searchTerms = ['Alex Timon Dartagnan Zoe'];
const filteredReports = OptionsListUtils.filterReports(reports, searchTerms);

expect(filteredReports).toEqual(reports);
});
});
});

0 comments on commit ba27d00

Please sign in to comment.