From f889e704596defc90287b318e1067d2b7eafae4a Mon Sep 17 00:00:00 2001 From: rory Date: Thu, 8 May 2025 15:52:03 -0700 Subject: [PATCH 1/3] Fix spaces not working in search bar on members page --- src/libs/StringUtils.ts | 17 +++++++++++++++++ src/pages/workspace/WorkspaceMembersPage.tsx | 11 +++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/libs/StringUtils.ts b/src/libs/StringUtils.ts index baa3ed594b43..5cabed26618f 100644 --- a/src/libs/StringUtils.ts +++ b/src/libs/StringUtils.ts @@ -74,6 +74,22 @@ function normalizeAccents(text: string) { return text.normalize('NFD').replace(/[\u0300-\u036f]/g, ''); } +/** + * Normalize a string by: + * - removing diacritical marks + * - Removing non-alphabetic and non-latin characters from a string + * - Removing invisible characters + * - normalizing space-like characters into normal spaces + * - collapsing whitespaces + * - trimming + */ +function normalize(text: string): string { + return removeInvisibleCharacters(sanitizeString(text)) + .replace(/[\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000]/g, ' ') // space-like -> ' ' + .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); From 7ce595a3a148dfa44b9967d34a0ef60a28de563d Mon Sep 17 00:00:00 2001 From: rory Date: Thu, 8 May 2025 16:11:41 -0700 Subject: [PATCH 2/3] Implement the same fix for all other usages of useSearchResults --- src/libs/CardUtils.ts | 17 ++++++++++++----- .../categories/WorkspaceCategoriesPage.tsx | 8 ++++++-- .../distanceRates/PolicyDistanceRatesPage.tsx | 7 ++++++- .../workspace/perDiem/WorkspacePerDiemPage.tsx | 7 ++++++- .../reportFields/ReportFieldsListValuesPage.tsx | 7 ++++++- src/pages/workspace/tags/WorkspaceTagsPage.tsx | 8 +++++++- .../workspace/tags/WorkspaceViewTagsPage.tsx | 8 +++++++- .../workspace/taxes/WorkspaceTaxesPage.tsx | 7 ++++--- 8 files changed, 54 insertions(+), 15 deletions(-) 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 { - 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..3dd4b4a13cc2 100644 --- a/src/pages/workspace/taxes/WorkspaceTaxesPage.tsx +++ b/src/pages/workspace/taxes/WorkspaceTaxesPage.tsx @@ -184,9 +184,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) => { From 61d0bdb7288f72a0173d80e6bf698b7064136eb8 Mon Sep 17 00:00:00 2001 From: rory Date: Thu, 8 May 2025 16:19:28 -0700 Subject: [PATCH 3/3] Fix types --- src/pages/workspace/categories/WorkspaceCategoriesPage.tsx | 4 ++-- src/pages/workspace/taxes/WorkspaceTaxesPage.tsx | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx b/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx index 597bb34d7b2a..ce6a7e4e6024 100644 --- a/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx +++ b/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx @@ -152,8 +152,8 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) { }, [policyCategories, isOffline, selectedCategories, canSelectMultiple, translate, updateWorkspaceRequiresCategory]); const filterCategory = useCallback((categoryOption: PolicyOption, searchInput: string) => { - const categoryText = StringUtils.normalize(categoryOption.text?.toLowerCase()); - const alternateText = StringUtils.normalize(categoryOption.alternateText?.toLowerCase()); + 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); }, []); diff --git a/src/pages/workspace/taxes/WorkspaceTaxesPage.tsx b/src/pages/workspace/taxes/WorkspaceTaxesPage.tsx index 3dd4b4a13cc2..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';