@@ -776,6 +776,14 @@ function getReportOrDraftReport(reportID: string | undefined): OnyxEntry<Report>
776
776
return allReports ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ reportID } ` ] ?? allReportsDraft ?. [ `${ ONYXKEYS . COLLECTION . REPORT_DRAFT } ${ reportID } ` ] ;
777
777
}
778
778
779
+ function getReportTransactions ( reportID : string | undefined ) : Transaction [ ] {
780
+ if ( ! reportID ) {
781
+ return [ ] ;
782
+ }
783
+
784
+ return reportsTransactions [ reportID ] ?? [ ] ;
785
+ }
786
+
779
787
/**
780
788
* Check if a report is a draft report
781
789
*/
@@ -1647,11 +1655,7 @@ function isPolicyAdmin(policyID: string | undefined, policies: OnyxCollection<Po
1647
1655
* Checks whether all the transactions linked to the IOU report are of the Distance Request type with pending routes
1648
1656
*/
1649
1657
function hasOnlyTransactionsWithPendingRoutes ( iouReportID : string | undefined ) : boolean {
1650
- if ( ! iouReportID ) {
1651
- return false ;
1652
- }
1653
-
1654
- const transactions = reportsTransactions [ iouReportID ] ?? [ ] ;
1658
+ const transactions = getReportTransactions ( iouReportID ) ;
1655
1659
1656
1660
// Early return false in case not having any transaction
1657
1661
if ( ! transactions || transactions . length === 0 ) {
@@ -1735,11 +1739,7 @@ function isMoneyRequestReport(reportOrID: OnyxInputOrEntry<Report> | SearchRepor
1735
1739
* Checks if a report contains only Non-Reimbursable transactions
1736
1740
*/
1737
1741
function hasOnlyNonReimbursableTransactions ( iouReportID : string | undefined ) : boolean {
1738
- if ( ! iouReportID ) {
1739
- return false ;
1740
- }
1741
-
1742
- const transactions = reportsTransactions [ iouReportID ] ?? [ ] ;
1742
+ const transactions = getReportTransactions ( iouReportID ) ;
1743
1743
if ( ! transactions || transactions . length === 0 ) {
1744
1744
return false ;
1745
1745
}
@@ -2906,11 +2906,7 @@ function requiresAttentionFromCurrentUser(optionOrReport: OnyxEntry<Report> | Op
2906
2906
* Checks if the report contains at least one Non-Reimbursable transaction
2907
2907
*/
2908
2908
function hasNonReimbursableTransactions ( iouReportID : string | undefined ) : boolean {
2909
- if ( ! iouReportID ) {
2910
- return false ;
2911
- }
2912
-
2913
- const transactions = reportsTransactions [ iouReportID ] ?? [ ] ;
2909
+ const transactions = getReportTransactions ( iouReportID ) ;
2914
2910
return transactions . filter ( ( transaction ) => transaction . reimbursable === false ) . length > 0 ;
2915
2911
}
2916
2912
@@ -3441,10 +3437,7 @@ const changeMoneyRequestHoldStatus = (reportAction: OnyxEntry<ReportAction>, bac
3441
3437
* Gets all transactions on an IOU report with a receipt
3442
3438
*/
3443
3439
function getTransactionsWithReceipts ( iouReportID : string | undefined ) : Transaction [ ] {
3444
- if ( ! iouReportID ) {
3445
- return [ ] ;
3446
- }
3447
- const transactions = reportsTransactions [ iouReportID ] ?? [ ] ;
3440
+ const transactions = getReportTransactions ( iouReportID ) ;
3448
3441
return transactions . filter ( ( transaction ) => TransactionUtils . hasReceipt ( transaction ) ) ;
3449
3442
}
3450
3443
@@ -3484,7 +3477,7 @@ function getLinkedTransaction(reportAction: OnyxEntry<ReportAction | OptimisticI
3484
3477
* Check if any of the transactions in the report has required missing fields
3485
3478
*/
3486
3479
function hasMissingSmartscanFields ( iouReportID : string ) : boolean {
3487
- const reportTransactions = reportsTransactions [ iouReportID ] ?? [ ] ;
3480
+ const reportTransactions = getReportTransactions ( iouReportID ) ;
3488
3481
3489
3482
return reportTransactions . some ( TransactionUtils . hasMissingSmartscanFields ) ;
3490
3483
}
@@ -6457,23 +6450,23 @@ function shouldDisplayViolationsRBRInLHN(report: OnyxEntry<Report>, transactionV
6457
6450
* Checks to see if a report contains a violation
6458
6451
*/
6459
6452
function hasViolations ( reportID : string , transactionViolations : OnyxCollection < TransactionViolation [ ] > , shouldShowInReview ?: boolean ) : boolean {
6460
- const transactions = reportsTransactions [ reportID ] ?? [ ] ;
6453
+ const transactions = getReportTransactions ( reportID ) ;
6461
6454
return transactions . some ( ( transaction ) => TransactionUtils . hasViolation ( transaction . transactionID , transactionViolations , shouldShowInReview ) ) ;
6462
6455
}
6463
6456
6464
6457
/**
6465
6458
* Checks to see if a report contains a violation of type `warning`
6466
6459
*/
6467
6460
function hasWarningTypeViolations ( reportID : string , transactionViolations : OnyxCollection < TransactionViolation [ ] > , shouldShowInReview ?: boolean ) : boolean {
6468
- const transactions = reportsTransactions [ reportID ] ?? [ ] ;
6461
+ const transactions = getReportTransactions ( reportID ) ;
6469
6462
return transactions . some ( ( transaction ) => TransactionUtils . hasWarningTypeViolation ( transaction . transactionID , transactionViolations , shouldShowInReview ) ) ;
6470
6463
}
6471
6464
6472
6465
/**
6473
6466
* Checks to see if a report contains a violation of type `notice`
6474
6467
*/
6475
6468
function hasNoticeTypeViolations ( reportID : string , transactionViolations : OnyxCollection < TransactionViolation [ ] > , shouldShowInReview ?: boolean ) : boolean {
6476
- const transactions = reportsTransactions [ reportID ] ?? [ ] ;
6469
+ const transactions = getReportTransactions ( reportID ) ;
6477
6470
return transactions . some ( ( transaction ) => TransactionUtils . hasNoticeTypeViolation ( transaction . transactionID , transactionViolations , shouldShowInReview ) ) ;
6478
6471
}
6479
6472
@@ -7803,18 +7796,15 @@ function navigateToPrivateNotes(report: OnyxEntry<Report>, session: OnyxEntry<Se
7803
7796
* Get all held transactions of a iouReport
7804
7797
*/
7805
7798
function getAllHeldTransactions ( iouReportID ?: string ) : Transaction [ ] {
7806
- if ( ! iouReportID ) {
7807
- return [ ] ;
7808
- }
7809
- const transactions = reportsTransactions [ iouReportID ] ?? [ ] ;
7799
+ const transactions = getReportTransactions ( iouReportID ) ;
7810
7800
return transactions . filter ( ( transaction ) => TransactionUtils . isOnHold ( transaction ) ) ;
7811
7801
}
7812
7802
7813
7803
/**
7814
7804
* Check if Report has any held expenses
7815
7805
*/
7816
7806
function hasHeldExpenses ( iouReportID ?: string , allReportTransactions ?: SearchTransaction [ ] ) : boolean {
7817
- const iouReportTransactions = iouReportID ? reportsTransactions [ iouReportID ] : undefined ;
7807
+ const iouReportTransactions = getReportTransactions ( iouReportID ) ;
7818
7808
const transactions = allReportTransactions ?? iouReportTransactions ?? [ ] ;
7819
7809
return transactions . some ( ( transaction ) => TransactionUtils . isOnHold ( transaction ) ) ;
7820
7810
}
@@ -7823,7 +7813,7 @@ function hasHeldExpenses(iouReportID?: string, allReportTransactions?: SearchTra
7823
7813
* Check if all expenses in the Report are on hold
7824
7814
*/
7825
7815
function hasOnlyHeldExpenses ( iouReportID : string , allReportTransactions ?: SearchTransaction [ ] ) : boolean {
7826
- const transactionsByIouReportID = iouReportID ? reportsTransactions [ iouReportID ] ?? [ ] : [ ] ;
7816
+ const transactionsByIouReportID = getReportTransactions ( iouReportID ) ;
7827
7817
const reportTransactions = allReportTransactions ?? transactionsByIouReportID ;
7828
7818
return reportTransactions . length > 0 && ! reportTransactions . some ( ( transaction ) => ! TransactionUtils . isOnHold ( transaction ) ) ;
7829
7819
}
@@ -7844,7 +7834,7 @@ function hasUpdatedTotal(report: OnyxInputOrEntry<Report>, policy: OnyxInputOrEn
7844
7834
return true ;
7845
7835
}
7846
7836
7847
- const allReportTransactions = reportsTransactions [ report . reportID ] ?? [ ] ;
7837
+ const allReportTransactions = getReportTransactions ( report . reportID ) ;
7848
7838
7849
7839
const hasPendingTransaction = allReportTransactions . some ( ( transaction ) => ! ! transaction . pendingAction ) ;
7850
7840
const hasTransactionWithDifferentCurrency = allReportTransactions . some ( ( transaction ) => transaction . currency !== report . currency ) ;
@@ -8121,12 +8111,7 @@ function getTripTransactions(tripRoomReportID: string | undefined, reportFieldTo
8121
8111
const tripTransactionReportIDs = Object . values ( allReports ?? { } )
8122
8112
. filter ( ( report ) => report && report ?. [ reportFieldToCompare ] === tripRoomReportID )
8123
8113
. map ( ( report ) => report ?. reportID ) ;
8124
- return tripTransactionReportIDs . flatMap ( ( reportID ) => {
8125
- if ( ! reportID ) {
8126
- return [ ] ;
8127
- }
8128
- return reportsTransactions [ reportID ] ?? [ ] ;
8129
- } ) ;
8114
+ return tripTransactionReportIDs . flatMap ( ( reportID ) => getReportTransactions ( reportID ) ) ;
8130
8115
}
8131
8116
8132
8117
function getTripIDFromTransactionParentReportID ( transactionParentReportID : string | undefined ) : string | undefined {
0 commit comments