Repository navigation
Fix transaction thread arrows navigation #63867
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
50f91b4
3d06ad4
b2bb073
3ed1b16
8a8b37b
a31b730
099dcfc
aef3c67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,10 +11,12 @@ import useLocalize from '@hooks/useLocalize'; | |
| import useResponsiveLayout from '@hooks/useResponsiveLayout'; | ||
| import useTheme from '@hooks/useTheme'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import {getReportIDForTransaction} from '@libs/MoneyRequestReportUtils'; | ||
| import Navigation from '@libs/Navigation/Navigation'; | ||
| import {isTransactionAmountTooLong, isTransactionTaxAmountTooLong} from '@libs/SearchUIUtils'; | ||
| import shouldShowTransactionYear from '@libs/TransactionUtils/shouldShowTransactionYear'; | ||
| import variables from '@styles/variables'; | ||
| import {setActiveTransactionThreadIDs} from '@userActions/TransactionThreadNavigation'; | ||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import ROUTES from '@src/ROUTES'; | ||
|
|
@@ -74,14 +76,14 @@ function ReportListItem<TItem extends ListItem>({ | |
| const openReportInRHP = (transactionItem: TransactionListItemType) => { | ||
| const backTo = Navigation.getActiveRoute(); | ||
|
|
||
| const isFromSelfDM = transactionItem.reportID === CONST.REPORT.UNREPORTED_REPORT_ID; | ||
| const reportID = getReportIDForTransaction(transactionItem); | ||
| const siblingTransactionThreadIDs = reportItem.transactions.map(getReportIDForTransaction); | ||
|
|
||
| const reportID = | ||
| (!transactionItem.isFromOneTransactionReport || isFromSelfDM) && transactionItem.transactionThreadReportID !== CONST.REPORT.UNREPORTED_REPORT_ID | ||
| ? transactionItem.transactionThreadReportID | ||
| : transactionItem.reportID; | ||
|
|
||
| Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID, backTo})); | ||
| // When opening the transaction thread in RHP we need to find every other ID for the rest of transactions | ||
| // to display prev/next arrows in RHP for navigation | ||
| setActiveTransactionThreadIDs(siblingTransactionThreadIDs).then(() => { | ||
|
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. I wonder, could you test with a report that will have 300 expenses for example. How long will this processing take before we navigate to the RHP? @Kicu @allroundexperts
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. Sure I can test. However I remember in the past asking about such cases in the context of other tasks, and the answer was that they won't happen. |
||
| Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID, backTo})); | ||
| }); | ||
| }; | ||
|
|
||
| if (!reportItem?.reportName && reportItem.transactions.length > 1) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import Onyx from 'react-native-onyx'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
|
|
||
| /** | ||
| * When a single transaction report is displayed in RHP it may need extra context in case user navigated to it from MoneyRequestReportView or Reports | ||
| * This context is the list of "sibling" transaction report ids. | ||
| * These "siblings" are child report IDs of every transaction connected to the same parent Report that the original transaction is connected. | ||
| * | ||
| * We save this value in onyx, so that we can correctly display navigation UI in transaction thread RHP. | ||
| */ | ||
|
|
||
| function setActiveTransactionThreadIDs(ids: string[]) { | ||
| return Onyx.set(ONYXKEYS.TRANSACTION_THREAD_NAVIGATION_REPORT_IDS, ids); | ||
| } | ||
|
|
||
| function clearActiveTransactionThreadIDs() { | ||
| return Onyx.set(ONYXKEYS.TRANSACTION_THREAD_NAVIGATION_REPORT_IDS, null); | ||
| } | ||
|
|
||
| export {setActiveTransactionThreadIDs, clearActiveTransactionThreadIDs}; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import type {TransactionListItemType} from '@components/SelectionList/types'; | ||
| import {getReportIDForTransaction} from '@libs/MoneyRequestReportUtils'; | ||
| import CONST from '@src/CONST'; | ||
|
|
||
| const transactionItemBaseMock = { | ||
| reportID: 'report123', | ||
| transactionThreadReportID: 'thread123', | ||
| } as TransactionListItemType; | ||
|
|
||
| describe('MoneyRequestReportUtils', () => { | ||
| describe('getReportIDForTransaction', () => { | ||
| it('returns transaction thread ID if its not from one transaction report', () => { | ||
| const transactionItem = {...transactionItemBaseMock}; | ||
| const resultID = getReportIDForTransaction(transactionItem); | ||
|
|
||
| expect(resultID).toBe('thread123'); | ||
| }); | ||
|
|
||
| it('returns transaction thread ID if its from self DM', () => { | ||
| const transactionItem = {...transactionItemBaseMock, reportID: CONST.REPORT.UNREPORTED_REPORT_ID}; | ||
| const resultID = getReportIDForTransaction(transactionItem); | ||
|
|
||
| expect(resultID).toBe('thread123'); | ||
| }); | ||
|
|
||
| it('returns expense reportID if its from one transaction report', () => { | ||
| const transactionItem = {...transactionItemBaseMock, isFromOneTransactionReport: true}; | ||
| const resultID = getReportIDForTransaction(transactionItem); | ||
|
|
||
| expect(resultID).toBe('report123'); | ||
| }); | ||
|
|
||
| it('returns reportID if transaction thread ID is 0 - unreported', () => { | ||
| const transactionItem = {...transactionItemBaseMock, transactionThreadReportID: CONST.REPORT.UNREPORTED_REPORT_ID}; | ||
| const resultID = getReportIDForTransaction(transactionItem); | ||
|
|
||
| expect(resultID).toBe('report123'); | ||
| }); | ||
| }); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.