From 13f840ce6e563730c3298e513da007c747001e92 Mon Sep 17 00:00:00 2001 From: apeyada Date: Fri, 9 Oct 2026 12:51:26 +0100 Subject: [PATCH 1/4] Remove report level actions from expense rows in Search --- src/libs/SearchUIUtils.ts | 18 ++-- tests/unit/Search/SearchUIUtilsTest.ts | 126 ++++++++++++++++++++----- 2 files changed, 108 insertions(+), 36 deletions(-) diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index 65bcd6f3c86d..c93ca4869607 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -2160,6 +2160,11 @@ function getActions( return [CONST.SEARCH.ACTION_TYPES.PAID]; } + // Submit/Approve/Pay are report level actions, so expense rows only offer View. + if (isTransaction) { + return [CONST.SEARCH.ACTION_TYPES.VIEW]; + } + // We need to check both options for a falsy value since the transaction might not have an error but the report associated with it might. We return early if there are any errors for performance reasons, so we don't need to compute any other possible actions. if (transaction?.errors || report?.errors) { @@ -2172,23 +2177,12 @@ function getActions( } const allActions: SearchTransactionAction[] = []; - let allReportTransactions: OnyxTypes.Transaction[]; - if (isReportEntry(key)) { - allReportTransactions = precomputedTransactionsForReport ?? getTransactionsForReport(data, report.reportID); - } else { - allReportTransactions = transaction ? [transaction] : []; - } + const allReportTransactions = precomputedTransactionsForReport ?? getTransactionsForReport(data, report.reportID); const reportNVP = getReportNameValuePairsFromKey(data, report); const isChatReportArchived = isArchivedReport(data[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.chatReportID}`]); - // Submit/Approve/Pay can only be taken on transactions if the transaction is the only one on the report, otherwise `View` is the only option. - // If this condition is not met, return early for performance reasons - if (isTransaction && !isOneTransactionReport(report)) { - return allActions.length > 0 ? allActions : [CONST.SEARCH.ACTION_TYPES.VIEW]; - } - const invoiceReceiverPolicy: OnyxTypes.Policy | undefined = isInvoiceReport(report) && report?.invoiceReceiver?.type === CONST.REPORT.INVOICE_RECEIVER_TYPE.BUSINESS ? data[`${ONYXKEYS.COLLECTION.POLICY}${report?.invoiceReceiver?.policyID}`] diff --git a/tests/unit/Search/SearchUIUtilsTest.ts b/tests/unit/Search/SearchUIUtilsTest.ts index d7dad7e96ef2..8ce1475b0a50 100644 --- a/tests/unit/Search/SearchUIUtilsTest.ts +++ b/tests/unit/Search/SearchUIUtilsTest.ts @@ -861,11 +861,11 @@ const reportActionListItems = createMock([ const transactionsListItems = createMock([ { - action: 'submit', - allActions: ['submit'], + action: 'view', + allActions: ['view'], canPay: false, canApprove: false, - canSubmit: true, + canSubmit: false, canChangeApprover: false, amount: -5000, report: report1, @@ -926,12 +926,12 @@ const transactionsListItems = createMock([ groupCurrency: 'USD', }, { - action: 'approve', - allActions: ['approve', 'changeApprover'], + action: 'view', + allActions: ['view'], canPay: false, - canApprove: true, + canApprove: false, canSubmit: false, - canChangeApprover: true, + canChangeApprover: false, amount: -5000, report: report2, policy, @@ -1216,11 +1216,11 @@ const transactionReportGroupListItems = createMock { expect(action).toStrictEqual(CONST.SEARCH.ACTION_TYPES.VIEW); }); - test('Should return `Submit` action for transaction on policy with delayed submission and no violations', () => { - let action = SearchUIUtils.getActions(searchResults.data, {}, `report_${reportID}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, '', adminAccountID, {}, {}, undefined).at(0); + test('Should return `Submit` action for report on policy with delayed submission and no violations', () => { + const action = SearchUIUtils.getActions(searchResults.data, {}, `report_${reportID}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, '', adminAccountID, {}, {}, undefined).at(0); expect(action).toStrictEqual(CONST.SEARCH.ACTION_TYPES.SUBMIT); + }); - action = SearchUIUtils.getActions(searchResults.data, {}, `transactions_${transactionID}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, '', adminAccountID, {}, {}, undefined).at(0); - expect(action).toStrictEqual(CONST.SEARCH.ACTION_TYPES.SUBMIT); + test('Should return only `View` action for the expense of a single-expense report that can be submitted', () => { + // Given report1 holds a single expense and the report itself can be submitted + const reportActions = SearchUIUtils.getActions(searchResults.data, {}, `report_${reportID}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, '', adminAccountID, {}, {}, undefined); + expect(reportActions).toContain(CONST.SEARCH.ACTION_TYPES.SUBMIT); + + // When the actions are computed for its expense row + const transactionActions = SearchUIUtils.getActions( + searchResults.data, + {}, + `transactions_${transactionID}`, + CONST.SEARCH.SEARCH_KEYS.EXPENSES, + '', + adminAccountID, + {}, + {}, + undefined, + ); + + // Then Submit is a report level action, so the expense row only offers View + expect(transactionActions).toStrictEqual([CONST.SEARCH.ACTION_TYPES.VIEW]); + }); + + test('Should return only `View` action for the expense of a single-expense report that can be paid', async () => { + // Given report3 is ready to be paid and holds a single expense + Onyx.merge(ONYXKEYS.SESSION, {accountID: adminAccountID}); + await waitForBatchedUpdates(); + const localSearchResults = { + ...searchResults.data, + [`report_${reportID3}`]: {...searchResults.data[`report_${reportID3}`], transactionCount: 1}, + }; + const reportActions = SearchUIUtils.getActions(localSearchResults, {}, `report_${reportID3}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, '', adminAccountID, {}, {}, undefined); + expect(reportActions).toContain(CONST.SEARCH.ACTION_TYPES.PAY); + + // When the actions are computed for its expense row + const transactionActions = SearchUIUtils.getActions( + localSearchResults, + {}, + `transactions_${transactionID3}`, + CONST.SEARCH.SEARCH_KEYS.EXPENSES, + '', + adminAccountID, + {}, + {}, + undefined, + ); + + // Then Pay is a report level action, so the expense row only offers View + expect(transactionActions).toStrictEqual([CONST.SEARCH.ACTION_TYPES.VIEW]); + }); + + test('Should show `View` and no Pay capability on the Expenses tab for a non-reimbursable single-expense report', async () => { + // Given report3 is ready to be paid and holds a single non-reimbursable expense + await Onyx.merge(ONYXKEYS.SESSION, {accountID: adminAccountID}); + const localSearchResults = { + ...searchResults.data, + [`report_${reportID3}`]: {...searchResults.data[`report_${reportID3}`], transactionCount: 1}, + [`transactions_${transactionID3}`]: {...searchResults.data[`transactions_${transactionID3}`], reimbursable: false}, + }; + + // When the Expenses tab sections are built + const [sections] = SearchUIUtils.getSections({ + dateFnsLocale: undefined, + type: CONST.SEARCH.DATA_TYPES.EXPENSE, + data: localSearchResults, + currentAccountID: adminAccountID, + currentUserEmail: adminEmail, + translate: translateLocal, + formatPhoneNumber, + bankAccountList: {}, + rules: undefined, + conciergeReportID: undefined, + convertToDisplayString, + reportAttributesDerivedValue: undefined, + }); + const transaction = sections.filter(SearchUIUtils.isTransactionListItemType).find((item) => item.transactionID === transactionID3); + + // Then the row shows View like the Reports tab, instead of a Pay button that does nothing + expect(transaction?.action).toStrictEqual(CONST.SEARCH.ACTION_TYPES.VIEW); + expect(transaction?.canPay).toBe(false); }); test('Should return `Submit` action for open expense report on Submit workspace when default submit-to is the owner', () => { @@ -2589,7 +2667,7 @@ describe('SearchUIUtils', () => { const action = SearchUIUtils.getActions( localSearchResults, {}, - `transactions_${dewTransactionID}`, + `report_${dewReportID}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, '', adminAccountID, @@ -2637,7 +2715,7 @@ describe('SearchUIUtils', () => { const action = SearchUIUtils.getActions( localSearchResults, {}, - `transactions_${dewTransactionID}`, + `report_${dewReportID}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, '', adminAccountID, @@ -2687,7 +2765,7 @@ describe('SearchUIUtils', () => { const action = SearchUIUtils.getActions( localSearchResults, {}, - `transactions_${nonDewTransactionID}`, + `report_${nonDewReportID}`, CONST.SEARCH.SEARCH_KEYS.EXPENSES, '', adminAccountID, @@ -2745,7 +2823,7 @@ describe('SearchUIUtils', () => { // report1 has ownerAccountID: adminAccountID, so adminAccountID is the owner const [sections] = SearchUIUtils.getSections({ dateFnsLocale: undefined, - type: CONST.SEARCH.DATA_TYPES.EXPENSE, + type: CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT, data: searchResults.data, currentAccountID: adminAccountID, currentUserEmail: adminEmail, @@ -2757,8 +2835,8 @@ describe('SearchUIUtils', () => { convertToDisplayString, reportAttributesDerivedValue: undefined, }); - const transaction = sections.filter(SearchUIUtils.isTransactionListItemType).find((item) => item.transactionID === transactionID); - expect(transaction?.action).toStrictEqual(CONST.SEARCH.ACTION_TYPES.SUBMIT); + const reportSection = sections.filter(SearchUIUtils.isTransactionReportGroupListItemType).find((item) => item.reportID === reportID); + expect(reportSection?.action).toStrictEqual(CONST.SEARCH.ACTION_TYPES.SUBMIT); }); }); From 912491d11b433b2043dab743bf7e863b81e2e588 Mon Sep 17 00:00:00 2001 From: apeyada Date: Fri, 9 Oct 2026 15:30:24 +0100 Subject: [PATCH 2/4] Keep report level actions on invoice rows in Search --- src/libs/SearchUIUtils.ts | 15 ++++++-- tests/unit/Search/SearchUIUtilsTest.ts | 47 ++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index c93ca4869607..fd063080c1e2 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -2161,7 +2161,7 @@ function getActions( } // Submit/Approve/Pay are report level actions, so expense rows only offer View. - if (isTransaction) { + if (isTransaction && !isInvoiceReport(report)) { return [CONST.SEARCH.ACTION_TYPES.VIEW]; } @@ -2177,12 +2177,23 @@ function getActions( } const allActions: SearchTransactionAction[] = []; - const allReportTransactions = precomputedTransactionsForReport ?? getTransactionsForReport(data, report.reportID); + let allReportTransactions: OnyxTypes.Transaction[]; + if (isReportEntry(key)) { + allReportTransactions = precomputedTransactionsForReport ?? getTransactionsForReport(data, report.reportID); + } else { + allReportTransactions = transaction ? [transaction] : []; + } const reportNVP = getReportNameValuePairsFromKey(data, report); const isChatReportArchived = isArchivedReport(data[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.chatReportID}`]); + // Submit/Approve/Pay can only be taken on transactions if the transaction is the only one on the report, otherwise `View` is the only option. + // If this condition is not met, return early for performance reasons + if (isTransaction && !isOneTransactionReport(report)) { + return allActions.length > 0 ? allActions : [CONST.SEARCH.ACTION_TYPES.VIEW]; + } + const invoiceReceiverPolicy: OnyxTypes.Policy | undefined = isInvoiceReport(report) && report?.invoiceReceiver?.type === CONST.REPORT.INVOICE_RECEIVER_TYPE.BUSINESS ? data[`${ONYXKEYS.COLLECTION.POLICY}${report?.invoiceReceiver?.policyID}`] diff --git a/tests/unit/Search/SearchUIUtilsTest.ts b/tests/unit/Search/SearchUIUtilsTest.ts index 8ce1475b0a50..4476e5ff4ee6 100644 --- a/tests/unit/Search/SearchUIUtilsTest.ts +++ b/tests/unit/Search/SearchUIUtilsTest.ts @@ -2345,6 +2345,53 @@ describe('SearchUIUtils', () => { expect(transactionActions).toStrictEqual([CONST.SEARCH.ACTION_TYPES.VIEW]); }); + test('Should keep `Pay` action for the expense of a single-line invoice the current user can pay', () => { + // Given a submitted single-line invoice sent to the current user + const invoiceReportID = 'invoice-report-pay'; + const invoiceChatReportID = 'invoice-chat-pay'; + const invoiceTransactionID = 'invoice-transaction-pay'; + const localSearchResults = { + ...searchResults.data, + [`report_${invoiceReportID}`]: { + ...searchResults.data[`report_${reportID3}`], + reportID: invoiceReportID, + chatReportID: invoiceChatReportID, + policyID: 'invoice-sender-policy', + type: CONST.REPORT.TYPE.INVOICE, + stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, + statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, + transactionCount: 1, + }, + [`report_${invoiceChatReportID}`]: { + ...searchResults.data[`report_${reportID4}`], + reportID: invoiceChatReportID, + chatType: CONST.REPORT.CHAT_TYPE.INVOICE, + invoiceReceiver: {type: CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL, accountID: adminAccountID}, + }, + [`transactions_${invoiceTransactionID}`]: { + ...searchResults.data[`transactions_${transactionID3}`], + transactionID: invoiceTransactionID, + reportID: invoiceReportID, + }, + }; + + // When the actions are computed for its invoice row + const action = SearchUIUtils.getActions( + localSearchResults, + {}, + `transactions_${invoiceTransactionID}`, + CONST.SEARCH.SEARCH_KEYS.EXPENSES, + '', + adminAccountID, + {}, + {}, + undefined, + ).at(0); + + // Then invoice rows still offer Pay since only expense rows drop report level actions + expect(action).toStrictEqual(CONST.SEARCH.ACTION_TYPES.PAY); + }); + test('Should show `View` and no Pay capability on the Expenses tab for a non-reimbursable single-expense report', async () => { // Given report3 is ready to be paid and holds a single non-reimbursable expense await Onyx.merge(ONYXKEYS.SESSION, {accountID: adminAccountID}); From 336ccd249b4ade68b27c4536b4e45a8451d941d2 Mon Sep 17 00:00:00 2001 From: apeyada Date: Fri, 9 Oct 2026 15:32:48 +0100 Subject: [PATCH 3/4] Skip export check for transaction rows in Search --- src/libs/SearchUIUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index fd063080c1e2..c9bf10d4758e 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -2154,7 +2154,7 @@ function getActions( } const policy = getPolicyFromKey(data, report); - const isExportAvailable = isExportAction(report, currentUserLogin, policy, reportActions) && !isTransaction; + const isExportAvailable = !isTransaction && isExportAction(report, currentUserLogin, policy, reportActions); if (isSettled(report) && !isExportAvailable) { return [CONST.SEARCH.ACTION_TYPES.PAID]; From 25d486ecf8d44cb37de0a4b8ecfcdc74923de96c Mon Sep 17 00:00:00 2001 From: apeyada Date: Fri, 9 Oct 2026 16:15:26 +0100 Subject: [PATCH 4/4] Update stale comment in Search getActions --- src/libs/SearchUIUtils.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index c9bf10d4758e..f63844d064d3 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -2188,8 +2188,7 @@ function getActions( const isChatReportArchived = isArchivedReport(data[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.chatReportID}`]); - // Submit/Approve/Pay can only be taken on transactions if the transaction is the only one on the report, otherwise `View` is the only option. - // If this condition is not met, return early for performance reasons + // Only invoice rows reach here. They get report actions only when the invoice has a single line. if (isTransaction && !isOneTransactionReport(report)) { return allActions.length > 0 ? allActions : [CONST.SEARCH.ACTION_TYPES.VIEW]; }