Repository navigation
[Payment due @truph01] Add natural language filter entry point to Spend page #94217
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
Merged
Changes from all commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
f052f4d
Register ParseExpenseFilters API command and parameters
marcaaron d1004df
Add route and screen registration for NL filter page
marcaaron fa8c23c
Build NL filter screen for SearchNLFilterPage
marcaaron a395095
Add NL filter entry point to AdvancedSearchFilters
marcaaron 892f1b7
Add parseExpenseFilters action and move to SIDE_EFFECT_REQUEST_COMMANDS
marcaaron c25c3ab
Merge origin/main and adapt NL filter to refactored filter architecture
marcaaron 457ece6
Update NL filter page and types to use searchURL returned by Auth Sea…
marcaaron 916d24c
Merge branch 'main' into marcaaron-nl-filters-ui
marcaaron c3e7f5d
Pass policyID from search context to NL filter parser
marcaaron fadc2c1
Use active search query policyID for NL filter category context
marcaaron 45161c2
Fall back to active workspace policyID for NL filter category context
marcaaron e1bad44
Pass client local date to ParseExpenseFilters for accurate relative f…
marcaaron f9d8f3e
Fix typecheck, knip, and missing translations
marcaaron 9fa7090
Add NL filter entry point to wide-screen filters popup
marcaaron c8d3580
Merge branch 'main' into marcaaron-nl-filters-ui
marcaaron f33b75c
Merge remote-tracking branch 'origin/main' into marcaaron-nl-filters-ui
marcaaron ba1fb65
Fix typecheck: remove ref type mismatch, restore bad merge in Workspa…
marcaaron 623215e
Merge branch 'main' into marcaaron-nl-filters-ui
marcaaron d180454
Merge branch 'main' into marcaaron-nl-filters-ui
marcaaron 481f6ee
Fix type error: use getFilterFromQuery to extract policyID from Searc…
marcaaron 006e668
Apply oxfmt formatting to search filter files
marcaaron 0d4f441
Merge branch 'main' into marcaaron-nl-filters-ui
marcaaron f7adec9
Merge remote-tracking branch 'origin/main' into marcaaron-nl-filters-ui
marcaaron 7f7adec
Merge branch 'marcaaron-nl-filters-ui' of github.com:Expensify/App in…
marcaaron 7c71978
Render NL filter inline in popup, fix hover bg, extract shared component
marcaaron de63849
Merge branch 'main' into marcaaron-nl-filters-ui
marcaaron 7ae4e64
Merge remote-tracking branch 'origin/main' into marcaaron-nl-filters-ui
marcaaron 414135e
Merge remote-tracking branch 'origin/main' into marcaaron-nl-filters-ui
marcaaron 3c5e71b
Add file header comment to SearchNLFilterContent
marcaaron 113a9bc
Add file header comment to SearchNLFilterPage
marcaaron 03e4d81
Document props on SearchNLFilterContentProps
marcaaron 2930920
Add catch handler to handleSubmit in SearchNLFilterContent
marcaaron d3f4c98
Add catch handler to parseExpenseFilters in Search.ts
marcaaron dae7cd7
Rename handleFilterHoverIn to selectFilter per review feedback
marcaaron 88461be
Close filters popover before navigating on NL filter success
marcaaron 54eb42d
Fix NL filter popup layout and describe button UX
marcaaron ef3adac
Remove unused maxAutoGrowHeight prop and variables import from Search…
marcaaron 39023ef
Cascade flex: 1 through TextInput hierarchy so NL textarea fills the …
marcaaron ce1b76e
Merge branch 'main' into marcaaron-nl-filters-ui
marcaaron ddc58ae
Update button text. Make input auto expand
marcaaron 9e289e9
Merge remote-tracking branch 'origin/main' into marcaaron-nl-filters-ui
marcaaron f21909f
Update translations and use named variable for max input height
marcaaron abc318b
Merge branch 'main' into marcaaron-nl-filters-ui
marcaaron e55debd
Add ADVANCED_FILTERS_DESCRIBE_RHP to SEARCH_TO_RHP relation
marcaaron c46dadc
Remove duplicate Support auth token login describe block in SessionTest
marcaaron 5a394f4
Add onFocus handler to describe-search pressable for keyboard nav
marcaaron b326108
Skip negated policyID filter when scoping NL parse request
marcaaron fe54a93
Remove duplicate formatCurrentUserToAttendee describe block in IOUUti…
marcaaron 1fea14e
Fix getIconFillColor and getButtonState call signatures in describe b…
marcaaron 5fd7006
Rebuild GitHub Actions bundles after expensify-common update
marcaaron 364862d
Merge remote-tracking branch 'origin/main' into marcaaron-nl-filters-ui
marcaaron f6c969f
Rebuild GitHub Actions bundles with npm-resolved dependencies
marcaaron 4965637
Use MEDIUM-size button in NL filter pane to match other filter panels
marcaaron 10a45ee
Merge origin/main into marcaaron-nl-filters-ui
marcaaron 2680a83
Fix mobile alignment, height, Enter-to-submit, and button disabled state
marcaaron b04e2da
Merge remote-tracking branch 'origin/main' into marcaaron-nl-filters-ui
marcaaron fc165dc
Fix ButtonComposed import and shiftKey type error
marcaaron 6a4e633
Merge branch 'main' into marcaaron-nl-filters-ui
marcaaron 408e3c9
Fix NL filter button height on mobile to match other filter pages
marcaaron 78f1c09
Merge branch 'marcaaron-nl-filters-ui' of github.com:Expensify/App in…
marcaaron 9017eba
Remove policyID prop from FilterList in popup — prop removed in main
marcaaron 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
123 changes: 123 additions & 0 deletions
123
src/components/Search/FilterComponents/AdvancedFilters/SearchNLFilterContent.tsx
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,123 @@ | ||
| /** | ||
| * Renders the natural-language ("Describe your search") input that parses a plain-English | ||
| * query into a structured search URL and navigates the user to the results. | ||
| */ | ||
| import Button from '@components/Button'; | ||
| import FormHelpMessage from '@components/FormHelpMessage'; | ||
| import {useSearchQueryContext} from '@components/Search/SearchContext'; | ||
| import Text from '@components/Text'; | ||
| import TextInput from '@components/TextInput'; | ||
|
|
||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useOnyx from '@hooks/useOnyx'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
|
|
||
| import {parseExpenseFilters} from '@libs/actions/Search'; | ||
| import {getFilterFromQuery} from '@libs/SearchQueryUtils'; | ||
|
|
||
| import variables from '@styles/variables'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import ROUTES from '@src/ROUTES'; | ||
| import type {Route} from '@src/ROUTES'; | ||
|
|
||
| import type {StyleProp, ViewStyle} from 'react-native'; | ||
| import type {ValueOf} from 'type-fest'; | ||
|
|
||
| import React, {useState} from 'react'; | ||
| import {View} from 'react-native'; | ||
|
|
||
| type SearchNLFilterContentProps = { | ||
| /** Called with the destination route once the query is successfully parsed */ | ||
| onSuccess: (route: Route) => void; | ||
|
|
||
| /** Optional style override for the input container */ | ||
| containerStyle?: StyleProp<ViewStyle>; | ||
|
|
||
| /** Optional style override for the submit button container */ | ||
| buttonContainerStyle?: StyleProp<ViewStyle>; | ||
|
|
||
| /** Size of the submit button */ | ||
| size?: Exclude<ValueOf<typeof CONST.BUTTON_SIZE>, typeof CONST.BUTTON_SIZE.SMALL>; | ||
| }; | ||
|
|
||
| function SearchNLFilterContent({onSuccess, containerStyle, buttonContainerStyle, size = CONST.BUTTON_SIZE.MEDIUM}: SearchNLFilterContentProps) { | ||
| const {translate} = useLocalize(); | ||
| const styles = useThemeStyles(); | ||
| const [nlQuery, setNlQuery] = useState(''); | ||
| const [isLoading, setIsLoading] = useState(false); | ||
| const [errorMessage, setErrorMessage] = useState(''); | ||
| const {currentSearchQueryJSON} = useSearchQueryContext(); | ||
| const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID); | ||
|
|
||
| const handleSubmit = () => { | ||
| const trimmedQuery = nlQuery.trim(); | ||
| if (!trimmedQuery) { | ||
| return; | ||
| } | ||
| setIsLoading(true); | ||
| setErrorMessage(''); | ||
| const {value: queryPolicyIDValues, isNegated: isPolicyIDNegated} = getFilterFromQuery(currentSearchQueryJSON, CONST.SEARCH.SYNTAX_FILTER_KEYS.POLICY_ID); | ||
| const policyID = !isPolicyIDNegated && queryPolicyIDValues?.at(0) ? queryPolicyIDValues.at(0) : activePolicyID; | ||
| parseExpenseFilters(trimmedQuery, policyID) | ||
| .then((result) => { | ||
| setIsLoading(false); | ||
| if (!result) { | ||
| return; | ||
| } | ||
| if (result.success) { | ||
| const searchQuery = new URL(result.searchURL).searchParams.get('q') ?? ''; | ||
| onSuccess(ROUTES.SEARCH_ROOT.getRoute({query: searchQuery})); | ||
| } else { | ||
| setErrorMessage(result.message); | ||
| } | ||
| }) | ||
| .catch(() => { | ||
| setIsLoading(false); | ||
| setErrorMessage(translate('common.genericErrorMessage')); | ||
| }); | ||
| }; | ||
|
|
||
| return ( | ||
| <View style={[styles.flex1]}> | ||
| <View style={[styles.ph5, styles.pt4, containerStyle]}> | ||
| <Text style={styles.mb5}>{translate('search.filters.describeSearch.description')}</Text> | ||
| <TextInput | ||
| label={translate('search.filters.describeSearch.inputLabel')} | ||
| accessibilityLabel={translate('search.filters.describeSearch.inputLabel')} | ||
| role={CONST.ROLE.PRESENTATION} | ||
| value={nlQuery} | ||
| onChangeText={setNlQuery} | ||
| onKeyPress={(e) => { | ||
| if (e.nativeEvent.key !== 'Enter' || ('shiftKey' in e.nativeEvent && e.nativeEvent.shiftKey)) { | ||
| return; | ||
| } | ||
| handleSubmit(); | ||
| }} | ||
| autoFocus | ||
| autoGrowHeight | ||
| maxAutoGrowHeight={variables.textInputAutoGrowMaxHeight} | ||
| /> | ||
| </View> | ||
| <View style={buttonContainerStyle ?? [styles.mtAuto, styles.m4, styles.mb5]}> | ||
| <FormHelpMessage | ||
| isError | ||
| message={errorMessage} | ||
| /> | ||
| <Button | ||
| variant={CONST.BUTTON_VARIANT.SUCCESS} | ||
| size={size} | ||
| isLoading={isLoading} | ||
| isDisabled={isLoading} | ||
| onPress={handleSubmit} | ||
| > | ||
| <Button.KeyboardShortcut /> | ||
| <Button.Text>{translate('search.filters.describeSearch.buttonText')}</Button.Text> | ||
| </Button> | ||
| </View> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| export default SearchNLFilterContent; | ||
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
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.