diff --git a/src/libs/ReportNameUtils.ts b/src/libs/ReportNameUtils.ts index 993d12eef873..ddd866242961 100644 --- a/src/libs/ReportNameUtils.ts +++ b/src/libs/ReportNameUtils.ts @@ -142,6 +142,19 @@ import { isUserCreatedPolicyRoom, } from './ReportUtils'; +type ComputeReportName = { + report?: Report; + reports?: OnyxCollection; + policies?: OnyxCollection; + transactions?: OnyxCollection; + allReportNameValuePairs?: OnyxCollection; + allPolicyTags?: OnyxCollection; + personalDetailsList?: PersonalDetailsList; + reportActions?: OnyxCollection; + currentUserAccountID?: number; + currentUserLogin: string; +}; + let allPersonalDetails: OnyxEntry; // eslint-disable-next-line rulesdir/no-onyx-connect -- allPersonalDetails is used by the deprecated getReportName function; will be removed as part of the Onyx.connect migration @@ -673,6 +686,7 @@ function computeChatThreadReportName( isArchived: boolean, report: Report, reports: OnyxCollection, + currentUserLogin: string, parentReportAction?: ReportAction, policyTags?: OnyxEntry, policy?: OnyxEntry, @@ -745,16 +759,14 @@ function computeChatThreadReportName( movedToReport, policyTags, policy, - // currentUserLogin is not threaded through this call chain yet; the empty string - // causes policy-admin checks to fall back to the non-admin message path. - // This will be addressed as part of the broader Onyx.connect migration. - currentUserLogin: '', + currentUserLogin, }) : getForReportAction({ reportAction: parentReportAction, policyID, movedFromReport, movedToReport, + currentUserLogin, }); return formatReportLastMessageText(modifiedMessage); } @@ -771,18 +783,18 @@ function computeChatThreadReportName( * @internal Use this only for computation in derived report attributes * In all other cases you should use `getReportName` */ -function computeReportName( - report?: Report, - reports?: OnyxCollection, - policies?: OnyxCollection, - transactions?: OnyxCollection, - allReportNameValuePairs?: OnyxCollection, - personalDetailsList?: PersonalDetailsList, - reportActions?: OnyxCollection, - currentUserAccountID?: number, - privateIsArchived?: string, - allPolicyTags?: OnyxCollection, -): string { +function computeReportName({ + report, + reports, + policies, + transactions, + allReportNameValuePairs, + personalDetailsList, + reportActions, + currentUserAccountID, + currentUserLogin, + allPolicyTags, +}: ComputeReportName): string { if (!report || !report.reportID) { return ''; } @@ -805,7 +817,17 @@ function computeReportName( if (isActionOfType(parentReportAction, CONST.REPORT.ACTIONS.TYPE.CREATED_REPORT_FOR_UNAPPROVED_TRANSACTIONS)) { const {originalID} = getOriginalMessage(parentReportAction) ?? {}; const originalReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${originalID}`]; - const reportName = computeReportName(originalReport, reports, policies, transactions, allReportNameValuePairs, personalDetailsList, reportActions, currentUserAccountID); + const reportName = computeReportName({ + report: originalReport, + reports, + policies, + transactions, + allReportNameValuePairs, + personalDetailsList, + reportActions, + currentUserAccountID, + currentUserLogin, + }); // eslint-disable-next-line @typescript-eslint/no-deprecated return getCreatedReportForUnapprovedTransactionsMessage(originalID, reportName, isOriginalReportDeleted(parentReportAction, originalReport), translateLocal); } @@ -816,12 +838,20 @@ function computeReportName( return Parser.isHTML(taskName) ? Parser.htmlToText(taskName).trim() : taskName.trim(); } - const privateIsArchivedValue = privateIsArchived ?? allReportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`]?.private_isArchived; + const privateIsArchivedValue = allReportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`]?.private_isArchived; - // eslint-disable-next-line @typescript-eslint/no-deprecated const policyTags = allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${report.policyID}`]; - // eslint-disable-next-line @typescript-eslint/no-deprecated -- translateLocal is deprecated; computeReportName is non-React code that cannot use the translate hook - const chatThreadReportName = computeChatThreadReportName(translateLocal, !!privateIsArchivedValue, report, reports ?? {}, parentReportAction, policyTags, reportPolicy); + const chatThreadReportName = computeChatThreadReportName( + // eslint-disable-next-line @typescript-eslint/no-deprecated -- translateLocal is deprecated; computeReportName is non-React code that cannot use the translate hook + translateLocal, + !!privateIsArchivedValue, + report, + reports ?? {}, + currentUserLogin ?? '', + parentReportAction, + policyTags, + reportPolicy, + ); if (chatThreadReportName) { return chatThreadReportName; } diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 5b296a00bb19..4dbc11204a9b 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5267,7 +5267,7 @@ function getReportPreviewMessage( const reportActionMessage = getReportActionHtml(iouReportAction); if (isCopyAction) { if (report) { - return computeReportName(report) || (originalReportAction?.childReportName ?? ''); + return computeReportName({report, currentUserLogin: ''}) || (originalReportAction?.childReportName ?? ''); } return originalReportAction?.childReportName ?? ''; } diff --git a/src/libs/actions/OnyxDerived/configs/reportAttributes.ts b/src/libs/actions/OnyxDerived/configs/reportAttributes.ts index 7be982ceb008..bb8c5420b757 100644 --- a/src/libs/actions/OnyxDerived/configs/reportAttributes.ts +++ b/src/libs/actions/OnyxDerived/configs/reportAttributes.ts @@ -211,7 +211,17 @@ export default createOnyxDerivedValueConfig({ acc[report.reportID] = { reportName: report - ? computeReportName(report, reports, policies, transactions, reportNameValuePairs, personalDetails, reportActions, session?.accountID ?? CONST.DEFAULT_NUMBER_ID) + ? computeReportName({ + report, + reports, + policies, + transactions, + allReportNameValuePairs: reportNameValuePairs, + personalDetailsList: personalDetails, + reportActions, + currentUserAccountID: session?.accountID ?? CONST.DEFAULT_NUMBER_ID, + currentUserLogin: session?.email ?? '', + }) : '', isEmpty: generateIsEmptyReport(report, isReportArchived), brickRoadStatus, diff --git a/tests/unit/ReportNameUtilsTest.ts b/tests/unit/ReportNameUtilsTest.ts index d3705f416128..f9dba6b2b2b4 100644 --- a/tests/unit/ReportNameUtilsTest.ts +++ b/tests/unit/ReportNameUtilsTest.ts @@ -22,6 +22,7 @@ import {fakePersonalDetails} from '../utils/LHNTestUtils'; import {formatPhoneNumber} from '../utils/TestHelper'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; +const currentUserLogin = 'lagertha2@vikings.net'; describe('ReportNameUtils', () => { const currentUserAccountID = 5; const computeReportName = ( @@ -33,7 +34,18 @@ describe('ReportNameUtils', () => { personalDetailsList?: PersonalDetailsList, reportActions?: OnyxCollection, currentUserID = currentUserAccountID, - ) => computeReportNameOriginal(report, reports, policies, transactions, allReportNameValuePairs, personalDetailsList, reportActions, currentUserID); + ) => + computeReportNameOriginal({ + report, + reports, + policies, + transactions, + allReportNameValuePairs, + personalDetailsList, + reportActions, + currentUserAccountID: currentUserID, + currentUserLogin, + }); const participantsPersonalDetails: PersonalDetailsList = [ { accountID: 1, @@ -534,18 +546,16 @@ describe('ReportNameUtils', () => { }, } as OnyxCollection; - const name = computeReportNameOriginal( - thread, - emptyCollections.reports, - emptyCollections.policies, - undefined, - undefined, - participantsPersonalDetails, - reportActionsCollection, + const name = computeReportNameOriginal({ + report: thread, + reports: emptyCollections.reports, + policies: emptyCollections.policies, + personalDetailsList: participantsPersonalDetails, + reportActions: reportActionsCollection, currentUserAccountID, - undefined, - policyTagsCollection, - ); + currentUserLogin: '', + allPolicyTags: policyTagsCollection, + }); expect(name).toContain('Cost Center'); }); diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 081c6df5e3b4..29cb5db1da2f 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -243,7 +243,18 @@ const computeReportName = ( personalDetailsList?: PersonalDetailsList, reportActions?: OnyxCollection, currentUserID = currentUserAccountID, -) => computeReportNameOriginal(report, reports, policies, transactions, allReportNameValuePairs, personalDetailsList, reportActions, currentUserID); +) => + computeReportNameOriginal({ + report, + reports, + policies, + transactions, + allReportNameValuePairs, + personalDetailsList, + reportActions, + currentUserAccountID: currentUserID, + currentUserLogin: currentUserEmail, + }); const participantsPersonalDetails: PersonalDetailsList = { '1': { accountID: 1,