Repository navigation
[Payment due @QichenZhu] Add currencies to amount search filters #104802
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
13 commits
Select commit
Hold shift + click to select a range
e7ba77e
Add optional currencies to amount search filters
luacmartins 7667c81
Merge remote-tracking branch 'origin/main' into cmartins-amount-filte…
luacmartins 54117c2
Reuse money request picker for amount filters
luacmartins 3cc64d8
Default new amount filters to policy currency
luacmartins 3eb09a7
Show Any currency in amount search filters
luacmartins 82f712c
Merge origin/main into cmartins-amount-filter-currency
luacmartins 9a82c30
Shorten any-currency amount filter labels
luacmartins c0901f6
Place Any currency under All in currency picker
luacmartins 6ce26e3
Clarify amount filter currency handling comments
luacmartins 5a4e86a
Address amount filter review feedback
luacmartins 003c0fc
Merge origin/main into cmartins-amount-filter-currency
luacmartins 19a9719
Merge latest origin/main into cmartins-amount-filter-currency
luacmartins f3a8380
Remove vacuous currency picker assertion
luacmartins 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
Some comments aren't visible on the classic Files Changed page.
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
102 changes: 102 additions & 0 deletions
102
src/components/Search/FilterComponents/AmountFilterInput.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,102 @@ | ||
| // Reuses money-request amount entry and currency selection without requiring a filter currency. | ||
| import AmountWithoutCurrencyInput from '@components/AmountWithoutCurrencyInput'; | ||
| import NumberWithSymbolForm from '@components/NumberWithSymbolForm'; | ||
| import type {SearchAmountFilterKeys} from '@components/Search/types'; | ||
| import type {BaseTextInputRef} from '@components/TextInput/BaseTextInput/types'; | ||
|
|
||
| import useLocalize from '@hooks/useLocalize'; | ||
|
|
||
| import {getLocalizedCurrencySymbol} from '@libs/CurrencyUtils'; | ||
| import getAmountFilterInputKeyboard from '@libs/getAmountFilterInputKeyboard'; | ||
| import {supportsAmountFilterCurrency} from '@libs/SearchAmountFilterUtils'; | ||
|
|
||
| import IOURequestStepCurrencyModal from '@pages/iou/request/step/IOURequestStepCurrencyModal'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
|
|
||
| import type {ForwardedRef} from 'react'; | ||
| import type {StyleProp, ViewStyle} from 'react-native'; | ||
|
|
||
| import React, {useState} from 'react'; | ||
| import {View} from 'react-native'; | ||
|
|
||
| type AmountFilterInputProps = { | ||
| ref?: ForwardedRef<BaseTextInputRef>; | ||
| baseFilterKey: SearchAmountFilterKeys; | ||
|
|
||
| /** Amount in major units, regardless of the saved operand's units. */ | ||
| amount: string; | ||
|
|
||
| /** Empty or omitted means Any currency instead of a currency comparison. */ | ||
| currency?: string; | ||
| label: string; | ||
| name?: string; | ||
| autoFocus?: boolean; | ||
| containerStyles?: StyleProp<ViewStyle>; | ||
| onAmountChange: (amount: string) => void; | ||
| onCurrencyChange: (currency: string) => void; | ||
| }; | ||
|
|
||
| function AmountFilterInput({ref, baseFilterKey, amount, currency, label, name, autoFocus, containerStyles, onAmountChange, onCurrencyChange}: AmountFilterInputProps) { | ||
| const {translate, preferredLocale} = useLocalize(); | ||
| const [isCurrencyPickerVisible, setIsCurrencyPickerVisible] = useState(false); | ||
| const [initialAmount] = useState(amount); | ||
|
|
||
| if (!supportsAmountFilterCurrency(baseFilterKey)) { | ||
| return ( | ||
| <AmountWithoutCurrencyInput | ||
| ref={ref} | ||
| containerStyles={containerStyles} | ||
| defaultValue={initialAmount} | ||
| onInputChange={onAmountChange} | ||
| label={label} | ||
| accessibilityLabel={label} | ||
| name={name} | ||
| role={CONST.ROLE.PRESENTATION} | ||
| inputMode={CONST.INPUT_MODE.DECIMAL} | ||
| shouldAllowNegative | ||
| autoFocus={autoFocus} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| const hideCurrencyPicker = () => setIsCurrencyPickerVisible(false); | ||
| const {keyboardType, shouldShowFlipButton} = getAmountFilterInputKeyboard(); | ||
|
|
||
| return ( | ||
| <View style={containerStyles}> | ||
| <NumberWithSymbolForm | ||
| ref={ref} | ||
| displayAsTextInput | ||
| value={amount} | ||
| currency={currency} | ||
| symbol={currency ? (getLocalizedCurrencySymbol(preferredLocale, currency) ?? '') : ''} | ||
| hideSymbol={!currency} | ||
| decimals={CONST.DEFAULT_CURRENCY_DECIMALS} | ||
| label={label} | ||
| testID={name} | ||
| onInputChange={onAmountChange} | ||
| allowNegativeInput | ||
| keyboardType={keyboardType} | ||
| shouldShowFlipButton={shouldShowFlipButton} | ||
| shouldShowCurrencyButton | ||
| currencyButtonLabel={currency || translate('common.any')} | ||
| currencyButtonAccessibilityLabel={[label.trim(), translate('common.selectCurrency'), currency || translate('common.anyCurrency')].join(', ')} | ||
| onCurrencyButtonPress={() => setIsCurrencyPickerVisible(true)} | ||
| shouldShowBigNumberPad={false} | ||
| shouldUseBorderlessButtons | ||
| autoFocus={autoFocus} | ||
| /> | ||
| <IOURequestStepCurrencyModal | ||
| isPickerVisible={isCurrencyPickerVisible} | ||
| hidePickerModal={hideCurrencyPicker} | ||
| headerText={translate('common.selectCurrency')} | ||
| value={currency} | ||
| onInputChange={onCurrencyChange} | ||
| shouldAllowEmptySelection | ||
| /> | ||
|
luacmartins marked this conversation as resolved.
Resolved
|
||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| export default AmountFilterInput; | ||
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.