-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Make SearchMoneyRequestReportPage show single transaction view correctly #59735
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
Changes from all commits
0492dc8
e43f322
c89bf11
ad749ec
4a9aa6b
33f6b0a
2421215
fdf60ae
4f35763
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import React, {useCallback} from 'react'; | ||
| import {InteractionManager, View} from 'react-native'; | ||
| import type {OnyxEntry} from 'react-native-onyx'; | ||
| import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; | ||
| import {useOnyx} from 'react-native-onyx'; | ||
| import HeaderGap from '@components/HeaderGap'; | ||
| import MoneyReportHeader from '@components/MoneyReportHeader'; | ||
|
|
@@ -15,10 +15,11 @@ import {removeFailedReport} from '@libs/actions/Report'; | |
| import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID'; | ||
| import Log from '@libs/Log'; | ||
| import navigationRef from '@libs/Navigation/navigationRef'; | ||
| import {isMoneyRequestAction} from '@libs/ReportActionsUtils'; | ||
| import {getIOUActionForTransactionID, getOneTransactionThreadReportID, isDeletedParentAction, isMoneyRequestAction} from '@libs/ReportActionsUtils'; | ||
| import {canEditReportAction, getReportOfflinePendingActionAndErrors} from '@libs/ReportUtils'; | ||
| import {buildCannedSearchQuery} from '@libs/SearchQueryUtils'; | ||
| import Navigation from '@navigation/Navigation'; | ||
| import ReportActionsView from '@pages/home/report/ReportActionsView'; | ||
| import ReportFooter from '@pages/home/report/ReportFooter'; | ||
| import NAVIGATORS from '@src/NAVIGATORS'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
|
|
@@ -81,6 +82,20 @@ function getParentReportAction(parentReportActions: OnyxEntry<OnyxTypes.ReportAc | |
| return parentReportActions[parentReportActionID]; | ||
| } | ||
|
|
||
| function selectTransactionsForReportID(transactions: OnyxCollection<OnyxTypes.Transaction>, reportID: string | undefined, reportActions: OnyxTypes.ReportAction[]) { | ||
| if (!reportID) { | ||
| return []; | ||
| } | ||
|
|
||
| return Object.values(transactions ?? {}).filter((transaction): transaction is OnyxTypes.Transaction => { | ||
| if (!transaction) { | ||
| return false; | ||
| } | ||
| const action = getIOUActionForTransactionID(reportActions, transaction.transactionID); | ||
| return transaction.reportID === reportID && !isDeletedParentAction(action); | ||
| }); | ||
| } | ||
|
|
||
| function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayReportFooter, backToRoute}: MoneyRequestReportViewProps) { | ||
| const styles = useThemeStyles(); | ||
| const {isOffline} = useNetwork(); | ||
|
|
@@ -92,6 +107,12 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe | |
| const {reportPendingAction, reportErrors} = getReportOfflinePendingActionAndErrors(report); | ||
|
|
||
| const {reportActions, hasNewerActions, hasOlderActions} = usePaginatedReportActions(reportID); | ||
| const transactionThreadReportID = getOneTransactionThreadReportID(reportID, reportActions ?? [], isOffline); | ||
|
|
||
| const [transactions = []] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, { | ||
| selector: (allTransactions): OnyxTypes.Transaction[] => selectTransactionsForReportID(allTransactions, reportID, reportActions), | ||
| }); | ||
| const shouldUseSingleTransactionView = transactions.length === 1; | ||
|
|
||
| const [parentReportAction] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${getNonEmptyStringOnyxID(report?.parentReportID)}`, { | ||
| canEvict: false, | ||
|
|
@@ -118,6 +139,26 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe | |
| return; | ||
| } | ||
|
|
||
| if (isLoadingApp) { | ||
| return ( | ||
| <View style={styles.flex1}> | ||
| <HeaderGap /> | ||
| <ReportHeaderSkeletonView /> | ||
| <ReportActionsSkeletonView /> | ||
| {shouldDisplayReportFooter ? ( | ||
| <ReportFooter | ||
| report={report} | ||
| reportMetadata={reportMetadata} | ||
| policy={policy} | ||
| pendingAction={reportPendingAction} | ||
| isComposerFullSize={!!isComposerFullSize} | ||
| lastReportAction={lastReportAction} | ||
| /> | ||
| ) : null} | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <View style={styles.flex1}> | ||
| <OfflineWithFeedback | ||
|
|
@@ -130,33 +171,39 @@ function MoneyRequestReportView({report, policy, reportMetadata, shouldDisplayRe | |
| errorRowStyles={[styles.ph5, styles.mv2]} | ||
| > | ||
| <HeaderGap /> | ||
| {!isLoadingApp ? ( | ||
| <MoneyReportHeader | ||
| <MoneyReportHeader | ||
| report={report} | ||
| policy={policy} | ||
| reportActions={reportActions} | ||
| transactionThreadReportID={undefined} | ||
|
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. @SzymczakJ @allgandalf Is there any reason why we pass undefined here? Or this is a mistake Coming from: #60079
Contributor
Author
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. I think it is a mistake. In fact, this is probably something that we forgot to add, because this transactionThreadReportID has been undefined, since the creation of this file. |
||
| shouldDisplayBackButton | ||
| onBackButtonPress={() => { | ||
| if (!backToRoute) { | ||
| goBackFromSearchMoneyRequest(activeWorkspaceID); | ||
| return; | ||
| } | ||
| Navigation.goBack(backToRoute); | ||
| }} | ||
| /> | ||
| {shouldUseSingleTransactionView ? ( | ||
| // This component originally lives in ReportScreen, it is used here to handle the case when the report has a single transaction. Any other case will be handled by MoneyRequestReportActionsList | ||
| <ReportActionsView | ||
| report={report} | ||
| policy={policy} | ||
| reportActions={reportActions} | ||
| transactionThreadReportID={undefined} | ||
| shouldDisplayBackButton | ||
| onBackButtonPress={() => { | ||
| if (!backToRoute) { | ||
| goBackFromSearchMoneyRequest(activeWorkspaceID); | ||
| return; | ||
| } | ||
| Navigation.goBack(backToRoute); | ||
| }} | ||
| isLoadingInitialReportActions={reportMetadata?.isLoadingInitialReportActions} | ||
| hasNewerActions={hasNewerActions} | ||
| hasOlderActions={hasOlderActions} | ||
| parentReportAction={parentReportAction} | ||
| transactionThreadReportID={transactionThreadReportID} | ||
| /> | ||
| ) : ( | ||
| <ReportHeaderSkeletonView /> | ||
| )} | ||
| {!isLoadingApp ? ( | ||
| <MoneyRequestReportActionsList | ||
| report={report} | ||
| transactions={transactions} | ||
| reportActions={reportActions} | ||
| hasOlderActions={hasOlderActions} | ||
| hasNewerActions={hasNewerActions} | ||
| /> | ||
| ) : ( | ||
| <ReportActionsSkeletonView /> | ||
| )} | ||
| {shouldDisplayReportFooter ? ( | ||
| <ReportFooter | ||
|
|
||
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.
I think it's great that you used an early return here instead of a ternary — it really improves readability.