Skip to content

Commit 1c959e9

Browse files
Remove one unused function
1 parent 3a75eb7 commit 1c959e9

2 files changed

Lines changed: 0 additions & 166 deletions

File tree

src/libs/ReportActionsUtils.ts

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,41 +1663,6 @@ function isNewerReportAction(a: ReportAction, b: ReportAction): boolean {
16631663
return a.reportActionID > b.reportActionID;
16641664
}
16651665

1666-
/**
1667-
* Finds the newest report action matching each of two filter criteria in a single pass.
1668-
* Returns:
1669-
* - lastVisibleAction: newest visible action
1670-
* - lastActionForDisplay: newest displayable action (not CREATED)
1671-
*/
1672-
function findLastReportActions(reportActions: OnyxEntry<ReportActions>, canUserPerformWriteAction?: boolean) {
1673-
if (!reportActions) {
1674-
return {lastVisibleAction: undefined, lastActionForDisplay: undefined};
1675-
}
1676-
1677-
let lastVisibleAction: ReportAction | undefined;
1678-
let lastActionForDisplay: ReportAction | undefined;
1679-
1680-
for (const [key, action] of Object.entries(reportActions)) {
1681-
if (!action) {
1682-
continue;
1683-
}
1684-
1685-
if (shouldReportActionBeVisible(action, key, canUserPerformWriteAction)) {
1686-
if (!lastVisibleAction || isNewerReportAction(action, lastVisibleAction)) {
1687-
lastVisibleAction = action;
1688-
}
1689-
}
1690-
1691-
if (isReportActionVisibleAsLastAction(action, canUserPerformWriteAction) && action.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED) {
1692-
if (!lastActionForDisplay || isNewerReportAction(action, lastActionForDisplay)) {
1693-
lastActionForDisplay = action;
1694-
}
1695-
}
1696-
}
1697-
1698-
return {lastVisibleAction, lastActionForDisplay};
1699-
}
1700-
17011666
/**
17021667
* The first visible action is the second last action in sortedReportActions which satisfy following conditions:
17031668
* 1. That is not pending deletion as pending deletion actions are kept in sortedReportActions in memory.
@@ -4707,7 +4672,6 @@ export {
47074672
isCardIssuedAction,
47084673
getCardIssuedMessage,
47094674
getRemovedConnectionMessage,
4710-
findLastReportActions,
47114675
getFilteredReportActionsForReportView,
47124676
wasMessageReceivedWhileOffline,
47134677
shouldShowAddMissingDetails,

tests/unit/ReportActionsUtilsTest.ts

Lines changed: 0 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {chatReportR14932 as mockChatReport, iouReportR14932 as mockIOUReport} fr
1313
import CONST from '../../src/CONST';
1414
import * as ReportActionsUtils from '../../src/libs/ReportActionsUtils';
1515
import {
16-
findLastReportActions,
1716
getAddedCardFeedMessage,
1817
getAssignedCompanyCardMessage,
1918
getAutoPayApprovedReportsEnabledMessage,
@@ -4433,135 +4432,6 @@ describe('ReportActionsUtils', () => {
44334432
});
44344433
});
44354434

4436-
describe('findLastReportActions', () => {
4437-
const makeAction = (overrides: Partial<ReportAction>): ReportAction =>
4438-
({
4439-
actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT,
4440-
reportActionID: '1',
4441-
reportID: 'testReportID',
4442-
created: '2024-01-01 00:00:00.000',
4443-
person: [{type: 'TEXT', style: 'strong', text: 'Actor'}],
4444-
message: [{html: 'hello', text: 'hello', type: 'COMMENT'}],
4445-
...overrides,
4446-
}) as ReportAction;
4447-
4448-
it('returns undefined for both when reportActions is undefined', () => {
4449-
const result = findLastReportActions(undefined);
4450-
expect(result.lastVisibleAction).toBeUndefined();
4451-
expect(result.lastActionForDisplay).toBeUndefined();
4452-
});
4453-
4454-
it('returns undefined for both when reportActions is empty', () => {
4455-
const result = findLastReportActions({});
4456-
expect(result.lastVisibleAction).toBeUndefined();
4457-
expect(result.lastActionForDisplay).toBeUndefined();
4458-
});
4459-
4460-
it('returns the single visible action for both when there is only one ADD_COMMENT action', () => {
4461-
const action = makeAction({reportActionID: '1', created: '2024-01-01 00:00:00.000'});
4462-
const result = findLastReportActions({[action.reportActionID]: action});
4463-
expect(result.lastVisibleAction).toBe(action);
4464-
expect(result.lastActionForDisplay).toBe(action);
4465-
});
4466-
4467-
it('returns undefined for lastActionForDisplay but not lastVisibleAction when only action is CREATED', () => {
4468-
const created = makeAction({actionName: CONST.REPORT.ACTIONS.TYPE.CREATED, reportActionID: '1', created: '2024-01-01 00:00:00.000'});
4469-
const result = findLastReportActions({[created.reportActionID]: created});
4470-
expect(result.lastVisibleAction).toBe(created);
4471-
expect(result.lastActionForDisplay).toBeUndefined();
4472-
});
4473-
4474-
it('returns the newest of multiple visible actions', () => {
4475-
const older = makeAction({reportActionID: '1', created: '2024-01-01 00:00:00.000'});
4476-
const newer = makeAction({reportActionID: '2', created: '2024-01-02 00:00:00.000'});
4477-
const result = findLastReportActions({
4478-
[older.reportActionID]: older,
4479-
[newer.reportActionID]: newer,
4480-
});
4481-
expect(result.lastVisibleAction).toBe(newer);
4482-
expect(result.lastActionForDisplay).toBe(newer);
4483-
});
4484-
4485-
it('skips deleted actions (no pendingAction, empty html) for both results', () => {
4486-
const visible = makeAction({reportActionID: '1', created: '2024-01-01 00:00:00.000'});
4487-
const deleted = makeAction({
4488-
reportActionID: '2',
4489-
created: '2024-01-02 00:00:00.000',
4490-
message: [{html: '', text: '', type: 'COMMENT'}],
4491-
pendingAction: undefined,
4492-
});
4493-
const result = findLastReportActions({
4494-
[visible.reportActionID]: visible,
4495-
[deleted.reportActionID]: deleted,
4496-
});
4497-
expect(result.lastVisibleAction).toBe(visible);
4498-
expect(result.lastActionForDisplay).toBe(visible);
4499-
});
4500-
4501-
it('excludes actions with errors from lastActionForDisplay but not from lastVisibleAction', () => {
4502-
const clean = makeAction({reportActionID: '1', created: '2024-01-01 00:00:00.000'});
4503-
const withErrors = makeAction({
4504-
reportActionID: '2',
4505-
created: '2024-01-02 00:00:00.000',
4506-
errors: {someError: 'error message'},
4507-
});
4508-
const result = findLastReportActions({
4509-
[clean.reportActionID]: clean,
4510-
[withErrors.reportActionID]: withErrors,
4511-
});
4512-
expect(result.lastVisibleAction).toBe(withErrors);
4513-
expect(result.lastActionForDisplay).toBe(clean);
4514-
});
4515-
4516-
it('agrees with getSortedReportActionsForDisplay for lastVisibleAction across multiple actions', () => {
4517-
const actionA = makeAction({reportActionID: 'actionA', created: '2024-01-01 00:00:00.000'});
4518-
const actionB = makeAction({reportActionID: 'actionB', created: '2024-01-03 00:00:00.000'});
4519-
const actionC = makeAction({reportActionID: 'actionC', created: '2024-01-02 00:00:00.000'});
4520-
const actions: ReportActions = {
4521-
actionA,
4522-
actionB,
4523-
actionC,
4524-
};
4525-
const {lastVisibleAction} = findLastReportActions(actions);
4526-
const fromSort = getSortedReportActionsForDisplay(actions).at(0);
4527-
expect(lastVisibleAction?.reportActionID).toBe(fromSort?.reportActionID);
4528-
});
4529-
4530-
it('agrees with the old getSortedReportActions+filter approach for lastActionForDisplay', () => {
4531-
const actionA = makeAction({reportActionID: 'actionA', created: '2024-01-01 00:00:00.000'});
4532-
const actionB = makeAction({reportActionID: 'actionB', created: '2024-01-03 00:00:00.000'});
4533-
const actionC = makeAction({
4534-
reportActionID: 'actionC',
4535-
created: '2024-01-02 00:00:00.000',
4536-
errors: {someError: 'error'},
4537-
});
4538-
const actions: ReportActions = {actionA, actionB, actionC};
4539-
const {lastActionForDisplay} = findLastReportActions(actions);
4540-
const fromOldApproach = getSortedReportActions(Object.values(actions)).findLast(
4541-
(a) => isReportActionVisibleAsLastAction(a) && a.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED,
4542-
);
4543-
expect(lastActionForDisplay?.reportActionID).toBe(fromOldApproach?.reportActionID);
4544-
});
4545-
4546-
it('respects canUserPerformWriteAction when determining visibility', () => {
4547-
const normalAction = makeAction({reportActionID: '1', created: '2024-01-01 00:00:00.000'});
4548-
// An actionable mention whisper is hidden when canUserPerformWriteAction is false
4549-
const joinRequestAction = makeAction({
4550-
reportActionID: '2',
4551-
created: '2024-01-02 00:00:00.000',
4552-
actionName: CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_MENTION_WHISPER,
4553-
});
4554-
4555-
const withWrite = findLastReportActions({[normalAction.reportActionID]: normalAction, [joinRequestAction.reportActionID]: joinRequestAction}, true);
4556-
const withoutWrite = findLastReportActions({[normalAction.reportActionID]: normalAction, [joinRequestAction.reportActionID]: joinRequestAction}, false);
4557-
4558-
// With write permission: join request is visible, so it should be selected as newer
4559-
expect(withWrite.lastVisibleAction?.reportActionID).toBe(joinRequestAction.reportActionID);
4560-
// Without write permission: join request hidden, so only the normal action remains
4561-
expect(withoutWrite.lastVisibleAction?.reportActionID).toBe(normalAction.reportActionID);
4562-
});
4563-
});
4564-
45654435
describe('isOriginalReportDeleted', () => {
45664436
it('should return true when action.isOriginalReportDeleted is true', () => {
45674437
const action = {

0 commit comments

Comments
 (0)