Skip to content

Refractoring selected transactions loop #61482

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

Merged
Merged
Changes from 1 commit
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
14 changes: 8 additions & 6 deletions src/hooks/useSelectedTransactionsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,26 @@ function useSelectedTransactionsActions({report, reportActions, session, onExpor
const isMoneyRequestReport = isMoneyRequestReportUtils(report);
const selectedTransactions = selectedTransactionsID.map((transactionID) => getTransaction(transactionID)).filter((t) => !!t);
const isReportReimbursed = report?.stateNum === CONST.REPORT.STATE_NUM.APPROVED && report?.statusNum === CONST.REPORT.STATUS_NUM.REIMBURSED;
let canHoldTransactions = isMoneyRequestReport && !isReportReimbursed;
let canUnholdTransactions = isMoneyRequestReport;
let canHoldTransactions = selectedTransactions.length > 0 && isMoneyRequestReport && !isReportReimbursed;
let canUnholdTransactions = selectedTransactions.length > 0 && isMoneyRequestReport;

selectedTransactions.forEach((selectedTransaction) => {
if (!canHoldTransactions && !canHoldTransactions) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Coming from this issue #62403, we’re currently checking the condition if (!canHoldTransactions && !canHoldTransactions) to return early. This is causing the issue where we’re seeing the "Remove Hold" option for expenses that aren't actually held. we should be using if (!canHoldTransactions && !canUnholdTransactions) instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, but I think this early return is just there for "performance", I don't think it can change the outcome for canHoldTransactions and canHoldTransactions. I do agree that we should fix it regardless. Are you sure this is the cause of your bug??

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I think this is causing an issue because when canHoldTransactions is false, it never updates the value of canUnholdTransactions since it returns early in that case.

Copy link
Contributor

Choose a reason for hiding this comment

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

ahh, that makes sense, thanks for explaining

return;
}

if (!selectedTransaction?.transactionID) {
canHoldTransactions = false;
canUnholdTransactions = false;
return true;
return;
}
const iouReportAction = getIOUActionForTransactionID(reportActions, selectedTransaction.transactionID);
const {canHoldRequest, canUnholdRequest} = canHoldUnholdReportAction(iouReportAction);

canHoldTransactions = canHoldTransactions && canHoldRequest;
canUnholdTransactions = canUnholdTransactions && canUnholdRequest;

return !(canHoldTransactions || canUnholdTransactions);
});

if (canHoldTransactions) {
options.push({
text: translate('iou.hold'),
Expand Down
Loading