Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ 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';
Expand Down Expand Up @@ -6361,12 +6362,8 @@ function getDeletedTransactionMessage(action: ReportAction) {

function getMovedTransactionMessage(report: OnyxEntry<Report>) {
const reportName = getReportName(report) ?? report?.reportName ?? '';
const reportUrl = `${environmentURL}/r/${report?.reportID}`;
const message = translateLocal('iou.movedTransaction', {
reportUrl,
reportName,
});
return message;
const reportUrl = getReportURLForCurrentContext(report?.reportID);
return translateLocal('iou.movedTransaction', {reportUrl, reportName});
}

function getUnreportedTransactionMessage() {
Expand All @@ -6391,8 +6388,8 @@ function getMovedActionMessage(action: ReportAction, report: OnyxEntry<Report>)
const toPolicyName = getPolicyNameByID(toPolicyID);
return translateLocal('iou.movedAction', {
shouldHideMovedReportUrl: !isDM(report),
movedReportUrl: `${environmentURL}/r/${movedReportID}`,
newParentReportUrl: `${environmentURL}/r/${newParentReportID}`,
movedReportUrl: getReportURLForCurrentContext(movedReportID),
newParentReportUrl: getReportURLForCurrentContext(newParentReportID),
toPolicyName,
});
}
Expand Down Expand Up @@ -6716,8 +6713,8 @@ function buildOptimisticMovedReportAction(
const movedActionMessage = [
{
html: shouldHideMovedReportUrl
? `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`
: `moved this report to the <a href='${CONST.NEW_EXPENSIFY_URL}r/${newParentReportID}' target='_blank' rel='noreferrer noopener'>${policyName}</a> workspace`,
? `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`
: `moved this report to the <a href='${getReportURLForCurrentContext(newParentReportID)}' target='_blank' rel='noreferrer noopener'>${policyName}</a> workspace`,
text: `moved this report to the ${policyName} workspace`,
type: CONST.REPORT.MESSAGE.TYPE.COMMENT,
},
Expand Down Expand Up @@ -6804,11 +6801,8 @@ function buildOptimisticTransactionAction(
targetReportID: string,
): ReportAction {
const reportName = allReports?.[targetReportID]?.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 <a href='${url}' target='_blank' rel='noreferrer noopener'>${reportName}</a>`]
: ['moved this expense to your personal space', 'moved this expense to your personal space'];
const url = getReportURLForCurrentContext(targetReportID);
const [actionText, messageHtml] = [`moved this expense to ${reportName}`, `moved this expense to <a href='${url}' target='_blank' rel='noreferrer noopener'>${reportName}</a>`];

return {
actionName: type,
Expand Down Expand Up @@ -11713,6 +11707,15 @@ 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,
Expand Down Expand Up @@ -12101,6 +12104,7 @@ export {
isWorkspaceThread,
isMoneyRequestReportEligibleForMerge,
getReportStatusTranslation,
getReportURLForCurrentContext,
getMovedActionMessage,
excludeParticipantsForDisplay,
getReportName,
Expand Down
44 changes: 44 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ 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,
Expand Down Expand Up @@ -54,6 +56,7 @@ import {
getReportIDFromLink,
getReportName,
getReportStatusTranslation,
getReportURLForCurrentContext,
getSearchReportName,
getWorkspaceIcon,
getWorkspaceNameUpdatedMessage,
Expand Down Expand Up @@ -86,6 +89,7 @@ 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,
Expand Down Expand Up @@ -136,6 +140,8 @@ 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: {
Expand Down Expand Up @@ -6999,6 +7005,44 @@ describe('ReportUtils', () => {
});
});

describe('getReportURLForCurrentContext', () => {
const flushPromises = () =>
new Promise<void>((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 = {
Expand Down