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
33 changes: 33 additions & 0 deletions config/eslint/eslint.seatbelt.tsv

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/components/AvatarWithDisplayName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import createDynamicRoute from '@libs/Navigation/helpers/dynamicRoutesUtils/crea
import Navigation from '@libs/Navigation/Navigation';
import {getPersonalDetailsForAccountIDs} from '@libs/OptionsListUtils';
import {getHumanAgentAccountIDFromReportAction, getHumanAgentFirstName} from '@libs/ReportActionsUtils';
import {getReportName} from '@libs/ReportNameUtils';
import {deprecatedGetReportName} from '@libs/ReportNameUtils';
import type {DisplayNameWithTooltips} from '@libs/ReportUtils';
import {
canEditReportTitle,
Expand Down Expand Up @@ -208,7 +208,7 @@ function AvatarWithDisplayName({
const reportAttributes = useReportAttributes();
const derivedParentReportName = useDerivedReportNameByReportID(report?.parentReportID);
const isReportArchived = useReportIsArchived(report?.reportID);
const title = getReportName(report, reportAttributes);
const title = deprecatedGetReportName(report, reportAttributes);
const isParentReportArchived = useReportIsArchived(report?.parentReportID);
const subtitle = getChatRoomSubtitle(report, policy, conciergeReportID, translate, true, isReportArchived);
const parentNavigationSubtitleData = getParentNavigationSubtitle(report, policy, conciergeReportID, translate, derivedParentReportName, isParentReportArchived);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import useReportAttributes from '@hooks/useReportAttributes';
import useThemeStyles from '@hooks/useThemeStyles';

import Navigation from '@libs/Navigation/Navigation';
import {getReportName} from '@libs/ReportNameUtils';
import {deprecatedGetReportName} from '@libs/ReportNameUtils';
import {generateReportID, getOutstandingReportsForUser, isMoneyRequestReport, isReportOutstanding} from '@libs/ReportUtils';

import CONST from '@src/CONST';
Expand Down Expand Up @@ -108,7 +108,7 @@ function ReportField({selectedParticipants, iouType, reportID, reportActionID, a
})();

const reportName = (() => {
const name = getReportName(selectedReport, reportAttributes);
const name = deprecatedGetReportName(selectedReport, reportAttributes);
if (!name) {
return isUnreported ? translate('common.none') : translate('iou.newReport');
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ import {
isTaxTrackingEnabled,
} from '@libs/PolicyUtils';
import {getOriginalMessage, isMoneyRequestAction} from '@libs/ReportActionsUtils';
import {getReportName} from '@libs/ReportNameUtils';
import {deprecatedGetReportName} from '@libs/ReportNameUtils';
import {isMarkAsCashActionForTransaction} from '@libs/ReportPrimaryActionUtils';
import {isSplitAction} from '@libs/ReportSecondaryActionUtils';
import {
Expand Down Expand Up @@ -554,7 +554,7 @@ function MoneyRequestView({
}
return {
reportID: match.reportID,
name: getReportName(match, reportAttributes) || match.reportName,
name: deprecatedGetReportName(match, reportAttributes) || match.reportName,
};
};
const [tripRoomInfo] = originalUseOnyx(ONYXKEYS.COLLECTION.REPORT, {selector: tripRoomReportSelector}, [transactionTripID, grandparentReportID, reportAttributes]);
Expand Down Expand Up @@ -1139,7 +1139,7 @@ function MoneyRequestView({

const reportNameToDisplay = isFromMergeTransaction
? (updatedTransaction?.reportName ?? translate('common.none'))
: getReportName(parentReport, reportAttributes) || parentReport?.reportName;
: deprecatedGetReportName(parentReport, reportAttributes) || parentReport?.reportName;
const shouldShowReport = !!parentReportID || (isFromMergeTransaction && !!reportNameToDisplay);
const reportCopyValue = !canEditReport && reportNameToDisplay !== translate('common.none') ? reportNameToDisplay : undefined;
const shouldShowCategoryAnalyzing = isCategoryBeingAnalyzed(updatedTransaction ?? transaction);
Expand Down
4 changes: 2 additions & 2 deletions src/components/ReportWelcomeText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import useThemeStyles from '@hooks/useThemeStyles';
import createDynamicRoute from '@libs/Navigation/helpers/dynamicRoutesUtils/createDynamicRoute';
import Navigation from '@libs/Navigation/Navigation';
import {getPersonalDetailsForAccountIDs} from '@libs/OptionsListUtils';
import {getReportName} from '@libs/ReportNameUtils';
import {deprecatedGetReportName} from '@libs/ReportNameUtils';
import {
getInvoiceReceiverPolicyID,
getParticipantsAccountIDsForDisplay,
Expand Down Expand Up @@ -91,7 +91,7 @@ function ReportWelcomeText({report, policy}: ReportWelcomeTextProps) {
)}`,
)
.join(', ');
const reportName = getReportName(report, reportAttributes);
const reportName = deprecatedGetReportName(report, reportAttributes);
const shouldShowUsePlusButtonText =
moneyRequestOptions.includes(CONST.IOU.TYPE.PAY) ||
moneyRequestOptions.includes(CONST.IOU.TYPE.SUBMIT) ||
Expand Down
4 changes: 2 additions & 2 deletions src/components/Search/hooks/useFilterReportValue.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import useOnyx from '@hooks/useOnyx';

import {getReportName} from '@libs/ReportNameUtils';
import {deprecatedGetReportName} from '@libs/ReportNameUtils';
import type {SearchFilter} from '@libs/SearchUIUtils';

import ONYXKEYS from '@src/ONYXKEYS';
Expand All @@ -14,7 +14,7 @@ function useFilterReportValue(reportIDs: SearchFilter['value']): string {
}

return reportIDs
.map((id) => getReportName(reports?.[`${ONYXKEYS.COLLECTION.REPORT}${id}`], reportAttributes?.reports))
.map((id) => deprecatedGetReportName(reports?.[`${ONYXKEYS.COLLECTION.REPORT}${id}`], reportAttributes?.reports))
.filter(Boolean)
.join(', ');
}
Expand Down
4 changes: 2 additions & 2 deletions src/libs/ModifiedExpenseMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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, getPolicyExpenseChatName, getReportName} from './ReportNameUtils';
import {buildReportNameFromParticipantNames, deprecatedGetReportName, getPolicyExpenseChatName} from './ReportNameUtils';
import {getPolicyName, getRootParentReport, isPolicyExpenseChat, isSelfDM} from './ReportUtils';
import {getFormattedAttendees, getTagArrayFromName} from './TransactionUtils';
import {isInvalidMerchantValue} from './ValidationUtils';
Expand Down Expand Up @@ -188,7 +188,7 @@ function getMovedFromOrToReportMessage(
}

if (movedFromReport) {
const originReportName = getReportName(movedFromReport, reportAttributes);
const originReportName = deprecatedGetReportName(movedFromReport, reportAttributes);
return originReportName ? translate('iou.movedFromReport', originReportName) : translate('iou.movedFromReportNoName');
}
}
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 {getReportName} from '@libs/ReportNameUtils';
import {deprecatedGetReportName} 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 = getReportName(report, reportAttributes);
const roomName = deprecatedGetReportName(report, reportAttributes);
title = roomName;
body = `${plainTextPerson}: ${plainTextMessage}`;
} else {
Expand Down
8 changes: 4 additions & 4 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 {getReportName} from '@libs/ReportNameUtils';
import {deprecatedGetReportName} from '@libs/ReportNameUtils';
import type {OptionData} from '@libs/ReportUtils';
import {
canUserPerformWriteAction,
Expand Down Expand Up @@ -1198,7 +1198,7 @@ function createOption({
},
);

const computedReportName = getReportName(report, reportAttributesDerived);
const computedReportName = deprecatedGetReportName(report, reportAttributesDerived);

reportName = showPersonalDetails
? getDisplayNameForParticipant({accountID: accountIDs.at(0), formatPhoneNumber: formatPhoneNumberPhoneUtils, translate: translateFn}) ||
Expand Down Expand Up @@ -1281,7 +1281,7 @@ function getReportOption(
if (option.isSelfDM) {
option.alternateText = translateLocal('reportActionsView.yourSpace');
} else if (option.isInvoiceRoom) {
option.text = getReportName(report, reportAttributesDerived);
option.text = deprecatedGetReportName(report, reportAttributesDerived);
option.alternateText = translateLocal('workspace.common.invoices');
} else {
option.text = getPolicyName({report, policy});
Expand Down Expand Up @@ -1338,7 +1338,7 @@ function getReportDisplayOption(
if (option.isSelfDM) {
option.alternateText = translateLocal('reportActionsView.yourSpace');
} else if (option.isInvoiceRoom) {
option.text = getReportName(report, reportAttributesDerived);
option.text = deprecatedGetReportName(report, reportAttributesDerived);
option.alternateText = translateLocal('workspace.common.invoices');
} else if (unknownUserDetails) {
option.text = unknownUserDetails.text ?? unknownUserDetails.login;
Expand Down
23 changes: 20 additions & 3 deletions src/libs/ReportNameUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1103,20 +1103,37 @@ function computeReportName({
/**
* Returns the report name from OnyxDerived `reportAttributes` when available, falling back to the raw report object.
*
* **Always prefer passing `reportAttributesDerivedValue` from the derived Onyx key** (`ONYXKEYS.DERIVED.REPORT_ATTRIBUTES`).
* **Always prefer passing `derivedReportName`**, sourced from the derived Onyx key (`ONYXKEYS.DERIVED.REPORT_ATTRIBUTES`)
* i.e. `reportAttributes?.[reportID]?.reportName`. Prefer the O(1) selectors (`useDerivedReportNameByReportID`) over
* subscribing to the whole attributes Record just to read one name.
* The fallback to `report.reportName` exists only for edge-cases where the derived value is not yet populated.
* Do NOT compute any part of the name here. Adjust `computeReportName` (internal) function if any change to report name are required.
*
* @param derivedReportName the cached name for this report from `ONYXKEYS.DERIVED.REPORT_ATTRIBUTES`.
*/
function getReportName(report?: Report, reportAttributesDerivedValue?: ReportAttributesDerivedValue['reports']): string {
function getReportName(report?: Report, derivedReportName?: string): string {
if (!report?.reportID) {
return '';
}
return reportAttributesDerivedValue?.[report.reportID]?.reportName ?? report.reportName ?? '';
return derivedReportName ?? report.reportName ?? '';
}

/**
* Transitional wrapper for call sites that still hold the whole attributes `Record`. Passing the Record forces a
* caller to subscribe to *every* report's attributes and re-render when any of them change, when all it needs is one
* name. Each call site is migrated to `getReportName` incrementally; this wrapper is removed once none remain.
* See https://github.com/Expensify/App/issues/66427.
*
* @deprecated Use `getReportName(report, derivedReportName)`, sourcing the name via `useDerivedReportNameByReportID`.
*/
function deprecatedGetReportName(report?: Report, reportAttributesDerivedValue?: ReportAttributesDerivedValue['reports']): string {
return getReportName(report, report?.reportID ? reportAttributesDerivedValue?.[report.reportID]?.reportName : undefined);
}

export {
computeReportName,
getReportName,
deprecatedGetReportName,
getInvoiceReportName,
getMoneyRequestReportName,
buildReportNameFromParticipantNames,
Expand Down
12 changes: 6 additions & 6 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,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 {getGroupChatName, getInvoicePayerName, getInvoiceReportName, getReportName} from './ReportNameUtils';
import {deprecatedGetReportName, getGroupChatName, getInvoicePayerName, getInvoiceReportName} from './ReportNameUtils';
import {shouldRestrictUserBillableActions} from './SubscriptionUtils';
import {isTaskCompleted} from './TaskUtils';
import {
Expand Down Expand Up @@ -5678,7 +5678,7 @@ function getReportPreviewMessageForCopy(
const originalReportAction = params.originalReportAction ?? iouReportAction;
const report = typeof reportOrID === 'string' ? getReport(reportOrID, deprecatedAllReports) : reportOrID;
if (report) {
return getReportName(report, reportAttributes ?? reportAttributesDerivedValue) || (originalReportAction?.childReportName ?? '');
return deprecatedGetReportName(report, reportAttributes ?? reportAttributesDerivedValue) || (originalReportAction?.childReportName ?? '');
}
return originalReportAction?.childReportName ?? '';
}
Expand Down Expand Up @@ -7166,7 +7166,7 @@ function getMovedTransactionMessage(translate: LocalizedTranslate, action: Repor

const report = fromReport ?? toReport;

const reportName = Parser.htmlToText(getReportName(report, reportAttributes) ?? report?.reportName ?? '');
const reportName = Parser.htmlToText(deprecatedGetReportName(report, reportAttributes) ?? report?.reportName ?? '');
const reportUrl = getReportURLForCurrentContext(report?.reportID);
if (typeof fromReportID === 'undefined') {
return reportName ? translate('iou.movedTransactionTo', reportUrl, reportName) : translate('iou.movedTransactionToAnotherReport');
Expand All @@ -7180,7 +7180,7 @@ function getUnreportedTransactionMessage(translate: LocalizedTranslate, action:

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

const reportName = Parser.htmlToText(getReportName(fromReport, reportAttributes) ?? fromReport?.reportName ?? '');
const reportName = Parser.htmlToText(deprecatedGetReportName(fromReport, reportAttributes) ?? fromReport?.reportName ?? '');

let reportUrl = getReportURLForCurrentContext(fromReportID);

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

if (report?.reportID) {
return getReportName(getReport(report?.reportID, deprecatedAllReports), reportAttributesDerivedValue);
return deprecatedGetReportName(getReport(report?.reportID, deprecatedAllReports), reportAttributesDerivedValue);
}

return getReportName(report, reportAttributesDerivedValue);
return deprecatedGetReportName(report, reportAttributesDerivedValue);
}

/**
Expand Down
4 changes: 2 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 {getReportName} from './ReportNameUtils';
import {deprecatedGetReportName} from './ReportNameUtils';
import {parse as parseSearchQuery} from './SearchParser/searchParser';
import StringUtils from './StringUtils';
import {hashText} from './UserUtils';
Expand Down Expand Up @@ -1623,7 +1623,7 @@ function getFilterDisplayValue({
return getBankAccountSearchLabel(bankAccount);
}
if (filterName === CONST.SEARCH.SYNTAX_FILTER_KEYS.IN) {
return getReportName(reports?.[`${ONYXKEYS.COLLECTION.REPORT}${filterValue}`], reportAttributes) || filterValue;
return deprecatedGetReportName(reports?.[`${ONYXKEYS.COLLECTION.REPORT}${filterValue}`], reportAttributes) || 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
6 changes: 3 additions & 3 deletions src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ import {
isResolvedActionableWhisper,
isWhisperActionTargetedToOthers,
} from './ReportActionsUtils';
import {getReportName} from './ReportNameUtils';
import {deprecatedGetReportName} from './ReportNameUtils';
import {isExportAction} from './ReportPrimaryActionUtils';
import {
canDeleteMoneyRequestReport,
Expand Down Expand Up @@ -2618,7 +2618,7 @@ function getTaskSections(
if (parentReport && personalDetails) {
const policy = data[`${ONYXKEYS.COLLECTION.POLICY}${parentReport.policyID}`];
const isParentReportArchived = isArchivedReport(reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${parentReport?.reportID}`]);
const parentReportName = getReportName(parentReport, reportAttributesDerivedValue);
const parentReportName = deprecatedGetReportName(parentReport, reportAttributesDerivedValue);
const icons = getIcons(parentReport, formatPhoneNumber, translate, personalDetails, null, '', -1, policy, undefined, isParentReportArchived);
const parentReportIcon = icons?.at(0);

Expand Down Expand Up @@ -2790,7 +2790,7 @@ function getReportActionsSections(
...reportAction,
reportID,
from,
reportName: getReportName(report, reportAttributesDerivedValue),
reportName: deprecatedGetReportName(report, reportAttributesDerivedValue),
formattedFrom: from?.displayName ?? from?.login ?? '',
date: reportAction.created,
keyForList: reportAction.reportActionID,
Expand Down
10 changes: 5 additions & 5 deletions src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ import {
isTagModificationAction,
isTaskAction,
} from './ReportActionsUtils';
import {getReportName as getReportNameFromDerived} from './ReportNameUtils';
import {deprecatedGetReportName} from './ReportNameUtils';
import {
canUserPerformWriteAction as canUserPerformWriteActionUtil,
excludeParticipantsForDisplay,
Expand Down Expand Up @@ -573,7 +573,7 @@ function categorizeReportsForLHN(
}

const reportID = report.reportID;
const displayName = getReportNameFromDerived(report, reportAttributes);
const displayName = deprecatedGetReportName(report, reportAttributes);
const miniReport: MiniReport = {
reportID,
displayName,
Expand Down Expand Up @@ -1062,7 +1062,7 @@ function getOptionData({
: translate('workspace.invite.removed');
const users = translate(targetAccountIDsLength > 1 ? 'common.members' : 'common.member')?.toLocaleLowerCase();
result.alternateText = formatReportLastMessageText(`${actorDisplayName ?? lastActorDisplayName}: ${verb} ${targetAccountIDsLength} ${users}`);
const roomName = getReportNameFromDerived(lastActionReport ?? undefined, reportAttributesDerived) || lastActionOriginalMessage?.roomName;
const roomName = deprecatedGetReportName(lastActionReport ?? undefined, reportAttributesDerived) || lastActionOriginalMessage?.roomName;
if (roomName) {
const preposition =
lastAction.actionName === CONST.REPORT.ACTIONS.TYPE.ROOM_CHANGE_LOG.INVITE_TO_ROOM || lastAction.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.INVITE_TO_ROOM
Expand Down Expand Up @@ -1380,7 +1380,7 @@ function getOptionData({
result.phoneNumber = personalDetail?.phoneNumber ?? '';
}

const reportName = getReportNameFromDerived(report, reportAttributesDerived);
const reportName = deprecatedGetReportName(report, reportAttributesDerived);

result.text = reportName;
result.subtitle = subtitle;
Expand Down Expand Up @@ -1511,7 +1511,7 @@ function getRoomWelcomeMessage(
): WelcomeMessage {
const welcomeMessage: WelcomeMessage = {};
const workspaceName = getPolicyName({report});
const reportName = getReportNameFromDerived(report ?? undefined, reportAttributes);
const reportName = deprecatedGetReportName(report ?? undefined, reportAttributes);

if (report?.description) {
welcomeMessage.messageHtml = getReportDescription(report);
Expand Down
Loading
Loading