From b6a1e74570f2666db02d406f08628b0546760a88 Mon Sep 17 00:00:00 2001 From: Linh Date: Sat, 4 Apr 2026 14:45:24 +0700 Subject: [PATCH] refactor: remove deprecatedAllTransactions in hasExpenses --- src/components/ReportActionItem/MoneyReportView.tsx | 2 +- src/libs/ReportNameUtils.ts | 2 +- src/libs/ReportUtils.ts | 11 ++++------- tests/unit/ReportUtilsTest.ts | 4 ++-- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/components/ReportActionItem/MoneyReportView.tsx b/src/components/ReportActionItem/MoneyReportView.tsx index c8a480278649..192b3b9c589f 100644 --- a/src/components/ReportActionItem/MoneyReportView.tsx +++ b/src/components/ReportActionItem/MoneyReportView.tsx @@ -125,7 +125,7 @@ function MoneyReportView({ (reportField) => !isReportFieldDisabled(report, reportField, policy) || reportField.type === CONST.REPORT_FIELD_TYPES.FORMULA, ); const isOnlyTitleFieldEnabled = enabledReportFields.length === 1 && isReportFieldOfTypeTitle(enabledReportFields.at(0)); - const isClosedExpenseReportWithNoExpenses = isClosedExpenseReportWithNoExpensesReportUtils(report); + const isClosedExpenseReportWithNoExpenses = isClosedExpenseReportWithNoExpensesReportUtils(report, transactions); const isPaidGroupPolicyExpenseReport = isPaidGroupPolicyExpenseReportUtils(report); const isInvoiceReport = isInvoiceReportUtils(report); diff --git a/src/libs/ReportNameUtils.ts b/src/libs/ReportNameUtils.ts index ea8f8ccddef3..4d9ff63214ff 100644 --- a/src/libs/ReportNameUtils.ts +++ b/src/libs/ReportNameUtils.ts @@ -893,7 +893,7 @@ function computeReportName({ return chatThreadReportName; } - const transactionsArray = transactions ? (Object.values(transactions).filter(Boolean) as Array>) : undefined; + const transactionsArray = transactions ? (Object.values(transactions).filter(Boolean) as Array>) : []; if (isClosedExpenseReportWithNoExpenses(report, transactionsArray)) { // eslint-disable-next-line @typescript-eslint/no-deprecated return translateLocal('parentReportAction.deletedReport'); diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 95786eefd8f7..35039ac69fd9 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2337,17 +2337,14 @@ function findLastAccessedReport(ignoreDomainRooms: boolean, openOnAdminRoom = fa /** * Whether the provided report has expenses */ -function hasExpenses(reportID?: string, transactions?: Array>): boolean { - if (transactions) { - return !!transactions?.find((transaction) => transaction?.reportID === reportID); - } - return !!Object.values(deprecatedAllTransactions ?? {}).find((transaction) => transaction?.reportID === reportID); +function hasExpenses(reportID: string | undefined, transactions: Array>): boolean { + return !!transactions.find((transaction) => transaction?.reportID === reportID); } /** * Whether the provided report is a closed expense report with no expenses */ -function isClosedExpenseReportWithNoExpenses(report: OnyxEntry, transactions?: Array>): boolean { +function isClosedExpenseReportWithNoExpenses(report: OnyxEntry, transactions: Array>): boolean { if (!report?.statusNum || report.statusNum !== CONST.REPORT.STATUS_NUM.CLOSED || !isExpenseReport(report)) { return false; } @@ -5990,7 +5987,7 @@ function getReportName(reportNameInformation: GetReportNameParams): string { return reportActionMessage; } - if (isClosedExpenseReportWithNoExpenses(report, transactions)) { + if (isClosedExpenseReportWithNoExpenses(report, transactions ?? [])) { // eslint-disable-next-line @typescript-eslint/no-deprecated return translateLocal('parentReportAction.deletedReport'); } diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 82d729fae281..4b958b0817e6 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -2527,7 +2527,7 @@ describe('ReportUtils', () => { }; // Then it should not be considered closed without expenses, because it has a total - expect(isClosedExpenseReportWithNoExpenses(expenseReport)).toBe(false); + expect(isClosedExpenseReportWithNoExpenses(expenseReport, [])).toBe(false); }); test('closed expense report with zero total but non-reimbursable total exists', () => { @@ -2541,7 +2541,7 @@ describe('ReportUtils', () => { }; // Then it should not be considered closed without expenses, because nonReimbursableTotal indicates expenses exist - expect(isClosedExpenseReportWithNoExpenses(expenseReport)).toBe(false); + expect(isClosedExpenseReportWithNoExpenses(expenseReport, [])).toBe(false); }); test('should handle paid elsewhere money request', () => {