Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix avatar tooltip issues across the app #21026

Merged
merged 1 commit into from
Jun 19, 2023
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/MoneyRequestConfirmationList.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import MenuItemWithTopDescription from './MenuItemWithTopDescription';
import Navigation from '../libs/Navigation/Navigation';
import optionPropTypes from './optionPropTypes';
import * as CurrencyUtils from '../libs/CurrencyUtils';
import * as ReportUtils from '../libs/ReportUtils';

const propTypes = {
/** Callback to inform parent modal of success */
Expand Down Expand Up @@ -234,10 +233,10 @@ function MoneyRequestConfirmationList(props) {
* @param {Object} option
*/
const navigateToUserDetail = (option) => {
if (!option.login) {
if (!option.accountID) {
return;
}
Navigation.navigate(ROUTES.getProfileRoute(ReportUtils.getAccountIDForLogin(option.login)));
Navigation.navigate(ROUTES.getProfileRoute(option.accountID));
};

/**
Expand Down
8 changes: 4 additions & 4 deletions src/components/MultipleAvatars.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function MultipleAvatars(props) {
if (props.icons.length === 1 && !props.shouldStackHorizontally) {
return (
<UserDetailsTooltip
accountID={ReportUtils.getAccountIDForLogin(props.icons[0].name)}
accountID={props.icons[0].id}
fallbackUserDetails={{
displayName: ReportUtils.getDisplayNameForParticipant(props.icons[0].name),
login: lodashGet(props.icons[0], 'name', tooltipTexts[0]),
Expand Down Expand Up @@ -124,7 +124,7 @@ function MultipleAvatars(props) {
{_.map([...props.icons].splice(0, 4), (icon, index) => (
<UserDetailsTooltip
key={`stackedAvatars-${index}`}
accountID={ReportUtils.getAccountIDForLogin(icon.name)}
accountID={icon.id}
>
<View
style={[
Expand Down Expand Up @@ -183,7 +183,7 @@ function MultipleAvatars(props) {
</>
) : (
<View style={singleAvatarStyles}>
<UserDetailsTooltip accountID={ReportUtils.getAccountIDForLogin(props.icons[0].name)}>
<UserDetailsTooltip accountID={props.icons[0].id}>
{/* View is necessary for tooltip to show for multiple avatars in LHN */}
<View>
<Avatar
Expand All @@ -198,7 +198,7 @@ function MultipleAvatars(props) {
</UserDetailsTooltip>
<View style={secondAvatarStyles}>
{props.icons.length === 2 ? (
<UserDetailsTooltip accountID={ReportUtils.getAccountIDForLogin(props.icons[1].name)}>
<UserDetailsTooltip accountID={props.icons[1].id}>
<View>
<Avatar
source={props.icons[1].source || props.fallbackIcon}
Expand Down
1 change: 1 addition & 0 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ function getAvatarsForAccountIDs(accountIDs, personalDetails) {
return _.map(accountIDs, (accountID) => {
const userPersonalDetail = lodashGet(personalDetails, accountID, {login: '', accountID, avatar: ''});
return {
id: accountID,
source: UserUtils.getAvatar(userPersonalDetail.avatar, userPersonalDetail.accountID),
type: CONST.ICON_TYPE_AVATAR,
name: userPersonalDetail.login,
Expand Down
28 changes: 9 additions & 19 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -684,22 +684,24 @@ function getIconsForParticipants(participants, personalDetails) {
const accountID = participantsList[i];
const avatarSource = UserUtils.getAvatar(lodashGet(personalDetails, [accountID, 'avatar'], ''), accountID);
participantDetails.push([
accountID,
lodashGet(personalDetails, [accountID, 'login'], lodashGet(personalDetails, [accountID, 'displayName'], '')),
lodashGet(personalDetails, [accountID, 'firstName'], ''),
avatarSource,
]);
}

// Sort all logins by first name (which is the second element in the array)
const sortedParticipantDetails = participantDetails.sort((a, b) => a[1] - b[1]);
const sortedParticipantDetails = participantDetails.sort((a, b) => a[2] - b[2]);

// Now that things are sorted, gather only the avatars (third element in the array) and return those
const avatars = [];
for (let i = 0; i < sortedParticipantDetails.length; i++) {
const userIcon = {
source: sortedParticipantDetails[i][2],
id: sortedParticipantDetails[i][0],
source: sortedParticipantDetails[i][3],
type: CONST.ICON_TYPE_AVATAR,
name: sortedParticipantDetails[i][0],
name: sortedParticipantDetails[i][1],
};
avatars.push(userIcon);
}
Expand Down Expand Up @@ -728,11 +730,6 @@ function getIcons(report, personalDetails, defaultIcon = null, isPayer = false)
result.source = defaultIcon || Expensicons.FallbackAvatar;
return [result];
}
if (isConciergeChatReport(report)) {
result.source = CONST.CONCIERGE_ICON_URL;
result.name = CONST.EMAIL.CONCIERGE;
return [result];
}
Beamanator marked this conversation as resolved.
Show resolved Hide resolved
if (isArchivedRoom(report)) {
result.source = Expensicons.DeletedRoomAvatar;
return [result];
Expand All @@ -743,6 +740,7 @@ function getIcons(report, personalDetails, defaultIcon = null, isPayer = false)
const actorEmail = lodashGet(parentReportAction, 'actorEmail', '');
const actorAccountID = lodashGet(parentReportAction, 'actorAccountID', '');
const actorIcon = {
id: actorAccountID,
source: UserUtils.getAvatar(lodashGet(personalDetails, [actorAccountID, 'avatar']), actorAccountID),
name: actorEmail,
type: CONST.ICON_TYPE_AVATAR,
Expand All @@ -753,6 +751,7 @@ function getIcons(report, personalDetails, defaultIcon = null, isPayer = false)
if (isTaskReport(report)) {
const ownerEmail = report.ownerEmail || '';
const ownerIcon = {
id: report.ownerAccountID,
source: UserUtils.getAvatar(lodashGet(personalDetails, [report.ownerAccountID, 'avatar']), report.ownerAccountID),
name: ownerEmail,
type: CONST.ICON_TYPE_AVATAR,
Expand Down Expand Up @@ -790,6 +789,7 @@ function getIcons(report, personalDetails, defaultIcon = null, isPayer = false)
}
Beamanator marked this conversation as resolved.
Show resolved Hide resolved

const adminIcon = {
id: report.ownerAccountID,
source: UserUtils.getAvatar(lodashGet(personalDetails, [report.ownerAccountID, 'avatar']), report.ownerAccountID),
name: report.ownerEmail,
type: CONST.ICON_TYPE_AVATAR,
Expand All @@ -810,6 +810,7 @@ function getIcons(report, personalDetails, defaultIcon = null, isPayer = false)
const accountID = isPayer ? report.managerID : report.ownerAccountID;
return [
{
id: accountID,
source: UserUtils.getAvatar(lodashGet(personalDetails, [accountID, 'avatar']), accountID),
name: email,
type: CONST.ICON_TYPE_AVATAR,
Expand Down Expand Up @@ -845,16 +846,6 @@ function getPersonalDetailsForAccountID(accountID) {
);
}

/**
* Gets the accountID for a login by looking in the ONYXKEYS.PERSONAL_DETAILS Onyx key (stored in the local variable, allPersonalDetails). If it doesn't exist in Onyx,
* then an empty string is returned.
* @param {String} login
* @returns {String}
*/
function getAccountIDForLogin(login) {
return lodashGet(allPersonalDetails, [login, 'accountID'], '');
}

/**
* Get the displayName for a single report participant.
*
Expand Down Expand Up @@ -2252,7 +2243,6 @@ function getParentReport(report) {
}

export {
getAccountIDForLogin,
getReportParticipantsTitle,
isReportMessageAttachment,
findLastAccessedReport,
Expand Down
1 change: 1 addition & 0 deletions src/pages/ReportParticipantsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const getAllParticipants = (report, personalDetails) => {
accountID: userPersonalDetail.accountID,
icons: [
{
id: accountID,
source: UserUtils.getAvatar(userPersonalDetail.avatar, accountID),
name: userLogin,
type: CONST.ICON_TYPE_AVATAR,
Expand Down