Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
58 changes: 7 additions & 51 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1740,7 +1740,6 @@ function shouldReportActionBeVisible(
reportID?: string,
isSupportTicketReport = false,
reportActions?: OnyxEntry<ReportActions>,
isInvoice?: boolean,
policy?: OnyxEntry<Policy>,
currentUserEmail?: string,
): boolean {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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<ReportActions>,
isInvoice?: boolean,
): boolean {
if (!reportAction?.reportActionID) {
return false;
Expand All @@ -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;
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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<ReportAction>): 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.
*/
Expand Down Expand Up @@ -6562,7 +6519,6 @@ export {
isActionableAddPaymentCard,
isActionableCardFraudAlert,
isActionableWhisperRequiringWritePermission,
isPaymentActionHiddenOutsideInvoices,
getExportIntegrationActionFragments,
getExportIntegrationLastMessageText,
getExportIntegrationMessageHTML,
Expand Down
10 changes: 1 addition & 9 deletions src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
27 changes: 4 additions & 23 deletions src/libs/actions/OnyxDerived/configs/visibleReportActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
isActionableWhisperRequiringWritePermission,
isActionOfType,
isConciergeCategoryOptions,
isPaymentActionHiddenOutsideInvoices,
shouldReportActionBeVisible,
} from '@libs/ReportActionsUtils';
import {isSupportTicket} from '@libs/ReportUtils';
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down
59 changes: 1 addition & 58 deletions tests/unit/OnyxDerived/visibleReportActionsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<typeof CONST.REPORT.ACTIONS.TYPE.REIMBURSED> = {
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<typeof CONST.REPORT.ACTIONS.TYPE.REIMBURSED> = {
reportActionID: hiddenReimbursedActionID,
actionName: CONST.REPORT.ACTIONS.TYPE.REIMBURSED,
created: '2026-10-13 12:00:00.500',
shouldShow: false,
};
const allReportActions: OnyxCollection<ReportActions> = {
[`${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<typeof visibleReportActionsConfig.compute>[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<OnyxKey>(),
});

// 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';
Expand Down
Loading
Loading