diff --git a/src/libs/CardUtils.ts b/src/libs/CardUtils.ts index f6aa51fcb8cc..aa3f8679612f 100644 --- a/src/libs/CardUtils.ts +++ b/src/libs/CardUtils.ts @@ -19,6 +19,7 @@ import localeCompare from './LocaleCompare'; import {translateLocal} from './Localize'; import {filterObject} from './ObjectUtils'; import {getDisplayNameOrDefault} from './PersonalDetailsUtils'; +import StringUtils from './StringUtils'; let allCards: OnyxValues[typeof ONYXKEYS.CARD_LIST] = {}; Onyx.connect({ @@ -271,11 +272,17 @@ function sortCardsByCardholderName(cards: Card[], personalDetails: OnyxEntry ' ' + .replace(/\s+/g, ' ') // collapse spaces + .trim(); +} + /** * Replace all CRLF with LF * @param value - The input string @@ -125,6 +141,7 @@ export default { sanitizeString, isEmptyString, removeInvisibleCharacters, + normalize, normalizeAccents, normalizeCRLF, lineBreaksToSpaces, diff --git a/src/pages/workspace/WorkspaceMembersPage.tsx b/src/pages/workspace/WorkspaceMembersPage.tsx index 4bd342da6a07..ca91f2058760 100644 --- a/src/pages/workspace/WorkspaceMembersPage.tsx +++ b/src/pages/workspace/WorkspaceMembersPage.tsx @@ -57,6 +57,7 @@ import {isPersonalDetailsReady, sortAlphabetically} from '@libs/OptionsListUtils import {getAccountIDsByLogins, getDisplayNameOrDefault, getPersonalDetailsByIDs} from '@libs/PersonalDetailsUtils'; import {getMemberAccountIDsForWorkspace, isDeletedPolicyEmployee, isExpensifyTeam, isPaidGroupPolicy, isPolicyAdmin as isPolicyAdminUtils} from '@libs/PolicyUtils'; import {getDisplayNameForParticipant} from '@libs/ReportUtils'; +import StringUtils from '@libs/StringUtils'; import {convertPolicyEmployeesToApprovalWorkflows, updateWorkflowDataOnApproverRemoval} from '@libs/WorkflowUtils'; import {close} from '@userActions/Modal'; import {dismissAddedWithPrimaryLoginMessages} from '@userActions/Policy/Policy'; @@ -491,10 +492,12 @@ function WorkspaceMembersPage({personalDetails, route, policy, currentUserPerson isPolicyAdmin, ]); - const filterMember = useCallback( - (memberOption: MemberOption, searchQuery: string) => !!memberOption.text?.toLowerCase().includes(searchQuery) || !!memberOption.alternateText?.toLowerCase().includes(searchQuery), - [], - ); + const filterMember = useCallback((memberOption: MemberOption, searchQuery: string) => { + const memberText = StringUtils.normalize(memberOption.text?.toLowerCase() ?? ''); + const alternateText = StringUtils.normalize(memberOption.alternateText?.toLowerCase() ?? ''); + const normalizedSearchQuery = StringUtils.normalize(searchQuery); + return memberText.includes(normalizedSearchQuery) || alternateText.includes(normalizedSearchQuery); + }, []); const sortMembers = useCallback((memberOptions: MemberOption[]) => sortAlphabetically(memberOptions, 'text'), []); const [inputValue, setInputValue, filteredData] = useSearchResults(data, filterMember, sortMembers); diff --git a/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx b/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx index 23ccdbccde48..ce6a7e4e6024 100644 --- a/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx +++ b/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx @@ -46,6 +46,7 @@ import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import type {WorkspaceSplitNavigatorParamList} from '@libs/Navigation/types'; import {getConnectedIntegration, getCurrentConnectionName, hasAccountingConnections, shouldShowSyncError} from '@libs/PolicyUtils'; +import StringUtils from '@libs/StringUtils'; import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; import {close} from '@userActions/Modal'; import {clearCategoryErrors, deleteWorkspaceCategories, downloadCategoriesCSV, openPolicyCategoriesPage, setWorkspaceCategoryEnabled} from '@userActions/Policy/Category'; @@ -132,7 +133,7 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) { acc.push({ text: value.name, keyForList: value.name, - isSelected: !!selectedCategories.includes(value.name) && canSelectMultiple, + isSelected: selectedCategories.includes(value.name) && canSelectMultiple, isDisabled, pendingAction: value.pendingAction, errors: value.errors ?? undefined, @@ -151,7 +152,10 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) { }, [policyCategories, isOffline, selectedCategories, canSelectMultiple, translate, updateWorkspaceRequiresCategory]); const filterCategory = useCallback((categoryOption: PolicyOption, searchInput: string) => { - return !!categoryOption.text?.toLowerCase().includes(searchInput) || !!categoryOption.alternateText?.toLowerCase().includes(searchInput); + const categoryText = StringUtils.normalize(categoryOption.text?.toLowerCase() ?? ''); + const alternateText = StringUtils.normalize(categoryOption.alternateText?.toLowerCase() ?? ''); + const normalizedSearchInput = StringUtils.normalize(searchInput); + return categoryText.includes(normalizedSearchInput) || alternateText.includes(normalizedSearchInput); }, []); const sortCategories = useCallback((data: PolicyOption[]) => { return lodashSortBy(data, 'text', localeCompare) as PolicyOption[]; diff --git a/src/pages/workspace/distanceRates/PolicyDistanceRatesPage.tsx b/src/pages/workspace/distanceRates/PolicyDistanceRatesPage.tsx index 69fdf3df33f3..802ec0312efe 100644 --- a/src/pages/workspace/distanceRates/PolicyDistanceRatesPage.tsx +++ b/src/pages/workspace/distanceRates/PolicyDistanceRatesPage.tsx @@ -38,6 +38,7 @@ import goBackFromWorkspaceCentralScreen from '@libs/Navigation/helpers/goBackFro import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import {getDistanceRateCustomUnit} from '@libs/PolicyUtils'; +import StringUtils from '@libs/StringUtils'; import type {WorkspaceSplitNavigatorParamList} from '@navigation/types'; import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; import ButtonWithDropdownMenu from '@src/components/ButtonWithDropdownMenu'; @@ -178,7 +179,11 @@ function PolicyDistanceRatesPage({ [customUnitRates, translate, customUnit, selectedDistanceRates, canSelectMultiple, policy?.pendingAction, updateDistanceRateEnabled], ); - const filterRate = useCallback((rate: RateForList, searchInput: string) => !!rate.text?.toLowerCase().includes(searchInput.toLowerCase()), []); + const filterRate = useCallback((rate: RateForList, searchInput: string) => { + const rateText = StringUtils.normalize(rate.text?.toLowerCase() ?? ''); + const normalizedSearchInput = StringUtils.normalize(searchInput.toLowerCase()); + return rateText.includes(normalizedSearchInput); + }, []); const sortRates = useCallback((rates: RateForList[]) => rates.sort((a, b) => (a.rate ?? 0) - (b.rate ?? 0)), []); const [inputValue, setInputValue, filteredDistanceRatesList] = useSearchResults(distanceRatesList, filterRate, sortRates); diff --git a/src/pages/workspace/perDiem/WorkspacePerDiemPage.tsx b/src/pages/workspace/perDiem/WorkspacePerDiemPage.tsx index a3d4271756c8..55851768d383 100644 --- a/src/pages/workspace/perDiem/WorkspacePerDiemPage.tsx +++ b/src/pages/workspace/perDiem/WorkspacePerDiemPage.tsx @@ -42,6 +42,7 @@ import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavig import type {WorkspaceSplitNavigatorParamList} from '@libs/Navigation/types'; import {hasEnabledOptions} from '@libs/OptionsListUtils'; import {getPerDiemCustomUnit} from '@libs/PolicyUtils'; +import StringUtils from '@libs/StringUtils'; import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; import {openExternalLink} from '@userActions/Link'; import {turnOffMobileSelectionMode} from '@userActions/MobileSelectionMode'; @@ -195,7 +196,11 @@ function WorkspacePerDiemPage({route}: WorkspacePerDiemPageProps) { [allSubRates, selectedPerDiem, canSelectMultiple, styles.flex2, styles.alignItemsStart, styles.textSupporting, styles.label, styles.pl2, styles.alignSelfEnd], ); - const filterRate = useCallback((rate: PolicyOption, searchInput: string) => !!rate.text?.toLowerCase().includes(searchInput), []); + const filterRate = useCallback((rate: PolicyOption, searchInput: string) => { + const rateText = StringUtils.normalize(rate.text?.toLowerCase() ?? ''); + const normalizedSearchInput = StringUtils.normalize(searchInput.toLowerCase()); + return rateText.includes(normalizedSearchInput); + }, []); const sortRates = useCallback((rates: PolicyOption[]) => lodashSortBy(rates, 'text', localeCompare) as PolicyOption[], []); const [inputValue, setInputValue, filteredSubRatesList] = useSearchResults(subRatesList, filterRate, sortRates); diff --git a/src/pages/workspace/reportFields/ReportFieldsListValuesPage.tsx b/src/pages/workspace/reportFields/ReportFieldsListValuesPage.tsx index 4d01113571ea..012922296792 100644 --- a/src/pages/workspace/reportFields/ReportFieldsListValuesPage.tsx +++ b/src/pages/workspace/reportFields/ReportFieldsListValuesPage.tsx @@ -38,6 +38,7 @@ import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import {hasAccountingConnections as hasAccountingConnectionsPolicyUtils} from '@libs/PolicyUtils'; import {getReportFieldKey} from '@libs/ReportUtils'; +import StringUtils from '@libs/StringUtils'; import type {SettingsNavigatorParamList} from '@navigation/types'; import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; import type {WithPolicyAndFullscreenLoadingProps} from '@pages/workspace/withPolicyAndFullscreenLoading'; @@ -138,7 +139,11 @@ function ReportFieldsListValuesPage({ [canSelectMultiple, disabledListValues, listValues, selectedValues, translate, updateReportFieldListValueEnabled], ); - const filterListValue = useCallback((item: ValueListItem, searchInput: string) => !!item.text?.toLowerCase().includes(searchInput.toLowerCase()), []); + const filterListValue = useCallback((item: ValueListItem, searchInput: string) => { + const itemText = StringUtils.normalize(item.text?.toLowerCase() ?? ''); + const normalizedSearchInput = StringUtils.normalize(searchInput.toLowerCase()); + return itemText.includes(normalizedSearchInput); + }, []); const sortListValues = useCallback((values: ValueListItem[]) => values.sort((a, b) => localeCompare(a.value, b.value)), []); const [inputValue, setInputValue, filteredListValues] = useSearchResults(data, filterListValue, sortListValues); diff --git a/src/pages/workspace/tags/WorkspaceTagsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsPage.tsx index fab5709f22ec..1b4c72095239 100644 --- a/src/pages/workspace/tags/WorkspaceTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsPage.tsx @@ -53,6 +53,7 @@ import { isMultiLevelTags as isMultiLevelTagsPolicyUtils, shouldShowSyncError, } from '@libs/PolicyUtils'; +import StringUtils from '@libs/StringUtils'; import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; import {close} from '@userActions/Modal'; import CONST from '@src/CONST'; @@ -209,7 +210,12 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) { })); }, [isMultiLevelTags, policyTagLists, selectedTags, canSelectMultiple, translate, updateWorkspaceRequiresTag, updateWorkspaceTagEnabled]); - const filterTag = useCallback((tag: TagListItem, searchInput: string) => !!tag.text?.toLowerCase().includes(searchInput) || !!tag.value?.toLowerCase().includes(searchInput), []); + const filterTag = useCallback((tag: TagListItem, searchInput: string) => { + const tagText = StringUtils.normalize(tag.text?.toLowerCase() ?? ''); + const tagValue = StringUtils.normalize(tag.value?.toLowerCase() ?? ''); + const normalizeSearchInput = StringUtils.normalize(searchInput.toLowerCase()); + return tagText.includes(normalizeSearchInput) || tagValue.includes(normalizeSearchInput); + }, []); const sortTags = useCallback((tags: TagListItem[]) => lodashSortBy(tags, 'value', localeCompare) as TagListItem[], []); const [inputValue, setInputValue, filteredTagList] = useSearchResults(tagList, filterTag, sortTags); diff --git a/src/pages/workspace/tags/WorkspaceViewTagsPage.tsx b/src/pages/workspace/tags/WorkspaceViewTagsPage.tsx index caee3ea059bd..96bb18b5ed01 100644 --- a/src/pages/workspace/tags/WorkspaceViewTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceViewTagsPage.tsx @@ -40,6 +40,7 @@ import localeCompare from '@libs/LocaleCompare'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import {getCleanedTagName, getTagListName, hasDependentTags as hasDependentTagsPolicyUtils, isMultiLevelTags as isMultiLevelTagsPolicyUtils} from '@libs/PolicyUtils'; +import StringUtils from '@libs/StringUtils'; import type {SettingsNavigatorParamList} from '@navigation/types'; import NotFoundPage from '@pages/ErrorPage/NotFoundPage'; import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; @@ -131,7 +132,12 @@ function WorkspaceViewTagsPage({route}: WorkspaceViewTagsProps) { [currentPolicyTag?.tags, selectedTags, canSelectMultiple, translate, updateWorkspaceTagEnabled], ); - const filterTag = useCallback((tag: TagListItem, searchInput: string) => !!tag.text?.toLowerCase().includes(searchInput) || !!tag.value?.toLowerCase().includes(searchInput), []); + const filterTag = useCallback((tag: TagListItem, searchInput: string) => { + const tagText = StringUtils.normalize(tag.text?.toLowerCase() ?? ''); + const tagValue = StringUtils.normalize(tag.text?.toLowerCase() ?? ''); + const normalizedSearchInput = StringUtils.normalize(searchInput.toLowerCase() ?? ''); + return tagText.includes(normalizedSearchInput) || tagValue.includes(normalizedSearchInput); + }, []); const sortTags = useCallback((tags: TagListItem[]) => tags.sort((tagA, tagB) => localeCompare(tagA.value, tagB.value)), []); const [inputValue, setInputValue, filteredTagList] = useSearchResults(tagList, filterTag, sortTags); diff --git a/src/pages/workspace/taxes/WorkspaceTaxesPage.tsx b/src/pages/workspace/taxes/WorkspaceTaxesPage.tsx index d28469d97744..306506a41c2d 100644 --- a/src/pages/workspace/taxes/WorkspaceTaxesPage.tsx +++ b/src/pages/workspace/taxes/WorkspaceTaxesPage.tsx @@ -42,6 +42,7 @@ import { hasAccountingConnections as hasAccountingConnectionsPolicyUtils, shouldShowSyncError, } from '@libs/PolicyUtils'; +import StringUtils from '@libs/StringUtils'; import type {WorkspaceSplitNavigatorParamList} from '@navigation/types'; import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; import type {WithPolicyAndFullscreenLoadingProps} from '@pages/workspace/withPolicyAndFullscreenLoading'; @@ -184,9 +185,10 @@ function WorkspaceTaxesPage({ }, [policy, textForDefault, selectedTaxesIDs, canSelectMultiple, translate, updateWorkspaceTaxEnabled]); const filterTax = useCallback((tax: ListItem, searchInput: string) => { - const taxName = tax.text?.toLowerCase() ?? ''; - const taxAlternateText = tax.alternateText?.toLowerCase() ?? ''; - return taxName.includes(searchInput) || taxAlternateText.includes(searchInput); + const taxName = StringUtils.normalize(tax.text?.toLowerCase() ?? ''); + const taxAlternateText = StringUtils.normalize(tax.alternateText?.toLowerCase() ?? ''); + const normalizedSearchInput = StringUtils.normalize(searchInput.toLowerCase() ?? ''); + return taxName.includes(normalizedSearchInput) || taxAlternateText.includes(normalizedSearchInput); }, []); const sortTaxes = useCallback((taxes: ListItem[]) => { return taxes.sort((a, b) => {