Skip to content
10 changes: 10 additions & 0 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
}

let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 91 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand All @@ -100,7 +100,7 @@
});

let allReports: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 103 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -109,13 +109,13 @@
});

let isNetworkOffline = false;
Onyx.connect({

Check warning on line 112 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NETWORK,
callback: (val) => (isNetworkOffline = val?.isOffline ?? false),
});

let deprecatedCurrentUserAccountID: number | undefined;
Onyx.connect({

Check warning on line 118 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, value is undefined
Expand Down Expand Up @@ -1149,6 +1149,16 @@
return false;
}

// Hide automatic TAKE_CONTROL actions created by OldDot's auto-pay workflow.
// When automaticAction is true and there are no mentionedAccountIDs, this indicates
// the TAKE_CONTROL was a side effect of auto-pay rather than a manual approver change.
if (actionName === CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL) {
const originalMessage = getOriginalMessage(reportAction as ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL>);
if (originalMessage?.automaticAction && !originalMessage?.mentionedAccountIDs?.length) {
return false;
}
}

if (isWhisperActionTargetedToOthers(reportAction)) {
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions src/types/onyx/OriginalMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,8 @@ type OriginalMessageTakeControl = {
lastModified: string;
/** Tagged account IDs of new approvers */
mentionedAccountIDs: number[];
/** Whether this action was triggered automatically (e.g., during auto-pay) */
automaticAction?: boolean;
};

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/OptionsListUtilsTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4501,7 +4501,7 @@ describe('OptionsListUtils', () => {
message: [{type: 'COMMENT', text: ''}],
originalMessage: {},
};
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, {
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, {
Comment thread
rlinoz marked this conversation as resolved.
Resolved
[takeControlAction.reportActionID]: takeControlAction,
});
const lastMessage = getLastMessageTextForReport({
Expand All @@ -4522,7 +4522,7 @@ describe('OptionsListUtils', () => {
message: [{type: 'COMMENT', text: ''}],
originalMessage: {},
};
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, {
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, {
Comment thread
rlinoz marked this conversation as resolved.
Resolved
[rerouteAction.reportActionID]: rerouteAction,
});
const lastMessage = getLastMessageTextForReport({
Expand Down
66 changes: 66 additions & 0 deletions tests/unit/ReportActionsUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1636,6 +1636,72 @@ describe('ReportActionsUtils', () => {
const actual = ReportActionsUtils.shouldReportActionBeVisible(reportAction, reportAction.reportActionID, true);
expect(actual).toBe(true);
});

it('should return false for TAKE_CONTROL when automaticAction is true and mentionedAccountIDs is empty', () => {
const reportAction = {
actionName: CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL,
reportActionID: '1',
created: '2025-09-29',
originalMessage: {
lastModified: '2025-09-29',
mentionedAccountIDs: [] as number[],
automaticAction: true,
},
} as ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL>;

const actual = ReportActionsUtils.shouldReportActionBeVisible(reportAction, reportAction.reportActionID, true);
expect(actual).toBe(false);
});

it('should return true for TAKE_CONTROL when automaticAction is true but mentionedAccountIDs has values', () => {
const reportAction = {
actionName: CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL,
reportActionID: '1',
created: '2025-09-29',
message: [{html: 'took control', type: 'COMMENT', text: 'took control'}],
originalMessage: {
lastModified: '2025-09-29',
mentionedAccountIDs: [123],
automaticAction: true,
},
} as ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL>;

const actual = ReportActionsUtils.shouldReportActionBeVisible(reportAction, reportAction.reportActionID, true);
expect(actual).toBe(true);
});

it('should return true for TAKE_CONTROL when automaticAction is false', () => {
const reportAction = {
actionName: CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL,
reportActionID: '1',
created: '2025-09-29',
message: [{html: 'took control', type: 'COMMENT', text: 'took control'}],
originalMessage: {
lastModified: '2025-09-29',
mentionedAccountIDs: [] as number[],
automaticAction: false,
},
} as ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL>;

const actual = ReportActionsUtils.shouldReportActionBeVisible(reportAction, reportAction.reportActionID, true);
expect(actual).toBe(true);
});

it('should return true for TAKE_CONTROL when automaticAction is not set', () => {
const reportAction = {
actionName: CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL,
reportActionID: '1',
created: '2025-09-29',
message: [{html: 'took control', type: 'COMMENT', text: 'took control'}],
originalMessage: {
lastModified: '2025-09-29',
mentionedAccountIDs: [456],
},
} as ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL>;

const actual = ReportActionsUtils.shouldReportActionBeVisible(reportAction, reportAction.reportActionID, true);
expect(actual).toBe(true);
});
});

describe('getPolicyChangeLogUpdateEmployee', () => {
Expand Down
Loading