@@ -863,7 +863,7 @@ type GetReportNameParams = {
863863 policies ?: SearchPolicy [ ] ;
864864} ;
865865
866- type ReportByPolicyMap = Record < string , Report [ ] > ;
866+ type ReportByPolicyMap = Record < string , OnyxCollection < Report > > ;
867867
868868let currentUserEmail : string | undefined ;
869869let currentUserPrivateDomain : string | undefined ;
@@ -949,7 +949,7 @@ Onyx.connect({
949949 return ;
950950 }
951951
952- reportsByPolicyID = Object . values ( value ) . reduce < ReportByPolicyMap > ( ( acc , report ) => {
952+ reportsByPolicyID = Object . entries ( value ) . reduce < ReportByPolicyMap > ( ( acc , [ reportID , report ] ) => {
953953 if ( ! report ) {
954954 return acc ;
955955 }
@@ -962,9 +962,13 @@ Onyx.connect({
962962 // - Belong to the same workspace
963963 if ( report . policyID && report . ownerAccountID === currentUserAccountID && ( report . stateNum ?? 0 ) <= 1 ) {
964964 if ( ! acc [ report . policyID ] ) {
965- acc [ report . policyID ] = [ ] ;
965+ acc [ report . policyID ] = { } ;
966966 }
967- acc [ report . policyID ] . push ( report ) ;
967+
968+ acc [ report . policyID ] = {
969+ ...acc [ report . policyID ] ,
970+ [ reportID ] : report ,
971+ } ;
968972 }
969973
970974 return acc ;
@@ -7935,8 +7939,12 @@ function shouldDisplayViolationsRBRInLHN(report: OnyxEntry<Report>, transactionV
79357939 }
79367940
79377941 // If any report has a violation, then it should have a RBR
7938- const potentialReports = reportsByPolicyID [ report . policyID ] ?? [ ] ;
7942+ const potentialReports = Object . values ( reportsByPolicyID [ report . policyID ] ?? { } ) ?? [ ] ;
79397943 return potentialReports . some ( ( potentialReport ) => {
7944+ if ( ! potentialReport ) {
7945+ return false ;
7946+ }
7947+
79407948 return (
79417949 ! isInvoiceReport ( potentialReport ) &&
79427950 ( hasViolations ( potentialReport . reportID , transactionViolations , true ) ||
@@ -9985,13 +9993,13 @@ function isReportOutstanding(
99859993function getOutstandingReportsForUser (
99869994 policyID : string | undefined ,
99879995 reportOwnerAccountID : number | undefined ,
9988- reports : Array < OnyxEntry < Report > > = Object . values ( allReports ?? { } ) ,
9996+ reports : OnyxCollection < Report > = allReports ,
99899997 reportNameValuePairs : OnyxCollection < ReportNameValuePairs > = allReportNameValuePair ,
99909998) : Array < OnyxEntry < Report > > {
99919999 if ( ! reports ) {
999210000 return [ ] ;
999310001 }
9994- return reports
10002+ return Object . values ( reports )
999510003 . filter ( ( report ) => isReportOutstanding ( report , policyID , reportNameValuePairs ) && report ?. ownerAccountID === reportOwnerAccountID )
999610004 . sort ( ( a , b ) => a ?. reportName ?. localeCompare ( b ?. reportName ?. toLowerCase ( ) ?? '' ) ?? 0 ) ;
999710005}
0 commit comments