Skip to content

Commit 372581d

Browse files
authored
Merge pull request #61617 from Expensify/tgolen-remove-rnvps-8
Remove a call to getReportNameValuePairs in the debug utilities flow
2 parents 9ad4ccb + b7a017c commit 372581d

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

src/libs/DebugUtils.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
1111
import type {Beta, Policy, Report, ReportAction, ReportActions, ReportNameValuePairs, Transaction, TransactionViolation} from '@src/types/onyx';
1212
import type {Comment} from '@src/types/onyx/Transaction';
1313
import {getLinkedTransactionID} from './ReportActionsUtils';
14-
import {getReasonAndReportActionThatRequiresAttention, getReportNameValuePairs, isArchivedReport, reasonForReportToBeInOptionList, shouldDisplayViolationsRBRInLHN} from './ReportUtils';
14+
import {getReasonAndReportActionThatRequiresAttention, reasonForReportToBeInOptionList, shouldDisplayViolationsRBRInLHN} from './ReportUtils';
1515
import SidebarUtils from './SidebarUtils';
1616
import {getTransactionID as TransactionUtilsGetTransactionID} from './TransactionUtils';
1717

@@ -1368,13 +1368,8 @@ type RBRReasonAndReportAction = {
13681368
/**
13691369
* Gets the report action that is causing the RBR to show up in LHN
13701370
*/
1371-
function getReasonAndReportActionForRBRInLHNRow(report: Report, reportActions: OnyxEntry<ReportActions>, hasViolations: boolean): RBRReasonAndReportAction | null {
1372-
// This will get removed as part of https://github.com/Expensify/App/issues/59961
1373-
// eslint-disable-next-line deprecation/deprecation
1374-
const reportNameValuePairs = getReportNameValuePairs(report?.reportID);
1375-
1376-
const {reason, reportAction} =
1377-
SidebarUtils.getReasonAndReportActionThatHasRedBrickRoad(report, reportActions, hasViolations, transactionViolations, isArchivedReport(reportNameValuePairs)) ?? {};
1371+
function getReasonAndReportActionForRBRInLHNRow(report: Report, reportActions: OnyxEntry<ReportActions>, hasViolations: boolean, isArchivedReport = false): RBRReasonAndReportAction | null {
1372+
const {reason, reportAction} = SidebarUtils.getReasonAndReportActionThatHasRedBrickRoad(report, reportActions, hasViolations, transactionViolations, isArchivedReport) ?? {};
13781373

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

src/pages/Debug/Report/DebugReportPage.tsx

+12-10
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@ import * as Expensicons from '@components/Icon/Expensicons';
77
import ScreenWrapper from '@components/ScreenWrapper';
88
import Text from '@components/Text';
99
import useLocalize from '@hooks/useLocalize';
10+
import useReportIsArchived from '@hooks/useReportIsArchived';
1011
import useStyleUtils from '@hooks/useStyleUtils';
1112
import useTheme from '@hooks/useTheme';
1213
import useThemeStyles from '@hooks/useThemeStyles';
1314
import {navigateToConciergeChatAndDeleteReport} from '@libs/actions/Report';
1415
import DebugUtils from '@libs/DebugUtils';
15-
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
16+
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
1617
import type {DebugTabNavigatorRoutes} from '@libs/Navigation/DebugTabNavigator';
1718
import DebugTabNavigator from '@libs/Navigation/DebugTabNavigator';
1819
import Navigation from '@libs/Navigation/Navigation';
1920
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
2021
import type {DebugParamList} from '@libs/Navigation/types';
21-
import * as ReportUtils from '@libs/ReportUtils';
22+
import {hasReportViolations, isReportOwner, shouldDisplayViolationsRBRInLHN} from '@libs/ReportUtils';
2223
import DebugDetails from '@pages/Debug/DebugDetails';
2324
import DebugJSON from '@pages/Debug/DebugJSON';
2425
import NotFoundPage from '@pages/ErrorPage/NotFoundPage';
@@ -50,21 +51,22 @@ function DebugReportPage({
5051
const styles = useThemeStyles();
5152
const StyleUtils = useStyleUtils();
5253
const theme = useTheme();
53-
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`);
54-
const [reportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`);
55-
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS);
54+
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {canBeMissing: true});
55+
const [reportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, {canBeMissing: true});
56+
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true});
5657
const transactionID = DebugUtils.getTransactionID(report, reportActions);
58+
const isReportArchived = useReportIsArchived(reportID);
5759

5860
const metadata = useMemo<Metadata[]>(() => {
5961
if (!report) {
6062
return [];
6163
}
6264

63-
const shouldDisplayViolations = ReportUtils.shouldDisplayViolationsRBRInLHN(report, transactionViolations);
64-
const shouldDisplayReportViolations = ReportUtils.isReportOwner(report) && ReportUtils.hasReportViolations(reportID);
65+
const shouldDisplayViolations = shouldDisplayViolationsRBRInLHN(report, transactionViolations);
66+
const shouldDisplayReportViolations = isReportOwner(report) && hasReportViolations(reportID);
6567
const hasViolations = !!shouldDisplayViolations || shouldDisplayReportViolations;
6668
const {reason: reasonGBR, reportAction: reportActionGBR} = DebugUtils.getReasonAndReportActionForGBRInLHNRow(report) ?? {};
67-
const {reason: reasonRBR, reportAction: reportActionRBR} = DebugUtils.getReasonAndReportActionForRBRInLHNRow(report, reportActions, hasViolations) ?? {};
69+
const {reason: reasonRBR, reportAction: reportActionRBR} = DebugUtils.getReasonAndReportActionForRBRInLHNRow(report, reportActions, hasViolations, isReportArchived) ?? {};
6870
const hasRBR = !!reasonRBR;
6971
const hasGBR = !hasRBR && !!reasonGBR;
7072
const reasonLHN = DebugUtils.getReasonForShowingRowInLHN(report, hasRBR);
@@ -112,7 +114,7 @@ function DebugReportPage({
112114
: undefined,
113115
},
114116
];
115-
}, [report, reportActions, reportID, transactionViolations, translate]);
117+
}, [report, reportActions, reportID, transactionViolations, translate, isReportArchived]);
116118

117119
const DebugDetailsTab = useCallback(
118120
() => (
@@ -213,7 +215,7 @@ function DebugReportPage({
213215
<ScreenWrapper
214216
includeSafeAreaPaddingBottom={false}
215217
shouldEnableKeyboardAvoidingView={false}
216-
shouldEnableMinHeight={DeviceCapabilities.canUseTouchScreen()}
218+
shouldEnableMinHeight={canUseTouchScreen()}
217219
testID={DebugReportPage.displayName}
218220
>
219221
{({safeAreaPaddingBottomStyle}) => (

tests/unit/DebugUtilsTest.ts

+12
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,18 @@ describe('DebugUtils', () => {
15471547
) ?? {};
15481548
expect(reason).toBe('debug.reasonRBR.hasViolations');
15491549
});
1550+
it('returns an undefined reason when the report is archived', () => {
1551+
const {reason} =
1552+
DebugUtils.getReasonAndReportActionForRBRInLHNRow(
1553+
{
1554+
reportID: '1',
1555+
},
1556+
undefined,
1557+
true,
1558+
true,
1559+
) ?? {};
1560+
expect(reason).toBe(undefined);
1561+
});
15501562
it('returns correct reason when there are reports on the workspace chat with violations', async () => {
15511563
const report: Report = {
15521564
reportID: '0',

0 commit comments

Comments
 (0)