Skip to content

Commit ba27d00

Browse files
authored
Merge pull request #55698 from nyomanjyotisa/issue-53671-2
User's name containing accent not shown in results if no accent in search query
2 parents 08cf4a9 + 2c7998d commit ba27d00

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/libs/OptionsListUtils.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ import {
127127
shouldReportShowSubscript,
128128
} from './ReportUtils';
129129
import type {OptionData} from './ReportUtils';
130+
import StringUtils from './StringUtils';
130131
import {getTaskCreatedMessage, getTaskReportActionMessage} from './TaskUtils';
131132
import {generateAccountID} from './UserUtils';
132133

@@ -1839,29 +1840,31 @@ function filteredPersonalDetailsOfRecentReports(recentReports: OptionData[], per
18391840
* Filters options based on the search input value
18401841
*/
18411842
function filterReports(reports: OptionData[], searchTerms: string[]): OptionData[] {
1843+
const normalizedSearchTerms = searchTerms.map((term) => StringUtils.normalizeAccents(term));
18421844
// We search eventually for multiple whitespace separated search terms.
18431845
// We start with the search term at the end, and then narrow down those filtered search results with the next search term.
18441846
// We repeat (reduce) this until all search terms have been used:
1845-
const filteredReports = searchTerms.reduceRight(
1847+
const filteredReports = normalizedSearchTerms.reduceRight(
18461848
(items, term) =>
18471849
filterArrayByMatch(items, term, (item) => {
18481850
const values: string[] = [];
18491851
if (item.text) {
1850-
values.push(item.text);
1852+
values.push(StringUtils.normalizeAccents(item.text));
1853+
values.push(StringUtils.normalizeAccents(item.text).replace(/['-]/g, ''));
18511854
}
18521855

18531856
if (item.login) {
1854-
values.push(item.login);
1855-
values.push(item.login.replace(CONST.EMAIL_SEARCH_REGEX, ''));
1857+
values.push(StringUtils.normalizeAccents(item.login));
1858+
values.push(StringUtils.normalizeAccents(item.login.replace(CONST.EMAIL_SEARCH_REGEX, '')));
18561859
}
18571860

18581861
if (item.isThread) {
18591862
if (item.alternateText) {
1860-
values.push(item.alternateText);
1863+
values.push(StringUtils.normalizeAccents(item.alternateText));
18611864
}
18621865
} else if (!!item.isChatRoom || !!item.isPolicyExpenseChat) {
18631866
if (item.subtitle) {
1864-
values.push(item.subtitle);
1867+
values.push(StringUtils.normalizeAccents(item.subtitle));
18651868
}
18661869
}
18671870

@@ -2125,6 +2128,7 @@ export {
21252128
filterWorkspaceChats,
21262129
orderWorkspaceOptions,
21272130
filterSelfDMChat,
2131+
filterReports,
21282132
};
21292133

21302134
export type {Section, SectionBase, MemberForList, Options, OptionList, SearchOption, PayeePersonalDetails, Option, OptionTree, ReportAndPersonalDetailOptions, GetUserToInviteConfig};

tests/unit/OptionsListUtilsTest.ts

+10
Original file line numberDiff line numberDiff line change
@@ -1251,4 +1251,14 @@ describe('OptionsListUtils', () => {
12511251
expect(result?.reportID).toEqual(REPORT.reportID);
12521252
});
12531253
});
1254+
1255+
describe('filterReports', () => {
1256+
it('should match a user with an accented name when searching using non-accented characters', () => {
1257+
const reports = [{text: "Álex Timón D'artagnan Zo-e"} as ReportUtils.OptionData];
1258+
const searchTerms = ['Alex Timon Dartagnan Zoe'];
1259+
const filteredReports = OptionsListUtils.filterReports(reports, searchTerms);
1260+
1261+
expect(filteredReports).toEqual(reports);
1262+
});
1263+
});
12541264
});

0 commit comments

Comments
 (0)