Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions src/libs/ReportPreviewActionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
getMoneyRequestSpendBreakdown,
getParentReport,
getReportTransactions,
hasExportError as hasExportErrorUtil,
hasOnlyNonReimbursableTransactions,
isClosedReport,
isCurrentUserSubmitter,
Expand Down Expand Up @@ -122,7 +123,7 @@ function canPay(
const isReimbursed = isSettled(report);

const isExported = report.isExportedToIntegration ?? false;
const hasExportError = report?.hasExportError ?? false;
const hasExportError = hasExportErrorUtil(undefined, report);
const didExportFail = !isExported && hasExportError;

if (
Expand Down Expand Up @@ -177,7 +178,7 @@ function canExport(report: Report, currentUserLogin: string, policy?: Policy) {
return false;
}

const hasExportError = report.hasExportError ?? false;
const hasExportError = hasExportErrorUtil(undefined, report);
if (syncEnabled && !hasExportError) {
return false;
}
Expand Down
13 changes: 7 additions & 6 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12568,7 +12568,6 @@ function getIntegrationNameFromExportMessage(reportActions: OnyxEntry<ReportActi
}

function isExported(reportActions: OnyxEntry<ReportActions> | ReportAction[], report?: OnyxEntry<Report>): boolean {
// If report object is provided and has the property, use it directly
if (report?.isExportedToIntegration !== undefined) {
return report.isExportedToIntegration;
}
Expand Down Expand Up @@ -12616,9 +12615,13 @@ function isExported(reportActions: OnyxEntry<ReportActions> | ReportAction[], re
}

function hasExportError(reportActions: OnyxEntry<ReportActions> | ReportAction[], report?: OnyxEntry<Report>) {
// If report object is provided and has the property, use it directly
if (report?.hasExportError !== undefined) {
return report.hasExportError;
if (report?.hasExportError) {
return true;
}
Comment on lines +12618 to +12620

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Honor explicit false export-error state

The new truthy check (if (report?.hasExportError)) no longer treats hasExportError: false as authoritative, so execution falls through to the report-action fallback and marks the report as errored whenever any historical INTEGRATIONS_MESSAGE exists. Because report actions are historical/append-only while isExported() is reset by later submit/reopen actions, this can incorrectly produce !isExported && hasExportError after a reopen cycle and block normal pay/export action selection for reports that no longer have an active export error.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hasExportError: false wouldn't fall through to the next block.


const exportErrors = report?.errorFields?.export;
if (exportErrors && Object.values(exportErrors).some((error) => error != null)) {
return true;
}

// Fallback to checking actions for backward compatibility
Expand Down Expand Up @@ -12926,7 +12929,6 @@ function canRejectReportAction(currentUserLogin: string, report: Report): boolea
}

function hasReportBeenReopened(report: OnyxEntry<Report>, reportActions?: OnyxEntry<ReportActions> | ReportAction[]): boolean {
// If report object is provided and has the property, use it directly
if (report?.hasReportBeenReopened !== undefined) {
return report.hasReportBeenReopened;
}
Expand All @@ -12941,7 +12943,6 @@ function hasReportBeenReopened(report: OnyxEntry<Report>, reportActions?: OnyxEn
}

function hasReportBeenRetracted(report: OnyxEntry<Report>, reportActions?: OnyxEntry<ReportActions> | ReportAction[]): boolean {
// If report object is provided and has the property, use it directly
if (report?.hasReportBeenRetracted !== undefined) {
return report.hasReportBeenRetracted;
}
Expand Down
36 changes: 36 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ import {
getWorkspaceNameUpdatedMessage,
hasActionWithErrorsForTransaction,
hasEmptyReportsForPolicy,
hasExportError,
hasReceiptError,
hasSmartscanError,
hasVisibleReportFieldViolations,
Expand Down Expand Up @@ -17619,4 +17620,39 @@ describe('ReportUtils', () => {
expect(createdActionForThread).toBeNull();
});
});

describe('hasExportError', () => {
it('returns true when report.hasExportError is true', () => {
const report = {hasExportError: true} as Report;
expect(hasExportError([], report)).toBe(true);
});

it('returns true when errorFields.export is populated but hasExportError is false', () => {
const report = {
hasExportError: false,
errorFields: {export: {'1708946640843000': 'export failed'}},
} as unknown as Report;
expect(hasExportError([], report)).toBe(true);
});

it('returns false when errorFields.export is cleared', () => {
const report = {
hasExportError: false,
errorFields: {export: null},
} as unknown as Report;
expect(hasExportError([], report)).toBe(false);
});

it('returns true when an integration message action exists in reportActions', () => {
const report = {hasExportError: false} as Report;
const reportActions = [
{
actionName: CONST.REPORT.ACTIONS.TYPE.INTEGRATIONS_MESSAGE,
reportActionID: '1',
created: '2024-01-01',
},
] as ReportAction[];
expect(hasExportError(reportActions, report)).toBe(true);
});
});
});
Loading