Skip to content
Closed
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
8 changes: 4 additions & 4 deletions src/components/ReportActionItem/MovedTransactionAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import RenderHTML from '@components/RenderHTML';

import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useReportAttributes from '@hooks/useReportAttributes';
import {useDerivedReportNameByReportID} from '@hooks/useReportAttributes';

import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import Parser from '@libs/Parser';
import {getOriginalMessage, hasReasoning} from '@libs/ReportActionsUtils';
import {getMovedTransactionMessage} from '@libs/ReportUtils';
import {getMovedTransactionMessage, getMovedTransactionReportID} from '@libs/ReportUtils';

import ReportActionItemBasicMessage from '@pages/inbox/report/ReportActionItemBasicMessage';
import ReportActionItemMessageWithExplain from '@pages/inbox/report/ReportActionItemMessageWithExplain';
Expand Down Expand Up @@ -35,11 +35,11 @@ function MovedTransactionAction({action, originalReport}: MovedTransactionAction

const [fromReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${fromReportID}`);
const [childReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(action.childReportID)}`);
const reportAttributes = useReportAttributes();

const isPendingDelete = fromReport?.pendingFields?.preview === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;

const message = getMovedTransactionMessage(translate, action, reportAttributes);
const derivedReportName = useDerivedReportNameByReportID(getMovedTransactionReportID(action));
const message = getMovedTransactionMessage(translate, action, derivedReportName);

if (hasReasoning(action)) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import RenderHTML from '@components/RenderHTML';

import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useReportAttributes from '@hooks/useReportAttributes';
import {useDerivedReportNameByReportID} from '@hooks/useReportAttributes';

import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import Parser from '@libs/Parser';
import {getOriginalMessage, hasReasoning} from '@libs/ReportActionsUtils';
import {getUnreportedTransactionMessage} from '@libs/ReportUtils';
import {getUnreportedTransactionMessage, getUnreportedTransactionReportID} from '@libs/ReportUtils';

import ReportActionItemBasicMessage from '@pages/inbox/report/ReportActionItemBasicMessage';
import ReportActionItemMessageWithExplain from '@pages/inbox/report/ReportActionItemMessageWithExplain';
Expand Down Expand Up @@ -35,10 +35,10 @@ function UnreportedTransactionAction({action, originalReport}: UnreportedTransac
const {translate} = useLocalize();
const [fromReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${fromReportID}`);
const [childReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(action.childReportID)}`);
const reportAttributes = useReportAttributes();

const isPendingDelete = fromReport?.pendingFields?.preview === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
const unreportedTransactionMessage = getUnreportedTransactionMessage(translate, action, reportAttributes);
const derivedReportName = useDerivedReportNameByReportID(getUnreportedTransactionReportID(action));
const unreportedTransactionMessage = getUnreportedTransactionMessage(translate, action, derivedReportName);

if (hasReasoning(action)) {
return (
Expand Down
15 changes: 11 additions & 4 deletions src/libs/ModifiedExpenseMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {getOriginalMessage, isModifiedExpenseAction} from './ReportActionsUtils'
// The functions imported here are pure utility functions that don't create initialization-time dependencies.
// ReportNameUtils imports helper functions from ReportUtils, and ReportUtils imports name generation functions from ReportNameUtils.
// eslint-disable-next-line import/no-cycle
import {buildReportNameFromParticipantNames, deprecatedGetReportName, getPolicyExpenseChatName} from './ReportNameUtils';
import {buildReportNameFromParticipantNames, getPolicyExpenseChatName, getReportName} from './ReportNameUtils';
import {getPolicyName, getRootParentReport, isPolicyExpenseChat, isSelfDM} from './ReportUtils';
import {getFormattedAttendees, getTagArrayFromName} from './TransactionUtils';
import {isInvalidMerchantValue} from './ValidationUtils';
Expand Down Expand Up @@ -189,14 +189,14 @@ function getMovedFromOrToReportMessage(
movedToReport: OnyxEntry<Report> | undefined,
currentUserLogin: string,
policy: OnyxEntry<Policy>,
reportAttributes?: ReportAttributesDerivedValue['reports'],
movedFromReportName?: string,
): string | undefined {
if (movedToReport) {
return getForExpenseMovedFromSelfDM(translate, movedToReport, currentUserLogin, policy);
}

if (movedFromReport) {
const originReportName = deprecatedGetReportName(movedFromReport, reportAttributes);
const originReportName = getReportName(movedFromReport, movedFromReportName);
return originReportName ? translate('iou.movedFromReport', originReportName) : translate('iou.movedFromReportNoName');
}
}
Expand Down Expand Up @@ -295,7 +295,14 @@ function getForReportAction({
return '';
}

const movedFromOrToReportMessage = getMovedFromOrToReportMessage(translate, movedFromReport, movedToReport, currentUserLogin, policy, reportAttributes);
const movedFromOrToReportMessage = getMovedFromOrToReportMessage(
translate,
movedFromReport,
movedToReport,
currentUserLogin,
policy,
movedFromReport ? reportAttributes?.[movedFromReport.reportID]?.reportName : undefined,
);
if (movedFromOrToReportMessage) {
return movedFromOrToReportMessage;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Log from '@libs/Log';
import {getForReportAction} from '@libs/ModifiedExpenseMessage';
import NotificationPermission from '@libs/Notification/notificationPermission';
import {getTextFromHtml} from '@libs/ReportActionsUtils';
import {deprecatedGetReportName} from '@libs/ReportNameUtils';
import {getReportName} from '@libs/ReportNameUtils';
import * as ReportUtils from '@libs/ReportUtils';
import playSound, {SOUNDS} from '@libs/Sound';

Expand Down Expand Up @@ -134,7 +134,7 @@ export default {
}

if (isRoomOrGroupChat) {
const roomName = deprecatedGetReportName(report, reportAttributes);
const roomName = getReportName(report, reportAttributes?.[report.reportID]?.reportName);
title = roomName;
body = `${plainTextPerson}: ${plainTextMessage}`;
} else {
Expand Down
12 changes: 6 additions & 6 deletions src/libs/OptionsListUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ import {
wasActionTakenByCurrentUser,
withDEWRoutedActionsArray,
} from '@libs/ReportActionsUtils';
import {deprecatedGetReportName} from '@libs/ReportNameUtils';
import {getReportName} from '@libs/ReportNameUtils';
import type {OptionData} from '@libs/ReportUtils';
import {
canUserPerformWriteAction,
Expand Down Expand Up @@ -809,7 +809,7 @@ function getLastMessageTextForReport({
const properSchemaForModifiedExpenseMessage = Parser.htmlToText(properSchemaForModifiedExpenseMessageWithHTML);
lastMessageTextFromReport = formatReportLastMessageText(properSchemaForModifiedExpenseMessage, true);
} else if (isMovedTransactionAction(lastReportAction)) {
lastMessageTextFromReport = Parser.htmlToText(getMovedTransactionMessage(translate, lastReportAction, reportAttributesDerived));
lastMessageTextFromReport = Parser.htmlToText(getMovedTransactionMessage(translate, lastReportAction));
} else if (isTaskAction(lastReportAction)) {
lastMessageTextFromReport = formatReportLastMessageText(getTaskReportActionMessage(translate, lastReportAction).text);
} else if (isCreatedTaskReportAction(lastReportAction)) {
Expand Down Expand Up @@ -914,7 +914,7 @@ function getLastMessageTextForReport({
} else if (isMovedAction(lastReportAction)) {
lastMessageTextFromReport = Parser.htmlToText(getMovedActionMessage(translate, lastReportAction, report));
} else if (isActionOfType(lastReportAction, CONST.REPORT.ACTIONS.TYPE.UNREPORTED_TRANSACTION)) {
lastMessageTextFromReport = Parser.htmlToText(getUnreportedTransactionMessage(translate, lastReportAction, reportAttributesDerived));
lastMessageTextFromReport = Parser.htmlToText(getUnreportedTransactionMessage(translate, lastReportAction));
} else if (isActionableMentionWhisper(lastReportAction)) {
const targetAccountIDs = getOriginalMessage(lastReportAction)?.inviteeAccountIDs;
lastMessageTextFromReport = Parser.htmlToText(getActionableMentionWhisperMessage(translate, lastReportAction, getPersonalDetailsListByIDs(targetAccountIDs, personalDetails)));
Expand Down Expand Up @@ -1212,7 +1212,7 @@ function createOption({
},
);

const computedReportName = deprecatedGetReportName(report, reportAttributesDerived);
const computedReportName = getReportName(report, report?.reportID ? reportAttributesDerived?.[report.reportID]?.reportName : undefined);

reportName = showPersonalDetails
? getDisplayNameForParticipant({accountID: accountIDs.at(0), formatPhoneNumber: formatPhoneNumberPhoneUtils, translate: translateFn}) ||
Expand Down Expand Up @@ -1297,7 +1297,7 @@ function getReportOption(
if (option.isSelfDM) {
option.alternateText = translate('reportActionsView.yourSpace');
} else if (option.isInvoiceRoom) {
option.text = deprecatedGetReportName(report, reportAttributesDerived);
option.text = getReportName(report, report?.reportID ? reportAttributesDerived?.[report.reportID]?.reportName : undefined);
option.alternateText = translate('workspace.common.invoices');
} else {
option.text = getPolicyName({report, policy, unavailableTranslation: translate('workspace.common.unavailable')});
Expand Down Expand Up @@ -1355,7 +1355,7 @@ function getReportDisplayOption(
if (option.isSelfDM) {
option.alternateText = translate('reportActionsView.yourSpace');
} else if (option.isInvoiceRoom) {
option.text = deprecatedGetReportName(report, reportAttributesDerived);
option.text = getReportName(report, report?.reportID ? reportAttributesDerived?.[report.reportID]?.reportName : undefined);
option.alternateText = translate('workspace.common.invoices');
} else if (unknownUserDetails) {
option.text = unknownUserDetails.text ?? unknownUserDetails.login;
Expand Down
4 changes: 2 additions & 2 deletions src/libs/ReportNameUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,11 +584,11 @@ function computeReportNameBasedOnReportAction(
}

if (isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.UNREPORTED_TRANSACTION)) {
return Parser.htmlToText(getUnreportedTransactionMessage(translate, parentReportAction, reportAttributes));
return Parser.htmlToText(getUnreportedTransactionMessage(translate, parentReportAction));
}

if (isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.MOVED_TRANSACTION)) {
return Parser.htmlToText(getMovedTransactionMessage(translate, parentReportAction, reportAttributes));
return Parser.htmlToText(getMovedTransactionMessage(translate, parentReportAction));
}

if (isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_MAX_EXPENSE_AMOUNT)) {
Expand Down
72 changes: 58 additions & 14 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ import {
// The functions imported here are pure utility functions that don't create initialization-time dependencies.
// ReportNameUtils imports helper functions from ReportUtils, and ReportUtils imports name generation functions from ReportNameUtils.
// eslint-disable-next-line import/no-cycle
import {deprecatedGetReportName, getGroupChatName, getInvoicePayerName, getInvoiceReportName} from './ReportNameUtils';
import {getGroupChatName, getInvoicePayerName, getInvoiceReportName, getReportName} from './ReportNameUtils';
import {shouldRestrictUserBillableActions} from './SubscriptionUtils';
import {isTaskCompleted} from './TaskUtils';
import {
Expand Down Expand Up @@ -5686,14 +5686,12 @@ type GetReportPreviewMessageBaseParams = {
* derived from report action content. Report action text is in English only, so this never needs
* `translateLocal`.
*/
function getReportPreviewMessageForCopy(
params: Pick<GetReportPreviewMessageBaseParams, 'reportOrID' | 'iouReportAction' | 'originalReportAction'> & {reportAttributes?: ReportAttributesDerivedValue['reports']},
): string {
const {reportOrID, iouReportAction = null, reportAttributes} = params;
function getReportPreviewMessageForCopy(params: Pick<GetReportPreviewMessageBaseParams, 'reportOrID' | 'iouReportAction' | 'originalReportAction'>): string {
const {reportOrID, iouReportAction = null} = params;
const originalReportAction = params.originalReportAction ?? iouReportAction;
const report = typeof reportOrID === 'string' ? getReport(reportOrID, deprecatedAllReports) : reportOrID;
if (report) {
return deprecatedGetReportName(report, reportAttributes ?? reportAttributesDerivedValue) || (originalReportAction?.childReportName ?? '');
return getReportName(report, reportAttributesDerivedValue?.[report.reportID]?.reportName) || (originalReportAction?.childReportName ?? '');
}
return originalReportAction?.childReportName ?? '';
}
Expand Down Expand Up @@ -7179,30 +7177,73 @@ function getDeletedTransactionMessage(translate: LocalizedTranslate, action: Rep
return message;
}

function getMovedTransactionMessage(translate: LocalizedTranslate, action: ReportAction, reportAttributes?: ReportAttributesDerivedValue['reports']) {
/**
* Resolves the report a moved transaction message points at, along with the raw `fromReportID`
* that tells "moved to" apart from "moved from".
*/
function getMovedTransactionReportContext(action: ReportAction) {
const movedTransactionOriginalMessage = getOriginalMessage(action) ?? {};
const {toReportID, fromReportID} = movedTransactionOriginalMessage as OriginalMessageMovedTransaction;

const toReport = deprecatedAllReports?.[`${ONYXKEYS.COLLECTION.REPORT}${toReportID}`];
const fromReport = deprecatedAllReports?.[`${ONYXKEYS.COLLECTION.REPORT}${fromReportID}`];

const report = fromReport ?? toReport;
return {report: fromReport ?? toReport, fromReportID};
}

/**
* ID of the report whose name a moved transaction message renders. Callers use this to look up that
* single report's derived name, so they never have to hold the whole report attributes map.
*/
function getMovedTransactionReportID(action: ReportAction): string | undefined {
return getMovedTransactionReportContext(action).report?.reportID;
}

/**
* `derivedReportName` only matters to callers that render this message: passing it (sourced via
* `useDerivedReportNameByReportID`, keyed by {@link getMovedTransactionReportID}) keeps the name reactive
* without subscribing to the whole report attributes map. Imperative callers can omit it and get the
* module-level derived value, which is already current whenever they run.
*/
function getMovedTransactionMessage(translate: LocalizedTranslate, action: ReportAction, derivedReportName?: string) {
const {report, fromReportID} = getMovedTransactionReportContext(action);

const reportName = Parser.htmlToText(deprecatedGetReportName(report, reportAttributes) ?? report?.reportName ?? '');
const reportName = Parser.htmlToText(getReportName(report, derivedReportName ?? (report?.reportID ? reportAttributesDerivedValue?.[report.reportID]?.reportName : undefined)));
const reportUrl = getReportURLForCurrentContext(report?.reportID);
if (typeof fromReportID === 'undefined') {
return reportName ? translate('iou.movedTransactionTo', reportUrl, reportName) : translate('iou.movedTransactionToAnotherReport');
}
return reportName ? translate('iou.movedTransactionFrom', reportUrl, reportName) : translate('iou.movedTransactionFromAnotherReport');
}

function getUnreportedTransactionMessage(translate: LocalizedTranslate, action: ReportAction, reportAttributes?: ReportAttributesDerivedValue['reports']) {
/**
* Resolves the report an unreported transaction message points at, along with the raw `fromReportID`,
* which stays meaningful even when no report exists for it (e.g. `UNREPORTED_REPORT_ID`).
*/
function getUnreportedTransactionReportContext(action: ReportAction) {
const movedTransactionOriginalMessage = getOriginalMessage(action) ?? {};
const {fromReportID} = movedTransactionOriginalMessage as OriginalMessageMovedTransaction;

const fromReport = deprecatedAllReports?.[`${ONYXKEYS.COLLECTION.REPORT}${fromReportID}`];
return {report: deprecatedAllReports?.[`${ONYXKEYS.COLLECTION.REPORT}${fromReportID}`], fromReportID};
}

const reportName = Parser.htmlToText(deprecatedGetReportName(fromReport, reportAttributes) ?? fromReport?.reportName ?? '');
/**
* ID of the report whose name an unreported transaction message renders. See {@link getMovedTransactionReportID}.
*/
function getUnreportedTransactionReportID(action: ReportAction): string | undefined {
return getUnreportedTransactionReportContext(action).report?.reportID;
}

/**
* `derivedReportName` behaves as described on {@link getMovedTransactionMessage}, keyed by
* {@link getUnreportedTransactionReportID}.
*/
function getUnreportedTransactionMessage(translate: LocalizedTranslate, action: ReportAction, derivedReportName?: string) {
const {report: fromReport, fromReportID} = getUnreportedTransactionReportContext(action);

const reportName = Parser.htmlToText(
getReportName(fromReport, derivedReportName ?? (fromReport?.reportID ? reportAttributesDerivedValue?.[fromReport.reportID]?.reportName : undefined)),
);

let reportUrl = getReportURLForCurrentContext(fromReportID);

Expand Down Expand Up @@ -13115,10 +13156,11 @@ function getChatListItemReportName(action: ReportAction & {reportName?: string},
}

if (report?.reportID) {
return deprecatedGetReportName(getReport(report?.reportID, deprecatedAllReports), reportAttributesDerivedValue);
const fullReport = getReport(report.reportID, deprecatedAllReports);
return getReportName(fullReport, fullReport?.reportID ? reportAttributesDerivedValue?.[fullReport.reportID]?.reportName : undefined);
}

return deprecatedGetReportName(report, reportAttributesDerivedValue);
return getReportName(report, report?.reportID ? reportAttributesDerivedValue?.[report.reportID]?.reportName : undefined);
}

/**
Expand Down Expand Up @@ -14145,7 +14187,9 @@ export {
getPolicyChangeMessage,
getPolicyChangeLogCopyMessage,
getMovedTransactionMessage,
getMovedTransactionReportID,
getUnreportedTransactionMessage,
getUnreportedTransactionReportID,
navigateToLinkedReportAction,
buildOptimisticUnreportedTransactionAction,
isBusinessInvoiceRoom,
Expand Down
5 changes: 3 additions & 2 deletions src/libs/SearchQueryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import navigationRef from './Navigation/navigationRef';
import {isRecord} from './ObjectUtils';
import {getPersonalDetailByEmail, temporaryGetDisplayNameOrDefault} from './PersonalDetailsUtils';
import {getCleanedTagName, getValidConnectedIntegration} from './PolicyUtils';
import {deprecatedGetReportName} from './ReportNameUtils';
import {getReportName} from './ReportNameUtils';
import {parse as parseSearchQuery} from './SearchParser/searchParser';
import StringUtils from './StringUtils';
import {hashText} from './UserUtils';
Expand Down Expand Up @@ -1707,7 +1707,8 @@ function getFilterDisplayValue({
return getBankAccountSearchLabel(bankAccount);
}
if (filterName === CONST.SEARCH.SYNTAX_FILTER_KEYS.IN) {
return deprecatedGetReportName(reports?.[`${ONYXKEYS.COLLECTION.REPORT}${filterValue}`], reportAttributes) || filterValue;
const filterReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${filterValue}`];
return getReportName(filterReport, filterReport?.reportID ? reportAttributes?.[filterReport.reportID]?.reportName : undefined) || filterValue;
}
if (filterName === CONST.SEARCH.SYNTAX_FILTER_KEYS.AMOUNT || filterName === CONST.SEARCH.SYNTAX_FILTER_KEYS.TOTAL || filterName === CONST.SEARCH.SYNTAX_FILTER_KEYS.PURCHASE_AMOUNT) {
// Added 2 here as this is the maximum number of decimals an amount can have. So, we can run a search with 2 decimals here.
Expand Down
Loading
Loading