-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Add search input field to top of "Add unreported expense" screen #70280
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
11 commits
Select commit
Hold shift + click to select a range
2e86466
feat: add search bar
lorretheboy 8aa5d7b
Merge branch 'main' of https://github.com/Expensify/App into fix/69978
lorretheboy 60aaf2b
fix: search issue
lorretheboy 7cddcd6
Merge branch 'main' of https://github.com/Expensify/App into fix/69978
lorretheboy 7e55a40
Merge branch 'main' of https://github.com/Expensify/App into fix/69978
lorretheboy fd80c6d
fix: selection issue
lorretheboy 354c743
fix: conflicts
lorretheboy 30c7aaf
chore: add icons
lorretheboy f8aae4d
Merge branch 'main' of https://github.com/Expensify/App into fix/69978
lorretheboy 95d06d8
feat: new requirements
lorretheboy 0c18a7b
fix: lint
lorretheboy 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,20 +10,23 @@ import ScreenWrapper from '@components/ScreenWrapper'; | |
| import SelectionList from '@components/SelectionListWithSections'; | ||
| import type {ListItem, SectionListDataType, SelectionListHandle} from '@components/SelectionListWithSections/types'; | ||
| import UnreportedExpensesSkeleton from '@components/Skeletons/UnreportedExpensesSkeleton'; | ||
| import useDebouncedState from '@hooks/useDebouncedState'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useNetwork from '@hooks/useNetwork'; | ||
| import useOnyx from '@hooks/useOnyx'; | ||
| import usePolicy from '@hooks/usePolicy'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import {fetchUnreportedExpenses} from '@libs/actions/UnreportedExpenses'; | ||
| import {convertToDisplayString} from '@libs/CurrencyUtils'; | ||
| import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID'; | ||
| import interceptAnonymousUser from '@libs/interceptAnonymousUser'; | ||
| import type {AddUnreportedExpensesParamList} from '@libs/Navigation/types'; | ||
| import Permissions from '@libs/Permissions'; | ||
| import {canSubmitPerDiemExpenseFromWorkspace, getPerDiemCustomUnit} from '@libs/PolicyUtils'; | ||
| import {isIOUReport} from '@libs/ReportUtils'; | ||
| import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils'; | ||
| import {createUnreportedExpenseSections, isPerDiemRequest} from '@libs/TransactionUtils'; | ||
| import tokenizedSearch from '@libs/tokenizedSearch'; | ||
| import {createUnreportedExpenseSections, getAmount, getCurrency, getDescription, getMerchant, isPerDiemRequest} from '@libs/TransactionUtils'; | ||
| import Navigation from '@navigation/Navigation'; | ||
| import type {PlatformStackScreenProps} from '@navigation/PlatformStackNavigation/types'; | ||
| import {convertBulkTrackedExpensesToIOU, startMoneyRequest} from '@userActions/IOU'; | ||
|
|
@@ -45,6 +48,7 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) { | |
| const [offset, setOffset] = useState(0); | ||
| const {isOffline} = useNetwork(); | ||
| const [selectedIds, setSelectedIds] = useState(new Set<string>()); | ||
| const [searchValue, debouncedSearchValue, setSearchValue] = useDebouncedState(''); | ||
|
|
||
| const {reportID, backToReport} = route.params; | ||
| const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {canBeMissing: true}); | ||
|
|
@@ -106,11 +110,50 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) { | |
|
|
||
| const styles = useThemeStyles(); | ||
| const selectionListRef = useRef<SelectionListHandle>(null); | ||
| const sections: Array<SectionListDataType<Transaction & ListItem>> = useMemo(() => createUnreportedExpenseSections(transactions), [transactions]); | ||
| const filteredTransactions = useMemo(() => { | ||
| if (!debouncedSearchValue.trim()) { | ||
| return transactions; | ||
| } | ||
|
|
||
| return tokenizedSearch(transactions, debouncedSearchValue, (transaction) => { | ||
| const searchableFields: string[] = []; | ||
|
|
||
| const merchant = getMerchant(transaction); | ||
| if (merchant !== CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT) { | ||
| searchableFields.push(merchant); | ||
| } | ||
|
|
||
| const description = getDescription(transaction); | ||
| if (description.trim()) { | ||
| searchableFields.push(description); | ||
| } | ||
|
|
||
| const amount = getAmount(transaction); | ||
| const currency = getCurrency(transaction); | ||
| const formattedAmount = convertToDisplayString(amount, currency); | ||
| searchableFields.push(formattedAmount); | ||
|
Comment on lines
+119
to
+134
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should have added a condition to normalize the amount. Not doing so caused #72803 |
||
|
|
||
| return searchableFields; | ||
| }); | ||
| }, [transactions, debouncedSearchValue]); | ||
|
|
||
| const sections: Array<SectionListDataType<Transaction & ListItem>> = useMemo(() => createUnreportedExpenseSections(filteredTransactions), [filteredTransactions]); | ||
|
|
||
| const shouldShowTextInput = useMemo(() => { | ||
| return transactions.length >= CONST.SEARCH_ITEM_LIMIT; | ||
| }, [transactions.length]); | ||
|
|
||
| const headerMessage = useMemo(() => { | ||
| if (debouncedSearchValue.trim() && sections.at(0)?.data.length === 0) { | ||
| return translate('common.noResultsFound'); | ||
| } | ||
| return ''; | ||
| }, [debouncedSearchValue, sections, translate]); | ||
|
|
||
| const thereIsNoUnreportedTransaction = !((sections.at(0)?.data.length ?? 0) > 0); | ||
| const hasSearchTerm = debouncedSearchValue.trim().length > 0; | ||
| const isShowingEmptyState = !hasSearchTerm && transactions.length === 0; | ||
|
|
||
| if (thereIsNoUnreportedTransaction && isLoadingUnreportedTransactions) { | ||
| if (isShowingEmptyState && isLoadingUnreportedTransactions) { | ||
| return ( | ||
| <ScreenWrapper | ||
| shouldEnableKeyboardAvoidingView={false} | ||
|
|
@@ -129,7 +172,7 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) { | |
| ); | ||
| } | ||
|
|
||
| if (thereIsNoUnreportedTransaction) { | ||
| if (isShowingEmptyState) { | ||
| return ( | ||
| <ScreenWrapper | ||
| shouldEnableKeyboardAvoidingView={false} | ||
|
|
@@ -203,7 +246,12 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) { | |
| return newIds; | ||
| }); | ||
| }} | ||
| shouldShowTextInput={false} | ||
| isSelected={(item) => selectedIds.has(item.transactionID)} | ||
| shouldShowTextInput={shouldShowTextInput} | ||
| textInputValue={searchValue} | ||
| textInputLabel={shouldShowTextInput ? translate('iou.findExpense') : undefined} | ||
| onChangeText={setSearchValue} | ||
| headerMessage={headerMessage} | ||
| canSelectMultiple | ||
| sections={sections} | ||
| ListItem={UnreportedExpenseListItem} | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://expensify.slack.com/archives/C01GTK53T8Q/p1759671500657619
Confirming here...