Skip to content

Commit cdf2eec

Browse files
mountinyOSBotify
authored andcommitted
Merge pull request #71376 from Expensify/revert-71021-fix-70509
[CP staging] Revert "Handle navigation properly when clicking on report link" (cherry picked from commit b637bc0) (cherry-picked to staging by mountiny)
1 parent 46bc26f commit cdf2eec

File tree

2 files changed

+15
-63
lines changed

2 files changed

+15
-63
lines changed

src/libs/ReportUtils.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ import {isEmailPublicDomain} from './LoginUtils';
100100
import {getForReportAction, getMovedReportID} from './ModifiedExpenseMessage';
101101
import getStateFromPath from './Navigation/helpers/getStateFromPath';
102102
import {isFullScreenName} from './Navigation/helpers/isNavigatorName';
103-
import isSearchTopmostFullScreenRoute from './Navigation/helpers/isSearchTopmostFullScreenRoute';
104103
import {linkingConfig} from './Navigation/linkingConfig';
105104
import Navigation, {navigationRef} from './Navigation/Navigation';
106105
import type {MoneyRequestNavigatorParamList, ReportsSplitNavigatorParamList} from './Navigation/types';
@@ -6338,8 +6337,12 @@ function getDeletedTransactionMessage(action: ReportAction) {
63386337

63396338
function getMovedTransactionMessage(report: OnyxEntry<Report>) {
63406339
const reportName = getReportName(report) ?? report?.reportName ?? '';
6341-
const reportUrl = getReportURLForCurrentContext(report?.reportID);
6342-
return translateLocal('iou.movedTransaction', {reportUrl, reportName});
6340+
const reportUrl = `${environmentURL}/r/${report?.reportID}`;
6341+
const message = translateLocal('iou.movedTransaction', {
6342+
reportUrl,
6343+
reportName,
6344+
});
6345+
return message;
63436346
}
63446347

63456348
function getUnreportedTransactionMessage() {
@@ -6364,8 +6367,8 @@ function getMovedActionMessage(action: ReportAction, report: OnyxEntry<Report>)
63646367
const toPolicyName = getPolicyNameByID(toPolicyID);
63656368
return translateLocal('iou.movedAction', {
63666369
shouldHideMovedReportUrl: !isDM(report),
6367-
movedReportUrl: getReportURLForCurrentContext(movedReportID),
6368-
newParentReportUrl: getReportURLForCurrentContext(newParentReportID),
6370+
movedReportUrl: `${environmentURL}/r/${movedReportID}`,
6371+
newParentReportUrl: `${environmentURL}/r/${newParentReportID}`,
63696372
toPolicyName,
63706373
});
63716374
}
@@ -6689,8 +6692,8 @@ function buildOptimisticMovedReportAction(
66896692
const movedActionMessage = [
66906693
{
66916694
html: shouldHideMovedReportUrl
6692-
? `moved this <a href='${getReportURLForCurrentContext(movedReportID)}' target='_blank' rel='noreferrer noopener'>report</a> to the <a href='${getReportURLForCurrentContext(newParentReportID)}' target='_blank' rel='noreferrer noopener'>${policyName}</a> workspace`
6693-
: `moved this report to the <a href='${getReportURLForCurrentContext(newParentReportID)}' target='_blank' rel='noreferrer noopener'>${policyName}</a> workspace`,
6695+
? `moved this <a href='${CONST.NEW_EXPENSIFY_URL}r/${movedReportID}' target='_blank' rel='noreferrer noopener'>report</a> to the <a href='${CONST.NEW_EXPENSIFY_URL}r/${newParentReportID}' target='_blank' rel='noreferrer noopener'>${policyName}</a> workspace`
6696+
: `moved this report to the <a href='${CONST.NEW_EXPENSIFY_URL}r/${newParentReportID}' target='_blank' rel='noreferrer noopener'>${policyName}</a> workspace`,
66946697
text: `moved this report to the ${policyName} workspace`,
66956698
type: CONST.REPORT.MESSAGE.TYPE.COMMENT,
66966699
},
@@ -6777,8 +6780,11 @@ function buildOptimisticTransactionAction(
67776780
targetReportID: string,
67786781
): ReportAction {
67796782
const reportName = allReports?.[targetReportID]?.reportName ?? '';
6780-
const url = getReportURLForCurrentContext(targetReportID);
6781-
const [actionText, messageHtml] = [`moved this expense to ${reportName}`, `moved this expense to <a href='${url}' target='_blank' rel='noreferrer noopener'>${reportName}</a>`];
6783+
const url = `${environmentURL}/r/${targetReportID}`;
6784+
const [actionText, messageHtml] =
6785+
type === CONST.REPORT.ACTIONS.TYPE.MOVED_TRANSACTION
6786+
? [`moved this expense to ${reportName}`, `moved this expense to <a href='${url}' target='_blank' rel='noreferrer noopener'>${reportName}</a>`]
6787+
: ['moved this expense to your personal space', 'moved this expense to your personal space'];
67826788

67836789
return {
67846790
actionName: type,
@@ -11722,15 +11728,6 @@ function getReportStatusTranslation(stateNum?: number, statusNum?: number): stri
1172211728
return '';
1172311729
}
1172411730

11725-
function getReportURLForCurrentContext(reportID: string | undefined): string {
11726-
if (!reportID) {
11727-
return `${environmentURL}/r/`;
11728-
}
11729-
const isInSearchContext = isSearchTopmostFullScreenRoute();
11730-
const relativePath = isInSearchContext ? ROUTES.SEARCH_MONEY_REQUEST_REPORT.getRoute({reportID}) : ROUTES.REPORT_WITH_ID.getRoute(reportID);
11731-
return `${environmentURL}/${relativePath}`;
11732-
}
11733-
1173411731
export {
1173511732
areAllRequestsBeingSmartScanned,
1173611733
buildOptimisticAddCommentReportAction,
@@ -12120,7 +12117,6 @@ export {
1212012117
isWorkspaceThread,
1212112118
isMoneyRequestReportEligibleForMerge,
1212212119
getReportStatusTranslation,
12123-
getReportURLForCurrentContext,
1212412120
getMovedActionMessage,
1212512121
excludeParticipantsForDisplay,
1212612122
getReportName,

tests/unit/ReportUtilsTest.ts

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ import useReportIsArchived from '@hooks/useReportIsArchived';
88
import {putOnHold} from '@libs/actions/IOU';
99
import type {OnboardingTaskLinks} from '@libs/actions/Welcome/OnboardingFlow';
1010
import DateUtils from '@libs/DateUtils';
11-
import {getEnvironmentURL} from '@libs/Environment/Environment';
1211
import getBase62ReportID from '@libs/getBase62ReportID';
1312
import {translateLocal} from '@libs/Localize';
14-
import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute';
1513
import {getOriginalMessage, isWhisperAction} from '@libs/ReportActionsUtils';
1614
import {
1715
buildOptimisticChatReport,
@@ -56,7 +54,6 @@ import {
5654
getReportIDFromLink,
5755
getReportName,
5856
getReportStatusTranslation,
59-
getReportURLForCurrentContext,
6057
getSearchReportName,
6158
getWorkspaceIcon,
6259
getWorkspaceNameUpdatedMessage,
@@ -89,7 +86,6 @@ import {buildOptimisticTransaction} from '@libs/TransactionUtils';
8986
import CONST from '@src/CONST';
9087
import IntlStore from '@src/languages/IntlStore';
9188
import ONYXKEYS from '@src/ONYXKEYS';
92-
import ROUTES from '@src/ROUTES';
9389
import type {
9490
Beta,
9591
OnyxInputOrEntry,
@@ -140,8 +136,6 @@ import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
140136
// Be sure to include the mocked permissions library or else the beta tests won't work
141137
jest.mock('@libs/Permissions');
142138

143-
jest.mock('@libs/Navigation/helpers/isSearchTopmostFullScreenRoute', () => jest.fn());
144-
145139
jest.mock('@libs/Navigation/Navigation', () => ({
146140
setNavigationActionToMicrotaskQueue: jest.fn(),
147141
navigationRef: {
@@ -6971,44 +6965,6 @@ describe('ReportUtils', () => {
69716965
});
69726966
});
69736967

6974-
describe('getReportURLForCurrentContext', () => {
6975-
const flushPromises = () =>
6976-
new Promise<void>((resolve) => {
6977-
setImmediate(resolve);
6978-
});
6979-
const mockIsSearchTopmostFullScreenRoute = jest.mocked(isSearchTopmostFullScreenRoute);
6980-
let environmentURL: string;
6981-
6982-
beforeAll(async () => {
6983-
environmentURL = await getEnvironmentURL();
6984-
await flushPromises();
6985-
});
6986-
6987-
afterAll(() => {
6988-
mockIsSearchTopmostFullScreenRoute.mockRestore();
6989-
});
6990-
6991-
beforeEach(() => {
6992-
mockIsSearchTopmostFullScreenRoute.mockReset();
6993-
mockIsSearchTopmostFullScreenRoute.mockReturnValue(false);
6994-
});
6995-
6996-
it('returns report route when not in search context', () => {
6997-
const reportID = '123';
6998-
expect(getReportURLForCurrentContext(reportID)).toBe(`${environmentURL}/${ROUTES.REPORT_WITH_ID.getRoute(reportID)}`);
6999-
});
7000-
7001-
it('returns search route when in search context', () => {
7002-
const reportID = '456';
7003-
mockIsSearchTopmostFullScreenRoute.mockReturnValue(true);
7004-
expect(getReportURLForCurrentContext(reportID)).toBe(`${environmentURL}/${ROUTES.SEARCH_MONEY_REQUEST_REPORT.getRoute({reportID})}`);
7005-
});
7006-
7007-
it('falls back to the base report path when reportID is missing', () => {
7008-
expect(getReportURLForCurrentContext(undefined)).toBe(`${environmentURL}/r/`);
7009-
});
7010-
});
7011-
70126968
describe('requiresManualSubmission', () => {
70136969
it('should return true when manual submit is enabled', () => {
70146970
const report: Report = {

0 commit comments

Comments
 (0)