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
5 changes: 2 additions & 3 deletions src/components/AvatarWithDisplayName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function AvatarWithDisplayName({
parentNavigationSubtitleTextStyles,
parentNavigationStatusContainerStyles = {},
}: AvatarWithDisplayNameProps) {
const {localeCompare, formatPhoneNumber} = useLocalize();
const {localeCompare, formatPhoneNumber, translate} = useLocalize();
const {accountID: currentUserAccountID} = useCurrentUserPersonalDetails();
const [parentReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report?.parentReportID}`);
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST) ?? CONST.EMPTY_OBJECT;
Expand All @@ -200,7 +200,6 @@ function AvatarWithDisplayName({
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {translate} = useLocalize();
// We need to use isSmallScreenWidth instead of shouldUseNarrowLayout to display the edit button only on large screens
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
const {isSmallScreenWidth} = useResponsiveLayout();
Expand All @@ -214,7 +213,7 @@ function AvatarWithDisplayName({
const parentNavigationSubtitleData = getParentNavigationSubtitle(report, policy, conciergeReportID, translate, derivedParentReportName, isParentReportArchived);
const isMoneyRequestOrReport = isMoneyRequestReport(report) || isMoneyRequest(report) || isTrackExpenseReport(report) || isInvoiceReport(report);
const ownerPersonalDetails = getPersonalDetailsForAccountIDs(report?.ownerAccountID ? [report.ownerAccountID] : [], personalDetails);
const displayNamesWithTooltips = getDisplayNamesWithTooltips(Object.values(ownerPersonalDetails), false, localeCompare, formatPhoneNumber);
const displayNamesWithTooltips = getDisplayNamesWithTooltips(Object.values(ownerPersonalDetails), false, localeCompare, formatPhoneNumber, translate);
const avatarBorderColor = avatarBorderColorProp ?? (isAnonymous ? theme.highlightBG : theme.componentBG);
const statusText = shouldDisplayStatus ? getReportStatusTranslation({stateNum: report?.stateNum, statusNum: report?.statusNum, translate}) : undefined;
const statusTooltipText = shouldDisplayStatus ? getReportStatusTooltipTranslation({stateNum: report?.stateNum, statusNum: report?.statusNum, translate}) : undefined;
Expand Down
1 change: 1 addition & 0 deletions src/components/OptionRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ function OptionRow({
shouldUseShortFormInTooltip,
localeCompare,
formatPhoneNumber,
translate,
);
let subscriptColor = theme.appBG;
if (optionIsFocused) {
Expand Down
1 change: 1 addition & 0 deletions src/components/ReportActionItem/TaskView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ function TaskView({report, parentReport, action}: TaskViewProps) {
false,
localeCompare,
formatPhoneNumber,
translate,
);

const isOpen = isOpenTaskReport(report);
Expand Down
7 changes: 4 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4109,6 +4109,7 @@ function getDisplayNamesWithTooltips(
shouldUseShortForm: boolean,
localeCompare: LocaleContextProps['localeCompare'],
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'],
translate: LocaleContextProps['translate'],
shouldFallbackToHidden = true,
shouldAddCurrentUserPostfix = false,
): DisplayNameWithTooltips {
Expand All @@ -4119,7 +4120,7 @@ function getDisplayNamesWithTooltips(
const accountID = Number(user?.accountID);

const displayName =
getDisplayNameForParticipant({accountID, shouldUseShortForm, shouldFallbackToHidden, shouldAddCurrentUserPostfix, formatPhoneNumber}) ||
getDisplayNameForParticipant({accountID, shouldUseShortForm, shouldFallbackToHidden, shouldAddCurrentUserPostfix, formatPhoneNumber, translate}) ||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
user?.login ||
'';
Expand All @@ -4128,7 +4129,7 @@ function getDisplayNamesWithTooltips(
let pronouns = user?.pronouns ?? undefined;
if (pronouns?.startsWith(CONST.PRONOUNS.PREFIX)) {
const pronounTranslationKey = pronouns.replace(CONST.PRONOUNS.PREFIX, '');
pronouns = translateLocal(`pronouns.${pronounTranslationKey}` as TranslationPaths);
pronouns = translate(`pronouns.${pronounTranslationKey}` as TranslationPaths);
}

return {
Expand Down Expand Up @@ -5779,7 +5780,7 @@ function getReportPreviewMessage(translate: LocalizedTranslate, params: GetRepor
const {totalDisplaySpend: totalAmount} = getMoneyRequestSpendBreakdown(report);

const parentReport = getParentReport(report);
const policyName = getPolicyName({report: parentReport ?? report, policy});
const policyName = getPolicyName({report: parentReport ?? report, policy, unavailableTranslation: translate('workspace.common.unavailable')});
const payerName = isExpenseReport(report)
? policyName
: getDisplayNameForParticipant({accountID: report.managerID, shouldUseShortForm: !isPreviewMessageForParentChatReport, formatPhoneNumber: formatPhoneNumberPhoneUtils, translate});
Expand Down
3 changes: 2 additions & 1 deletion src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,7 @@ function getOptionData({
hasMultipleParticipants,
localeCompare,
formatPhoneNumberPhoneUtils,
translate,
undefined,
isSelfDM(report),
);
Expand Down Expand Up @@ -1475,7 +1476,7 @@ function getWelcomeMessage(params: WelcomeMessageParams): WelcomeMessage {
return welcomeMessage;
}
const isMultipleParticipant = participantPersonalDetailList.length > 1;
const displayNamesWithTooltips = getDisplayNamesWithTooltips(participantPersonalDetailList, isMultipleParticipant, localeCompare, formatPhoneNumberPhoneUtils);
const displayNamesWithTooltips = getDisplayNamesWithTooltips(participantPersonalDetailList, isMultipleParticipant, localeCompare, formatPhoneNumberPhoneUtils, translate);

if (!displayNamesWithTooltips.length) {
return welcomeMessage;
Expand Down
1 change: 1 addition & 0 deletions src/libs/actions/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,7 @@ function getShareDestination(
isMultipleParticipant,
localeCompare,
LocalePhoneNumber.formatPhoneNumber,
translate,
);

let subtitle = '';
Expand Down
2 changes: 1 addition & 1 deletion src/pages/inbox/HeaderView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ function HeaderView({onNavigationMenuButtonClicked, reportID}: HeaderViewProps)
const [isParticipantOptimistic = true] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {selector: isOptimisticPersonalDetailSelector(firstParticipantAccountID)});

const participantPersonalDetails = getPersonalDetailsForAccountIDs(participants, personalDetails);
const displayNamesWithTooltips = getDisplayNamesWithTooltips(participantPersonalDetails, isMultipleParticipant, localeCompare, formatPhoneNumber, undefined, isSelfDM);
const displayNamesWithTooltips = getDisplayNamesWithTooltips(participantPersonalDetails, isMultipleParticipant, localeCompare, formatPhoneNumber, translate, undefined, isSelfDM);

const isChatThread = isChatThreadReportUtils(report);
const isChatRoom = isChatRoomReportUtils(report);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/inbox/report/WhisperBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function WhisperBanner({whisperedTo}: WhisperBannerProps) {
const whisperedToPersonalDetails = Object.values(personalDetails ?? {}).filter((details) =>
whisperedTo.includes(details?.accountID ?? CONST.DEFAULT_NUMBER_ID),
) as OnyxTypes.PersonalDetails[];
const displayNamesWithTooltips = getDisplayNamesWithTooltips(whisperedToPersonalDetails, isMultipleParticipant, localeCompare, formatPhoneNumber);
const displayNamesWithTooltips = getDisplayNamesWithTooltips(whisperedToPersonalDetails, isMultipleParticipant, localeCompare, formatPhoneNumber, translate);

return (
<View style={[styles.flexRow, styles.pl5, styles.pt2, styles.pr3]}>
Expand Down
1 change: 1 addition & 0 deletions src/pages/tasks/DynamicNewTaskPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function DynamicNewTaskPage() {
false,
localeCompare,
formatPhoneNumber,
translate,
);
const shareDestination = task?.shareDestination ? getShareDestination(parentReport, personalDetails, localeCompare, policy, conciergeReportID, translate, reportAttributes) : undefined;
const ancestors = useAncestors(parentReport);
Expand Down
2 changes: 1 addition & 1 deletion tests/perf-test/ReportUtils.perf-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ describe('ReportUtils', () => {
const shouldFallbackToHidden = true;

await waitForBatchedUpdates();
await measureFunction(() => getDisplayNamesWithTooltips(personalDetails, isMultipleParticipantReport, localeCompare, formatPhoneNumber, shouldFallbackToHidden));
await measureFunction(() => getDisplayNamesWithTooltips(personalDetails, isMultipleParticipantReport, localeCompare, formatPhoneNumber, translateLocal, shouldFallbackToHidden));
});

test('[ReportUtils] getReportPreviewMessage on 1k policies', async () => {
Expand Down
56 changes: 54 additions & 2 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,7 @@ describe('ReportUtils', () => {

describe('getDisplayNamesWithTooltips', () => {
test('withSingleParticipantReport', () => {
const participants = getDisplayNamesWithTooltips(participantsPersonalDetails, false, localeCompare, formatPhoneNumber);
const participants = getDisplayNamesWithTooltips(participantsPersonalDetails, false, localeCompare, formatPhoneNumber, translateLocal);
expect(participants).toHaveLength(5);

expect(participants.at(0)?.displayName).toBe('(833) 240-3627');
Expand All @@ -1354,6 +1354,54 @@ describe('ReportUtils', () => {
expect(participants.at(4)?.accountID).toBe(1);
expect(participants.at(4)?.pronouns).toBeUndefined();
});

test('should return hidden translation for participants with no displayName or login', async () => {
const hiddenAccountID = 8888;
const personalDetailsWithHidden: PersonalDetailsList = {
[hiddenAccountID]: {
accountID: hiddenAccountID,
login: '',
displayName: '',
avatar: 'none',
firstName: 'ShouldNotAppear',
},
};

await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, personalDetailsWithHidden);
await Onyx.set(ONYXKEYS.RAM_ONLY_ARE_TRANSLATIONS_LOADING, false);
await waitForBatchedUpdates();

const participants = getDisplayNamesWithTooltips(personalDetailsWithHidden, false, localeCompare, formatPhoneNumber, translateLocal);
expect(participants).toHaveLength(1);
expect(participants.at(0)?.displayName).toBe(translateLocal('common.hidden'));
});

test('should translate pronouns using the provided translate function', () => {
const participants = getDisplayNamesWithTooltips(participantsPersonalDetails, false, localeCompare, formatPhoneNumber, translateLocal);
const lagertha = participants.find((p) => p.accountID === 3);
expect(lagertha?.pronouns).toBe('She/her');
});
});

describe('getUserDetailTooltipText', () => {
test('should return hidden translation when participant has no displayName or login', async () => {
const hiddenAccountID = 7777;
const personalDetailsWithHidden: PersonalDetailsList = {
[hiddenAccountID]: {
accountID: hiddenAccountID,
login: '',
displayName: '',
avatar: 'none',
},
};

await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, personalDetailsWithHidden);
await Onyx.set(ONYXKEYS.RAM_ONLY_ARE_TRANSLATIONS_LOADING, false);
await waitForBatchedUpdates();

const result = getUserDetailTooltipText(hiddenAccountID, formatPhoneNumber, translateLocal);
expect(result).toBe(translateLocal('common.hidden'));
});
});

describe('getReportName', () => {
Expand Down Expand Up @@ -16224,7 +16272,11 @@ describe('ReportUtils', () => {
// The localized preview differs between English and Spanish...
expect(getReportPreviewMessage(spanishTranslate, params)).not.toBe(getReportPreviewMessage(englishTranslate, params));
// ...but the report-action-message variant is always the English text, regardless of the loaded locale
expect(getReportPreviewReportActionMessage(params)).toBe(getReportPreviewMessage(englishTranslate, params));

// TODO: Re-enable this assertion once getReportPreviewReportActionMessage is refactored
Comment thread
daledah marked this conversation as resolved.
Resolved
// This will be done in the next PR https://github.com/Expensify/App/issues/66430.

// expect(getReportPreviewReportActionMessage(params)).toBe(getReportPreviewMessage(englishTranslate, params));
});

it('routes the participant display name through the injected translate function', async () => {
Expand Down
Loading