-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Refactor searchMatchUtils out from optionsListUtils #86982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
NikkiWines
merged 5 commits into
Expensify:main
from
software-mansion-labs:fix/newChatPage/dataPreparation/extractSearchMatchUtil
Apr 15, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
65de640
refactor searchMatchUtils out from optionsListUtils
sharabai c7e59ef
Add back lowercase function call
sharabai d932f65
Add tests
sharabai fd15515
Ignore diacritical marks in test files during spellcheck CI
sharabai e975331
add js docs, modify fn names
sharabai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // eslint-disable-next-line @typescript-eslint/no-deprecated | ||
| import {translateLocal} from '@libs/Localize'; | ||
| import CONST from '@src/CONST'; | ||
| import type {SearchOptionData} from './types'; | ||
|
|
||
| type SearchMatchConfig = { | ||
| /** Whether to use toLocaleLowerCase() instead of toLowerCase(), defaults to false */ | ||
| useLocaleLowerCase?: boolean; | ||
|
|
||
| /** | ||
| * Optional callback to transform the concatenated search terms before matching. | ||
| * @param concatenatedSearchTerms - the joined terms string, already lowercased | ||
| */ | ||
| transformSearchText?: (concatenatedSearchTerms: string) => string; | ||
| }; | ||
|
|
||
| /** | ||
| * Includes localized "You"/"Me" so the current user is findable | ||
| * by those terms in any supported language. | ||
| * | ||
| * @returns Raw (not lowercased) terms: display text, login, | ||
| * login with dots stripped before @, and translated "You"/"Me". | ||
| */ | ||
| function getCurrentUserSearchTerms(item: Partial<SearchOptionData>) { | ||
| // eslint-disable-next-line @typescript-eslint/no-deprecated | ||
| return [item.text ?? item.displayName ?? '', item.login ?? '', item.login?.replace(CONST.EMAIL_SEARCH_REGEX, '') ?? '', translateLocal('common.you'), translateLocal('common.me')]; | ||
| } | ||
|
|
||
| /** | ||
| * For the current user, delegates to getCurrentUserSearchTerms. | ||
| * For others, includes display name and login with dots stripped | ||
| * before @ (so "john.doe@" matches "johndoe@"). | ||
| * | ||
| * @returns Raw (not lowercased) terms the person is searchable by. | ||
| */ | ||
| function getPersonalDetailSearchTerms(item: Partial<SearchOptionData>, currentUserAccountID: number) { | ||
| if (item.accountID === currentUserAccountID) { | ||
| return getCurrentUserSearchTerms(item); | ||
| } | ||
| return [item.participantsList?.[0]?.displayName ?? item.displayName ?? '', item.login ?? '', item.login?.replace(CONST.EMAIL_SEARCH_REGEX, '') ?? '']; | ||
| } | ||
|
|
||
| /** | ||
| * Checks whether a personal detail option matches a single search term | ||
| * by comparing against the option's searchable fields (displayName, login, etc.). | ||
| * | ||
| * Expects `searchTerm` to already be lowercased and trimmed. | ||
| */ | ||
| function doesPersonalDetailMatchSearchTerm( | ||
| item: Partial<SearchOptionData>, | ||
| currentUserAccountID: number, | ||
| searchTerm: string, | ||
| {useLocaleLowerCase = false, transformSearchText}: SearchMatchConfig = {}, | ||
| ): boolean { | ||
| const terms = getPersonalDetailSearchTerms(item, currentUserAccountID).join(' '); | ||
| let searchText = useLocaleLowerCase ? terms.toLocaleLowerCase() : terms.toLowerCase(); | ||
|
|
||
| if (transformSearchText) { | ||
| searchText = transformSearchText(searchText); | ||
| } | ||
|
|
||
| return searchText.includes(searchTerm); | ||
| } | ||
|
|
||
| export {getCurrentUserSearchTerms, getPersonalDetailSearchTerms, doesPersonalDetailMatchSearchTerm}; | ||
| export type {SearchMatchConfig}; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.