Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2bafa07
fix getEffectiveDisplayName
allgandalf Jul 23, 2025
2ef9333
Update tests/unit/libs/PersonalDetailsUtilsTest.ts
allgandalf Jul 23, 2025
c757a14
Update tests/unit/libs/PersonalDetailsUtilsTest.ts
allgandalf Jul 23, 2025
62e2c54
Merge branch 'Expensify:main' into fixgetEffectiveDisplayName
allgandalf Jul 23, 2025
66557b9
Merge branch 'Expensify:main' into fixgetEffectiveDisplayName
allgandalf Jul 23, 2025
e1e5367
remove unwanted import
allgandalf Jul 23, 2025
8e629c5
fix getEffectiveDisplayName
allgandalf Jul 23, 2025
9960554
Update tests/unit/libs/PersonalDetailsUtilsTest.ts
allgandalf Jul 23, 2025
b76bc9f
Update tests/unit/libs/PersonalDetailsUtilsTest.ts
allgandalf Jul 23, 2025
c6a74ec
feat: 65634 Reduce amount of items perg page
MrMuzyk Jul 16, 2025
9821e7d
fix: add comment
MrMuzyk Jul 18, 2025
060315d
fix: search cases
MrMuzyk Jul 21, 2025
5c47c1a
fix: go back to ceil
MrMuzyk Jul 22, 2025
c46ea82
feat: More tests for BaseSelectionList
MrMuzyk Jul 22, 2025
429b2a4
Add word to cspell
mountiny Jul 23, 2025
553285d
remove unwanted import
allgandalf Jul 23, 2025
59bd52d
Merge branch 'fixgetEffectiveDisplayName' of https://github.com/allga…
allgandalf Jul 24, 2025
cc2726b
fix prettier
allgandalf Jul 24, 2025
4b0b3b6
Merge branch 'Expensify:main' into fixgetEffectiveDisplayName
allgandalf Jul 24, 2025
5eb09cf
fix lint
allgandalf Jul 24, 2025
db958fd
Merge branch 'main' into fixgetEffectiveDisplayName
allgandalf Jul 30, 2025
57d810a
format unit test
allgandalf Jul 30, 2025
e446f57
Update tests/unit/libs/PersonalDetailsUtilsTest.ts
allgandalf Jul 30, 2025
34c1870
fix prettier
allgandalf Jul 30, 2025
fba8021
fix failing test
allgandalf Jul 30, 2025
192b2a6
Apply suggestion from @shubham1206agra
allgandalf Jul 30, 2025
97e6b33
fix unit test
allgandalf Jul 30, 2025
f70aebe
Merge branch 'Expensify:main' into fixgetEffectiveDisplayName
allgandalf Jul 30, 2025
19cb378
Merge branch 'Expensify:main' into fixgetEffectiveDisplayName
allgandalf Jul 30, 2025
19e387b
Merge branch 'Expensify:main' into fixgetEffectiveDisplayName
allgandalf Jul 31, 2025
0e6cdcb
Merge branch 'Expensify:main' into fixgetEffectiveDisplayName
allgandalf Jul 31, 2025
14f67b1
Merge branch 'Expensify:main' into fixgetEffectiveDisplayName
allgandalf Jul 31, 2025
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
4 changes: 2 additions & 2 deletions src/libs/PersonalDetailsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
let personalDetails: Array<PersonalDetails | null> = [];
let allPersonalDetails: OnyxEntry<PersonalDetailsList> = {};
let emailToPersonalDetailsCache: Record<string, PersonalDetails> = {};
Onyx.connect({

Check warning on line 25 in src/libs/PersonalDetailsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (val) => {
personalDetails = Object.values(val ?? {});
Expand All @@ -39,7 +39,7 @@
let hiddenTranslation = '';
let youTranslation = '';

Onyx.connect({

Check warning on line 42 in src/libs/PersonalDetailsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.ARE_TRANSLATIONS_LOADING,
initWithStoredValues: false,
callback: (value) => {
Expand All @@ -53,7 +53,7 @@

let defaultCountry = '';

Onyx.connect({

Check warning on line 56 in src/libs/PersonalDetailsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COUNTRY,
callback: (value) => {
if (!value) {
Expand Down Expand Up @@ -328,9 +328,9 @@
* @param personalDetail - details object
* @returns - The effective display name
*/
function getEffectiveDisplayName(personalDetail?: PersonalDetails): string | undefined {
function getEffectiveDisplayName(formatPhoneNumber: LocaleContextProps['formatPhoneNumber'], personalDetail?: PersonalDetails): string | undefined {
if (personalDetail) {
return formatPhoneNumberUtils(personalDetail?.login ?? '') || personalDetail.displayName;
return formatPhoneNumber(personalDetail?.login ?? '') || personalDetail.displayName;
}

return undefined;
Expand Down
4 changes: 2 additions & 2 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
type MemberChangeMessageElement = MessageTextElement | MemberChangeMessageUserMentionElement | MemberChangeMessageRoomReferenceElement;

let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 60 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand All @@ -69,7 +69,7 @@
});

let allReports: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 72 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -78,14 +78,14 @@
});

let isNetworkOffline = false;
Onyx.connect({

Check warning on line 81 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NETWORK,
callback: (val) => (isNetworkOffline = val?.isOffline ?? false),
});

let currentUserAccountID: number | undefined;
let currentEmail = '';
Onyx.connect({

Check warning on line 88 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, value is undefined
Expand All @@ -99,7 +99,7 @@
});

let privatePersonalDetails: PrivatePersonalDetails | undefined;
Onyx.connect({

Check warning on line 102 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PRIVATE_PERSONAL_DETAILS,
callback: (personalDetails) => {
privatePersonalDetails = personalDetails;
Expand Down Expand Up @@ -1424,7 +1424,7 @@

const mentionElements = targetAccountIDs.map((accountID): MemberChangeMessageUserMentionElement => {
const personalDetail = personalDetails.find((personal) => personal.accountID === accountID);
const handleText = getEffectiveDisplayName(personalDetail) ?? translateLocal('common.hidden');
const handleText = getEffectiveDisplayName(formatPhoneNumber, personalDetail) ?? translateLocal('common.hidden');

return {
kind: 'userMention',
Expand Down Expand Up @@ -1888,7 +1888,7 @@
const personalDetails = getPersonalDetailsByIDs({accountIDs: targetAccountIDs, currentUserAccountID: 0});
const mentionElements = targetAccountIDs.map((accountID): string => {
const personalDetail = personalDetails.find((personal) => personal.accountID === accountID);
const displayName = getEffectiveDisplayName(personalDetail);
const displayName = getEffectiveDisplayName(formatPhoneNumber, personalDetail);
const handleText = isEmpty(displayName) ? translateLocal('common.hidden') : displayName;
return `<mention-user accountID=${accountID}>@${handleText}</mention-user>`;
});
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@
const parsedReportActionMessageCache: Record<string, string> = {};

let conciergeReportID: OnyxEntry<string>;
Onyx.connect({

Check warning on line 901 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.CONCIERGE_REPORT_ID,
callback: (value) => {
conciergeReportID = value;
Expand All @@ -906,7 +906,7 @@
});

const defaultAvatarBuildingIconTestID = 'SvgDefaultAvatarBuilding Icon';
Onyx.connect({

Check warning on line 909 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, val is undefined
Expand Down Expand Up @@ -4818,7 +4818,7 @@
const personalDetails = getPersonalDetailsByIDs({accountIDs: originalMessage?.targetAccountIDs ?? [], currentUserAccountID: 0});

const participants = personalDetails.map((personalDetail) => {
const name = getEffectiveDisplayName(personalDetail);
const name = getEffectiveDisplayName(formatPhoneNumber, personalDetail);
if (name && name?.length > 0) {
return name;
}
Expand Down
91 changes: 90 additions & 1 deletion tests/unit/libs/PersonalDetailsUtilsTest.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,98 @@
import Onyx from 'react-native-onyx';
import {getPersonalDetailsOnyxDataForOptimisticUsers} from '@libs/PersonalDetailsUtils';
import {getEffectiveDisplayName, getPersonalDetailsOnyxDataForOptimisticUsers} from '@libs/PersonalDetailsUtils';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PersonalDetails} from '@src/types/onyx';
import {formatPhoneNumber} from '../../utils/TestHelper';

describe('PersonalDetailsUtils', () => {
describe('getEffectiveDisplayName', () => {
test('should return undefined when personalDetail is undefined', () => {
const result = getEffectiveDisplayName(formatPhoneNumber, undefined);
expect(result).toBeUndefined();
});

test('should return undefined when personalDetail has neither login nor displayName', () => {
const personalDetail: PersonalDetails = {accountID: 123};
const result = getEffectiveDisplayName(formatPhoneNumber, personalDetail);
expect(result).toBeUndefined();
});

test('should return displayName when login is empty or null but displayName exists', () => {
const personalDetail1: PersonalDetails = {accountID: 123, displayName: 'John Doe', login: ''};
const personalDetail2: PersonalDetails = {accountID: 456, displayName: 'Jane Smith', login: null as unknown as string}; // Simulate null login

let result = getEffectiveDisplayName(formatPhoneNumber, personalDetail1);
expect(result).toBe('John Doe');

result = getEffectiveDisplayName(formatPhoneNumber, personalDetail2);
expect(result).toBe('Jane Smith');
});

test('should return login (email) when only login exists (not a phone number)', () => {
const personalDetail: PersonalDetails = {accountID: 123, login: 'john.doe@example.com'};
const result = getEffectiveDisplayName(formatPhoneNumber, personalDetail);
expect(result).toBe('john.doe@example.com');
});

test('should return national format for phone login if from the same region (US)', () => {
const personalDetail: PersonalDetails = {accountID: 123, login: '+15551234567'};
const result = getEffectiveDisplayName(formatPhoneNumber, personalDetail);
expect(result).toBe('+1 555-123-4567');
});

test('should return international format for phone login if from a different region (GB)', () => {
const personalDetail: PersonalDetails = {accountID: 123, login: '+442079460000'};
const result = getEffectiveDisplayName(formatPhoneNumber, personalDetail);
expect(result).toBe('+44 20 7946 0000');
});

test('should return formatted login (email) when both login and displayName exist (login takes precedence)', () => {
const personalDetail: PersonalDetails = {
accountID: 123,
login: 'john.doe@example.com',
displayName: 'John Doe Full Name',
};
const result = getEffectiveDisplayName(formatPhoneNumber, personalDetail);
expect(result).toBe('john.doe@example.com');
});

test('should return formatted login (phone) when both login (same region) and displayName exist', () => {
const personalDetail: PersonalDetails = {
accountID: 123,
login: '+15551234567',
displayName: 'John Doe Full Name',
};
const result = getEffectiveDisplayName(formatPhoneNumber, personalDetail);
expect(result).toBe('+1 555-123-4567');
});

test('should return formatted login (phone) when both login (different region) and displayName exist', () => {
const personalDetail: PersonalDetails = {
accountID: 123,
login: '+442079460000',
displayName: 'Jane Smith Full Name',
};
const result = getEffectiveDisplayName(formatPhoneNumber, personalDetail);
expect(result).toBe('+44 20 7946 0000');
});

test('should correctly handle login with SMS domain', () => {
const personalDetail: PersonalDetails = {
accountID: 123,
login: `+18005550000`,
displayName: 'SMS User',
};
const result = getEffectiveDisplayName(formatPhoneNumber, personalDetail);
expect(result).toBe('(800) 555-0000');
});

test('should fall back to displayName if formatted login is an empty string and displayName exists', () => {
const personalDetail: PersonalDetails = {accountID: 123, login: '', displayName: 'Fallback Name'};
const result = getEffectiveDisplayName(formatPhoneNumber, personalDetail);
expect(result).toBe('Fallback Name');
});
});

describe('getPersonalDetailsOnyxDataForOptimisticUsers', () => {
test('should return correct optimistic and finally data', () => {
const newLogins = ['3322076524', 'test2@test.com', '+14185438090'];
Expand Down
Loading