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
4 changes: 3 additions & 1 deletion src/components/MultipleAvatars.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {ValueOf} from 'type-fest';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import * as ReportUtils from '@libs/ReportUtils';
import type {AvatarSource} from '@libs/UserUtils';
import variables from '@styles/variables';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -106,7 +107,8 @@ function MultipleAvatars({
let avatarContainerStyles = StyleUtils.getContainerStyles(size, isInReportAction);
const {singleAvatarStyle, secondAvatarStyles} = useMemo(() => avatarSizeToStylesMap[size as AvatarSizeToStyles] ?? avatarSizeToStylesMap.default, [size, avatarSizeToStylesMap]);

const tooltipTexts = useMemo(() => (shouldShowTooltip ? icons.map((icon) => icon.name) : ['']), [shouldShowTooltip, icons]);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have to remove this memo. Why can't we just add the ReportUtils.getUserDetailsTooltipText( part to it.

@dukenv0307 dukenv0307 Jan 30, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@parasharrajat Actually, we use tooltipTexts as an array of user tooltip text and it will be slice accordingly below. We have two option

  1. No need to change any thing in MultipleAvatars because icon.name already uses getDisplayNameForParticipant function

  2. keep the change

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@parasharrajat I merged main, what do you think about my comment above?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant to say was that tooltiptexts contain all the icons and it is used twice in the code below. Why can't we calculate the getUserDetailsTooltipText once over this array here and use to where needed.

  1. Now, you are calculating the getUserDetailsTooltipText from these icons at both places.
  2. Both those places use different slicing over this array.
  3. My suggestion was that we could convert the tooltipTexts icon array to an array of getUserDetailsTooltipText. Then just use this in those slicing operations.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@parasharrajat was your concern here addressed/resolved?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is no blocker for me.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now addressed.

const tooltipTexts = useMemo(() => (shouldShowTooltip ? icons.map((icon) => ReportUtils.getUserDetailTooltipText(Number(icon.id), icon.name)) : ['']), [shouldShowTooltip, icons]);

const avatarSize = useMemo(() => {
if (isFocusMode) {
return CONST.AVATAR_SIZE.MID_SUBSCRIPT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function BaseUserDetailsTooltip({accountID, fallbackUserDetails, icon, delegateA
const personalDetails = usePersonalDetails();

const userDetails = personalDetails?.[accountID] ?? fallbackUserDetails ?? {};
let userDisplayName = ReportUtils.getDisplayNameForParticipant(accountID) || (userDetails.displayName ? userDetails.displayName.trim() : '');
let userDisplayName = ReportUtils.getUserDetailTooltipText(accountID, userDetails.displayName ? userDetails.displayName.trim() : '');
let userLogin = userDetails.login?.trim() && userDetails.login !== userDetails.displayName ? Str.removeSMSDomain(userDetails.login) : '';

let userAvatar = userDetails.avatar;
Expand All @@ -29,7 +29,7 @@ function BaseUserDetailsTooltip({accountID, fallbackUserDetails, icon, delegateA
// the Copilot feature is implemented.
if (delegateAccountID) {
const delegateUserDetails = personalDetails?.[delegateAccountID];
const delegateUserDisplayName = ReportUtils.getDisplayNameForParticipant(delegateAccountID);
const delegateUserDisplayName = ReportUtils.getUserDetailTooltipText(delegateAccountID);
userDisplayName = `${delegateUserDisplayName} (${translate('reportAction.asCopilot')} ${userDisplayName})`;
userLogin = delegateUserDetails?.login ?? '';
userAvatar = delegateUserDetails?.avatar;
Expand Down
9 changes: 9 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1694,6 +1694,14 @@ function getDisplayNamesWithTooltips(
});
}

/**
* Returns the the display names of the given user accountIDs
*/
function getUserDetailTooltipText(accountID: number, fallbackUserDisplayName = ''): string {
const displayNameForParticipant = getDisplayNameForParticipant(accountID);
return displayNameForParticipant || fallbackUserDisplayName;
}

/**
* For a deleted parent report action within a chat report,
* let us return the appropriate display message
Expand Down Expand Up @@ -5195,6 +5203,7 @@ export {
buildOptimisticUnHoldReportAction,
shouldDisplayThreadReplies,
shouldDisableThread,
getUserDetailTooltipText,
doesReportBelongToWorkspace,
getChildReportNotificationPreference,
getAllAncestorReportActions,
Expand Down