From 6fc056a9c1464855e5b75f82d4fc7d1ef2bf0df9 Mon Sep 17 00:00:00 2001 From: Ionatan Wiznia Date: Fri, 26 Sep 2025 09:21:34 -0700 Subject: [PATCH] Revert "Handle navigation properly when clicking on report link" --- src/libs/ReportUtils.ts | 34 ++++++++++++--------------- tests/unit/ReportUtilsTest.ts | 44 ----------------------------------- 2 files changed, 15 insertions(+), 63 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index e24c1824ee5c..51d5a5a7b552 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -100,7 +100,6 @@ import {isEmailPublicDomain} from './LoginUtils'; import {getForReportAction, getMovedReportID} from './ModifiedExpenseMessage'; import getStateFromPath from './Navigation/helpers/getStateFromPath'; import {isFullScreenName} from './Navigation/helpers/isNavigatorName'; -import isSearchTopmostFullScreenRoute from './Navigation/helpers/isSearchTopmostFullScreenRoute'; import {linkingConfig} from './Navigation/linkingConfig'; import Navigation, {navigationRef} from './Navigation/Navigation'; import type {MoneyRequestNavigatorParamList, ReportsSplitNavigatorParamList} from './Navigation/types'; @@ -6397,8 +6396,12 @@ function getDeletedTransactionMessage(action: ReportAction) { function getMovedTransactionMessage(report: OnyxEntry) { const reportName = getReportName(report) ?? report?.reportName ?? ''; - const reportUrl = getReportURLForCurrentContext(report?.reportID); - return translateLocal('iou.movedTransaction', {reportUrl, reportName}); + const reportUrl = `${environmentURL}/r/${report?.reportID}`; + const message = translateLocal('iou.movedTransaction', { + reportUrl, + reportName, + }); + return message; } function getUnreportedTransactionMessage() { @@ -6423,8 +6426,8 @@ function getMovedActionMessage(action: ReportAction, report: OnyxEntry) const toPolicyName = getPolicyNameByID(toPolicyID); return translateLocal('iou.movedAction', { shouldHideMovedReportUrl: !isDM(report), - movedReportUrl: getReportURLForCurrentContext(movedReportID), - newParentReportUrl: getReportURLForCurrentContext(newParentReportID), + movedReportUrl: `${environmentURL}/r/${movedReportID}`, + newParentReportUrl: `${environmentURL}/r/${newParentReportID}`, toPolicyName, }); } @@ -6748,8 +6751,8 @@ function buildOptimisticMovedReportAction( const movedActionMessage = [ { html: shouldHideMovedReportUrl - ? `moved this report to the ${policyName} workspace` - : `moved this report to the ${policyName} workspace`, + ? `moved this report to the ${policyName} workspace` + : `moved this report to the ${policyName} workspace`, text: `moved this report to the ${policyName} workspace`, type: CONST.REPORT.MESSAGE.TYPE.COMMENT, }, @@ -6836,8 +6839,11 @@ function buildOptimisticTransactionAction( targetReportID: string, ): ReportAction { const reportName = allReports?.[targetReportID]?.reportName ?? ''; - const url = getReportURLForCurrentContext(targetReportID); - const [actionText, messageHtml] = [`moved this expense to ${reportName}`, `moved this expense to ${reportName}`]; + const url = `${environmentURL}/r/${targetReportID}`; + const [actionText, messageHtml] = + type === CONST.REPORT.ACTIONS.TYPE.MOVED_TRANSACTION + ? [`moved this expense to ${reportName}`, `moved this expense to ${reportName}`] + : ['moved this expense to your personal space', 'moved this expense to your personal space']; return { actionName: type, @@ -11791,15 +11797,6 @@ function getReportStatusTranslation(stateNum?: number, statusNum?: number): stri return ''; } -function getReportURLForCurrentContext(reportID: string | undefined): string { - if (!reportID) { - return `${environmentURL}/r/`; - } - const isInSearchContext = isSearchTopmostFullScreenRoute(); - const relativePath = isInSearchContext ? ROUTES.SEARCH_MONEY_REQUEST_REPORT.getRoute({reportID}) : ROUTES.REPORT_WITH_ID.getRoute(reportID); - return `${environmentURL}/${relativePath}`; -} - export { areAllRequestsBeingSmartScanned, buildOptimisticAddCommentReportAction, @@ -12190,7 +12187,6 @@ export { isWorkspaceThread, isMoneyRequestReportEligibleForMerge, getReportStatusTranslation, - getReportURLForCurrentContext, getMovedActionMessage, excludeParticipantsForDisplay, getReportName, diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 2a813f18a2e4..e6c070a19a84 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -8,10 +8,8 @@ import useReportIsArchived from '@hooks/useReportIsArchived'; import {putOnHold} from '@libs/actions/IOU'; import type {OnboardingTaskLinks} from '@libs/actions/Welcome/OnboardingFlow'; import DateUtils from '@libs/DateUtils'; -import {getEnvironmentURL} from '@libs/Environment/Environment'; import getBase62ReportID from '@libs/getBase62ReportID'; import {translateLocal} from '@libs/Localize'; -import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute'; import {getOriginalMessage, isWhisperAction} from '@libs/ReportActionsUtils'; import { buildOptimisticChatReport, @@ -56,7 +54,6 @@ import { getReportIDFromLink, getReportName, getReportStatusTranslation, - getReportURLForCurrentContext, getSearchReportName, getWorkspaceIcon, getWorkspaceNameUpdatedMessage, @@ -89,7 +86,6 @@ import {buildOptimisticTransaction} from '@libs/TransactionUtils'; import CONST from '@src/CONST'; import IntlStore from '@src/languages/IntlStore'; import ONYXKEYS from '@src/ONYXKEYS'; -import ROUTES from '@src/ROUTES'; import type { Beta, OnyxInputOrEntry, @@ -140,8 +136,6 @@ import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; // Be sure to include the mocked permissions library or else the beta tests won't work jest.mock('@libs/Permissions'); -jest.mock('@libs/Navigation/helpers/isSearchTopmostFullScreenRoute', () => jest.fn()); - jest.mock('@libs/Navigation/Navigation', () => ({ setNavigationActionToMicrotaskQueue: jest.fn(), navigationRef: { @@ -6971,44 +6965,6 @@ describe('ReportUtils', () => { }); }); - describe('getReportURLForCurrentContext', () => { - const flushPromises = () => - new Promise((resolve) => { - setImmediate(resolve); - }); - const mockIsSearchTopmostFullScreenRoute = jest.mocked(isSearchTopmostFullScreenRoute); - let environmentURL: string; - - beforeAll(async () => { - environmentURL = await getEnvironmentURL(); - await flushPromises(); - }); - - afterAll(() => { - mockIsSearchTopmostFullScreenRoute.mockRestore(); - }); - - beforeEach(() => { - mockIsSearchTopmostFullScreenRoute.mockReset(); - mockIsSearchTopmostFullScreenRoute.mockReturnValue(false); - }); - - it('returns report route when not in search context', () => { - const reportID = '123'; - expect(getReportURLForCurrentContext(reportID)).toBe(`${environmentURL}/${ROUTES.REPORT_WITH_ID.getRoute(reportID)}`); - }); - - it('returns search route when in search context', () => { - const reportID = '456'; - mockIsSearchTopmostFullScreenRoute.mockReturnValue(true); - expect(getReportURLForCurrentContext(reportID)).toBe(`${environmentURL}/${ROUTES.SEARCH_MONEY_REQUEST_REPORT.getRoute({reportID})}`); - }); - - it('falls back to the base report path when reportID is missing', () => { - expect(getReportURLForCurrentContext(undefined)).toBe(`${environmentURL}/r/`); - }); - }); - describe('requiresManualSubmission', () => { it('should return true when manual submit is enabled', () => { const report: Report = {