-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into revert-54260-revert-54064-and-53396
- Loading branch information
Showing
41 changed files
with
1,535 additions
and
182 deletions.
There are no files selected for viewing
Submodule Mobile-Expensify
updated
from f370c5 to 768d69
This file contains 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
217 changes: 128 additions & 89 deletions
217
...rticles/expensify-classic/connect-credit-cards/company-cards/Troubleshooting.md
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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,113 @@ | ||
import {useMemo} from 'react'; | ||
import FastSearch from '@libs/FastSearch'; | ||
import * as OptionsListUtils from '@libs/OptionsListUtils'; | ||
|
||
type AllOrSelectiveOptions = OptionsListUtils.ReportAndPersonalDetailOptions | OptionsListUtils.Options; | ||
|
||
type Options = { | ||
includeUserToInvite: boolean; | ||
}; | ||
|
||
const emptyResult = { | ||
personalDetails: [], | ||
recentReports: [], | ||
}; | ||
|
||
// You can either use this to search within report and personal details options | ||
function useFastSearchFromOptions( | ||
options: OptionsListUtils.ReportAndPersonalDetailOptions, | ||
config?: {includeUserToInvite: false}, | ||
): (searchInput: string) => OptionsListUtils.ReportAndPersonalDetailOptions; | ||
// Or you can use this to include the user invite option. This will require passing all options | ||
function useFastSearchFromOptions(options: OptionsListUtils.Options, config?: {includeUserToInvite: true}): (searchInput: string) => OptionsListUtils.Options; | ||
|
||
/** | ||
* Hook for making options from OptionsListUtils searchable with FastSearch. | ||
* Builds a suffix tree and returns a function to search in it. | ||
* | ||
* @example | ||
* ``` | ||
* const options = OptionsListUtils.getSearchOptions(...); | ||
* const filterOptions = useFastSearchFromOptions(options); | ||
*/ | ||
function useFastSearchFromOptions( | ||
options: OptionsListUtils.ReportAndPersonalDetailOptions | OptionsListUtils.Options, | ||
{includeUserToInvite}: Options = {includeUserToInvite: false}, | ||
): (searchInput: string) => AllOrSelectiveOptions { | ||
const findInSearchTree = useMemo(() => { | ||
const fastSearch = FastSearch.createFastSearch([ | ||
{ | ||
data: options.personalDetails, | ||
toSearchableString: (option) => { | ||
const displayName = option.participantsList?.[0]?.displayName ?? ''; | ||
return [option.login ?? '', option.login !== displayName ? displayName : ''].join(); | ||
}, | ||
uniqueId: (option) => option.login, | ||
}, | ||
{ | ||
data: options.recentReports, | ||
toSearchableString: (option) => { | ||
const searchStringForTree = [option.text ?? '', option.login ?? '']; | ||
|
||
if (option.isThread) { | ||
if (option.alternateText) { | ||
searchStringForTree.push(option.alternateText); | ||
} | ||
} else if (!!option.isChatRoom || !!option.isPolicyExpenseChat) { | ||
if (option.subtitle) { | ||
searchStringForTree.push(option.subtitle); | ||
} | ||
} | ||
|
||
return searchStringForTree.join(); | ||
}, | ||
}, | ||
]); | ||
|
||
function search(searchInput: string): AllOrSelectiveOptions { | ||
const searchWords = searchInput.split(' ').sort(); // asc sorted | ||
const longestSearchWord = searchWords.at(searchWords.length - 1); // longest word is the last element | ||
if (!longestSearchWord) { | ||
return emptyResult; | ||
} | ||
|
||
// The user might separated words with spaces to do a search such as: "jo d" -> "john doe" | ||
// With the suffix search tree you can only search for one word at a time. Its most efficient to search for the longest word, | ||
// (as this will limit the results the most) and then afterwards run a quick filter on the results to see if the other words are present. | ||
let [personalDetails, recentReports] = fastSearch.search(longestSearchWord); | ||
|
||
if (searchWords.length > 1) { | ||
personalDetails = personalDetails.filter((pd) => OptionsListUtils.isSearchStringMatch(searchInput, pd.text)); | ||
recentReports = recentReports.filter((rr) => OptionsListUtils.isSearchStringMatch(searchInput, rr.text)); | ||
} | ||
|
||
if (includeUserToInvite && 'currentUserOption' in options) { | ||
const userToInvite = OptionsListUtils.filterUserToInvite( | ||
{ | ||
...options, | ||
personalDetails, | ||
recentReports, | ||
}, | ||
searchInput, | ||
); | ||
return { | ||
personalDetails, | ||
recentReports, | ||
userToInvite, | ||
currentUserOption: options.currentUserOption, | ||
}; | ||
} | ||
|
||
return { | ||
personalDetails, | ||
recentReports, | ||
}; | ||
} | ||
|
||
return search; | ||
}, [includeUserToInvite, options]); | ||
|
||
return findInSearchTree; | ||
} | ||
|
||
export default useFastSearchFromOptions; |
This file contains 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.