Skip to content

Commit

Permalink
Merge pull request #50831 from callstack-internal/pac-guerreiro/featu…
Browse files Browse the repository at this point in the history
…re/50665-add-rbr-reason-to-lhn-debugging

Add RBR reason to LHN debugging
  • Loading branch information
puneetlath authored Oct 21, 2024
2 parents b176976 + 22019b3 commit 23ea36a
Show file tree
Hide file tree
Showing 8 changed files with 433 additions and 267 deletions.
6 changes: 6 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5972,6 +5972,12 @@ const CONST = {
HAS_CHILD_REPORT_AWAITING_ACTION: 'hasChildReportAwaitingAction',
HAS_MISSING_INVOICE_BANK_ACCOUNT: 'hasMissingInvoiceBankAccount',
},

RBR_REASONS: {
HAS_ERRORS: 'hasErrors',
HAS_VIOLATIONS: 'hasViolations',
HAS_TRANSACTION_THREAD_VIOLATIONS: 'hasTransactionThreadViolations',
},
} as const;

type Country = keyof typeof CONST.ALL_COUNTRIES;
Expand Down
5 changes: 5 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5148,6 +5148,11 @@ const translations = {
hasChildReportAwaitingAction: 'Has child report awaiting action',
hasMissingInvoiceBankAccount: 'Has missing invoice bank account',
},
reasonRBR: {
hasErrors: 'Has errors in report or report actions data',
hasViolations: 'Has violations',
hasTransactionThreadViolations: 'Has transaction thread violations',
},
indicatorStatus: {
theresAReportAwaitingAction: "There's a report awaiting action",
theresAReportWithErrors: "There's a report with errors",
Expand Down
5 changes: 5 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5664,6 +5664,11 @@ const translations = {
hasChildReportAwaitingAction: 'Informe secundario pendiente de acción',
hasMissingInvoiceBankAccount: 'Falta la cuenta bancaria de la factura',
},
reasonRBR: {
hasErrors: 'Tiene errores en los datos o las acciones del informe',
hasViolations: 'Tiene violaciones',
hasTransactionThreadViolations: 'Tiene violaciones de hilo de transacciones',
},
indicatorStatus: {
theresAReportAwaitingAction: 'Hay un informe pendiente de acción',
theresAReportWithErrors: 'Hay un informe con errores',
Expand Down
18 changes: 14 additions & 4 deletions src/libs/DebugUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Beta, Policy, Report, ReportAction, ReportActions, TransactionViolation} from '@src/types/onyx';
import * as ReportUtils from './ReportUtils';
import SidebarUtils from './SidebarUtils';

class NumberError extends SyntaxError {
constructor() {
Expand Down Expand Up @@ -645,13 +646,22 @@ function getReasonAndReportActionForGBRInLHNRow(report: OnyxEntry<Report>): GBRR
return null;
}

type RBRReasonAndReportAction = {
reason: TranslationPaths;
reportAction: OnyxEntry<ReportAction>;
};

/**
* Gets the report action that is causing the RBR to show up in LHN
*/
function getRBRReportAction(report: OnyxEntry<Report>, reportActions: OnyxEntry<ReportActions>): OnyxEntry<ReportAction> {
const {reportAction} = ReportUtils.getAllReportActionsErrorsAndReportActionThatRequiresAttention(report, reportActions);
function getReasonAndReportActionForRBRInLHNRow(report: Report, reportActions: OnyxEntry<ReportActions>, hasViolations: boolean): RBRReasonAndReportAction | null {
const {reason, reportAction} = SidebarUtils.getReasonAndReportActionThatHasRedBrickRoad(report, reportActions, hasViolations, transactionViolations) ?? {};

return reportAction;
if (reason) {
return {reason: `debug.reasonRBR.${reason}`, reportAction};
}

return null;
}

const DebugUtils = {
Expand All @@ -673,7 +683,7 @@ const DebugUtils = {
validateReportActionJSON,
getReasonForShowingRowInLHN,
getReasonAndReportActionForGBRInLHNRow,
getRBRReportAction,
getReasonAndReportActionForRBRInLHNRow,
REPORT_ACTION_REQUIRED_PROPERTIES,
REPORT_REQUIRED_PROPERTIES,
};
Expand Down
40 changes: 36 additions & 4 deletions src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Str} from 'expensify-common';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import type {PolicySelector, ReportActionsSelector} from '@hooks/useReportIDs';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -222,10 +223,21 @@ function getOrderedReportIDs(
return LHNReports;
}

function shouldShowRedBrickRoad(report: Report, reportActions: OnyxEntry<ReportActions>, hasViolations: boolean, transactionViolations?: OnyxCollection<TransactionViolation[]>) {
const hasErrors = Object.keys(ReportUtils.getAllReportErrors(report, reportActions)).length !== 0;
type ReasonAndReportActionThatHasRedBrickRoad = {
reason: ValueOf<typeof CONST.RBR_REASONS>;
reportAction?: OnyxEntry<ReportAction>;
};

function getReasonAndReportActionThatHasRedBrickRoad(
report: Report,
reportActions: OnyxEntry<ReportActions>,
hasViolations: boolean,
transactionViolations?: OnyxCollection<TransactionViolation[]>,
): ReasonAndReportActionThatHasRedBrickRoad | null {
const {errors, reportAction} = ReportUtils.getAllReportActionsErrorsAndReportActionThatRequiresAttention(report, reportActions);
const hasErrors = Object.keys(errors).length !== 0;
const oneTransactionThreadReportID = ReportActionsUtils.getOneTransactionThreadReportID(report.reportID, ReportActionsUtils.getAllReportActions(report.reportID));

if (oneTransactionThreadReportID) {
const oneTransactionThreadReport = ReportUtils.getReport(oneTransactionThreadReportID);

Expand All @@ -236,11 +248,30 @@ function shouldShowRedBrickRoad(report: Report, reportActions: OnyxEntry<ReportA
ReportActionsUtils.getAllReportActions(report.reportID)[oneTransactionThreadReport?.parentReportActionID ?? '-1'],
)
) {
return true;
return {
reason: CONST.RBR_REASONS.HAS_TRANSACTION_THREAD_VIOLATIONS,
};
}
}

return hasErrors || hasViolations;
if (hasErrors) {
return {
reason: CONST.RBR_REASONS.HAS_ERRORS,
reportAction,
};
}

if (hasViolations) {
return {
reason: CONST.RBR_REASONS.HAS_VIOLATIONS,
};
}

return null;
}

function shouldShowRedBrickRoad(report: Report, reportActions: OnyxEntry<ReportActions>, hasViolations: boolean, transactionViolations?: OnyxCollection<TransactionViolation[]>) {
return !!getReasonAndReportActionThatHasRedBrickRoad(report, reportActions, hasViolations, transactionViolations);
}

/**
Expand Down Expand Up @@ -618,5 +649,6 @@ export default {
getOptionData,
getOrderedReportIDs,
getWelcomeMessage,
getReasonAndReportActionThatHasRedBrickRoad,
shouldShowRedBrickRoad,
};
6 changes: 2 additions & 4 deletions src/pages/Debug/Report/DebugReportActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ function DebugReportActions({reportID}: DebugReportActionsProps) {
</PressableWithFeedback>
);
return (
<ScrollView
style={styles.mt5}
contentContainerStyle={styles.pb5}
>
<ScrollView style={styles.mv5}>
<Button
success
large
Expand All @@ -51,6 +48,7 @@ function DebugReportActions({reportID}: DebugReportActionsProps) {
<FlatList
data={sortedAllReportActions}
renderItem={renderItem}
scrollEnabled={false}
/>
</ScrollView>
);
Expand Down
9 changes: 5 additions & 4 deletions src/pages/Debug/Report/DebugReportPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import Navigation from '@libs/Navigation/Navigation';
import OnyxTabNavigator, {TopTab} from '@libs/Navigation/OnyxTabNavigator';
import type {DebugParamList} from '@libs/Navigation/types';
import * as ReportUtils from '@libs/ReportUtils';
import SidebarUtils from '@libs/SidebarUtils';
import DebugDetails from '@pages/Debug/DebugDetails';
import DebugJSON from '@pages/Debug/DebugJSON';
import Debug from '@userActions/Debug';
Expand Down Expand Up @@ -61,11 +60,12 @@ function DebugReportPage({

const shouldDisplayViolations = ReportUtils.shouldDisplayTransactionThreadViolations(report, transactionViolations, parentReportAction);
const shouldDisplayReportViolations = ReportUtils.isReportOwner(report) && ReportUtils.hasReportViolations(reportID);
const hasRBR = SidebarUtils.shouldShowRedBrickRoad(report, reportActions, !!shouldDisplayViolations || shouldDisplayReportViolations, transactionViolations);
const reasonLHN = DebugUtils.getReasonForShowingRowInLHN(report, hasRBR);
const hasViolations = !!shouldDisplayViolations || shouldDisplayReportViolations;
const {reason: reasonGBR, reportAction: reportActionGBR} = DebugUtils.getReasonAndReportActionForGBRInLHNRow(report) ?? {};
const reportActionRBR = DebugUtils.getRBRReportAction(report, reportActions);
const {reason: reasonRBR, reportAction: reportActionRBR} = DebugUtils.getReasonAndReportActionForRBRInLHNRow(report, reportActions, hasViolations) ?? {};
const hasRBR = !!reasonRBR;
const hasGBR = !hasRBR && !!reasonGBR;
const reasonLHN = DebugUtils.getReasonForShowingRowInLHN(report, hasRBR);

return [
{
Expand Down Expand Up @@ -94,6 +94,7 @@ function DebugReportPage({
{
title: translate('debug.RBR'),
subtitle: translate(`debug.${hasRBR}`),
message: hasRBR ? translate(reasonRBR) : undefined,
action:
hasRBR && reportActionRBR
? {
Expand Down
Loading

0 comments on commit 23ea36a

Please sign in to comment.