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
2 changes: 0 additions & 2 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,6 @@ const CONST = {
REIMBURSEMENT_SETUP_REQUESTED: 'REIMBURSEMENTSETUPREQUESTED', // Deprecated OldDot Action
REIMBURSEMENT_DIRECTOR_INFORMATION_REQUIRED: 'DIRECTORINFORMATIONREQUIRED',
REJECTED: 'REJECTED',
REJECTED_TO_SUBMITTER: 'REJECTEDTOSUBMITTER',
REMOVED_FROM_APPROVAL_CHAIN: 'REMOVEDFROMAPPROVALCHAIN',
DEMOTED_FROM_WORKSPACE: 'DEMOTEDFROMWORKSPACE',
RENAMED: 'RENAMED',
Expand All @@ -1344,7 +1343,6 @@ const CONST = {
STRIPE_PAID: 'STRIPEPAID', // OldDot Action
SUBMITTED: 'SUBMITTED',
SUBMITTED_AND_CLOSED: 'SUBMITTEDCLOSED',
ACTION_DELEGATE_SUBMIT: 'DELEGATESUBMIT',
TAKE_CONTROL: 'TAKECONTROL', // OldDot Action
TASK_CANCELLED: 'TASKCANCELLED',
TASK_COMPLETED: 'TASKCOMPLETED',
Expand Down
2 changes: 1 addition & 1 deletion src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ function MoneyReportHeader({

const {duplicateTransactions, duplicateTransactionViolations} = useDuplicateTransactionsAndViolations(transactions.map((t) => t.transactionID));
const {deleteTransactions} = useDeleteTransactions({report: chatReport, reportActions, policy});
const isExported = useMemo(() => isExportedUtils(reportActions, moneyRequestReport), [reportActions, moneyRequestReport]);
const isExported = useMemo(() => isExportedUtils(reportActions), [reportActions]);
// wrapped in useMemo to improve performance because this is an operation on array
const integrationNameFromExportMessage = useMemo(() => {
if (!isExported) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function ExportWithDropdownMenu({

const iconToDisplay = getIntegrationIcon(connectionName, expensifyIcons);
const canBeExported = canBeExportedUtils(report);
const isExported = isExportedUtils(reportActions, report);
const isExported = isExportedUtils(reportActions);
const flattenedWrapperStyle = StyleSheet.flatten([styles.flex1, wrapperStyle]);

const dropdownOptions: Array<DropdownOption<ReportExportType>> = useMemo(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ReportPrimaryActionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ function isExportAction(report: Report, currentUserLogin: string, policy?: Polic
}

const syncEnabled = hasIntegrationAutoSync(policy, connectedIntegration);
const isExported = isExportedUtil(reportActions, report);
const isExported = isExportedUtil(reportActions);
if (isExported) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/libs/ReportSecondaryActionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ function isChangeWorkspaceAction(report: Report, policies: OnyxCollection<Policy
}

const reportPolicy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`];
return hasAvailablePolicies && canEditReportPolicy(report, reportPolicy) && !isExportedUtils(reportActions, report);
return hasAvailablePolicies && canEditReportPolicy(report, reportPolicy) && !isExportedUtils(reportActions);
}

function isDeleteAction(report: Report, reportTransactions: Transaction[], reportActions: ReportAction[]): boolean {
Expand Down Expand Up @@ -859,7 +859,7 @@ function getSecondaryReportActions({
}): Array<ValueOf<typeof CONST.REPORT.SECONDARY_ACTIONS>> {
const options: Array<ValueOf<typeof CONST.REPORT.SECONDARY_ACTIONS>> = [];

const isExported = isExportedUtils(reportActions, report);
const isExported = isExportedUtils(reportActions);
const hasExportError = hasExportErrorUtils(reportActions, report);
const didExportFail = !isExported && hasExportError;

Expand Down
44 changes: 17 additions & 27 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@
};

let conciergeReportIDOnyxConnect: OnyxEntry<string>;
Onyx.connect({

Check warning on line 1016 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.CONCIERGE_REPORT_ID,
callback: (value) => {
conciergeReportIDOnyxConnect = value;
Expand All @@ -1021,7 +1021,7 @@
});

const defaultAvatarBuildingIconTestID = 'SvgDefaultAvatarBuilding Icon';
Onyx.connect({

Check warning on line 1024 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, val is undefined
Expand All @@ -1039,7 +1039,7 @@
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
let allPersonalDetailLogins: string[];
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({

Check warning on line 1042 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
if (currentUserAccountID) {
Expand All @@ -1051,7 +1051,7 @@
});

let allReportsDraft: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 1054 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_DRAFT,
waitForCollectionCallback: true,
callback: (value) => (allReportsDraft = value),
Expand All @@ -1060,7 +1060,7 @@
let allPolicies: OnyxCollection<Policy>;
let hasPolicies: boolean;
let policiesArray: Policy[] = [];
Onyx.connect({

Check warning on line 1063 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1071,7 +1071,7 @@
});

let allPolicyDrafts: OnyxCollection<Policy>;
Onyx.connect({

Check warning on line 1074 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY_DRAFTS,
waitForCollectionCallback: true,
callback: (value) => (allPolicyDrafts = value),
Expand All @@ -1079,7 +1079,7 @@

let allReports: OnyxCollection<Report>;
let reportsByPolicyID: ReportByPolicyMap;
Onyx.connect({

Check warning on line 1082 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -1115,14 +1115,14 @@
});

let betaConfiguration: OnyxEntry<BetaConfiguration> = {};
Onyx.connect({

Check warning on line 1118 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.BETA_CONFIGURATION,
callback: (value) => (betaConfiguration = value ?? {}),
});

let allTransactions: OnyxCollection<Transaction> = {};
let reportsTransactions: Record<string, Transaction[]> = {};
Onyx.connect({

Check warning on line 1125 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1148,7 +1148,7 @@
});

let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 1151 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand Down Expand Up @@ -12230,41 +12230,31 @@
return false;
}

const reportActionList = Array.isArray(reportActions) ? reportActions : Object.values(reportActions);

// Actions that reset the approval state and invalidate previous exports
const resetApprovalActionTypes = new Set<string>([
CONST.REPORT.ACTIONS.TYPE.REJECTED_TO_SUBMITTER,
CONST.REPORT.ACTIONS.TYPE.RETRACTED,
CONST.REPORT.ACTIONS.TYPE.SUBMITTED,
CONST.REPORT.ACTIONS.TYPE.ACTION_DELEGATE_SUBMIT,
CONST.REPORT.ACTIONS.TYPE.REOPENED,
CONST.REPORT.ACTIONS.TYPE.UNAPPROVED,
]);
const validExportLabels = new Set<string>(Object.values(CONST.EXPORT_LABELS));

let lastResetCreated = '';
let lastSuccessfulExportCreated = '';
let exportIntegrationActionsCount = 0;
let integrationMessageActionsCount = 0;

const reportActionList = Array.isArray(reportActions) ? reportActions : Object.values(reportActions);
for (const action of reportActionList) {
if (resetApprovalActionTypes.has(action.actionName)) {
if (action.created > lastResetCreated) {
lastResetCreated = action.created;
}
}
if (isExportIntegrationAction(action)) {
const originalMessage = getOriginalMessage(action);
const label = originalMessage?.label;
// It's possible for originalMessage?.markedManually to be `false`, but the report is still has a valid automatic export.
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const isValidExport = originalMessage?.markedManually || (label && validExportLabels.has(label) && originalMessage?.type !== CONST.EXPORT_TEMPLATE);
if (isValidExport && action.created > lastSuccessfulExportCreated) {
lastSuccessfulExportCreated = action.created;
// We consider any reports marked manually as exported to be exported, so we shortcut here.
if (originalMessage?.markedManually) {
return true;
}
// exportTemplate type is a CSV export, so we don't count it as an export integration action
if (originalMessage?.type !== CONST.EXPORT_TEMPLATE) {
exportIntegrationActionsCount++;
}
}
if (isIntegrationMessageAction(action)) {
integrationMessageActionsCount++;
}
}

return lastSuccessfulExportCreated > lastResetCreated;
// We need to make sure that there was at least one successful export to consider the report exported.
// We add one EXPORT_INTEGRATION action to the report when we start exporting it (with pendingAction: 'add') and then another EXPORT_INTEGRATION when the export finishes successfully.
// If the export fails, we add an INTEGRATIONS_MESSAGE action to the report, but the initial EXPORT_INTEGRATION action is still present, so we compare the counts of these two actions to determine if the report was exported successfully.
return exportIntegrationActionsCount > integrationMessageActionsCount;
Comment on lines +12254 to +12257

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 Reset export state when approval cycle restarts

This logic now marks a report as exported solely from action counts, so a previously exported report stays exported after RETRACTED/REOPENED/UNAPPROVED transitions because the historical EXPORT_INTEGRATION actions still outnumber integration errors. In that state, downstream checks that call isExported() continue to hide/alter export-related actions even though the backend has reset the approval/export cycle, so users can be forced into an unnecessary “export again” flow or blocked from expected actions after reopening a report.

Useful? React with 👍 / 👎.

}

function hasExportError(reportActions: OnyxEntry<ReportActions> | ReportAction[], report?: OnyxEntry<Report>) {
Expand Down
Loading