Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RBR reason to LHN debugging #50831

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
6819a11
feat(debug mode): add RBR reason to LHN debugging
pac-guerreiro Oct 15, 2024
69181c7
Merge branch 'main' into pac-guerreiro/feature/50665-add-rbr-reason-t…
pac-guerreiro Oct 16, 2024
fd8cdec
chore(debug mode): add RBR reason unit tests
pac-guerreiro Oct 16, 2024
e9d9106
fix(debug mode): RBR reason unit test for transaction thread violations
pac-guerreiro Oct 17, 2024
3e3adfe
Merge branch 'main' into pac-guerreiro/feature/50665-add-rbr-reason-t…
pac-guerreiro Oct 17, 2024
d47ed26
fix(debug mode): hasRBR not showing in visible in LHN
pac-guerreiro Oct 17, 2024
03579b9
chore: fix eslint issues
pac-guerreiro Oct 17, 2024
5a7f97f
Merge branch 'main' into pac-guerreiro/feature/50665-add-rbr-reason-t…
pac-guerreiro Oct 17, 2024
77be888
Merge branch 'main' into pac-guerreiro/feature/50665-add-rbr-reason-t…
pac-guerreiro Oct 17, 2024
1066c8d
chore(debug mode): update translation for has errors
pac-guerreiro Oct 18, 2024
7d137ab
fix: VirtualizedLists should never be nested inside plain ScrollViews
pac-guerreiro Oct 18, 2024
6934949
Merge branch 'main' into pac-guerreiro/feature/50665-add-rbr-reason-t…
pac-guerreiro Oct 18, 2024
a33673a
fix: unit tests failing
pac-guerreiro Oct 18, 2024
2d3aaee
Merge branch 'main' into pac-guerreiro/feature/50665-add-rbr-reason-t…
pac-guerreiro Oct 19, 2024
2462c82
chore: revert merge conflict resolution
pac-guerreiro Oct 19, 2024
99e4d9d
refactor: apply suggestion
pac-guerreiro Oct 19, 2024
eba07b6
fix(debug mode): spanish translation for violation related errors
pac-guerreiro Oct 19, 2024
d740283
Merge branch 'main' into pac-guerreiro/feature/50665-add-rbr-reason-t…
pac-guerreiro Oct 21, 2024
22019b3
chore: fix eslint issues
pac-guerreiro Oct 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading