-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Draft
marcaaron
wants to merge
38
commits into
main
Choose a base branch
from
marcaaron-nl-filters-ui
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
38 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 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
106 changes: 106 additions & 0 deletions
106
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,106 @@ | ||
| /** | ||
| * 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 FormAlertWithSubmitButton from '@components/FormAlertWithSubmitButton'; | ||
| 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 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 React, {useState} from 'react'; | ||
| import {View} from 'react-native'; | ||
|
|
||
| type SearchNLFilterContentProps = { | ||
|
marcaaron marked this conversation as resolved.
|
||
| /** 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>; | ||
| }; | ||
|
|
||
| function SearchNLFilterContent({onSuccess, containerStyle, buttonContainerStyle}: 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 queryPolicyID = getFilterFromQuery(currentSearchQueryJSON, CONST.SEARCH.SYNTAX_FILTER_KEYS.POLICY_ID).value?.at(0); | ||
| const policyID = queryPolicyID ?? 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, 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} | ||
| autoFocus | ||
| multiline | ||
| containerStyles={[styles.flex1]} | ||
| touchableInputWrapperStyle={[styles.flex1]} | ||
| textInputContainerStyles={[styles.flex1]} | ||
| inputStyle={[styles.flex1]} | ||
| /> | ||
| </View> | ||
| <FormAlertWithSubmitButton | ||
| buttonText={translate('search.filters.describeSearch.buttonText')} | ||
| containerStyles={buttonContainerStyle ?? [styles.m4, styles.mb5]} | ||
| isLoading={isLoading} | ||
| isAlertVisible={!!errorMessage} | ||
| message={errorMessage} | ||
| onSubmit={handleSubmit} | ||
| isDisabled={!nlQuery.trim() || isLoading} | ||
| /> | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| 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
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.