Skip to content

Commit 8bca960

Browse files
Extract the all-held exclusion into a single isReportExcludedForHeldExpenses helper
Co-authored-by: DylanDylann <DylanDylann@users.noreply.github.com>
1 parent 73fe723 commit 8bca960

2 files changed

Lines changed: 16 additions & 16 deletions

File tree

‎src/libs/ReportUtils.ts‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4656,18 +4656,11 @@ function getReasonAndReportActionThatRequiresAttention(
46564656
const hasOnlyPendingTransactions = transactions.length > 0 && transactions.every((t) => isPending(t));
46574657

46584658
const iouReport = reports ? reports[`${ONYXKEYS.COLLECTION.REPORT}${iouReportID}`] : getReportOrDraftReport(iouReportID);
4659-
const hasAllExpensesHeld = hasOnlyHeldExpenses(transactions);
46604659
const iouReportActions = allReportActionsParam?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReportID}`] ?? getAllReportActions(iouReportID);
4661-
// An all-held report can't move to its next state, so it isn't a to-do. Keep it only for a report awaiting
4662-
// approval or payment where the current user placed a hold, since they can remove it. An open report stays
4663-
// excluded because only its owner can place a hold there, and that owner is the one who submits.
46644660
// This only has to run on the fallback path: when a candidate was found, getBadgeFromIOUReport has already applied
46654661
// the same exclusion while picking it, so the chat is known to have an actionable child even when a sibling of that
46664662
// child is fully held.
4667-
const isFallbackReportExcludedForHeldExpenses =
4668-
!iouReportActionToApproveOrPay &&
4669-
hasAllExpensesHeld &&
4670-
(isOpenExpenseReport(iouReport) || !didCurrentUserPlaceHoldOnReportExpense(iouReportActions, transactions, currentUserAccountID));
4663+
const isFallbackReportExcludedForHeldExpenses = !iouReportActionToApproveOrPay && isReportExcludedForHeldExpenses(iouReport, transactions, iouReportActions, currentUserAccountID);
46714664

46724665
// Has a child report that is awaiting action (e.g. approve, pay, add bank account) from current user.
46734666
// A report whose only expenses are pending Expensify Card transactions can't be actioned until they post, so it
@@ -4942,6 +4935,18 @@ function didCurrentUserPlaceHoldOnReportExpense(reportActions: OnyxEntry<ReportA
49424935
});
49434936
}
49444937

4938+
/**
4939+
* An all-held report can't move to its next state, so it isn't a to-do and doesn't get an action badge. Keep it only
4940+
* for a report awaiting approval or payment where the current user placed a hold, since they can remove it. An open
4941+
* report stays excluded because only its owner can place a hold there, and that owner is the one who submits.
4942+
*/
4943+
function isReportExcludedForHeldExpenses(iouReport: OnyxEntry<Report>, transactions: Transaction[], reportActions: OnyxEntry<ReportActions>, currentUserAccountID?: number): boolean {
4944+
if (!hasOnlyHeldExpenses(transactions)) {
4945+
return false;
4946+
}
4947+
return isOpenExpenseReport(iouReport) || !didCurrentUserPlaceHoldOnReportExpense(reportActions, transactions, currentUserAccountID);
4948+
}
4949+
49454950
/**
49464951
* Given a report field, check if the field can be edited or not.
49474952
* For title fields, its considered disabled if `deletable` prop is `true` (https://github.com/Expensify/App/issues/35043#issuecomment-1911275433)
@@ -14739,6 +14744,7 @@ export {
1473914744
isAwaitingFirstLevelApproval,
1474014745
isPublicRoom,
1474114746
isReportApproved,
14747+
isReportExcludedForHeldExpenses,
1474214748
isReportManuallyReimbursed,
1474314749
isReportFieldDisabled,
1474414750
isReportFieldDisabledForUser,

‎src/libs/actions/IOU/ReportWorkflow.ts‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import {
4040
buildOptimisticUnapprovedReportAction,
4141
canBeAutoReimbursed,
4242
canSubmitAndIsAwaitingForCurrentUser,
43-
didCurrentUserPlaceHoldOnReportExpense,
4443
getAllHeldTransactions as getAllHeldTransactionsReportUtils,
4544
getMoneyRequestSpendBreakdown,
4645
getNextApproverAccountID,
@@ -64,6 +63,7 @@ import {
6463
isPayer as isPayerReportUtils,
6564
isProcessingReport,
6665
isReportApproved,
66+
isReportExcludedForHeldExpenses,
6767
isReportPendingDelete,
6868
isSettled,
6969
} from '@libs/ReportUtils';
@@ -339,13 +339,7 @@ function getBadgeFromIOUReport(
339339
): ValueOf<typeof CONST.REPORT.ACTION_BADGE> | undefined {
340340
const reportTransactions = getReportTransactions(iouReport?.reportID);
341341

342-
// An all-held report can't move to its next state, so it doesn't get an action badge. Keep it only for a report
343-
// awaiting approval or payment where the current user placed a hold, since they can remove it. An open report stays
344-
// excluded because only its owner can place a hold there, and that owner is the one who submits.
345-
const isExcludedForHeldExpenses =
346-
hasOnlyHeldExpenses(reportTransactions) &&
347-
(isOpenExpenseReportReportUtils(iouReport) || !didCurrentUserPlaceHoldOnReportExpense(iouReportActions, reportTransactions, currentUserAccountID));
348-
if (isExcludedForHeldExpenses) {
342+
if (isReportExcludedForHeldExpenses(iouReport, reportTransactions, iouReportActions, currentUserAccountID)) {
349343
return undefined;
350344
}
351345

0 commit comments

Comments
 (0)