@@ -9070,7 +9070,8 @@ function shouldHideReport(
90709070}
90719071
90729072/**
9073- * Should we display a RBR on the LHN on this report due to violations?
9073+ * Returns the reportID of the first child expense report that has violations under the same policy,
9074+ * or undefined if none found. Used to find the REPORT_PREVIEW action to deep-link to.
90749075 */
90759076function getViolatingReportIDForRBRInLHN(report: OnyxEntry<Report>, transactionViolations: OnyxCollection<TransactionViolation[]>): string | null {
90769077 // We only show the RBR in the highest level, which is the expense chat
@@ -9088,49 +9089,32 @@ function getViolatingReportIDForRBRInLHN(report: OnyxEntry<Report>, transactionV
90889089
90899090 // If any report has a violation, then it should have a RBR
90909091 const potentialReports = Object.values(reportsByPolicyID[report.policyID] ?? {}) ?? [];
9091- const violatingReport = potentialReports.find((potentialReport) => {
9092- if (!potentialReport) {
9093- return false;
9094- }
9095- const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${potentialReport.policyID}`];
9096- const transactions = getReportTransactions(potentialReport.reportID);
9092+ const violatingReport = potentialReports
9093+ // eslint-disable-next-line rulesdir/prefer-locale-compare-from-context
9094+ .sort((a, b) => (a?.created ?? '').localeCompare(b?.created ?? ''))
9095+ .find((potentialReport) => {
9096+ if (!potentialReport) {
9097+ return false;
9098+ }
9099+ const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${potentialReport.policyID}`];
9100+ const transactions = getReportTransactions(potentialReport.reportID);
90979101
9098- // Allow both open and processing reports to show RBR for violations
9099- if (!isOpenOrProcessingReport(potentialReport)) {
9100- return false;
9101- }
9102+ // Allow both open and processing reports to show RBR for violations
9103+ if (!isOpenOrProcessingReport(potentialReport)) {
9104+ return false;
9105+ }
91029106
9103- return (
9104- !isInvoiceReport(potentialReport) &&
9105- ViolationsUtils.hasVisibleViolationsForUser(
9106- potentialReport,
9107- transactionViolations,
9108- currentUserEmail ?? '',
9109- currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID,
9110- policy,
9111- transactions,
9112- ) &&
9113- (hasViolations(
9114- potentialReport.reportID,
9115- transactionViolations,
9116- currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID,
9117- currentUserEmail ?? '',
9118- true,
9119- transactions,
9120- potentialReport,
9121- policy,
9122- ) ||
9123- hasWarningTypeViolations(
9124- potentialReport.reportID,
9107+ return (
9108+ !isInvoiceReport(potentialReport) &&
9109+ ViolationsUtils.hasVisibleViolationsForUser(
9110+ potentialReport,
91259111 transactionViolations,
9126- currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID,
91279112 currentUserEmail ?? '',
9128- true,
9129- transactions,
9130- potentialReport,
9113+ currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID,
91319114 policy,
9132- ) ||
9133- hasNoticeTypeViolations(
9115+ transactions,
9116+ ) &&
9117+ (hasViolations(
91349118 potentialReport.reportID,
91359119 transactionViolations,
91369120 currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID,
@@ -9139,9 +9123,29 @@ function getViolatingReportIDForRBRInLHN(report: OnyxEntry<Report>, transactionV
91399123 transactions,
91409124 potentialReport,
91419125 policy,
9142- ))
9143- );
9144- });
9126+ ) ||
9127+ hasWarningTypeViolations(
9128+ potentialReport.reportID,
9129+ transactionViolations,
9130+ currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID,
9131+ currentUserEmail ?? '',
9132+ true,
9133+ transactions,
9134+ potentialReport,
9135+ policy,
9136+ ) ||
9137+ hasNoticeTypeViolations(
9138+ potentialReport.reportID,
9139+ transactionViolations,
9140+ currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID,
9141+ currentUserEmail ?? '',
9142+ true,
9143+ transactions,
9144+ potentialReport,
9145+ policy,
9146+ ))
9147+ );
9148+ });
91459149 return violatingReport ? violatingReport.reportID : null;
91469150}
91479151
0 commit comments