diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 192086af9c13..778645e9eeca 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -1740,7 +1740,6 @@ function shouldReportActionBeVisible( reportID?: string, isSupportTicketReport = false, reportActions?: OnyxEntry, - isInvoice?: boolean, policy?: OnyxEntry, currentUserEmail?: string, ): boolean { @@ -1820,12 +1819,10 @@ function shouldReportActionBeVisible( return false; } - // Hide REIMBURSED and MARKED_REIMBURSED actions created from NewDot since an IOU PAY action is displayed instead. - // ReimburseReport and MarkReimbursed add no IOU PAY action to an invoice, and neither does paying its linked bill, so the payment action stays visible on invoices. - // Auth sets shouldShow to false on MARKED_REIMBURSED actions created from NewDot for the same reason, so invoices ignore it too. + // Auth sets shouldShow to false on REIMBURSED and MARKED_REIMBURSED actions created from NewDot, because NewDot shows an IOU PAY action instead. + // Invoices keep them visible, because paying a linked bill adds no IOU PAY action to the invoice. if (isPaymentRecordedByReimbursedAction(reportAction)) { - // Search passes isInvoice because its invoice can exist only in the Search snapshot, not in Onyx. - if (isPaymentActionHiddenOutsideInvoices(reportAction) && !(isInvoice ?? isInvoiceReportID(reportAction.reportID ?? reportID))) { + if (reportAction.shouldShow === false) { return false; } @@ -1884,7 +1881,6 @@ function isReportActionVisible( // TODO: Remove optional (?) once all callers pass currentUserAccountID. Refactor issue: https://github.com/Expensify/App/issues/66408 currentUserAccountID?: number, reportActions?: OnyxEntry, - isInvoice?: boolean, ): boolean { if (!reportAction?.reportActionID) { return false; @@ -1896,45 +1892,18 @@ function isReportActionVisible( // from what's cached in visibleReportActions (which reflects persisted Onyx data). // We must recalculate visibility at runtime to ensure accuracy for these transient states. if (reportAction.pendingAction) { - return shouldReportActionBeVisible( - reportAction, - reportAction.reportActionID, - canUserPerformWriteAction, - currentUserAccountID, - reportID, - isSupportTicketReport, - reportActions, - isInvoice, - ); + return shouldReportActionBeVisible(reportAction, reportAction.reportActionID, canUserPerformWriteAction, currentUserAccountID, reportID, isSupportTicketReport, reportActions); } if (visibleReportActions && reportID) { const reportCache = visibleReportActions[reportID]; if (!reportCache) { - return shouldReportActionBeVisible( - reportAction, - reportAction.reportActionID, - canUserPerformWriteAction, - currentUserAccountID, - reportID, - isSupportTicketReport, - reportActions, - isInvoice, - ); + return shouldReportActionBeVisible(reportAction, reportAction.reportActionID, canUserPerformWriteAction, currentUserAccountID, reportID, isSupportTicketReport, reportActions); } const staticVisibility = reportCache[reportAction.reportActionID]; // If action is not in derived value cache, fall back to runtime calculation if (staticVisibility === undefined) { - return shouldReportActionBeVisible( - reportAction, - reportAction.reportActionID, - canUserPerformWriteAction, - currentUserAccountID, - reportID, - isSupportTicketReport, - reportActions, - isInvoice, - ); + return shouldReportActionBeVisible(reportAction, reportAction.reportActionID, canUserPerformWriteAction, currentUserAccountID, reportID, isSupportTicketReport, reportActions); } if (!staticVisibility) { return false; @@ -1944,7 +1913,7 @@ function isReportActionVisible( } return true; } - return shouldReportActionBeVisible(reportAction, reportAction.reportActionID, canUserPerformWriteAction, currentUserAccountID, reportID, isSupportTicketReport, reportActions, isInvoice); + return shouldReportActionBeVisible(reportAction, reportAction.reportActionID, canUserPerformWriteAction, currentUserAccountID, reportID, isSupportTicketReport, reportActions); } /** @@ -3606,18 +3575,6 @@ function isPaymentRecordedByReimbursedAction( return isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.REIMBURSED) || isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.MARKED_REIMBURSED); } -function isInvoiceReportID(reportID: string | undefined): boolean { - return !!reportID && getReportOrDraftReport({reportID})?.type === CONST.REPORT.TYPE.INVOICE; -} - -/** - * Returns true for a REIMBURSED or MARKED_REIMBURSED action that was created from NewDot or that Auth marked with - * shouldShow false. Such an action is hidden on every report except an invoice. - */ -function isPaymentActionHiddenOutsideInvoices(reportAction: OnyxEntry): boolean { - return isPaymentRecordedByReimbursedAction(reportAction) && (!!getOriginalMessage(reportAction)?.isNewDot || reportAction.shouldShow === false); -} - /** * Checks if a report action is an actionable whisper that requires write permission to be visible. */ @@ -6562,7 +6519,6 @@ export { isActionableAddPaymentCard, isActionableCardFraudAlert, isActionableWhisperRequiringWritePermission, - isPaymentActionHiddenOutsideInvoices, getExportIntegrationActionFragments, getExportIntegrationLastMessageText, getExportIntegrationMessageHTML, diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index d73fa700e1f1..2dce500b2335 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -2836,15 +2836,7 @@ function getReportActionsSections( const isReportArchived = isArchivedReport(data[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`]); if ( !reportID || - !isReportActionVisible( - reportAction, - reportID, - canUserPerformWriteAction(report, isReportArchived), - visibleReportActionsData, - undefined, - reportActionsCollection, - isInvoiceReport(report), - ) || + !isReportActionVisible(reportAction, reportID, canUserPerformWriteAction(report, isReportArchived), visibleReportActionsData, undefined, reportActionsCollection) || isDeletedAction(reportAction) || isResolvedActionableWhisper(reportAction) || reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CLOSED || diff --git a/src/libs/actions/OnyxDerived/configs/visibleReportActions.ts b/src/libs/actions/OnyxDerived/configs/visibleReportActions.ts index 27aadd4a860f..18aa234d6fad 100644 --- a/src/libs/actions/OnyxDerived/configs/visibleReportActions.ts +++ b/src/libs/actions/OnyxDerived/configs/visibleReportActions.ts @@ -3,7 +3,6 @@ import { isActionableWhisperRequiringWritePermission, isActionOfType, isConciergeCategoryOptions, - isPaymentActionHiddenOutsideInvoices, shouldReportActionBeVisible, } from '@libs/ReportActionsUtils'; import {isSupportTicket} from '@libs/ReportUtils'; @@ -19,20 +18,13 @@ import type {OnyxEntry} from 'react-native-onyx'; /** * Returns true if the action's visibility depends on runtime context that can't be cached, - * such as write permissions, policy settings, the type of its report, or sibling actions. + * such as write permissions, policy settings, or sibling actions. */ function shouldSkipCachingAction(action: ReportAction): boolean { if (isActionableReportMentionWhisper(action)) { return false; } - // A payment action hidden outside invoices depends on its report's type. The cache doesn't pass a reportID, so it - // can't tell that the report is an invoice and would hide the action there. - return ( - isActionableWhisperRequiringWritePermission(action) || - isConciergeCategoryOptions(action) || - isPaymentActionHiddenOutsideInvoices(action) || - isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.MARKED_REIMBURSED) - ); + return isActionableWhisperRequiringWritePermission(action) || isConciergeCategoryOptions(action) || isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.MARKED_REIMBURSED); } /** @@ -64,18 +56,7 @@ function computeReportVisibility( } if (isActionableReportMentionWhisper(action)) { // Write permission is still checked at runtime in isReportActionVisible, so pass true here to run the remaining visibility checks (deleted, resolved, targeted, room-creation permission) against the snapshot. - reportVisibility[action.reportActionID] = shouldReportActionBeVisible( - action, - actionID, - true, - currentUserAccountID, - undefined, - false, - undefined, - undefined, - policy, - currentUserEmail, - ); + reportVisibility[action.reportActionID] = shouldReportActionBeVisible(action, actionID, true, currentUserAccountID, undefined, false, undefined, policy, currentUserEmail); continue; } // A replacement ticket has its own active survey, so the original ticket's survey is stale. @@ -106,7 +87,7 @@ function updateReportMentionWhispersVisibility( if (!action || actionID !== action.reportActionID || !isActionableReportMentionWhisper(action)) { continue; } - const isVisible = shouldReportActionBeVisible(action, actionID, true, currentUserAccountID, undefined, false, undefined, undefined, policy, currentUserEmail); + const isVisible = shouldReportActionBeVisible(action, actionID, true, currentUserAccountID, undefined, false, undefined, policy, currentUserEmail); if (nextReportVisibility?.[action.reportActionID] === isVisible) { continue; } diff --git a/tests/unit/OnyxDerived/visibleReportActionsTest.ts b/tests/unit/OnyxDerived/visibleReportActionsTest.ts index 68f263d171dd..4e7ea6ec396c 100644 --- a/tests/unit/OnyxDerived/visibleReportActionsTest.ts +++ b/tests/unit/OnyxDerived/visibleReportActionsTest.ts @@ -3,7 +3,7 @@ import visibleReportActionsConfig from '@libs/actions/OnyxDerived/configs/visibl import CONST from '@src/CONST'; import type {OnyxKey} from '@src/ONYXKEYS'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {Policy, Report, ReportAction, ReportActions, ReportNameValuePairs} from '@src/types/onyx'; +import type {Policy, Report, ReportActions, ReportNameValuePairs} from '@src/types/onyx'; import type {VisibleReportActionsDerivedValue} from '@src/types/onyx/DerivedValues'; import type {OnyxCollection} from 'react-native-onyx'; @@ -82,63 +82,6 @@ describe('visibleReportActions', () => { expect(result[unrelatedReportID]).toBe(currentValue[unrelatedReportID]); }); - it('does not cache the visibility of a REIMBURSED action that is hidden outside invoices', () => { - // Given a NewDot REIMBURSED action and one that Auth marked with shouldShow false. Both are hidden on expense reports and shown on invoices. - const reportID = 'reportWithNewDotPayment'; - const reimbursedActionID = 'reimbursedActionID'; - const hiddenReimbursedActionID = 'hiddenReimbursedActionID'; - const commentActionID = 'commentActionID'; - const reimbursedAction: ReportAction = { - reportActionID: reimbursedActionID, - actionName: CONST.REPORT.ACTIONS.TYPE.REIMBURSED, - created: '2026-10-13 12:00:00.000', - // eslint-disable-next-line @typescript-eslint/no-deprecated -- Auth sends isNewDot on originalMessage, which getOriginalMessage reads. - originalMessage: {isNewDot: true}, - }; - const hiddenReimbursedAction: ReportAction = { - reportActionID: hiddenReimbursedActionID, - actionName: CONST.REPORT.ACTIONS.TYPE.REIMBURSED, - created: '2026-10-13 12:00:00.500', - shouldShow: false, - }; - const allReportActions: OnyxCollection = { - [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`]: { - [reimbursedActionID]: reimbursedAction, - [hiddenReimbursedActionID]: hiddenReimbursedAction, - [commentActionID]: { - reportActionID: commentActionID, - actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, - created: '2026-10-13 12:00:01.000', - message: [{type: 'COMMENT', html: 'Hello', text: 'Hello'}], - }, - }, - }; - const args: Parameters[0] = [ - allReportActions, - undefined, - { - [`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]: { - reportID, - type: CONST.REPORT.TYPE.INVOICE, - }, - }, - {}, - {}, - ]; - - // When the derived value computes the report's visibility - const result = visibleReportActionsConfig.compute(args, { - currentValue: undefined, - sourceValues: undefined, - triggeredKeys: new Set(), - }); - - // Then it leaves both payment actions out, because their visibility depends on the report type, which the cache doesn't track - expect(result[reportID]?.[reimbursedActionID]).toBeUndefined(); - expect(result[reportID]?.[hiddenReimbursedActionID]).toBeUndefined(); - expect(result[reportID]?.[commentActionID]).toBe(true); - }); - it('recomputes only the changed report when a report changes', () => { // Given a closed report that turned into a support ticket, where the closed action shows only for support tickets const reportID = 'ticketReportID'; diff --git a/tests/unit/ReportActionsUtilsTest.ts b/tests/unit/ReportActionsUtilsTest.ts index ec453f01385c..cce04bf519f1 100644 --- a/tests/unit/ReportActionsUtilsTest.ts +++ b/tests/unit/ReportActionsUtilsTest.ts @@ -3498,8 +3498,8 @@ describe('ReportActionsUtils', () => { expect(actual).toBe(true); }); - it('should return false for REIMBURSED action from NewDot', () => { - // Given a REIMBURSED action created from NewDot (isNewDot=true) + it('should return false for REIMBURSED action that Auth hides', () => { + // Given a REIMBURSED action created from NewDot, which Auth sends with shouldShow false const reportAction: ReportAction = { actionName: CONST.REPORT.ACTIONS.TYPE.REIMBURSED, reportActionID: '1', @@ -3512,6 +3512,7 @@ describe('ReportActionsUtils', () => { }, ], originalMessage: {isNewDot: true}, + shouldShow: false, }; // Then the action should NOT be visible (IOU PAY action is shown instead) @@ -3565,8 +3566,8 @@ describe('ReportActionsUtils', () => { expect(actual).toBe(true); }); - it('should return false for MARKED_REIMBURSED action from NewDot', () => { - // Given a MARKED_REIMBURSED action created from NewDot (isNewDot=true) + it('should return false for MARKED_REIMBURSED action that Auth hides', () => { + // Given a MARKED_REIMBURSED action created from NewDot, which Auth sends with shouldShow false const reportAction: ReportAction = { actionName: CONST.REPORT.ACTIONS.TYPE.MARKED_REIMBURSED, reportActionID: '1', @@ -3579,6 +3580,7 @@ describe('ReportActionsUtils', () => { }, ], originalMessage: {isNewDot: true}, + shouldShow: false, }; // Then the action should NOT be visible (IOU PAY action is shown instead) @@ -3586,67 +3588,26 @@ describe('ReportActionsUtils', () => { expect(actual).toBe(false); }); - it.each([ - [CONST.REPORT.TYPE.INVOICE, true], - [CONST.REPORT.TYPE.EXPENSE, false], - [CONST.REPORT.TYPE.IOU, false], - ] as const)('shows a NewDot REIMBURSED action on a %s report: %s', async (reportType, isVisible) => { - // Given a NewDot payment action on a report. Paying a bill adds no IOU PAY action to its invoice. - const reportID = `newDotReimbursed-${reportType}`; - await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, { - reportID, - type: reportType, - }); - const reportAction: ReportAction = { - actionName: CONST.REPORT.ACTIONS.TYPE.REIMBURSED, + it.each([CONST.REPORT.ACTIONS.TYPE.REIMBURSED, CONST.REPORT.ACTIONS.TYPE.MARKED_REIMBURSED] as const)('shows a NewDot %s action that Auth shows', (actionName) => { + // Given a NewDot payment action on an invoice. Auth sends it with shouldShow true, because paying a bill adds no IOU PAY action to its invoice. + const reportAction = { + actionName, reportActionID: '1', created: '2025-01-01', message: [{type: 'TEXT', style: 'normal', text: 'paid this report'}], originalMessage: {isNewDot: true}, - }; - - // When the action's visibility is checked for its report - const actual = ReportActionsUtils.shouldReportActionBeVisible(reportAction, reportAction.reportActionID, true, undefined, reportID); - - // Then only invoices show it, because other reports show their IOU PAY action instead - expect(actual).toBe(isVisible); - }); - - it.each([ - [CONST.REPORT.TYPE.INVOICE, true], - [CONST.REPORT.TYPE.EXPENSE, false], - [CONST.REPORT.TYPE.IOU, false], - ] as const)('shows a NewDot MARKED_REIMBURSED action that Auth hides on a %s report: %s', async (reportType, isVisible) => { - // Given a report marked as paid from NewDot. Auth sets shouldShow to false on it, because expense reports show an IOU PAY action instead. - const reportID = `newDotMarkedReimbursed-${reportType}`; - await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, { - reportID, - type: reportType, - }); - const reportAction: ReportAction = { - actionName: CONST.REPORT.ACTIONS.TYPE.MARKED_REIMBURSED, - reportActionID: '2', - created: '2026-10-30 21:11:55.001', - message: [ - { - type: 'TEXT', - style: 'normal', - text: 'marked this report as reimbursed', - }, - ], - originalMessage: {isNewDot: true, message: ''}, - shouldShow: false, - }; + shouldShow: true, + } as ReportAction; - // When the action's visibility is checked for its report - const actual = ReportActionsUtils.shouldReportActionBeVisible(reportAction, reportAction.reportActionID, true, undefined, reportID); + // When the action's visibility is checked + const actual = ReportActionsUtils.shouldReportActionBeVisible(reportAction, reportAction.reportActionID, true); - // Then only invoices show it, because marking a bill as paid adds no IOU PAY action to its invoice - expect(actual).toBe(isVisible); + // Then it shows, because App follows shouldShow instead of isNewDot + expect(actual).toBe(true); }); it('hides a NewDot MARKED_REIMBURSED action on an invoice that has an IOU PAY action', async () => { - // Given an invoice paid in NewDot. PayInvoice adds a MARKED_REIMBURSED action and an IOU PAY action for the same payment. + // Given an invoice paid in NewDot. PayInvoice adds a MARKED_REIMBURSED action and an IOU PAY action for the same payment, and Auth shows payment actions on invoices. const reportID = 'paidInvoiceWithPaySibling'; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, { reportID, @@ -3665,7 +3626,7 @@ describe('ReportActionsUtils', () => { }, ], originalMessage: {isNewDot: true, message: ''}, - shouldShow: false, + shouldShow: true, }; const payAction = { actionName: CONST.REPORT.ACTIONS.TYPE.IOU, @@ -3692,26 +3653,6 @@ describe('ReportActionsUtils', () => { expect(actual).toBe(false); }); - it("uses the action's reportID to find the invoice when no reportID is passed", async () => { - // Given a NewDot REIMBURSED action whose own reportID points to an invoice - const reportID = 'invoiceFromActionReportID'; - await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {reportID, type: CONST.REPORT.TYPE.INVOICE}); - const reimbursedAction: ReportAction = { - actionName: CONST.REPORT.ACTIONS.TYPE.REIMBURSED, - reportActionID: '1', - reportID, - created: '2025-01-01 00:00:00', - message: [{type: 'TEXT', style: 'normal', text: 'paid this report'}], - originalMessage: {isNewDot: true}, - }; - - // When the action's visibility is checked without a reportID - const actual = ReportActionsUtils.shouldReportActionBeVisible(reimbursedAction, reimbursedAction.reportActionID, true); - - // Then it shows, because the action's own reportID tells that it belongs to an invoice - expect(actual).toBe(true); - }); - it('should return false for MARKED_REIMBURSED with stale flags when the report has a sibling IOU PAY action', async () => { // Given a MARKED_REIMBURSED action with stale write-time flags (no isNewDot, shouldShow not false) const reportID = 'reportWithPaySibling'; @@ -3974,18 +3915,7 @@ describe('ReportActionsUtils', () => { } as ReportAction; // When checking visibility of the room creation whisper - const actual = ReportActionsUtils.shouldReportActionBeVisible( - reportAction, - reportAction.reportActionID, - true, - undefined, - reportID, - false, - undefined, - undefined, - policy, - 'member@test.com', - ); + const actual = ReportActionsUtils.shouldReportActionBeVisible(reportAction, reportAction.reportActionID, true, undefined, reportID, false, undefined, policy, 'member@test.com'); // Then it is hidden because approve-only members cannot create policy rooms expect(actual).toBe(false); @@ -4014,18 +3944,7 @@ describe('ReportActionsUtils', () => { } as ReportAction; // When checking visibility of the room creation whisper - const actual = ReportActionsUtils.shouldReportActionBeVisible( - reportAction, - reportAction.reportActionID, - true, - undefined, - reportID, - false, - undefined, - undefined, - policy, - 'member@test.com', - ); + const actual = ReportActionsUtils.shouldReportActionBeVisible(reportAction, reportAction.reportActionID, true, undefined, reportID, false, undefined, policy, 'member@test.com'); // Then it is visible because regular members can create policy rooms expect(actual).toBe(true); diff --git a/tests/unit/Search/SearchUIUtilsTest.ts b/tests/unit/Search/SearchUIUtilsTest.ts index 992c64bd20c3..0a221f2b57af 100644 --- a/tests/unit/Search/SearchUIUtilsTest.ts +++ b/tests/unit/Search/SearchUIUtilsTest.ts @@ -3043,47 +3043,6 @@ describe('SearchUIUtils', () => { expect(snapshotReportActionIDs).toStrictEqual([payAction.reportActionID]); }); - it('should show a NewDot REIMBURSED action on an invoice that is only in the Search snapshot', () => { - // Given a CHAT search result whose invoice isn't loaded into Onyx, with a NewDot REIMBURSED action - const snapshotInvoiceID = 'snapshotOnlyInvoiceID'; - const reimbursedAction = { - actionName: CONST.REPORT.ACTIONS.TYPE.REIMBURSED, - reportActionID: 'snapshotReimbursedActionID', - reportID: snapshotInvoiceID, - created: '2025-01-01 00:00:00', - message: [{type: 'TEXT', style: 'normal', text: 'paid this report'}], - originalMessage: {isNewDot: true}, - } as OnyxTypes.ReportAction; - const data: OnyxTypes.SearchResults['data'] = { - ...searchResults.data, - [`${ONYXKEYS.COLLECTION.REPORT}${snapshotInvoiceID}`]: createMock({reportID: snapshotInvoiceID, type: CONST.REPORT.TYPE.INVOICE}), - [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${snapshotInvoiceID}`]: {[reimbursedAction.reportActionID]: reimbursedAction}, - }; - - // When the CHAT sections are built from the snapshot - const [sections] = SearchUIUtils.getSections({ - dateFnsLocale: undefined, - type: CONST.SEARCH.DATA_TYPES.CHAT, - data, - currentAccountID: 2074551, - currentUserEmail: '', - translate: translateLocal, - formatPhoneNumber, - bankAccountList: {}, - rules: undefined, - conciergeReportID: undefined, - convertToDisplayString, - reportAttributesDerivedValue: {}, - }); - - // Then the payment action is listed, because the snapshot shows the report is an invoice, and invoices have no IOU PAY action for this payment - const snapshotReportActionIDs = sections - .filter(SearchUIUtils.isReportActionListItemType) - .filter((item) => item.reportID === snapshotInvoiceID) - .map((item) => item.reportActionID); - expect(snapshotReportActionIDs).toStrictEqual([reimbursedAction.reportActionID]); - }); - it('should return getTransactionsSections result when groupBy is undefined', () => { expect( SearchUIUtils.getSections({