From 99ae528e816d749ae2a588c035c0647f9a214599 Mon Sep 17 00:00:00 2001 From: dukenv0307 <129500732+dukenv0307@users.noreply.github.com> Date: Tue, 3 Mar 2026 21:31:26 +0700 Subject: [PATCH] Revert "remove CONCIERGE_REPORT_ID onyx connect in Report.ts" --- package.json | 2 +- src/libs/actions/Report/index.ts | 11 +- src/libs/actions/Task.ts | 7 +- src/pages/ReportDetailsPage.tsx | 3 +- tests/actions/TaskTest.ts | 297 +------------------------------ 5 files changed, 15 insertions(+), 305 deletions(-) diff --git a/package.json b/package.json index 9c0ece2216e06..28e528db1dabf 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "perf-test": "NODE_OPTIONS=--experimental-vm-modules npx reassure", "typecheck": "NODE_OPTIONS=--max_old_space_size=8192 tsc", "typecheck-tsgo": "tsgo --project tsconfig.tsgo.json", - "lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=382 --cache --cache-location=node_modules/.cache/eslint --cache-strategy content --concurrency=auto", + "lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=383 --cache --cache-location=node_modules/.cache/eslint --cache-strategy content --concurrency=auto", "lint-changed": "NODE_OPTIONS=--max_old_space_size=8192 ./scripts/lintChanged.sh", "check-lazy-loading": "ts-node scripts/checkLazyLoading.ts", "lint-watch": "npx eslint-watch --watch --changed", diff --git a/src/libs/actions/Report/index.ts b/src/libs/actions/Report/index.ts index 564bea866c955..31a6d3cacecf5 100644 --- a/src/libs/actions/Report/index.ts +++ b/src/libs/actions/Report/index.ts @@ -311,6 +311,7 @@ type AddAttachmentWithCommentParams = { }; const addNewMessageWithText = new Set([WRITE_COMMANDS.ADD_COMMENT, WRITE_COMMANDS.ADD_TEXT_AND_ATTACHMENT]); +let conciergeReportIDOnyxConnect: string | undefined; let deprecatedCurrentUserAccountID = -1; /** @deprecated This value is deprecated and will be removed soon after migration. Use the email from useCurrentUserPersonalDetails hook instead. */ let deprecatedCurrentUserLogin: string | undefined; @@ -320,6 +321,7 @@ Onyx.connect({ callback: (value) => { // When signed out, val is undefined if (!value?.accountID) { + conciergeReportIDOnyxConnect = undefined; return; } // eslint-disable-next-line @typescript-eslint/no-deprecated @@ -328,6 +330,11 @@ Onyx.connect({ }, }); +Onyx.connect({ + key: ONYXKEYS.CONCIERGE_REPORT_ID, + callback: (value) => (conciergeReportIDOnyxConnect = value), +}); + // map of reportID to all reportActions for that report const allReportActions: OnyxCollection = {}; @@ -4065,9 +4072,9 @@ function navigateToMostRecentReport(currentReport: OnyxEntry, conciergeR } } -function getMostRecentReportID(currentReport: OnyxEntry, conciergeReportID: string | undefined) { +function getMostRecentReportID(currentReport: OnyxEntry) { const lastAccessedReportID = findLastAccessedReport(false, false, currentReport?.reportID)?.reportID; - return lastAccessedReportID ?? conciergeReportID; + return lastAccessedReportID ?? conciergeReportIDOnyxConnect; } function joinRoom(report: OnyxEntry, currentUserAccountID: number) { diff --git a/src/libs/actions/Task.ts b/src/libs/actions/Task.ts index 451286240055e..2498ddeb1fe17 100644 --- a/src/libs/actions/Task.ts +++ b/src/libs/actions/Task.ts @@ -1061,7 +1061,7 @@ function getShareDestination( * @param report - The task report being deleted * @returns The URL to navigate to */ -function getNavigationUrlOnTaskDelete(report: OnyxEntry, conciergeReportID: string | undefined): string | undefined { +function getNavigationUrlOnTaskDelete(report: OnyxEntry): string | undefined { if (!report) { return undefined; } @@ -1076,7 +1076,7 @@ function getNavigationUrlOnTaskDelete(report: OnyxEntry, conci } // If no parent report, try to navigate to most recent report - const mostRecentReportID = getMostRecentReportID(report, conciergeReportID); + const mostRecentReportID = getMostRecentReportID(report); if (mostRecentReportID) { return ROUTES.REPORT_WITH_ID.getRoute(mostRecentReportID); } @@ -1094,7 +1094,6 @@ function deleteTask( currentUserAccountID: number, hasOutstandingChildTask: boolean, parentReportAction: OnyxEntry, - conciergeReportID: string | undefined, ancestors: ReportUtils.Ancestor[] = [], ) { if (!report) { @@ -1220,7 +1219,7 @@ function deleteTask( API.write(WRITE_COMMANDS.CANCEL_TASK, parameters, {optimisticData, successData, failureData}); notifyNewAction(report.reportID, undefined, true); - const urlToNavigateBack = getNavigationUrlOnTaskDelete(report, conciergeReportID); + const urlToNavigateBack = getNavigationUrlOnTaskDelete(report); if (urlToNavigateBack) { Navigation.goBack(); return urlToNavigateBack; diff --git a/src/pages/ReportDetailsPage.tsx b/src/pages/ReportDetailsPage.tsx index a3e3c02ea48c3..5486193bb0873 100644 --- a/src/pages/ReportDetailsPage.tsx +++ b/src/pages/ReportDetailsPage.tsx @@ -875,7 +875,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail const deleteTransaction = useCallback(() => { if (caseID === CASES.DEFAULT) { - deleteTask(report, parentReport, isReportArchived, currentUserPersonalDetails.accountID, hasOutstandingChildTask, parentReportAction, conciergeReportID, ancestors); + deleteTask(report, parentReport, isReportArchived, currentUserPersonalDetails.accountID, hasOutstandingChildTask, parentReportAction, ancestors); return; } @@ -928,7 +928,6 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail deleteTransactions, currentSearchHash, removeTransaction, - conciergeReportID, ]); // Where to navigate back to after deleting the transaction and its report. diff --git a/tests/actions/TaskTest.ts b/tests/actions/TaskTest.ts index 97e69a53ccce7..333a34327b880 100644 --- a/tests/actions/TaskTest.ts +++ b/tests/actions/TaskTest.ts @@ -5,26 +5,13 @@ import Onyx from 'react-native-onyx'; import type {OnyxEntry} from 'react-native-onyx'; import useParentReport from '@hooks/useParentReport'; import useReportIsArchived from '@hooks/useReportIsArchived'; -// eslint-disable-next-line no-restricted-syntax -- this is required to allow mocking -import * as ReportModule from '@libs/actions/Report'; -import { - canActionTask, - canModifyTask, - completeTask, - completeTestDriveTask, - createTaskAndNavigate, - deleteTask, - getFinishOnboardingTaskOnyxData, - getNavigationUrlOnTaskDelete, -} from '@libs/actions/Task'; +import {canActionTask, canModifyTask, completeTask, completeTestDriveTask, createTaskAndNavigate, getFinishOnboardingTaskOnyxData} from '@libs/actions/Task'; // eslint-disable-next-line no-restricted-syntax -- this is required to allow mocking import * as API from '@libs/API'; // eslint-disable-next-line no-restricted-syntax -- this is required to allow mocking import DateUtils from '@libs/DateUtils'; import Navigation from '@libs/Navigation/Navigation'; // eslint-disable-next-line no-restricted-syntax -- this is required to allow mocking -import * as ReportActionsUtils from '@libs/ReportActionsUtils'; -// eslint-disable-next-line no-restricted-syntax -- this is required to allow mocking import * as ReportUtils from '@libs/ReportUtils'; import initOnyxDerivedValues from '@userActions/OnyxDerived'; import CONST from '@src/CONST'; @@ -850,286 +837,4 @@ describe('actions/Task', () => { expect(parentReportActionUpdate).toBeUndefined(); }); }); - - describe('getNavigationUrlOnTaskDelete', () => { - let doesReportHaveVisibleActionsSpy: jest.SpyInstance; - let getMostRecentReportIDSpy: jest.SpyInstance; - - beforeEach(() => { - doesReportHaveVisibleActionsSpy = jest.spyOn(ReportActionsUtils, 'doesReportHaveVisibleActions'); - getMostRecentReportIDSpy = jest.spyOn(ReportModule, 'getMostRecentReportID'); - }); - - afterEach(() => { - doesReportHaveVisibleActionsSpy.mockRestore(); - getMostRecentReportIDSpy.mockRestore(); - }); - - it('should return undefined when report is undefined', () => { - expect(getNavigationUrlOnTaskDelete(undefined, 'concierge_123')).toBeUndefined(); - }); - - it('should return undefined when report has visible actions (should not delete)', () => { - const taskReport = getFakeReport(); - doesReportHaveVisibleActionsSpy.mockReturnValue(true); - - expect(getNavigationUrlOnTaskDelete(taskReport, 'concierge_123')).toBeUndefined(); - }); - - it('should return parent report route when report has parentReportID and no visible actions', () => { - const parentReportID = 'parent_123'; - const taskReport = {...getFakeReport(), parentReportID}; - doesReportHaveVisibleActionsSpy.mockReturnValue(false); - - const result = getNavigationUrlOnTaskDelete(taskReport, 'concierge_123'); - expect(result).toBe(`r/${parentReportID}`); - }); - - it('should return most recent report route when no parentReportID and getMostRecentReportID returns a value', () => { - const taskReport = {...getFakeReport(), parentReportID: undefined}; - const mostRecentReportID = 'recent_456'; - doesReportHaveVisibleActionsSpy.mockReturnValue(false); - getMostRecentReportIDSpy.mockReturnValue(mostRecentReportID); - - const result = getNavigationUrlOnTaskDelete(taskReport, 'concierge_123'); - expect(result).toBe(`r/${mostRecentReportID}`); - expect(getMostRecentReportIDSpy).toHaveBeenCalledWith(taskReport, 'concierge_123'); - }); - - it('should pass conciergeReportID to getMostRecentReportID as fallback', () => { - const taskReport = {...getFakeReport(), parentReportID: undefined}; - const conciergeReportID = 'concierge_789'; - doesReportHaveVisibleActionsSpy.mockReturnValue(false); - getMostRecentReportIDSpy.mockReturnValue(conciergeReportID); - - const result = getNavigationUrlOnTaskDelete(taskReport, conciergeReportID); - expect(result).toBe(`r/${conciergeReportID}`); - expect(getMostRecentReportIDSpy).toHaveBeenCalledWith(taskReport, conciergeReportID); - }); - - it('should return undefined when no parentReportID, no most recent report, and conciergeReportID is undefined', () => { - const taskReport = {...getFakeReport(), parentReportID: undefined}; - doesReportHaveVisibleActionsSpy.mockReturnValue(false); - getMostRecentReportIDSpy.mockReturnValue(undefined); - - expect(getNavigationUrlOnTaskDelete(taskReport, undefined)).toBeUndefined(); - }); - }); - - describe('deleteTask', () => { - let doesReportHaveVisibleActionsSpy: jest.SpyInstance; - let getMostRecentReportIDSpy: jest.SpyInstance; - const mockCurrentUserAccountID = 123; - - beforeEach(async () => { - jest.clearAllMocks(); - writeSpy.mockClear(); - - global.fetch = getGlobalFetchMock(); - - doesReportHaveVisibleActionsSpy = jest.spyOn(ReportActionsUtils, 'doesReportHaveVisibleActions'); - getMostRecentReportIDSpy = jest.spyOn(ReportModule, 'getMostRecentReportID'); - - await act(async () => { - await Onyx.clear(); - await Onyx.set(ONYXKEYS.SESSION, { - email: 'user@example.com', - accountID: mockCurrentUserAccountID, - }); - }); - await waitForBatchedUpdatesWithAct(); - }); - - afterEach(() => { - doesReportHaveVisibleActionsSpy.mockRestore(); - getMostRecentReportIDSpy.mockRestore(); - }); - - it('should return early when report is undefined', () => { - deleteTask(undefined, undefined, false, mockCurrentUserAccountID, false, undefined, 'concierge_123'); - - // eslint-disable-next-line rulesdir/no-multiple-api-calls - expect(API.write).not.toHaveBeenCalled(); - }); - - it('should call API.write with CancelTask and pass conciergeReportID through to navigation', async () => { - const taskReportID = 'task_report_delete_1'; - const parentReportID = 'parent_report_delete_1'; - const parentReportActionID = 'parent_action_delete_1'; - - const taskReport = { - reportID: taskReportID, - type: CONST.REPORT.TYPE.TASK, - reportName: 'Test Task', - parentReportID, - parentReportActionID, - stateNum: CONST.REPORT.STATE_NUM.OPEN, - statusNum: CONST.REPORT.STATUS_NUM.OPEN, - ownerAccountID: mockCurrentUserAccountID, - }; - - const parentReport = { - reportID: parentReportID, - type: CONST.REPORT.TYPE.CHAT, - }; - - const parentReportAction = { - reportActionID: parentReportActionID, - reportID: parentReportID, - childReportID: taskReportID, - } as OnyxEntry; - - await act(async () => { - await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`, taskReport); - await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`, parentReport); - }); - await waitForBatchedUpdatesWithAct(); - - doesReportHaveVisibleActionsSpy.mockReturnValue(true); - - deleteTask(taskReport, parentReport, false, mockCurrentUserAccountID, false, parentReportAction, 'concierge_123'); - - // eslint-disable-next-line rulesdir/no-multiple-api-calls - expect(API.write).toHaveBeenCalledWith( - 'CancelTask', - expect.objectContaining({ - taskReportID, - }), - expect.objectContaining({ - optimisticData: expect.any(Array), - successData: expect.any(Array), - failureData: expect.any(Array), - }), - ); - }); - - it('should return navigation URL when task report has no visible actions and has parentReportID', async () => { - const taskReportID = 'task_report_delete_2'; - const parentReportID = 'parent_report_delete_2'; - - const taskReport = { - reportID: taskReportID, - type: CONST.REPORT.TYPE.TASK, - reportName: 'Test Task To Delete', - parentReportID, - stateNum: CONST.REPORT.STATE_NUM.OPEN, - statusNum: CONST.REPORT.STATUS_NUM.OPEN, - ownerAccountID: mockCurrentUserAccountID, - }; - - const parentReport = { - reportID: parentReportID, - type: CONST.REPORT.TYPE.CHAT, - }; - - await act(async () => { - await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`, taskReport); - await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`, parentReport); - }); - await waitForBatchedUpdatesWithAct(); - - // No visible actions means the task report should be deleted - doesReportHaveVisibleActionsSpy.mockReturnValue(false); - - const result = deleteTask(taskReport, parentReport, false, mockCurrentUserAccountID, false, undefined, 'concierge_123'); - - expect(result).toBe(`r/${parentReportID}`); - expect(Navigation.goBack).toHaveBeenCalled(); - }); - - it('should return conciergeReportID-based URL when no parentReportID and no recent report', async () => { - const taskReportID = 'task_report_delete_3'; - const conciergeReportID = 'concierge_456'; - - const taskReport = { - reportID: taskReportID, - type: CONST.REPORT.TYPE.TASK, - reportName: 'Orphan Task', - parentReportID: undefined, - stateNum: CONST.REPORT.STATE_NUM.OPEN, - statusNum: CONST.REPORT.STATUS_NUM.OPEN, - ownerAccountID: mockCurrentUserAccountID, - }; - - await act(async () => { - await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`, taskReport); - }); - await waitForBatchedUpdatesWithAct(); - - doesReportHaveVisibleActionsSpy.mockReturnValue(false); - getMostRecentReportIDSpy.mockReturnValue(conciergeReportID); - - const result = deleteTask(taskReport, undefined, false, mockCurrentUserAccountID, false, undefined, conciergeReportID); - - expect(result).toBe(`r/${conciergeReportID}`); - expect(getMostRecentReportIDSpy).toHaveBeenCalledWith(taskReport, conciergeReportID); - expect(Navigation.goBack).toHaveBeenCalled(); - }); - - it('should not return navigation URL when task report has visible actions', async () => { - const taskReportID = 'task_report_delete_4'; - const parentReportID = 'parent_report_delete_4'; - - const taskReport = { - reportID: taskReportID, - type: CONST.REPORT.TYPE.TASK, - reportName: 'Task With Visible Actions', - parentReportID, - stateNum: CONST.REPORT.STATE_NUM.OPEN, - statusNum: CONST.REPORT.STATUS_NUM.OPEN, - ownerAccountID: mockCurrentUserAccountID, - }; - - const parentReport = { - reportID: parentReportID, - type: CONST.REPORT.TYPE.CHAT, - }; - - await act(async () => { - await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`, taskReport); - await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`, parentReport); - }); - await waitForBatchedUpdatesWithAct(); - - // Has visible actions, so should not navigate away - doesReportHaveVisibleActionsSpy.mockReturnValue(true); - - const result = deleteTask(taskReport, parentReport, false, mockCurrentUserAccountID, false, undefined, 'concierge_123'); - - expect(result).toBeUndefined(); - expect(Navigation.goBack).not.toHaveBeenCalled(); - }); - - it('should return undefined when no parentReportID, no recent report, and conciergeReportID is undefined', async () => { - const taskReportID = 'task_report_delete_5'; - - const taskReport = { - reportID: taskReportID, - type: CONST.REPORT.TYPE.TASK, - reportName: 'Orphan Task No Fallback', - parentReportID: undefined, - stateNum: CONST.REPORT.STATE_NUM.OPEN, - statusNum: CONST.REPORT.STATUS_NUM.OPEN, - ownerAccountID: mockCurrentUserAccountID, - }; - - await act(async () => { - await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`, taskReport); - }); - await waitForBatchedUpdatesWithAct(); - - doesReportHaveVisibleActionsSpy.mockReturnValue(false); - getMostRecentReportIDSpy.mockReturnValue(undefined); - - const result = deleteTask(taskReport, undefined, false, mockCurrentUserAccountID, false, undefined, undefined); - - // API.write should still be called - // eslint-disable-next-line rulesdir/no-multiple-api-calls - expect(API.write).toHaveBeenCalledWith('CancelTask', expect.any(Object), expect.any(Object)); - - // But no navigation should happen - expect(result).toBeUndefined(); - expect(Navigation.goBack).not.toHaveBeenCalled(); - }); - }); });