From cf99decb16b01182b22c3cfad3c7b1d2a76af518 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Sun, 17 Aug 2025 15:21:08 +0700 Subject: [PATCH 1/3] remove connect method --- .../LHNOptionsList/OptionRowLHNData.tsx | 1 + src/libs/ReportActionsUtils.ts | 14 ++++---- src/libs/SidebarUtils.ts | 36 ++----------------- tests/unit/SidebarUtilsTest.ts | 13 +++++++ 4 files changed, 24 insertions(+), 40 deletions(-) diff --git a/src/components/LHNOptionsList/OptionRowLHNData.tsx b/src/components/LHNOptionsList/OptionRowLHNData.tsx index 35f5d0495910..b993de58d4fc 100644 --- a/src/components/LHNOptionsList/OptionRowLHNData.tsx +++ b/src/components/LHNOptionsList/OptionRowLHNData.tsx @@ -72,6 +72,7 @@ function OptionRowLHNData({ lastMessageTextFromReport, invoiceReceiverPolicy, card, + lastAction, localeCompare, }); // eslint-disable-next-line react-compiler/react-compiler diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 8b38c5c1503c..15e1362743aa 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -2348,32 +2348,32 @@ function getWorkspaceCategoryUpdateMessage(action: ReportAction, policy?: OnyxEn return getReportActionText(action); } -function getWorkspaceTagUpdateMessage(action: ReportAction): string { +function getWorkspaceTagUpdateMessage(action: ReportAction | undefined): string { const {tagListName, tagName, enabled, newName, newValue, oldName, oldValue, updatedField, count} = getOriginalMessage(action as ReportAction) ?? {}; - if (action.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.ADD_TAG && tagListName && tagName) { + if (action?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.ADD_TAG && tagListName && tagName) { return translateLocal('workspaceActions.addTag', { tagListName, tagName, }); } - if (action.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.DELETE_TAG && tagListName && tagName) { + if (action?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.DELETE_TAG && tagListName && tagName) { return translateLocal('workspaceActions.deleteTag', { tagListName, tagName, }); } - if (action.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.DELETE_MULTIPLE_TAGS && count && tagListName) { + if (action?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.DELETE_MULTIPLE_TAGS && count && tagListName) { return translateLocal('workspaceActions.deleteMultipleTags', { count, tagListName, }); } - if (action.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_TAG_ENABLED && tagListName && tagName) { + if (action?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_TAG_ENABLED && tagListName && tagName) { return translateLocal('workspaceActions.updateTagEnabled', { tagListName, tagName, @@ -2381,7 +2381,7 @@ function getWorkspaceTagUpdateMessage(action: ReportAction): string { }); } - if (action.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_TAG_NAME && tagListName && newName && oldName) { + if (action?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_TAG_NAME && tagListName && newName && oldName) { return translateLocal('workspaceActions.updateTagName', { tagListName, newName, @@ -2390,7 +2390,7 @@ function getWorkspaceTagUpdateMessage(action: ReportAction): string { } if ( - action.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_TAG && + action?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_TAG && tagListName && (typeof oldValue === 'string' || typeof oldValue === 'undefined') && typeof newValue === 'string' && diff --git a/src/libs/SidebarUtils.ts b/src/libs/SidebarUtils.ts index 854e890afaf2..8b73b819b556 100644 --- a/src/libs/SidebarUtils.ts +++ b/src/libs/SidebarUtils.ts @@ -14,7 +14,6 @@ import type Policy from '@src/types/onyx/Policy'; import type PriorityMode from '@src/types/onyx/PriorityMode'; import type Report from '@src/types/onyx/Report'; import type ReportAction from '@src/types/onyx/ReportAction'; -import {extractCollectionItemID} from './CollectionUtils'; import {hasValidDraftComment} from './DraftCommentUtils'; import {translateLocal} from './Localize'; import {getLastActorDisplayName, getLastMessageTextForReport, getPersonalDetailsForAccountIDs, shouldShowLastActorDisplayName} from './OptionsListUtils'; @@ -45,7 +44,6 @@ import { getReportAction, getReportActionMessageText, getRetractedMessage, - getSortedReportActions, getTagListNameUpdatedMessage, getTravelUpdateMessage, getUpdatedApprovalRuleMessage, @@ -73,7 +71,6 @@ import { isTagModificationAction, isTaskAction, isTransactionThread, - shouldReportActionBeVisibleAsLastAction, } from './ReportActionsUtils'; import type {OptionData} from './ReportUtils'; import { @@ -129,7 +126,6 @@ import {getTransactionID} from './TransactionUtils'; type WelcomeMessage = {phrase1?: string; messageText?: string; messageHtml?: string}; -const visibleReportActionItems: ReportActions = {}; let allPersonalDetails: OnyxEntry; Onyx.connect({ key: ONYXKEYS.PERSONAL_DETAILS_LIST, @@ -147,32 +143,6 @@ Onyx.connect({ }, }); -Onyx.connect({ - key: ONYXKEYS.COLLECTION.REPORT_ACTIONS, - callback: (actions, key) => { - if (!actions || !key) { - return; - } - const reportID = extractCollectionItemID(key); - const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; - const canUserPerformWriteAction = canUserPerformWriteActionUtil(report); - const actionsArray: ReportAction[] = getSortedReportActions(Object.values(actions)); - - // The report is only visible if it is the last action not deleted that - // does not match a closed or created state. - const reportActionsForDisplay = actionsArray.filter( - (reportAction) => shouldReportActionBeVisibleAsLastAction(reportAction, canUserPerformWriteAction) && reportAction.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED, - ); - - const reportAction = reportActionsForDisplay.at(-1); - if (!reportAction) { - delete visibleReportActionItems[reportID]; - return; - } - visibleReportActionItems[reportID] = reportAction; - }, -}); - function compareStringDates(a: string, b: string): 0 | 1 | -1 { if (a < b) { return -1; @@ -593,6 +563,7 @@ function getOptionData({ lastMessageTextFromReport: lastMessageTextFromReportProp, invoiceReceiverPolicy, card, + lastAction, localeCompare, }: { report: OnyxEntry; @@ -605,6 +576,7 @@ function getOptionData({ invoiceReceiverPolicy?: OnyxEntry; reportAttributes: OnyxEntry; card: Card | undefined; + lastAction: ReportAction | undefined; localeCompare: LocaleContextProps['localeCompare']; }): OptionData | undefined { // When a user signs out, Onyx is cleared. Due to the lazy rendering with a virtual list, it's possible for @@ -701,8 +673,6 @@ function getOptionData({ // We only create tooltips for the first 10 users or so since some reports have hundreds of users, causing performance to degrade. const displayNamesWithTooltips = getDisplayNamesWithTooltips((participantPersonalDetailList || []).slice(0, 10), hasMultipleParticipants, localeCompare, undefined, isSelfDM(report)); - const lastAction = visibleReportActionItems[report.reportID]; - // lastActorAccountID can be an empty string // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const lastActorAccountID = lastAction?.actorAccountID || report.lastActorAccountID; // If the last actor's details are not currently saved in Onyx Collection, @@ -801,7 +771,7 @@ function getOptionData({ result.alternateText = getWorkspaceCategoryUpdateMessage(lastAction); } else if (isActionOfType(lastAction, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_TAG_LIST_NAME)) { result.alternateText = getCleanedTagName(getTagListNameUpdatedMessage(lastAction) ?? ''); - } else if (isTagModificationAction(lastAction?.actionName)) { + } else if (isTagModificationAction(lastAction?.actionName ?? '')) { result.alternateText = getCleanedTagName(getWorkspaceTagUpdateMessage(lastAction) ?? ''); } else if (isActionOfType(lastAction, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_CUSTOM_UNIT)) { result.alternateText = getWorkspaceCustomUnitUpdatedMessage(lastAction); diff --git a/tests/unit/SidebarUtilsTest.ts b/tests/unit/SidebarUtilsTest.ts index 1bdf5483fae9..beafa2fd4250 100644 --- a/tests/unit/SidebarUtilsTest.ts +++ b/tests/unit/SidebarUtilsTest.ts @@ -344,6 +344,7 @@ describe('SidebarUtils', () => { oneTransactionThreadReport: undefined, card: undefined, localeCompare, + lastAction: undefined, }); const optionDataUnpinned = SidebarUtils.getOptionData({ report: MOCK_REPORT_UNPINNED, @@ -355,6 +356,7 @@ describe('SidebarUtils', () => { oneTransactionThreadReport: undefined, card: undefined, localeCompare, + lastAction: undefined, }); expect(optionDataPinned?.isPinned).toBe(true); @@ -850,6 +852,7 @@ describe('SidebarUtils', () => { oneTransactionThreadReport: undefined, card: undefined, localeCompare, + lastAction, }); // Then the alternate text should be equal to the message of the last action prepended with the last actor display name. @@ -909,6 +912,7 @@ describe('SidebarUtils', () => { oneTransactionThreadReport: undefined, card: undefined, localeCompare, + lastAction, }); // Then the alternate text should show @Hidden. @@ -950,6 +954,7 @@ describe('SidebarUtils', () => { lastMessageTextFromReport: 'test message', oneTransactionThreadReport: undefined, card: undefined, + lastAction: undefined, localeCompare, }); @@ -985,6 +990,7 @@ describe('SidebarUtils', () => { lastMessageTextFromReport: 'test message', oneTransactionThreadReport: undefined, card: undefined, + lastAction: undefined, localeCompare, }); @@ -1017,6 +1023,7 @@ describe('SidebarUtils', () => { lastMessageTextFromReport: 'test message', oneTransactionThreadReport: undefined, card: undefined, + lastAction: undefined, localeCompare, }); @@ -1138,6 +1145,7 @@ describe('SidebarUtils', () => { parentReportAction: undefined, oneTransactionThreadReport: undefined, card: undefined, + lastAction: undefined, localeCompare, }); const {totalDisplaySpend} = getMoneyRequestSpendBreakdown(iouReport); @@ -1181,6 +1189,7 @@ describe('SidebarUtils', () => { lastMessageTextFromReport: 'test message', oneTransactionThreadReport: undefined, card: undefined, + lastAction: undefined, localeCompare, }); @@ -1248,6 +1257,7 @@ describe('SidebarUtils', () => { oneTransactionThreadReport: undefined, card: undefined, localeCompare, + lastAction, }); // Then the alternate text should be equal to the message of the last action prepended with the last actor display name. @@ -1291,6 +1301,7 @@ describe('SidebarUtils', () => { oneTransactionThreadReport: undefined, card: undefined, localeCompare, + lastAction, }); expect(result?.alternateText).toBe(`You: ${getReportActionMessageText(lastAction)}`); @@ -1356,6 +1367,7 @@ describe('SidebarUtils', () => { oneTransactionThreadReport: undefined, card: undefined, localeCompare, + lastAction, }); expect(result?.alternateText).toBe(`You: ${getReportActionMessageText(lastAction)}`); @@ -1468,6 +1480,7 @@ describe('SidebarUtils', () => { oneTransactionThreadReport: undefined, card: undefined, localeCompare, + lastAction, }); expect(result?.alternateText).toContain(`${getReportActionMessageText(lastAction)}`); From ff95ed8b57f5526e118749ea7fcd1804d09e4e59 Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Sun, 17 Aug 2025 15:27:03 +0700 Subject: [PATCH 2/3] fix UT --- tests/perf-test/SidebarUtils.perf-test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/perf-test/SidebarUtils.perf-test.ts b/tests/perf-test/SidebarUtils.perf-test.ts index a6633fc1c3a1..472b969cee93 100644 --- a/tests/perf-test/SidebarUtils.perf-test.ts +++ b/tests/perf-test/SidebarUtils.perf-test.ts @@ -85,6 +85,7 @@ describe('SidebarUtils', () => { parentReportAction, oneTransactionThreadReport: undefined, card: undefined, + lastAction: undefined, localeCompare, }), ); From cbdf7e5f2b8db841248f77e8883b99a306af09ac Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Mon, 18 Aug 2025 15:38:48 +0700 Subject: [PATCH 3/3] update max-warning --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e9a1fd1d3576..569a3db205d8 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "test:debug": "TZ=utc NODE_OPTIONS='--inspect-brk --experimental-vm-modules' jest --runInBand", "perf-test": "NODE_OPTIONS=--experimental-vm-modules npx reassure", "typecheck": "NODE_OPTIONS=--max_old_space_size=8192 tsc", - "lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=250 --cache --cache-location=node_modules/.cache/eslint", + "lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=249 --cache --cache-location=node_modules/.cache/eslint", "lint-changed": "NODE_OPTIONS=--max_old_space_size=8192 ./scripts/lintChanged.sh", "lint-watch": "npx eslint-watch --watch --changed", "shellcheck": "./scripts/shellCheck.sh",