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
12 changes: 11 additions & 1 deletion src/components/ReportActionAvatars/useReportActionAvatars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,17 @@ function useReportActionAvatars({
const useNearestReportAvatars = (!accountID || !action) && accountIDs.length === 0;

const getIconsWithDefaults = (onyxReport: OnyxInputOrEntry<Report>) =>
getIcons(onyxReport, formatPhoneNumber, personalDetails, avatar ?? fallbackIcon ?? defaultAvatars.FallbackAvatar, defaultDisplayName, accountID, policy, invoiceReceiverPolicy);
getIcons(
onyxReport,
formatPhoneNumber,
translate,
personalDetails,
avatar ?? fallbackIcon ?? defaultAvatars.FallbackAvatar,
defaultDisplayName,
accountID,
policy,
invoiceReceiverPolicy,
);

const reportIcons = getIconsWithDefaults(chatReport?.reportID ? chatReport : iouReport);

Expand Down
3 changes: 2 additions & 1 deletion src/libs/OptionsListUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,7 @@ function createOption({
sortedActions,
}: CreateOptionParams): SearchOptionData {
const {showChatPreviewLine = false, forcePolicyNamePreview = false, showPersonalDetails = false, selected, isSelected, isDisabled} = config ?? {};
const translateFn = translate ?? translateLocal;

// Initialize only the properties that are actually used in SearchOption context
const result: SearchOptionData = {
Expand Down Expand Up @@ -1210,7 +1211,6 @@ function createOption({

// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- below is a boolean expression
hasMultipleParticipants = personalDetailList.length > 1 || result.isChatRoom || result.isPolicyExpenseChat || reportUtilsIsGroupChat(report);
const translateFn = translate ?? translateLocal;
subtitle = getChatRoomSubtitle(report, policy, conciergeReportID, translateFn, true, result.private_isArchived);

// If displaying chat preview line is needed, let's overwrite the default alternate text
Expand Down Expand Up @@ -1267,6 +1267,7 @@ function createOption({
result.icons = getIcons(
report,
formatPhoneNumberPhoneUtils,
translateFn,
personalDetails,
personalDetail?.avatar,
personalDetail?.login,
Expand Down
45 changes: 31 additions & 14 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ import Parser from './Parser';
import {getParsedMessageWithShortMentions} from './ParsingUtils';
import {getBankAccountLastFourDigits} from './PaymentUtils';
import Permissions from './Permissions';
import {getAccountIDsByLogins, getDisplayNameOrDefault, getLoginByAccountID, getPersonalDetailByEmail} from './PersonalDetailsUtils';
import {getAccountIDsByLogins, getDisplayNameOrDefault, getLoginByAccountID, getPersonalDetailByEmail, temporaryGetDisplayNameOrDefault} from './PersonalDetailsUtils';
import {
canSendInvoiceFromWorkspace,
getActivePolicies,
Expand Down Expand Up @@ -3689,7 +3689,7 @@ function buildParticipantsFromAccountIDs(accountIDs: number[]): Participants {
}, finalParticipants);
}

function getParticipantIcon(accountID: number | undefined, personalDetails: OnyxInputOrEntry<PersonalDetailsList>, shouldUseShortForm = false): Icon {
function getParticipantIcon(accountID: number | undefined, personalDetails: OnyxInputOrEntry<PersonalDetailsList>, translate: LocalizedTranslate, shouldUseShortForm = false): Icon {
if (!accountID) {
return {
id: CONST.DEFAULT_NUMBER_ID,
Expand All @@ -3699,7 +3699,7 @@ function getParticipantIcon(accountID: number | undefined, personalDetails: Onyx
};
}
const details = personalDetails?.[accountID];
const displayName = getDisplayNameOrDefault(details, '', shouldUseShortForm);
const displayName = temporaryGetDisplayNameOrDefault({passedPersonalDetails: details, defaultValue: '', shouldFallbackToHidden: shouldUseShortForm, translate});

return {
id: accountID,
Expand Down Expand Up @@ -3777,14 +3777,15 @@ function getIconsForChatThread(
personalDetails: OnyxInputOrEntry<PersonalDetailsList>,
policy: OnyxInputOrEntry<Policy>,
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'],
translate: LocalizedTranslate,
): Icon[] {
if (!report?.parentReportID || !report?.parentReportActionID) {
return [];
}
const parentReportAction = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`]?.[report.parentReportActionID];
const actorAccountID = getReportActionActorAccountID(parentReportAction, report as OnyxEntry<Report>, report as OnyxEntry<Report>);
const actorDetails = actorAccountID ? personalDetails?.[actorAccountID] : undefined;
const actorDisplayName = getDisplayNameOrDefault(actorDetails, '', false);
const actorDisplayName = temporaryGetDisplayNameOrDefault({passedPersonalDetails: actorDetails, defaultValue: '', shouldFallbackToHidden: false, translate});
const actorIcon = {
id: actorAccountID,
source: actorDetails?.avatar ?? (actorAccountID ? getDefaultAvatarURL({accountID: actorAccountID}) : FallbackAvatar),
Expand All @@ -3803,8 +3804,13 @@ function getIconsForChatThread(
/**
* Helper function to get the icons for a task report. Only to be used in getIcons().
*/
function getIconsForTaskReport(report: OnyxInputOrEntry<Report>, personalDetails: OnyxInputOrEntry<PersonalDetailsList>, policy: OnyxInputOrEntry<Policy>): Icon[] {
const ownerIcon = getParticipantIcon(report?.ownerAccountID, personalDetails, true);
function getIconsForTaskReport(
report: OnyxInputOrEntry<Report>,
personalDetails: OnyxInputOrEntry<PersonalDetailsList>,
policy: OnyxInputOrEntry<Policy>,
translate: LocalizedTranslate,
): Icon[] {
const ownerIcon = getParticipantIcon(report?.ownerAccountID, personalDetails, translate, true);
if (report && isWorkspaceTaskReport(report)) {
const workspaceIcon = getWorkspaceIcon(report, policy);
return [ownerIcon, workspaceIcon];
Expand Down Expand Up @@ -3849,24 +3855,34 @@ function getIconsForPolicyRoom(
/**
* Helper function to get the icons for a policy expense chat. Only to be used in getIcons().
*/
function getIconsForPolicyExpenseChat(report: OnyxInputOrEntry<Report>, personalDetails: OnyxInputOrEntry<PersonalDetailsList>, policy: OnyxInputOrEntry<Policy>): Icon[] {
function getIconsForPolicyExpenseChat(
report: OnyxInputOrEntry<Report>,
personalDetails: OnyxInputOrEntry<PersonalDetailsList>,
policy: OnyxInputOrEntry<Policy>,
translate: LocalizedTranslate,
): Icon[] {
if (!report) {
return [];
}
const workspaceIcon = getWorkspaceIcon(report, policy);
const memberIcon = getParticipantIcon(report?.ownerAccountID, personalDetails, true);
const memberIcon = getParticipantIcon(report?.ownerAccountID, personalDetails, translate, true);
return [workspaceIcon, memberIcon];
}

/**
* Helper function to get the icons for an expense report. Only to be used in getIcons().
*/
function getIconsForExpenseReport(report: OnyxInputOrEntry<Report>, personalDetails: OnyxInputOrEntry<PersonalDetailsList>, policy: OnyxInputOrEntry<Policy>): Icon[] {
function getIconsForExpenseReport(
report: OnyxInputOrEntry<Report>,
personalDetails: OnyxInputOrEntry<PersonalDetailsList>,
policy: OnyxInputOrEntry<Policy>,
translate: LocalizedTranslate,
): Icon[] {
if (!report) {
return [];
}
const workspaceIcon = getWorkspaceIcon(report, policy);
const memberIcon = getParticipantIcon(report?.ownerAccountID, personalDetails, true);
const memberIcon = getParticipantIcon(report?.ownerAccountID, personalDetails, translate, true);
return [memberIcon, workspaceIcon];
}

Expand Down Expand Up @@ -3977,6 +3993,7 @@ function getIconsForUserCreatedPolicyRoom(report: OnyxInputOrEntry<Report>, poli
function getIcons(
report: OnyxInputOrEntry<Report>,
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'],
translate: LocalizedTranslate,
personalDetails: OnyxInputOrEntry<PersonalDetailsList> = allPersonalDetails,
defaultIcon: AvatarSource | null = null,
defaultName = '',
Expand All @@ -3999,7 +4016,7 @@ function getIcons(
return getIconsForExpenseRequest(report, personalDetails, policy);
}
if (isExpenseReport(report)) {
return getIconsForExpenseReport(report, personalDetails, policy);
return getIconsForExpenseReport(report, personalDetails, policy, translate);
}
if (isIOUReport(report)) {
return getIconsForIOUReport(report, personalDetails);
Expand All @@ -4008,16 +4025,16 @@ function getIcons(
return getIconsForInvoiceReport(report, personalDetails, policy, invoiceReceiverPolicy);
}
if (isChatThread(report)) {
return getIconsForChatThread(report, personalDetails, policy, formatPhoneNumber);
return getIconsForChatThread(report, personalDetails, policy, formatPhoneNumber, translate);
}
if (isTaskReport(report)) {
return getIconsForTaskReport(report, personalDetails, policy);
return getIconsForTaskReport(report, personalDetails, policy, translate);
}
if (isDomainRoom(report)) {
return getIconsForDomainRoom(report);
}
if (isPolicyExpenseChat(report)) {
return getIconsForPolicyExpenseChat(report, personalDetails, policy);
return getIconsForPolicyExpenseChat(report, personalDetails, policy, translate);
}
if (isUserCreatedPolicyRoom(report)) {
return getIconsForUserCreatedPolicyRoom(report, policy);
Expand Down
7 changes: 4 additions & 3 deletions src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2298,11 +2298,12 @@ function getReportNameValuePairsFromKey(data: OnyxTypes.SearchResults['data'], r
function getSearchReportAvatarProps(
report: OnyxTypes.Report,
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'],
translate: LocalizedTranslate,
personalDetailsList: OnyxTypes.PersonalDetailsList,
policy?: OnyxTypes.Policy,
isReportArchived = false,
) {
const avatarIcons = getIcons(report, formatPhoneNumber, personalDetailsList, null, '', -1, policy, undefined, isReportArchived);
const avatarIcons = getIcons(report, formatPhoneNumber, translate, personalDetailsList, null, '', -1, policy, undefined, isReportArchived);
const hasSecondAvatar = avatarIcons.length > 1 && !!avatarIcons.at(1)?.name;

let avatarType: ValueOf<typeof CONST.REPORT_ACTION_AVATARS.TYPE>;
Expand Down Expand Up @@ -2607,7 +2608,7 @@ function getTaskSections(
const policy = data[`${ONYXKEYS.COLLECTION.POLICY}${parentReport.policyID}`];
const isParentReportArchived = isArchivedReport(reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${parentReport?.reportID}`]);
const parentReportName = getReportName(parentReport, reportAttributesDerivedValue);
const icons = getIcons(parentReport, formatPhoneNumber, personalDetails, null, '', -1, policy, undefined, isParentReportArchived);
const icons = getIcons(parentReport, formatPhoneNumber, translate, personalDetails, null, '', -1, policy, undefined, isParentReportArchived);
const parentReportIcon = icons?.at(0);

result.parentReportName = parentReportName;
Expand Down Expand Up @@ -2909,7 +2910,7 @@ function getReportSections({

const {totalDisplaySpend, nonReimbursableSpend, reimbursableSpend} = getMoneyRequestSpendBreakdown(reportItem);
const reportIsArchived = isArchivedReport(getReportNameValuePairsFromKey(data, reportItem));
const avatarProps = getSearchReportAvatarProps(reportItem, formatPhoneNumber, mergedPersonalDetails, policy, reportIsArchived);
const avatarProps = getSearchReportAvatarProps(reportItem, formatPhoneNumber, translate, mergedPersonalDetails, policy, reportIsArchived);

const isRejectedReport =
reportItem.stateNum === CONST.REPORT.STATE_NUM.OPEN &&
Expand Down
1 change: 1 addition & 0 deletions src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1381,6 +1381,7 @@ function getOptionData({
const reportIcons = getIcons(
report,
formatPhoneNumberPhoneUtils,
translate,
personalDetails,
personalDetail?.avatar,
personalDetail?.login,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ function getShareDestination(
subtitle = ReportUtils.getChatRoomSubtitle(report, policy, conciergeReportID, translate) ?? '';
}
return {
icons: ReportUtils.getIcons(report, LocalePhoneNumber.formatPhoneNumber, personalDetails, FallbackAvatar),
icons: ReportUtils.getIcons(report, LocalePhoneNumber.formatPhoneNumber, translate, personalDetails, FallbackAvatar),
displayName: getReportName(report, reportAttributes),
subtitle,
displayNamesWithTooltips,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/DynamicReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -736,8 +736,8 @@ function DynamicReportDetailsPage({policy, report, route, reportMetadata, report
]);

const icons = useMemo(
() => getIcons(report, formatPhoneNumber, personalDetails, null, '', -1, policy, undefined, isReportArchived),
[report, formatPhoneNumber, personalDetails, policy, isReportArchived],
() => getIcons(report, formatPhoneNumber, translate, personalDetails, null, '', -1, policy, undefined, isReportArchived),
[report, formatPhoneNumber, translate, personalDetails, policy, isReportArchived],
);

const renderedAvatar = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ function QuickActionMenuItem({reportID}: QuickActionMenuItemProps) {

let quickActionAvatars: ReturnType<typeof getIcons> = [];
if (isValidReport) {
const avatars = getIcons(quickActionReport, formatPhoneNumber, personalDetails, null, undefined, undefined, undefined, undefined, isReportArchived);
const avatars = getIcons(quickActionReport, formatPhoneNumber, translate, personalDetails, null, undefined, undefined, undefined, undefined, isReportArchived);
quickActionAvatars = avatars.length <= 1 || isPolicyExpenseChat(quickActionReport) ? avatars : avatars.filter((avatar) => avatar.id !== currentUserPersonalDetails.accountID);
} else if (!isEmptyObject(policyChatForActivePolicy)) {
quickActionAvatars = getIcons(policyChatForActivePolicy, formatPhoneNumber, personalDetails, null, undefined, undefined, undefined, undefined, isReportArchived);
quickActionAvatars = getIcons(policyChatForActivePolicy, formatPhoneNumber, translate, personalDetails, null, undefined, undefined, undefined, undefined, isReportArchived);
}

let quickActionTitle = '';
Expand Down
15 changes: 13 additions & 2 deletions src/pages/iou/request/step/IOURequestEditReportCommon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,21 @@ function IOURequestEditReportCommon({
isSelected: report.reportID === selectedReportID,
policyID: report.policyID,
reportID: report.reportID,
icons: getIconsForExpenseReport(report, personalDetails, policy),
icons: getIconsForExpenseReport(report, personalDetails, policy, translate),
};
});
}, [debouncedSearchValue, outstandingReports, selectedReportID, personalDetails, localeCompare, allPolicies, currentUserPersonalDetails.accountID, isPerDiemRequest, isTimeRequest]);
}, [
debouncedSearchValue,
outstandingReports,
selectedReportID,
personalDetails,
localeCompare,
allPolicies,
currentUserPersonalDetails.accountID,
isPerDiemRequest,
isTimeRequest,
translate,
]);

const navigateBack = () => {
Navigation.goBack(backTo);
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 @@ -130,7 +130,7 @@ describe('ReportUtils', () => {
const defaultIconId = -1;

await waitForBatchedUpdates();
await measureFunction(() => getIcons(report, formatPhoneNumber, personalDetails, defaultIcon, defaultName, defaultIconId, policy));
await measureFunction(() => getIcons(report, formatPhoneNumber, translateLocal, personalDetails, defaultIcon, defaultName, defaultIconId, policy));
});

test('[ReportUtils] getDisplayNamesWithTooltips 1k participants', async () => {
Expand Down
Loading
Loading