Skip to content

Commit c52b34b

Browse files
authored
Merge pull request Expensify#65782 from Expensify/dangrous-reportpreviewdetails
Use BE report data instead of report actions for Report Previews
2 parents 44d8ae5 + 76b012f commit c52b34b

7 files changed

Lines changed: 52 additions & 27 deletions

File tree

src/components/ReportActionItem/MoneyRequestReportPreview/MoneyRequestReportPreviewContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ function MoneyRequestReportPreviewContent({
439439
if (isPaidAnimationRunning) {
440440
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY;
441441
}
442-
return getReportPreviewAction(violations, isIouReportArchived || isChatReportArchived, iouReport, policy, transactions, reportActions, invoiceReceiverPolicy);
442+
return getReportPreviewAction(violations, isIouReportArchived || isChatReportArchived, iouReport, policy, transactions, invoiceReceiverPolicy);
443443
}, [isPaidAnimationRunning, violations, iouReport, policy, transactions, isIouReportArchived, reportActions, invoiceReceiverPolicy, isChatReportArchived]);
444444

445445
const addExpenseDropdownOptions = useMemo(

src/libs/DebugUtils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,9 @@ function validateReportDraftProperty(key: keyof Report | keyof ReportNameValuePa
472472
case 'isDeletedParentAction':
473473
case 'isWaitingOnBankAccount':
474474
case 'isCancelledIOU':
475+
case 'hasReportBeenReopened':
476+
case 'isExportedToIntegration':
477+
case 'hasExportError':
475478
return validateBoolean(value);
476479
case 'exportFailedTime':
477480
case 'lastReadSequenceNumber':
@@ -623,6 +626,9 @@ function validateReportDraftProperty(key: keyof Report | keyof ReportNameValuePa
623626
unheldNonReimbursableTotal: CONST.RED_BRICK_ROAD_PENDING_ACTION,
624627
isWaitingOnBankAccount: CONST.RED_BRICK_ROAD_PENDING_ACTION,
625628
isCancelledIOU: CONST.RED_BRICK_ROAD_PENDING_ACTION,
629+
hasReportBeenReopened: CONST.RED_BRICK_ROAD_PENDING_ACTION,
630+
isExportedToIntegration: CONST.RED_BRICK_ROAD_PENDING_ACTION,
631+
hasExportError: CONST.RED_BRICK_ROAD_PENDING_ACTION,
626632
iouReportID: CONST.RED_BRICK_ROAD_PENDING_ACTION,
627633
preexistingReportID: CONST.RED_BRICK_ROAD_PENDING_ACTION,
628634
nonReimbursableTotal: CONST.RED_BRICK_ROAD_PENDING_ACTION,

src/libs/ReportPreviewActionUtils.ts

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
1+
import type {OnyxCollection} from 'react-native-onyx';
22
import type {ValueOf} from 'type-fest';
33
import CONST from '@src/CONST';
4-
import type {Policy, Report, ReportAction, ReportActions, Transaction, TransactionViolation} from '@src/types/onyx';
4+
import type {Policy, Report, Transaction, TransactionViolation} from '@src/types/onyx';
55
import {getCurrentUserAccountID} from './actions/Report';
66
import {
77
arePaymentsEnabled,
@@ -18,13 +18,10 @@ import {
1818
getParentReport,
1919
getReportTransactions,
2020
hasAnyViolations as hasAnyViolationsUtil,
21-
hasExportError as hasExportErrorUtil,
2221
hasMissingSmartscanFields,
23-
hasReportBeenReopened,
2422
isClosedReport,
2523
isCurrentUserSubmitter,
2624
isExpenseReport,
27-
isExported as isExportedUtil,
2825
isInvoiceReport,
2926
isIOUReport,
3027
isOpenExpenseReport,
@@ -38,14 +35,7 @@ import {
3835
import {getSession} from './SessionUtils';
3936
import {allHavePendingRTERViolation, isPending, isScanning, shouldShowBrokenConnectionViolationForMultipleTransactions} from './TransactionUtils';
4037

41-
function canSubmit(
42-
report: Report,
43-
violations: OnyxCollection<TransactionViolation[]>,
44-
isReportArchived: boolean,
45-
reportActions?: OnyxEntry<ReportActions> | ReportAction[],
46-
policy?: Policy,
47-
transactions?: Transaction[],
48-
) {
38+
function canSubmit(report: Report, violations: OnyxCollection<TransactionViolation[]>, isReportArchived: boolean, policy?: Policy, transactions?: Transaction[]) {
4939
if (isReportArchived) {
5040
return false;
5141
}
@@ -55,7 +45,7 @@ function canSubmit(
5545
const isOpen = isOpenReport(report);
5646
const isManager = report.managerID === getCurrentUserAccountID();
5747
const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN;
58-
const hasBeenReopened = hasReportBeenReopened(reportActions);
48+
const hasBeenReopened = report.hasReportBeenReopened ?? false;
5949
const isManualSubmitEnabled = getCorrectedAutoReportingFrequency(policy) === CONST.POLICY.AUTO_REPORTING_FREQUENCIES.MANUAL;
6050

6151
if (!!transactions && transactions?.length > 0 && transactions.every((transaction) => isPending(transaction))) {
@@ -164,7 +154,7 @@ function canPay(
164154
return invoiceReceiverPolicy?.role === CONST.POLICY.ROLE.ADMIN && reimbursableSpend > 0;
165155
}
166156

167-
function canExport(report: Report, violations: OnyxCollection<TransactionViolation[]>, policy?: Policy, reportActions?: OnyxEntry<ReportActions> | ReportAction[]) {
157+
function canExport(report: Report, violations: OnyxCollection<TransactionViolation[]>, policy?: Policy) {
168158
const isExpense = isExpenseReport(report);
169159
const isExporter = policy ? isPreferredExporter(policy) : false;
170160
const isReimbursed = isSettled(report);
@@ -178,12 +168,12 @@ function canExport(report: Report, violations: OnyxCollection<TransactionViolati
178168
return false;
179169
}
180170

181-
const isExported = isExportedUtil(reportActions);
171+
const isExported = report.isExportedToIntegration ?? false;
182172
if (isExported) {
183173
return false;
184174
}
185175

186-
const hasExportError = hasExportErrorUtil(reportActions);
176+
const hasExportError = report.hasExportError ?? false;
187177
if (syncEnabled && !hasExportError) {
188178
return false;
189179
}
@@ -234,7 +224,6 @@ function getReportPreviewAction(
234224
report?: Report,
235225
policy?: Policy,
236226
transactions?: Transaction[],
237-
reportActions?: OnyxEntry<ReportActions> | ReportAction[],
238227
invoiceReceiverPolicy?: Policy,
239228
): ValueOf<typeof CONST.REPORT.REPORT_PREVIEW_ACTIONS> {
240229
if (!report) {
@@ -243,7 +232,7 @@ function getReportPreviewAction(
243232
if (isAddExpenseAction(report, transactions ?? [], isReportArchived)) {
244233
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.ADD_EXPENSE;
245234
}
246-
if (canSubmit(report, violations, isReportArchived, reportActions, policy, transactions)) {
235+
if (canSubmit(report, violations, isReportArchived, policy, transactions)) {
247236
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.SUBMIT;
248237
}
249238
if (canApprove(report, violations, policy, transactions)) {
@@ -252,7 +241,7 @@ function getReportPreviewAction(
252241
if (canPay(report, violations, isReportArchived, policy, invoiceReceiverPolicy)) {
253242
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY;
254243
}
255-
if (canExport(report, violations, policy, reportActions)) {
244+
if (canExport(report, violations, policy)) {
256245
return CONST.REPORT.REPORT_PREVIEW_ACTIONS.EXPORT_TO_ACCOUNTING;
257246
}
258247
if (canReview(report, violations, isReportArchived, policy, transactions)) {

src/libs/ReportUtils.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10832,7 +10832,13 @@ function getIntegrationNameFromExportMessage(reportActions: OnyxEntry<ReportActi
1083210832
}
1083310833
}
1083410834

10835-
function isExported(reportActions: OnyxEntry<ReportActions> | ReportAction[]) {
10835+
function isExported(reportActions: OnyxEntry<ReportActions> | ReportAction[], report?: OnyxEntry<Report>): boolean {
10836+
// If report object is provided and has the property, use it directly
10837+
if (report?.isExportedToIntegration !== undefined) {
10838+
return report.isExportedToIntegration;
10839+
}
10840+
10841+
// Fallback to checking actions for backward compatibility
1083610842
if (!reportActions) {
1083710843
return false;
1083810844
}
@@ -10860,7 +10866,13 @@ function isExported(reportActions: OnyxEntry<ReportActions> | ReportAction[]) {
1086010866
return exportIntegrationActionsCount > integrationMessageActionsCount;
1086110867
}
1086210868

10863-
function hasExportError(reportActions: OnyxEntry<ReportActions> | ReportAction[]) {
10869+
function hasExportError(reportActions: OnyxEntry<ReportActions> | ReportAction[], report?: OnyxEntry<Report>) {
10870+
// If report object is provided and has the property, use it directly
10871+
if (report?.hasExportError !== undefined) {
10872+
return report.hasExportError;
10873+
}
10874+
10875+
// Fallback to checking actions for backward compatibility
1086410876
if (!reportActions) {
1086510877
return false;
1086610878
}
@@ -11137,7 +11149,13 @@ function findReportIDForAction(action?: ReportAction): string | undefined {
1113711149
?.replace(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}`, '');
1113811150
}
1113911151

11140-
function hasReportBeenReopened(reportActions: OnyxEntry<ReportActions> | ReportAction[]): boolean {
11152+
function hasReportBeenReopened(reportActions: OnyxEntry<ReportActions> | ReportAction[], report?: OnyxEntry<Report>): boolean {
11153+
// If report object is provided and has the property, use it directly
11154+
if (report?.hasReportBeenReopened !== undefined) {
11155+
return report.hasReportBeenReopened;
11156+
}
11157+
11158+
// Fallback to checking actions for backward compatibility
1114111159
if (!reportActions) {
1114211160
return false;
1114311161
}

src/types/onyx/Report.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,15 @@ type Report = OnyxCommon.OnyxValueWithOfflineFeedback<
194194
/** Whether the report is cancelled */
195195
isCancelledIOU?: boolean;
196196

197+
/** Whether the report has been reopened */
198+
hasReportBeenReopened?: boolean;
199+
200+
/** Whether the report has been exported to integration */
201+
isExportedToIntegration?: boolean;
202+
203+
/** Whether the report has any export errors */
204+
hasExportError?: boolean;
205+
197206
/** The ID of the IOU report */
198207
iouReportID?: string;
199208

src/types/utils/whitelistedReportKeys.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ type WhitelistedReport = OnyxCommon.OnyxValueWithOfflineFeedback<
5050
errors: unknown;
5151
isWaitingOnBankAccount: unknown;
5252
isCancelledIOU: unknown;
53+
hasReportBeenReopened: unknown;
54+
isExportedToIntegration: unknown;
55+
hasExportError: unknown;
5356
iouReportID: unknown;
5457
preexistingReportID: unknown;
5558
nonReimbursableTotal: unknown;

tests/actions/ReportPreviewActionUtilsTest.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ describe('getReportPreviewAction', () => {
287287
} as unknown as Transaction;
288288

289289
const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID));
290-
expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, report, policy, [transaction], undefined, invoiceReceiverPolicy)).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY);
290+
expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, report, policy, [transaction], invoiceReceiverPolicy)).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY);
291291
});
292292

293293
it('getReportPreviewAction should return VIEW action for zero value invoice', async () => {
@@ -332,7 +332,7 @@ describe('getReportPreviewAction', () => {
332332

333333
const {result: isReportArchived} = renderHook(() => useReportIsArchived(report.parentReportID));
334334

335-
expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, report, policy, [transaction], undefined, invoiceReceiverPolicy)).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW);
335+
expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, report, policy, [transaction], invoiceReceiverPolicy)).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.VIEW);
336336
});
337337

338338
it('canPay should return false for archived invoice', async () => {
@@ -364,7 +364,7 @@ describe('getReportPreviewAction', () => {
364364
reportID: `${REPORT_ID}`,
365365
} as unknown as Transaction;
366366
const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.parentReportID));
367-
expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, report, policy, [transaction], undefined, invoiceReceiverPolicy)).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY);
367+
expect(getReportPreviewAction(VIOLATIONS, isReportArchived.current, report, policy, [transaction], invoiceReceiverPolicy)).toBe(CONST.REPORT.REPORT_PREVIEW_ACTIONS.PAY);
368368
});
369369

370370
it('getReportPreviewAction should return VIEW action for invoice when the chat report is archived', async () => {

0 commit comments

Comments
 (0)