@@ -6324,65 +6324,53 @@ function shouldHideReport(report: OnyxEntry<Report>, currentReportId: string): b
6324
6324
}
6325
6325
6326
6326
/**
6327
- * Checks to see if a report's parentAction is an expense that contains a violation type of either violation or warning
6327
+ * Should we display a RBR on the LHN on this report due to violations?
6328
6328
*/
6329
- function doesTransactionThreadHaveViolations (
6330
- report : OnyxInputOrEntry < Report > ,
6331
- transactionViolations : OnyxCollection < TransactionViolation [ ] > ,
6332
- parentReportAction : OnyxInputOrEntry < ReportAction > ,
6333
- ) : boolean {
6334
- if ( ! ReportActionsUtils . isMoneyRequestAction ( parentReportAction ) ) {
6335
- return false ;
6336
- }
6337
- const { IOUTransactionID, IOUReportID} = ReportActionsUtils . getOriginalMessage ( parentReportAction ) ?? { } ;
6338
- if ( ! IOUTransactionID || ! IOUReportID ) {
6329
+ function shouldDisplayViolationsRBRInLHN ( report : OnyxEntry < Report > , transactionViolations : OnyxCollection < TransactionViolation [ ] > ) : boolean {
6330
+ // We only show the RBR in the highest level, which is the workspace chat
6331
+ if ( ! report || ! isPolicyExpenseChat ( report ) ) {
6339
6332
return false ;
6340
6333
}
6341
- if ( ! isCurrentUserSubmitter ( IOUReportID ) ) {
6342
- return false ;
6343
- }
6344
- if ( report ?. stateNum !== CONST . REPORT . STATE_NUM . OPEN && report ?. stateNum !== CONST . REPORT . STATE_NUM . SUBMITTED ) {
6334
+
6335
+ // We only show the RBR to the submitter
6336
+ if ( ! isCurrentUserSubmitter ( report . reportID ?? '' ) ) {
6345
6337
return false ;
6346
6338
}
6347
- return (
6348
- TransactionUtils . hasViolation ( IOUTransactionID , transactionViolations ) ||
6349
- TransactionUtils . hasWarningTypeViolation ( IOUTransactionID , transactionViolations ) ||
6350
- ( isPaidGroupPolicy ( report ) && TransactionUtils . hasModifiedAmountOrDateViolation ( IOUTransactionID , transactionViolations ) )
6339
+
6340
+ // Get all potential reports, which are the ones that are:
6341
+ // - Owned by the same user
6342
+ // - Are either open or submitted
6343
+ // - Belong to the same workspace
6344
+ // And if any have a violation, then it should have a RBR
6345
+ const allReports = Object . values ( ReportConnection . getAllReports ( ) ?? { } ) as Report [ ] ;
6346
+ const potentialReports = allReports . filter ( ( r ) => r . ownerAccountID === currentUserAccountID && ( r . stateNum ?? 0 ) <= 1 && r . policyID === report . policyID ) ;
6347
+ return potentialReports . some (
6348
+ ( potentialReport ) => hasViolations ( potentialReport . reportID , transactionViolations ) || hasWarningTypeViolations ( potentialReport . reportID , transactionViolations ) ,
6351
6349
) ;
6352
6350
}
6353
6351
6354
6352
/**
6355
- * Checks if we should display violation - we display violations when the expense has violation and it is not settled
6353
+ * Checks to see if a report contains a violation
6356
6354
*/
6357
- function shouldDisplayTransactionThreadViolations (
6358
- report : OnyxEntry < Report > ,
6359
- transactionViolations : OnyxCollection < TransactionViolation [ ] > ,
6360
- parentReportAction : OnyxEntry < ReportAction > ,
6361
- ) : boolean {
6362
- if ( ! ReportActionsUtils . isMoneyRequestAction ( parentReportAction ) ) {
6363
- return false ;
6364
- }
6365
- const { IOUReportID} = ReportActionsUtils . getOriginalMessage ( parentReportAction ) ?? { } ;
6366
- if ( isSettled ( IOUReportID ) || isReportApproved ( IOUReportID ?. toString ( ) ) ) {
6367
- return false ;
6368
- }
6369
- return doesTransactionThreadHaveViolations ( report , transactionViolations , parentReportAction ) ;
6355
+ function hasViolations ( reportID : string , transactionViolations : OnyxCollection < TransactionViolation [ ] > , shouldShowInReview ?: boolean ) : boolean {
6356
+ const transactions = reportsTransactions [ reportID ] ?? [ ] ;
6357
+ return transactions . some ( ( transaction ) => TransactionUtils . hasViolation ( transaction . transactionID , transactionViolations , shouldShowInReview ) ) ;
6370
6358
}
6371
6359
6372
6360
/**
6373
- * Checks to see if a report contains a violation
6361
+ * Checks to see if a report contains a violation of type `warning`
6374
6362
*/
6375
- function hasViolations ( reportID : string , transactionViolations : OnyxCollection < TransactionViolation [ ] > ) : boolean {
6363
+ function hasWarningTypeViolations ( reportID : string , transactionViolations : OnyxCollection < TransactionViolation [ ] > , shouldShowInReview ?: boolean ) : boolean {
6376
6364
const transactions = reportsTransactions [ reportID ] ?? [ ] ;
6377
- return transactions . some ( ( transaction ) => TransactionUtils . hasViolation ( transaction . transactionID , transactionViolations ) ) ;
6365
+ return transactions . some ( ( transaction ) => TransactionUtils . hasWarningTypeViolation ( transaction . transactionID , transactionViolations , shouldShowInReview ) ) ;
6378
6366
}
6379
6367
6380
6368
/**
6381
- * Checks to see if a report contains a violation of type `warning `
6369
+ * Checks to see if a report contains a violation of type `notice `
6382
6370
*/
6383
- function hasWarningTypeViolations ( reportID : string , transactionViolations : OnyxCollection < TransactionViolation [ ] > ) : boolean {
6371
+ function hasNoticeTypeViolations ( reportID : string , transactionViolations : OnyxCollection < TransactionViolation [ ] > , shouldShowInReview ?: boolean ) : boolean {
6384
6372
const transactions = reportsTransactions [ reportID ] ?? [ ] ;
6385
- return transactions . some ( ( transaction ) => TransactionUtils . hasWarningTypeViolation ( transaction . transactionID , transactionViolations ) ) ;
6373
+ return transactions . some ( ( transaction ) => TransactionUtils . hasNoticeTypeViolation ( transaction . transactionID , transactionViolations , shouldShowInReview ) ) ;
6386
6374
}
6387
6375
6388
6376
function hasReportViolations ( reportID : string ) {
@@ -6404,23 +6392,6 @@ function shouldAdminsRoomBeVisible(report: OnyxEntry<Report>): boolean {
6404
6392
return true ;
6405
6393
}
6406
6394
6407
- /**
6408
- * Check whether report has violations
6409
- */
6410
- function shouldShowViolations ( report : Report , transactionViolations : OnyxCollection < TransactionViolation [ ] > ) {
6411
- const { parentReportID, parentReportActionID} = report ?? { } ;
6412
- const canGetParentReport = parentReportID && parentReportActionID && allReportActions ;
6413
- if ( ! canGetParentReport ) {
6414
- return false ;
6415
- }
6416
- const parentReportActions = allReportActions ? allReportActions [ `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ parentReportID } ` ] ?? { } : { } ;
6417
- const parentReportAction = parentReportActions [ parentReportActionID ] ?? null ;
6418
- if ( ! parentReportAction ) {
6419
- return false ;
6420
- }
6421
- return shouldDisplayTransactionThreadViolations ( report , transactionViolations , parentReportAction ) ;
6422
- }
6423
-
6424
6395
type ReportErrorsAndReportActionThatRequiresAttention = {
6425
6396
errors : ErrorFields ;
6426
6397
reportAction ?: OnyxEntry < ReportAction > ;
@@ -6503,7 +6474,7 @@ function hasReportErrorsOtherThanFailedReceipt(report: Report, doesReportHaveVio
6503
6474
let doesTransactionThreadReportHasViolations = false ;
6504
6475
if ( oneTransactionThreadReportID ) {
6505
6476
const transactionReport = getReport ( oneTransactionThreadReportID ) ;
6506
- doesTransactionThreadReportHasViolations = ! ! transactionReport && shouldShowViolations ( transactionReport , transactionViolations ) ;
6477
+ doesTransactionThreadReportHasViolations = ! ! transactionReport && shouldDisplayViolationsRBRInLHN ( transactionReport , transactionViolations ) ;
6507
6478
}
6508
6479
return (
6509
6480
doesTransactionThreadReportHasViolations ||
@@ -8497,7 +8468,6 @@ export {
8497
8468
chatIncludesConcierge ,
8498
8469
createDraftTransactionAndNavigateToParticipantSelector ,
8499
8470
doesReportBelongToWorkspace ,
8500
- doesTransactionThreadHaveViolations ,
8501
8471
findLastAccessedReport ,
8502
8472
findSelfDMReportID ,
8503
8473
formatReportLastMessageText ,
@@ -8601,6 +8571,7 @@ export {
8601
8571
hasUpdatedTotal ,
8602
8572
hasViolations ,
8603
8573
hasWarningTypeViolations ,
8574
+ hasNoticeTypeViolations ,
8604
8575
isActionCreator ,
8605
8576
isAdminRoom ,
8606
8577
isAdminsOnlyPostingRoom ,
@@ -8702,7 +8673,7 @@ export {
8702
8673
shouldDisableRename ,
8703
8674
shouldDisableThread ,
8704
8675
shouldDisplayThreadReplies ,
8705
- shouldDisplayTransactionThreadViolations ,
8676
+ shouldDisplayViolationsRBRInLHN ,
8706
8677
shouldReportBeInOptionList ,
8707
8678
shouldReportShowSubscript ,
8708
8679
shouldShowFlagComment ,
@@ -8750,7 +8721,6 @@ export {
8750
8721
buildOptimisticChangeFieldAction ,
8751
8722
isPolicyRelatedReport ,
8752
8723
hasReportErrorsOtherThanFailedReceipt ,
8753
- shouldShowViolations ,
8754
8724
getAllReportErrors ,
8755
8725
getAllReportActionsErrorsAndReportActionThatRequiresAttention ,
8756
8726
hasInvoiceReports ,
0 commit comments