From 70dc6df6026ae9b6ea30cee9f7c20c811848b623 Mon Sep 17 00:00:00 2001 From: allgandalf Date: Tue, 4 Nov 2025 17:08:47 +0530 Subject: [PATCH 01/12] Remove Onyx.connect() for the key: ONYXKEYS.COUNTRY_CODE in src/libs/LocalePhoneNumber.ts --- src/libs/ReportUtils.ts | 18 ++++++++++++------ src/pages/GroupChatNameEditPage.tsx | 7 +++++-- src/pages/InviteReportParticipantsPage.tsx | 2 +- src/pages/NewChatConfirmPage.tsx | 4 ++-- tests/unit/ReportUtilsTest.ts | 20 ++++++++++---------- 5 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 408803e4be8b0..8c82b64cd2321 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3241,7 +3241,13 @@ const customCollator = new Intl.Collator('en', {usage: 'sort', sensitivity: 'var /** * Returns the report name if the report is a group chat */ -function getGroupChatName(participants?: SelectedParticipant[], shouldApplyLimit = false, report?: OnyxEntry, reportMetadataParam?: OnyxEntry): string | undefined { +function getGroupChatName( + formatPhoneNumber: LocaleContextProps['formatPhoneNumber'], + participants?: SelectedParticipant[], + shouldApplyLimit = false, + report?: OnyxEntry, + reportMetadataParam?: OnyxEntry, +): string | undefined { // If we have a report always try to get the name from the report. if (report?.reportName) { return report.reportName; @@ -3267,8 +3273,8 @@ function getGroupChatName(participants?: SelectedParticipant[], shouldApplyLimit return participantAccountIDs .map( (participantAccountID, index) => - getDisplayNameForParticipant({accountID: participantAccountID, shouldUseShortForm: isMultipleParticipantReport, formatPhoneNumber: formatPhoneNumberPhoneUtils}) || - formatPhoneNumberPhoneUtils(participants?.[index]?.login ?? ''), + getDisplayNameForParticipant({accountID: participantAccountID, shouldUseShortForm: isMultipleParticipantReport, formatPhoneNumber}) || + formatPhoneNumber(participants?.[index]?.login ?? ''), ) .sort((first, second) => customCollator.compare(first ?? '', second ?? '')) .filter(Boolean) @@ -3278,7 +3284,7 @@ function getGroupChatName(participants?: SelectedParticipant[], shouldApplyLimit } // eslint-disable-next-line @typescript-eslint/no-deprecated return translateLocal('groupChat.defaultReportName', { - displayName: getDisplayNameForParticipant({accountID: participantAccountIDs.at(0), formatPhoneNumber: formatPhoneNumberPhoneUtils}), + displayName: getDisplayNameForParticipant({accountID: participantAccountIDs.at(0), formatPhoneNumber}), }); } @@ -3500,7 +3506,7 @@ function getIconsForGroupChat(report: OnyxInputOrEntry): Icon[] { source: report.avatarUrl || getDefaultGroupAvatar(report.reportID), id: -1, type: CONST.ICON_TYPE_AVATAR, - name: getGroupChatName(undefined, true, report), + name: getGroupChatName(formatPhoneNumberPhoneUtils, undefined, true, report), }; return [groupChatIcon]; } @@ -5797,7 +5803,7 @@ function getReportName( } if (isGroupChat(report)) { - return getGroupChatName(undefined, true, report) ?? ''; + return getGroupChatName(formatPhoneNumberPhoneUtils, undefined, true, report) ?? ''; } if (isChatRoom(report)) { diff --git a/src/pages/GroupChatNameEditPage.tsx b/src/pages/GroupChatNameEditPage.tsx index 1b686f3562c74..603e974868b63 100644 --- a/src/pages/GroupChatNameEditPage.tsx +++ b/src/pages/GroupChatNameEditPage.tsx @@ -35,10 +35,13 @@ function GroupChatNameEditPage({report}: GroupChatNameEditPageProps) { const [groupChatDraft = getGroupChatDraft()] = useOnyx(ONYXKEYS.NEW_GROUP_CHAT_DRAFT, {canBeMissing: true}); const styles = useThemeStyles(); - const {translate} = useLocalize(); + const {translate, formatPhoneNumber} = useLocalize(); const {inputCallbackRef} = useAutoFocusInput(); - const existingReportName = useMemo(() => (report ? getGroupChatName(undefined, false, report) : getGroupChatName(groupChatDraft?.participants)), [groupChatDraft?.participants, report]); + const existingReportName = useMemo( + () => (report ? getGroupChatName(formatPhoneNumber, undefined, false, report) : getGroupChatName(formatPhoneNumber, groupChatDraft?.participants)), + [formatPhoneNumber, groupChatDraft?.participants, report], + ); // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const currentChatName = reportID ? existingReportName : groupChatDraft?.reportName || existingReportName; diff --git a/src/pages/InviteReportParticipantsPage.tsx b/src/pages/InviteReportParticipantsPage.tsx index 3caabff9d8d81..3237a7e7e1c6a 100644 --- a/src/pages/InviteReportParticipantsPage.tsx +++ b/src/pages/InviteReportParticipantsPage.tsx @@ -123,7 +123,7 @@ function InviteReportParticipantsPage({report}: InviteReportParticipantsPageProp const validate = useCallback(() => selectedOptions.length > 0, [selectedOptions]); const reportID = report.reportID; - const reportName = useMemo(() => getGroupChatName(undefined, true, report), [report]); + const reportName = useMemo(() => getGroupChatName(formatPhoneNumber, undefined, true, report), [formatPhoneNumber, report]); const goBack = useCallback(() => { Navigation.goBack(ROUTES.REPORT_PARTICIPANTS.getRoute(reportID, route.params.backTo)); diff --git a/src/pages/NewChatConfirmPage.tsx b/src/pages/NewChatConfirmPage.tsx index a82f90748fc84..5c7ddb60fce33 100644 --- a/src/pages/NewChatConfirmPage.tsx +++ b/src/pages/NewChatConfirmPage.tsx @@ -36,7 +36,7 @@ function navigateToEditChatName() { function NewChatConfirmPage() { const optimisticReportID = useRef(generateReportID()); const [avatarFile, setAvatarFile] = useState(); - const {translate, localeCompare} = useLocalize(); + const {translate, localeCompare, formatPhoneNumber} = useLocalize(); const styles = useThemeStyles(); const personalData = useCurrentUserPersonalDetails(); const [newGroupDraft, newGroupDraftMetaData] = useOnyx(ONYXKEYS.NEW_GROUP_CHAT_DRAFT, {canBeMissing: true}); @@ -52,7 +52,7 @@ function NewChatConfirmPage() { return options; }, [allPersonalDetails, newGroupDraft?.participants]); - const groupName = newGroupDraft?.reportName ? newGroupDraft?.reportName : getGroupChatName(newGroupDraft?.participants); + const groupName = newGroupDraft?.reportName ? newGroupDraft?.reportName : getGroupChatName(formatPhoneNumber, newGroupDraft?.participants); const sections: ListItem[] = useMemo( () => selectedOptions diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 19da1739d341f..0bf683bf4501f 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -3588,27 +3588,27 @@ describe('ReportUtils', () => { describe('When participantAccountIDs is passed to getGroupChatName', () => { it('Should show all participants name if count <= 5 and shouldApplyLimit is false', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(fourParticipants)).toEqual('Four, One, Three, Two'); + expect(getGroupChatName(formatPhoneNumber, fourParticipants)).toEqual('Four, One, Three, Two'); }); it('Should show all participants name if count <= 5 and shouldApplyLimit is true', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(fourParticipants)).toEqual('Four, One, Three, Two'); + expect(getGroupChatName(formatPhoneNumber, fourParticipants)).toEqual('Four, One, Three, Two'); }); it('Should show 5 participants name with ellipsis if count > 5 and shouldApplyLimit is true', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(eightParticipants, true)).toEqual('Five, Four, One, Three, Two...'); + expect(getGroupChatName(formatPhoneNumber, eightParticipants, true)).toEqual('Five, Four, One, Three, Two...'); }); it('Should show all participants name if count > 5 and shouldApplyLimit is false', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(eightParticipants, false)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); + expect(getGroupChatName(formatPhoneNumber, eightParticipants, false)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); }); it('Should use correct display name for participants', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, participantsPersonalDetails); - expect(getGroupChatName(fourParticipants, true)).toEqual('(833) 240-3627, floki@vikings.net, Lagertha, Ragnar'); + expect(getGroupChatName(formatPhoneNumber, fourParticipants, true)).toEqual('(833) 240-3627, floki@vikings.net, Lagertha, Ragnar'); }); }); @@ -3622,7 +3622,7 @@ describe('ReportUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(undefined, false, report)).toEqual("Let's talk"); + expect(getGroupChatName(formatPhoneNumber, undefined, false, report)).toEqual("Let's talk"); }); it('Should show report name if count <= 5 and shouldApplyLimit is true', async () => { @@ -3634,7 +3634,7 @@ describe('ReportUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(undefined, true, report)).toEqual("Let's talk"); + expect(getGroupChatName(formatPhoneNumber, undefined, true, report)).toEqual("Let's talk"); }); it('Should show report name if count > 5 and shouldApplyLimit is true', async () => { @@ -3646,7 +3646,7 @@ describe('ReportUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(undefined, true, report)).toEqual("Let's talk"); + expect(getGroupChatName(formatPhoneNumber, undefined, true, report)).toEqual("Let's talk"); }); it('Should show report name if count > 5 and shouldApplyLimit is false', async () => { @@ -3658,7 +3658,7 @@ describe('ReportUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(undefined, false, report)).toEqual("Let's talk"); + expect(getGroupChatName(formatPhoneNumber, undefined, false, report)).toEqual("Let's talk"); }); it('Should show participant names if report name is not available', async () => { @@ -3670,7 +3670,7 @@ describe('ReportUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(undefined, false, report)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); + expect(getGroupChatName(formatPhoneNumber, undefined, false, report)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); }); }); }); From 8a4d782d517c513663686a5976b98750aa41f3c5 Mon Sep 17 00:00:00 2001 From: allgandaf Date: Tue, 2 Dec 2025 09:32:02 +0530 Subject: [PATCH 02/12] part 1: Try fixing changed files eslint --- src/libs/ReportNameUtils.ts | 75 +++++++++++++++++----- src/pages/GroupChatNameEditPage.tsx | 3 +- src/pages/InviteReportParticipantsPage.tsx | 3 +- src/pages/NewChatConfirmPage.tsx | 3 +- tests/unit/ReportUtilsTest.ts | 2 +- 5 files changed, 67 insertions(+), 19 deletions(-) diff --git a/src/libs/ReportNameUtils.ts b/src/libs/ReportNameUtils.ts index b8f81525bdf7d..061acf91c3fe8 100644 --- a/src/libs/ReportNameUtils.ts +++ b/src/libs/ReportNameUtils.ts @@ -4,6 +4,7 @@ import {Str} from 'expensify-common'; import Onyx from 'react-native-onyx'; import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; +import type {LocaleContextProps} from '@components/LocaleContextProvider'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type { @@ -21,7 +22,6 @@ import type { import type {SelectedParticipant} from '@src/types/onyx/NewGroupChatDraft'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import {convertToDisplayString} from './CurrencyUtils'; -import {formatPhoneNumber} from './LocalePhoneNumber'; // eslint-disable-next-line @typescript-eslint/no-deprecated import {translateLocal} from './Localize'; import {getForReportAction, getMovedReportID} from './ModifiedExpenseMessage'; @@ -137,7 +137,15 @@ function generateArchivedReportName(reportName: string): string { * This function is useful in contexts such as 1:1 direct messages (DMs) or other group chats. * It limits to a maximum of 5 participants for the title and uses short names unless there is only one participant. */ -const buildReportNameFromParticipantNames = ({report, personalDetailsList: personalDetailsData}: {report: OnyxEntry; personalDetailsList?: Partial}) => +const buildReportNameFromParticipantNames = ({ + report, + personalDetailsList: personalDetailsData, + formatPhoneNumber, +}: { + report: OnyxEntry; + personalDetailsList?: Partial; + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; +}) => Object.keys(report?.participants ?? {}) .map(Number) .filter((id) => id !== currentUserAccountID) @@ -175,7 +183,13 @@ const customCollator = new Intl.Collator('en', {usage: 'sort', sensitivity: 'var /** * Returns the report name if the report is a group chat */ -function getGroupChatName(participants?: SelectedParticipant[], shouldApplyLimit = false, report?: OnyxEntry, reportMetadataParam?: OnyxEntry): string | undefined { +function getGroupChatName( + formatPhoneNumber: LocaleContextProps['formatPhoneNumber'], + participants?: SelectedParticipant[], + shouldApplyLimit = false, + report?: OnyxEntry, + reportMetadataParam?: OnyxEntry, +): string | undefined { // If we have a report always try to get the name from the report. if (report?.reportName) { return report.reportName; @@ -217,7 +231,15 @@ function getGroupChatName(participants?: SelectedParticipant[], shouldApplyLimit /** * Get the title for a policy expense chat */ -function getPolicyExpenseChatName({report, personalDetailsList}: {report: OnyxEntry; personalDetailsList?: Partial}): string | undefined { +function getPolicyExpenseChatName({ + report, + personalDetailsList, + formatPhoneNumber, +}: { + report: OnyxEntry; + personalDetailsList?: Partial; + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; +}): string | undefined { const ownerAccountID = report?.ownerAccountID; const personalDetails = ownerAccountID ? personalDetailsList?.[ownerAccountID] : undefined; const login = personalDetails ? personalDetails.login : null; @@ -240,11 +262,13 @@ function getInvoicesChatName({ receiverPolicy, personalDetails, policies, + formatPhoneNumber, }: { report: OnyxEntry; receiverPolicy: OnyxEntry; personalDetails?: Partial; policies?: Policy[]; + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; }): string { const invoiceReceiver = report?.invoiceReceiver; const isIndividual = invoiceReceiver?.type === CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL; @@ -266,8 +290,13 @@ function getInvoicesChatName({ return getPolicyName({report, policy: receiverPolicyResolved, policies}); } -function getInvoiceReportName(report: OnyxEntry, policy?: OnyxEntry, invoiceReceiverPolicy?: OnyxEntry): string { - const moneyRequestReportName = getMoneyRequestReportName({report, policy, invoiceReceiverPolicy}); +function getInvoiceReportName( + report: OnyxEntry, + formatPhoneNumber: LocaleContextProps['formatPhoneNumber'], + policy?: OnyxEntry, + invoiceReceiverPolicy?: OnyxEntry, +): string { + const moneyRequestReportName = getMoneyRequestReportName({report, formatPhoneNumber, policy, invoiceReceiverPolicy}); const oldDotInvoiceName = report?.reportName ?? moneyRequestReportName; return isNewDotInvoice(report?.chatReportID) ? moneyRequestReportName : oldDotInvoiceName; } @@ -277,7 +306,12 @@ function getInvoiceReportName(report: OnyxEntry, policy?: OnyxEntry, invoiceReceiverPolicy?: OnyxEntry, invoiceReceiverPersonalDetail?: PersonalDetails | null): string { +function getInvoicePayerName( + report: OnyxEntry, + formatPhoneNumber: LocaleContextProps['formatPhoneNumber'], + invoiceReceiverPolicy?: OnyxEntry, + invoiceReceiverPersonalDetail?: PersonalDetails | null, +): string { const invoiceReceiver = report?.invoiceReceiver; const isIndividual = invoiceReceiver?.type === CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL; @@ -292,7 +326,17 @@ function getInvoicePayerName(report: OnyxEntry, invoiceReceiverPolicy?: /** * Get the title for an IOU or expense chat which will be showing the payer and the amount */ -function getMoneyRequestReportName({report, policy, invoiceReceiverPolicy}: {report: OnyxEntry; policy?: OnyxEntry; invoiceReceiverPolicy?: OnyxEntry}): string { +function getMoneyRequestReportName({ + report, + formatPhoneNumber, + policy, + invoiceReceiverPolicy, +}: { + report: OnyxEntry; + formatPhoneNumber: LocaleContextProps['formatPhoneNumber']; + policy?: OnyxEntry; + invoiceReceiverPolicy?: OnyxEntry; +}): string { if (report?.reportName && isExpenseReport(report)) { return report.reportName; } @@ -306,7 +350,7 @@ function getMoneyRequestReportName({report, policy, invoiceReceiverPolicy}: {rep payerOrApproverName = getPolicyName({report: parentReport ?? report, policy}); } else if (isInvoiceReport(report)) { const chatReport = getReportOrDraftReport(report?.chatReportID); - payerOrApproverName = getInvoicePayerName(chatReport, invoiceReceiverPolicy); + payerOrApproverName = getInvoicePayerName(chatReport, formatPhoneNumber, invoiceReceiverPolicy); } else { payerOrApproverName = getDisplayNameForParticipant({accountID: report?.managerID, formatPhoneNumber}) ?? ''; } @@ -601,6 +645,7 @@ function computeChatThreadReportName(report: Report, reportNameValuePairs: Repor } function computeReportName( + formatPhoneNumber: LocaleContextProps['formatPhoneNumber'], report?: Report, reports?: OnyxCollection, policies?: OnyxCollection, @@ -643,7 +688,7 @@ function computeReportName( } if (isGroupChat(report)) { - return getGroupChatName(undefined, true, report) ?? ''; + return getGroupChatName(formatPhoneNumber, undefined, true, report) ?? ''; } let formattedName: string | undefined; @@ -653,12 +698,12 @@ function computeReportName( } if (isPolicyExpenseChat(report)) { - formattedName = getPolicyExpenseChatName({report, personalDetailsList}); + formattedName = getPolicyExpenseChatName({report, personalDetailsList, formatPhoneNumber}); } const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`]; if (isMoneyRequestReport(report)) { - formattedName = getMoneyRequestReportName({report, policy}); + formattedName = getMoneyRequestReportName({report, formatPhoneNumber, policy}); } if (isInvoiceReport(report)) { @@ -669,7 +714,7 @@ function computeReportName( chatReceiverPolicyID = (chatReceiver as {policyID: string}).policyID; } const invoiceReceiverPolicy = chatReceiverPolicyID ? policies?.[`${ONYXKEYS.COLLECTION.POLICY}${chatReceiverPolicyID}`] : undefined; - formattedName = getInvoiceReportName(report, policy, invoiceReceiverPolicy); + formattedName = getInvoiceReportName(report, formatPhoneNumber, policy, invoiceReceiverPolicy); } if (isInvoiceRoom(report)) { @@ -679,7 +724,7 @@ function computeReportName( receiverPolicyID = (receiver as {policyID: string}).policyID; } const invoiceReceiverPolicy = receiverPolicyID ? policies?.[`${ONYXKEYS.COLLECTION.POLICY}${receiverPolicyID}`] : undefined; - formattedName = getInvoicesChatName({report, receiverPolicy: invoiceReceiverPolicy, personalDetails: personalDetailsList}); + formattedName = getInvoicesChatName({report, formatPhoneNumber, receiverPolicy: invoiceReceiverPolicy, personalDetails: personalDetailsList}); } if (isSelfDM(report)) { @@ -695,7 +740,7 @@ function computeReportName( } // Not a room or PolicyExpenseChat, generate title from first 5 other participants - formattedName = buildReportNameFromParticipantNames({report, personalDetailsList}); + formattedName = buildReportNameFromParticipantNames({report, personalDetailsList, formatPhoneNumber}); const finalName = formattedName ?? report?.reportName ?? ''; diff --git a/src/pages/GroupChatNameEditPage.tsx b/src/pages/GroupChatNameEditPage.tsx index 603e974868b63..457325bfd3c15 100644 --- a/src/pages/GroupChatNameEditPage.tsx +++ b/src/pages/GroupChatNameEditPage.tsx @@ -12,7 +12,8 @@ import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import type {NewChatNavigatorParamList} from '@libs/Navigation/types'; -import {getGroupChatDraft, getGroupChatName} from '@libs/ReportUtils'; +import {getGroupChatName} from '@libs/ReportNameUtils'; +import {getGroupChatDraft} from '@libs/ReportUtils'; import StringUtils from '@libs/StringUtils'; import {setGroupDraft, updateChatName} from '@userActions/Report'; import CONST from '@src/CONST'; diff --git a/src/pages/InviteReportParticipantsPage.tsx b/src/pages/InviteReportParticipantsPage.tsx index ad81f8729607e..04a105ee916b9 100644 --- a/src/pages/InviteReportParticipantsPage.tsx +++ b/src/pages/InviteReportParticipantsPage.tsx @@ -23,8 +23,9 @@ import type {ParticipantsNavigatorParamList} from '@libs/Navigation/types'; import {getHeaderMessage} from '@libs/OptionsListUtils'; import {getLoginsByAccountIDs} from '@libs/PersonalDetailsUtils'; import {addSMSDomainIfPhoneNumber, parsePhoneNumber} from '@libs/PhoneNumber'; +import {getGroupChatName} from '@libs/ReportNameUtils'; import type {OptionData} from '@libs/ReportUtils'; -import {getGroupChatName, getParticipantsAccountIDsForDisplay} from '@libs/ReportUtils'; +import {getParticipantsAccountIDsForDisplay} from '@libs/ReportUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; diff --git a/src/pages/NewChatConfirmPage.tsx b/src/pages/NewChatConfirmPage.tsx index 45f334e7115d7..dfb820b338306 100644 --- a/src/pages/NewChatConfirmPage.tsx +++ b/src/pages/NewChatConfirmPage.tsx @@ -18,7 +18,8 @@ import type {CustomRNImageManipulatorResult} from '@libs/cropOrRotateImage/types import {readFileAsync} from '@libs/fileDownload/FileUtils'; import Navigation from '@libs/Navigation/Navigation'; import {getParticipantsOption} from '@libs/OptionsListUtils'; -import {generateReportID, getDefaultGroupAvatar, getGroupChatName} from '@libs/ReportUtils'; +import {getGroupChatName} from '@libs/ReportNameUtils'; +import {generateReportID, getDefaultGroupAvatar} from '@libs/ReportUtils'; import {navigateToAndOpenReport, setGroupDraft} from '@userActions/Report'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 68b39d125e884..039f2593047bc 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -69,7 +69,6 @@ import { getReasonAndReportActionThatRequiresAttention, getReportActionActorAccountID, getReportIDFromLink, - getReportName, getReportOrDraftReport, getReportStatusTranslation, getReportURLForCurrentContext, @@ -110,6 +109,7 @@ import { sortOutstandingReportsBySelected, temporary_getMoneyRequestOptions, } from '@libs/ReportUtils'; +import {getGroupChatName} from '@libs/ReportNameUtils'; import {buildOptimisticTransaction} from '@libs/TransactionUtils'; import CONST from '@src/CONST'; import IntlStore from '@src/languages/IntlStore'; From 0d1e7078140d743afedc261124e139d4a48f59ad Mon Sep 17 00:00:00 2001 From: allgandaf Date: Tue, 2 Dec 2025 09:32:43 +0530 Subject: [PATCH 03/12] fix --- tests/unit/ReportUtilsTest.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 039f2593047bc..a3213a0550ced 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -55,7 +55,6 @@ import { getDefaultWorkspaceAvatar, getDisplayNameForParticipant, getDisplayNamesWithTooltips, - getGroupChatName, getIconsForParticipants, getIOUReportActionDisplayMessage, getMoneyReportPreviewName, From 82001fe78953f20e7afb0cee50426c2176d64f8a Mon Sep 17 00:00:00 2001 From: allgandaf Date: Tue, 2 Dec 2025 10:45:37 +0530 Subject: [PATCH 04/12] try fixing errors --- tests/unit/ReportUtilsTest.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index a3213a0550ced..5b5002741f80e 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -19,6 +19,7 @@ import {translate} from '@libs/Localize'; import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute'; import Navigation from '@libs/Navigation/Navigation'; import {getOriginalMessage, getReportAction, isWhisperAction} from '@libs/ReportActionsUtils'; +import {getGroupChatName, getPolicyExpenseChatName} from '@libs/ReportNameUtils'; import type {OptionData} from '@libs/ReportUtils'; import { buildOptimisticChatReport, @@ -63,11 +64,11 @@ import { getParentNavigationSubtitle, getParticipantsList, getPolicyExpenseChat, - getPolicyExpenseChatName, getPolicyIDsWithEmptyReportsForAccount, getReasonAndReportActionThatRequiresAttention, getReportActionActorAccountID, getReportIDFromLink, + getReportName, getReportOrDraftReport, getReportStatusTranslation, getReportURLForCurrentContext, @@ -108,7 +109,6 @@ import { sortOutstandingReportsBySelected, temporary_getMoneyRequestOptions, } from '@libs/ReportUtils'; -import {getGroupChatName} from '@libs/ReportNameUtils'; import {buildOptimisticTransaction} from '@libs/TransactionUtils'; import CONST from '@src/CONST'; import IntlStore from '@src/languages/IntlStore'; @@ -531,7 +531,7 @@ describe('ReportUtils', () => { reportName: 'Fallback Report Name', } as unknown as OnyxEntry; - const name = getPolicyExpenseChatName({report, personalDetailsList: participantsPersonalDetails}); + const name = getPolicyExpenseChatName({report, personalDetailsList: participantsPersonalDetails, formatPhoneNumber}); expect(name).toBe(translate(CONST.LOCALES.EN, 'workspace.common.policyExpenseChatName', {displayName: 'Ragnar Lothbrok'})); }); @@ -541,7 +541,7 @@ describe('ReportUtils', () => { reportName: 'Fallback Report Name', } as unknown as OnyxEntry; - const name = getPolicyExpenseChatName({report, personalDetailsList: participantsPersonalDetails}); + const name = getPolicyExpenseChatName({report, personalDetailsList: participantsPersonalDetails, formatPhoneNumber}); expect(name).toBe(translate(CONST.LOCALES.EN, 'workspace.common.policyExpenseChatName', {displayName: 'floki'})); }); @@ -551,7 +551,7 @@ describe('ReportUtils', () => { reportName: 'Fallback Report Name', } as unknown as OnyxEntry; - const name = getPolicyExpenseChatName({report, personalDetailsList: {}}); + const name = getPolicyExpenseChatName({report, personalDetailsList: {}, formatPhoneNumber}); expect(name).toBe('Fallback Report Name'); }); }); From 910f129e0ca5e6365e4ff797e3b7b7c1de4b7987 Mon Sep 17 00:00:00 2001 From: allgandaf Date: Tue, 2 Dec 2025 10:58:42 +0530 Subject: [PATCH 05/12] revert full tests file --- tests/unit/ReportUtilsTest.ts | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 5b5002741f80e..da12c6e028d85 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -19,7 +19,6 @@ import {translate} from '@libs/Localize'; import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute'; import Navigation from '@libs/Navigation/Navigation'; import {getOriginalMessage, getReportAction, isWhisperAction} from '@libs/ReportActionsUtils'; -import {getGroupChatName, getPolicyExpenseChatName} from '@libs/ReportNameUtils'; import type {OptionData} from '@libs/ReportUtils'; import { buildOptimisticChatReport, @@ -56,6 +55,7 @@ import { getDefaultWorkspaceAvatar, getDisplayNameForParticipant, getDisplayNamesWithTooltips, + getGroupChatName, getIconsForParticipants, getIOUReportActionDisplayMessage, getMoneyReportPreviewName, @@ -64,6 +64,7 @@ import { getParentNavigationSubtitle, getParticipantsList, getPolicyExpenseChat, + getPolicyExpenseChatName, getPolicyIDsWithEmptyReportsForAccount, getReasonAndReportActionThatRequiresAttention, getReportActionActorAccountID, @@ -531,7 +532,7 @@ describe('ReportUtils', () => { reportName: 'Fallback Report Name', } as unknown as OnyxEntry; - const name = getPolicyExpenseChatName({report, personalDetailsList: participantsPersonalDetails, formatPhoneNumber}); + const name = getPolicyExpenseChatName({report, personalDetailsList: participantsPersonalDetails}); expect(name).toBe(translate(CONST.LOCALES.EN, 'workspace.common.policyExpenseChatName', {displayName: 'Ragnar Lothbrok'})); }); @@ -541,7 +542,7 @@ describe('ReportUtils', () => { reportName: 'Fallback Report Name', } as unknown as OnyxEntry; - const name = getPolicyExpenseChatName({report, personalDetailsList: participantsPersonalDetails, formatPhoneNumber}); + const name = getPolicyExpenseChatName({report, personalDetailsList: participantsPersonalDetails}); expect(name).toBe(translate(CONST.LOCALES.EN, 'workspace.common.policyExpenseChatName', {displayName: 'floki'})); }); @@ -551,7 +552,7 @@ describe('ReportUtils', () => { reportName: 'Fallback Report Name', } as unknown as OnyxEntry; - const name = getPolicyExpenseChatName({report, personalDetailsList: {}, formatPhoneNumber}); + const name = getPolicyExpenseChatName({report, personalDetailsList: {}}); expect(name).toBe('Fallback Report Name'); }); }); @@ -3811,27 +3812,27 @@ describe('ReportUtils', () => { describe('When participantAccountIDs is passed to getGroupChatName', () => { it('Should show all participants name if count <= 5 and shouldApplyLimit is false', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(formatPhoneNumber, fourParticipants)).toEqual('Four, One, Three, Two'); + expect(getGroupChatName(fourParticipants)).toEqual('Four, One, Three, Two'); }); it('Should show all participants name if count <= 5 and shouldApplyLimit is true', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(formatPhoneNumber, fourParticipants)).toEqual('Four, One, Three, Two'); + expect(getGroupChatName(fourParticipants)).toEqual('Four, One, Three, Two'); }); it('Should show 5 participants name with ellipsis if count > 5 and shouldApplyLimit is true', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(formatPhoneNumber, eightParticipants, true)).toEqual('Five, Four, One, Three, Two...'); + expect(getGroupChatName(eightParticipants, true)).toEqual('Five, Four, One, Three, Two...'); }); it('Should show all participants name if count > 5 and shouldApplyLimit is false', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(formatPhoneNumber, eightParticipants, false)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); + expect(getGroupChatName(eightParticipants, false)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); }); it('Should use correct display name for participants', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, participantsPersonalDetails); - expect(getGroupChatName(formatPhoneNumber, fourParticipants, true)).toEqual('(833) 240-3627, floki@vikings.net, Lagertha, Ragnar'); + expect(getGroupChatName(fourParticipants, true)).toEqual('(833) 240-3627, floki@vikings.net, Lagertha, Ragnar'); }); }); @@ -3845,7 +3846,7 @@ describe('ReportUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(formatPhoneNumber, undefined, false, report)).toEqual("Let's talk"); + expect(getGroupChatName(undefined, false, report)).toEqual("Let's talk"); }); it('Should show report name if count <= 5 and shouldApplyLimit is true', async () => { @@ -3857,7 +3858,7 @@ describe('ReportUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(formatPhoneNumber, undefined, true, report)).toEqual("Let's talk"); + expect(getGroupChatName(undefined, true, report)).toEqual("Let's talk"); }); it('Should show report name if count > 5 and shouldApplyLimit is true', async () => { @@ -3869,7 +3870,7 @@ describe('ReportUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(formatPhoneNumber, undefined, true, report)).toEqual("Let's talk"); + expect(getGroupChatName(undefined, true, report)).toEqual("Let's talk"); }); it('Should show report name if count > 5 and shouldApplyLimit is false', async () => { @@ -3881,7 +3882,7 @@ describe('ReportUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(formatPhoneNumber, undefined, false, report)).toEqual("Let's talk"); + expect(getGroupChatName(undefined, false, report)).toEqual("Let's talk"); }); it('Should show participant names if report name is not available', async () => { @@ -3893,7 +3894,7 @@ describe('ReportUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(formatPhoneNumber, undefined, false, report)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); + expect(getGroupChatName(undefined, false, report)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); }); }); }); @@ -9842,4 +9843,4 @@ describe('ReportUtils', () => { unmount(); await Onyx.clear(); }); -}); +}); \ No newline at end of file From bcb9adb24122ba2c68abd62d62a57630be27cc44 Mon Sep 17 00:00:00 2001 From: allgandaf Date: Tue, 2 Dec 2025 10:59:49 +0530 Subject: [PATCH 06/12] fix typeerror --- tests/unit/ReportUtilsTest.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index da12c6e028d85..0b8c27f47e9c5 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -3812,27 +3812,27 @@ describe('ReportUtils', () => { describe('When participantAccountIDs is passed to getGroupChatName', () => { it('Should show all participants name if count <= 5 and shouldApplyLimit is false', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(fourParticipants)).toEqual('Four, One, Three, Two'); + expect(getGroupChatName(formatPhoneNumber, fourParticipants)).toEqual('Four, One, Three, Two'); }); it('Should show all participants name if count <= 5 and shouldApplyLimit is true', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(fourParticipants)).toEqual('Four, One, Three, Two'); + expect(getGroupChatName(formatPhoneNumber,fourParticipants)).toEqual('Four, One, Three, Two'); }); it('Should show 5 participants name with ellipsis if count > 5 and shouldApplyLimit is true', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(eightParticipants, true)).toEqual('Five, Four, One, Three, Two...'); + expect(getGroupChatName(formatPhoneNumber, eightParticipants, true)).toEqual('Five, Four, One, Three, Two...'); }); it('Should show all participants name if count > 5 and shouldApplyLimit is false', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(eightParticipants, false)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); + expect(getGroupChatName(formatPhoneNumber, eightParticipants, false)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); }); it('Should use correct display name for participants', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, participantsPersonalDetails); - expect(getGroupChatName(fourParticipants, true)).toEqual('(833) 240-3627, floki@vikings.net, Lagertha, Ragnar'); + expect(getGroupChatName(formatPhoneNumber, fourParticipants, true)).toEqual('(833) 240-3627, floki@vikings.net, Lagertha, Ragnar'); }); }); @@ -3846,7 +3846,7 @@ describe('ReportUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(undefined, false, report)).toEqual("Let's talk"); + expect(getGroupChatName(formatPhoneNumber, undefined, false, report)).toEqual("Let's talk"); }); it('Should show report name if count <= 5 and shouldApplyLimit is true', async () => { @@ -3858,7 +3858,7 @@ describe('ReportUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(undefined, true, report)).toEqual("Let's talk"); + expect(getGroupChatName(formatPhoneNumber, undefined, true, report)).toEqual("Let's talk"); }); it('Should show report name if count > 5 and shouldApplyLimit is true', async () => { @@ -3870,7 +3870,7 @@ describe('ReportUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(undefined, true, report)).toEqual("Let's talk"); + expect(getGroupChatName(formatPhoneNumber, undefined, true, report)).toEqual("Let's talk"); }); it('Should show report name if count > 5 and shouldApplyLimit is false', async () => { @@ -3882,7 +3882,7 @@ describe('ReportUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(undefined, false, report)).toEqual("Let's talk"); + expect(getGroupChatName(formatPhoneNumber, undefined, false, report)).toEqual("Let's talk"); }); it('Should show participant names if report name is not available', async () => { @@ -3894,7 +3894,7 @@ describe('ReportUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(undefined, false, report)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); + expect(getGroupChatName(formatPhoneNumber, undefined, false, report)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); }); }); }); From e6b65e72cba31d418fa91e8b68c8c689ff88f301 Mon Sep 17 00:00:00 2001 From: allgandaf Date: Tue, 2 Dec 2025 16:55:37 +0530 Subject: [PATCH 07/12] fix prettier --- tests/unit/ReportUtilsTest.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 0b8c27f47e9c5..68b39d125e884 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -3817,7 +3817,7 @@ describe('ReportUtils', () => { it('Should show all participants name if count <= 5 and shouldApplyLimit is true', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(formatPhoneNumber,fourParticipants)).toEqual('Four, One, Three, Two'); + expect(getGroupChatName(formatPhoneNumber, fourParticipants)).toEqual('Four, One, Three, Two'); }); it('Should show 5 participants name with ellipsis if count > 5 and shouldApplyLimit is true', async () => { @@ -9843,4 +9843,4 @@ describe('ReportUtils', () => { unmount(); await Onyx.clear(); }); -}); \ No newline at end of file +}); From c5819371cb40eca6d2feb39c8bfdfffbe9fab816 Mon Sep 17 00:00:00 2001 From: allgandaf Date: Tue, 2 Dec 2025 17:10:44 +0530 Subject: [PATCH 08/12] fix typefailure --- tests/unit/ReportNameUtilsTest.ts | 140 +++++++++++++++++++++++++----- 1 file changed, 117 insertions(+), 23 deletions(-) diff --git a/tests/unit/ReportNameUtilsTest.ts b/tests/unit/ReportNameUtilsTest.ts index ec43d40c2bd6c..855d6d6f8c91a 100644 --- a/tests/unit/ReportNameUtilsTest.ts +++ b/tests/unit/ReportNameUtilsTest.ts @@ -7,6 +7,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import type {PersonalDetailsList, Policy, Report, ReportAction, ReportActions, ReportAttributesDerivedValue, ReportNameValuePairs} from '@src/types/onyx'; import {createAdminRoom, createPolicyExpenseChat, createRegularChat, createRegularTaskReport, createSelfDM, createWorkspaceThread} from '../utils/collections/reports'; import {fakePersonalDetails} from '../utils/LHNTestUtils'; +import {formatPhoneNumber} from '../utils/TestHelper'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; describe('ReportNameUtils', () => { @@ -73,7 +74,16 @@ describe('ReportNameUtils', () => { ownerAccountID: currentUserAccountID, }; - const name = computeReportName(report, emptyCollections.reports, emptyCollections.policies, undefined, undefined, participantsPersonalDetails, emptyCollections.reportActions); + const name = computeReportName( + formatPhoneNumber, + report, + emptyCollections.reports, + emptyCollections.policies, + undefined, + undefined, + participantsPersonalDetails, + emptyCollections.reportActions, + ); expect(name).toBe('Ragnar Lothbrok'); }); @@ -83,7 +93,16 @@ describe('ReportNameUtils', () => { ownerAccountID: currentUserAccountID, }; - const name = computeReportName(report, emptyCollections.reports, emptyCollections.policies, undefined, undefined, participantsPersonalDetails, emptyCollections.reportActions); + const name = computeReportName( + formatPhoneNumber, + report, + emptyCollections.reports, + emptyCollections.policies, + undefined, + undefined, + participantsPersonalDetails, + emptyCollections.reportActions, + ); expect(name).toBe('floki@vikings.net'); }); @@ -93,7 +112,16 @@ describe('ReportNameUtils', () => { ownerAccountID: currentUserAccountID, }; - const name = computeReportName(report, emptyCollections.reports, emptyCollections.policies, undefined, undefined, participantsPersonalDetails, emptyCollections.reportActions); + const name = computeReportName( + formatPhoneNumber, + report, + emptyCollections.reports, + emptyCollections.policies, + undefined, + undefined, + participantsPersonalDetails, + emptyCollections.reportActions, + ); expect(name).toBe('(833) 240-3627'); }); @@ -105,7 +133,16 @@ describe('ReportNameUtils', () => { }; await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, participantsPersonalDetails); - const name = computeReportName(report, emptyCollections.reports, emptyCollections.policies, undefined, undefined, participantsPersonalDetails, emptyCollections.reportActions); + const name = computeReportName( + formatPhoneNumber, + report, + emptyCollections.reports, + emptyCollections.policies, + undefined, + undefined, + participantsPersonalDetails, + emptyCollections.reportActions, + ); expect(name).toBe('Ragnar, floki@vikings.net, Lagertha, (833) 240-3627'); }); }); @@ -113,7 +150,16 @@ describe('ReportNameUtils', () => { describe('computeReportName - Admin room', () => { test('Active admin room', () => { const report = createAdminRoom(10); - const name = computeReportName(report, emptyCollections.reports, emptyCollections.policies, undefined, undefined, participantsPersonalDetails, emptyCollections.reportActions); + const name = computeReportName( + formatPhoneNumber, + report, + emptyCollections.reports, + emptyCollections.policies, + undefined, + undefined, + participantsPersonalDetails, + emptyCollections.reportActions, + ); expect(name).toBe('#admins'); }); @@ -124,6 +170,7 @@ describe('ReportNameUtils', () => { } as Record; const nameEn = computeReportName( + formatPhoneNumber, report, emptyCollections.reports, emptyCollections.policies, @@ -136,6 +183,7 @@ describe('ReportNameUtils', () => { await IntlStore.load(CONST.LOCALES.ES); const nameEs = computeReportName( + formatPhoneNumber, report, emptyCollections.reports, emptyCollections.policies, @@ -158,7 +206,16 @@ describe('ReportNameUtils', () => { }; await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, participantsPersonalDetails); - const name = computeReportName(report, emptyCollections.reports, emptyCollections.policies, undefined, undefined, participantsPersonalDetails, emptyCollections.reportActions); + const name = computeReportName( + formatPhoneNumber, + report, + emptyCollections.reports, + emptyCollections.policies, + undefined, + undefined, + participantsPersonalDetails, + emptyCollections.reportActions, + ); expect(name).toBe("Ragnar Lothbrok's expenses"); }); }); @@ -171,7 +228,16 @@ describe('ReportNameUtils', () => { }; await Onyx.merge(ONYXKEYS.SESSION, {accountID: currentUserAccountID, email: 'lagertha2@vikings.net', authTokenType: CONST.AUTH_TOKEN_TYPES.SUPPORT}); - const name = computeReportName(report, emptyCollections.reports, emptyCollections.policies, undefined, undefined, participantsPersonalDetails, emptyCollections.reportActions); + const name = computeReportName( + formatPhoneNumber, + report, + emptyCollections.reports, + emptyCollections.policies, + undefined, + undefined, + participantsPersonalDetails, + emptyCollections.reportActions, + ); expect(name).toBe('Lagertha Lothbrok (you)'); }); }); @@ -184,7 +250,16 @@ describe('ReportNameUtils', () => { reportName: htmlTaskTitle, }; - const name = computeReportName(report, emptyCollections.reports, emptyCollections.policies, undefined, undefined, participantsPersonalDetails, emptyCollections.reportActions); + const name = computeReportName( + formatPhoneNumber, + report, + emptyCollections.reports, + emptyCollections.policies, + undefined, + undefined, + participantsPersonalDetails, + emptyCollections.reportActions, + ); expect(name).toBe('heading with link'); }); }); @@ -217,7 +292,16 @@ describe('ReportNameUtils', () => { }; const expected = translate(CONST.LOCALES.EN, 'iou.submitted', {memo: 'via workflow'}); - const name = computeReportName(thread, emptyCollections.reports, emptyCollections.policies, undefined, undefined, participantsPersonalDetails, reportActionsCollection); + const name = computeReportName( + formatPhoneNumber, + thread, + emptyCollections.reports, + emptyCollections.policies, + undefined, + undefined, + participantsPersonalDetails, + reportActionsCollection, + ); expect(name).toBe(expected); }); @@ -245,7 +329,16 @@ describe('ReportNameUtils', () => { }; const expected = translate(CONST.LOCALES.EN, 'iou.rejectedThisReport'); - const name = computeReportName(thread, emptyCollections.reports, emptyCollections.policies, undefined, undefined, participantsPersonalDetails, reportActionsCollection); + const name = computeReportName( + formatPhoneNumber, + thread, + emptyCollections.reports, + emptyCollections.policies, + undefined, + undefined, + participantsPersonalDetails, + reportActionsCollection, + ); expect(name).toBe(expected); }); }); @@ -307,6 +400,7 @@ describe('ReportNameUtils', () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, participantsPersonalDetails); const name = computeReportName( + formatPhoneNumber, report, emptyCollections.reports, emptyCollections.policies, @@ -326,7 +420,7 @@ describe('ReportNameUtils', () => { reportName: 'Fallback Report Name', } as unknown as Report; - const name = getPolicyExpenseChatName({report, personalDetailsList: participantsPersonalDetails}); + const name = getPolicyExpenseChatName({formatPhoneNumber, report, personalDetailsList: participantsPersonalDetails}); expect(name).toBe(translate(CONST.LOCALES.EN, 'workspace.common.policyExpenseChatName', {displayName: 'Ragnar Lothbrok'})); }); @@ -336,7 +430,7 @@ describe('ReportNameUtils', () => { reportName: 'Fallback Report Name', } as unknown as Report; - const name = getPolicyExpenseChatName({report, personalDetailsList: participantsPersonalDetails}); + const name = getPolicyExpenseChatName({formatPhoneNumber, report, personalDetailsList: participantsPersonalDetails}); expect(name).toBe(translate(CONST.LOCALES.EN, 'workspace.common.policyExpenseChatName', {displayName: 'floki'})); }); @@ -346,7 +440,7 @@ describe('ReportNameUtils', () => { reportName: 'Fallback Report Name', } as unknown as Report; - const name = getPolicyExpenseChatName({report, personalDetailsList: {}}); + const name = getPolicyExpenseChatName({formatPhoneNumber, report, personalDetailsList: {}}); expect(name).toBe('Fallback Report Name'); }); }); @@ -375,27 +469,27 @@ describe('ReportNameUtils', () => { describe('When participantAccountIDs is passed to getGroupChatName', () => { it('shows all participants when count <= 5 and shouldApplyLimit is false', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(fourParticipants)).toEqual('Four, One, Three, Two'); + expect(getGroupChatName(formatPhoneNumber, fourParticipants)).toEqual('Four, One, Three, Two'); }); it('shows all participants when count <= 5 and shouldApplyLimit is true', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(fourParticipants, true)).toEqual('Four, One, Three, Two'); + expect(getGroupChatName(formatPhoneNumber, fourParticipants, true)).toEqual('Four, One, Three, Two'); }); it('shows 5 participants with ellipsis when count > 5 and shouldApplyLimit is true', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(eightParticipants, true)).toEqual('Five, Four, One, Three, Two...'); + expect(getGroupChatName(formatPhoneNumber, eightParticipants, true)).toEqual('Five, Four, One, Three, Two...'); }); it('shows all participants when count > 5 and shouldApplyLimit is false', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(eightParticipants, false)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); + expect(getGroupChatName(formatPhoneNumber, eightParticipants, false)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); }); it('uses correct display names for participants', async () => { await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, participantsPersonalDetails); - expect(getGroupChatName(fourParticipants, true)).toEqual('(833) 240-3627, floki@vikings.net, Lagertha, Ragnar'); + expect(getGroupChatName(formatPhoneNumber, fourParticipants, true)).toEqual('(833) 240-3627, floki@vikings.net, Lagertha, Ragnar'); }); }); @@ -408,7 +502,7 @@ describe('ReportNameUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(undefined, false, report)).toEqual("Let's talk"); + expect(getGroupChatName(formatPhoneNumber, undefined, false, report)).toEqual("Let's talk"); }); it('uses report name when available (limit true)', async () => { @@ -419,7 +513,7 @@ describe('ReportNameUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(undefined, true, report)).toEqual("Let's talk"); + expect(getGroupChatName(formatPhoneNumber, undefined, true, report)).toEqual("Let's talk"); }); it('uses report name when >5 participants and limit true', async () => { @@ -430,7 +524,7 @@ describe('ReportNameUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(undefined, true, report)).toEqual("Let's talk"); + expect(getGroupChatName(formatPhoneNumber, undefined, true, report)).toEqual("Let's talk"); }); it('uses report name when >5 participants and limit false', async () => { @@ -441,7 +535,7 @@ describe('ReportNameUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(undefined, false, report)).toEqual("Let's talk"); + expect(getGroupChatName(formatPhoneNumber, undefined, false, report)).toEqual("Let's talk"); }); it('falls back to participant names when report name is empty', async () => { @@ -452,7 +546,7 @@ describe('ReportNameUtils', () => { }; await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report); await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails); - expect(getGroupChatName(undefined, false, report)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); + expect(getGroupChatName(formatPhoneNumber, undefined, false, report)).toEqual('Eight, Five, Four, One, Seven, Six, Three, Two'); }); }); }); From 4812a189eb0c3bd0ad6d539850003d6565fbc914 Mon Sep 17 00:00:00 2001 From: allgandaf Date: Tue, 2 Dec 2025 22:56:49 +0530 Subject: [PATCH 09/12] fix typecheck --- src/libs/actions/OnyxDerived/configs/reportAttributes.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/OnyxDerived/configs/reportAttributes.ts b/src/libs/actions/OnyxDerived/configs/reportAttributes.ts index 9dfc6262c7c8a..8d22a6de1432f 100644 --- a/src/libs/actions/OnyxDerived/configs/reportAttributes.ts +++ b/src/libs/actions/OnyxDerived/configs/reportAttributes.ts @@ -1,4 +1,5 @@ import type {OnyxEntry} from 'react-native-onyx'; +import {formatPhoneNumberWithCountryCode} from '@libs/LocalePhoneNumber'; import {computeReportName} from '@libs/ReportNameUtils'; import {generateIsEmptyReport, generateReportAttributes, isArchivedReport, isValidReport} from '@libs/ReportUtils'; import SidebarUtils from '@libs/SidebarUtils'; @@ -70,9 +71,10 @@ export default createOnyxDerivedValueConfig({ ONYXKEYS.PERSONAL_DETAILS_LIST, ONYXKEYS.COLLECTION.POLICY, ONYXKEYS.COLLECTION.REPORT_METADATA, + ONYXKEYS.COUNTRY_CODE, ], compute: ( - [reports, preferredLocale, transactionViolations, reportActions, reportNameValuePairs, transactions, personalDetails, policies], + [reports, preferredLocale, transactionViolations, reportActions, reportNameValuePairs, transactions, personalDetails, policies, reportMetadata, countryCode], {currentValue, sourceValues, areAllConnectionsSet}, ) => { if (!areAllConnectionsSet) { @@ -82,6 +84,8 @@ export default createOnyxDerivedValueConfig({ }; } + const formatPhoneNumber = (phoneNumber: string) => formatPhoneNumberWithCountryCode(phoneNumber, countryCode ?? 1); + // Check if display names changed when personal details are updated let displayNamesChanged = false; if (hasKeyTriggeredCompute(ONYXKEYS.PERSONAL_DETAILS_LIST, sourceValues)) { @@ -204,7 +208,7 @@ export default createOnyxDerivedValueConfig({ } acc[report.reportID] = { - reportName: report ? computeReportName(report, reports, policies, transactions, reportNameValuePairs, personalDetails, reportActions) : '', + reportName: report ? computeReportName(formatPhoneNumber, report, reports, policies, transactions, reportNameValuePairs, personalDetails, reportActions) : '', isEmpty: generateIsEmptyReport(report, isReportArchived), brickRoadStatus, requiresAttention, From 6dbe9c82f4191e12e8bb60e1819aa8e35949d2dc Mon Sep 17 00:00:00 2001 From: allgandaf Date: Wed, 3 Dec 2025 14:03:06 +0530 Subject: [PATCH 10/12] fix: add missing argument to reportAttributes compute --- tests/unit/OnyxDerivedTest.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/OnyxDerivedTest.tsx b/tests/unit/OnyxDerivedTest.tsx index a7b948e999d2f..28db98115185f 100644 --- a/tests/unit/OnyxDerivedTest.tsx +++ b/tests/unit/OnyxDerivedTest.tsx @@ -129,8 +129,8 @@ describe('OnyxDerived', () => { const transaction = createRandomTransaction(1); // When the report attributes are recomputed with both report and transaction updates - reportAttributes.compute([reports, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined], {areAllConnectionsSet: true}); - const reportAttributesComputedValue = reportAttributes.compute([reports, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined], { + reportAttributes.compute([reports, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined], {areAllConnectionsSet: true}); + const reportAttributesComputedValue = reportAttributes.compute([reports, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined], { sourceValues: { [ONYXKEYS.COLLECTION.REPORT]: { [`${ONYXKEYS.COLLECTION.REPORT}${reportID1}`]: reports[`${ONYXKEYS.COLLECTION.REPORT}${reportID1}`], From 5ee53788e54c7b7950fe92a38ac2eec8b59398fb Mon Sep 17 00:00:00 2001 From: allgandaf Date: Wed, 3 Dec 2025 14:39:43 +0530 Subject: [PATCH 11/12] fix --- src/libs/actions/OnyxDerived/configs/reportAttributes.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/OnyxDerived/configs/reportAttributes.ts b/src/libs/actions/OnyxDerived/configs/reportAttributes.ts index 8d22a6de1432f..784f0a6a4f2d0 100644 --- a/src/libs/actions/OnyxDerived/configs/reportAttributes.ts +++ b/src/libs/actions/OnyxDerived/configs/reportAttributes.ts @@ -63,7 +63,8 @@ export default createOnyxDerivedValueConfig({ key: ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, dependencies: [ ONYXKEYS.COLLECTION.REPORT, - ONYXKEYS.NVP_PREFERRED_LOCALE, + ONYXKEYS.NVP_PREFERRED_LOCALE, + ONYXKEYS.COUNTRY_CODE, ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, ONYXKEYS.COLLECTION.REPORT_ACTIONS, ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS, @@ -71,10 +72,10 @@ export default createOnyxDerivedValueConfig({ ONYXKEYS.PERSONAL_DETAILS_LIST, ONYXKEYS.COLLECTION.POLICY, ONYXKEYS.COLLECTION.REPORT_METADATA, - ONYXKEYS.COUNTRY_CODE, + ], compute: ( - [reports, preferredLocale, transactionViolations, reportActions, reportNameValuePairs, transactions, personalDetails, policies, reportMetadata, countryCode], + [reports, preferredLocale, countryCode, transactionViolations, reportActions, reportNameValuePairs, transactions, personalDetails, policies], {currentValue, sourceValues, areAllConnectionsSet}, ) => { if (!areAllConnectionsSet) { From 04ee1fb210aa99d20106a334631d2ed4123c60f4 Mon Sep 17 00:00:00 2001 From: allgandaf Date: Wed, 3 Dec 2025 14:40:33 +0530 Subject: [PATCH 12/12] fix prettier --- src/libs/actions/OnyxDerived/configs/reportAttributes.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/actions/OnyxDerived/configs/reportAttributes.ts b/src/libs/actions/OnyxDerived/configs/reportAttributes.ts index 784f0a6a4f2d0..be921f5a07710 100644 --- a/src/libs/actions/OnyxDerived/configs/reportAttributes.ts +++ b/src/libs/actions/OnyxDerived/configs/reportAttributes.ts @@ -63,7 +63,7 @@ export default createOnyxDerivedValueConfig({ key: ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, dependencies: [ ONYXKEYS.COLLECTION.REPORT, - ONYXKEYS.NVP_PREFERRED_LOCALE, + ONYXKEYS.NVP_PREFERRED_LOCALE, ONYXKEYS.COUNTRY_CODE, ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, ONYXKEYS.COLLECTION.REPORT_ACTIONS, @@ -72,7 +72,6 @@ export default createOnyxDerivedValueConfig({ ONYXKEYS.PERSONAL_DETAILS_LIST, ONYXKEYS.COLLECTION.POLICY, ONYXKEYS.COLLECTION.REPORT_METADATA, - ], compute: ( [reports, preferredLocale, countryCode, transactionViolations, reportActions, reportNameValuePairs, transactions, personalDetails, policies],