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

Use icon data to determine tool tips for MultipleAvatars #19104

Merged
merged 13 commits into from
May 24, 2023
3 changes: 1 addition & 2 deletions src/components/LHNOptionsList/OptionRowLHN.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ const OptionRowLHN = (props) => {
const hoveredBackgroundColor = props.hoverStyle && props.hoverStyle.backgroundColor ? props.hoverStyle.backgroundColor : themeColors.sidebar;
const focusedBackgroundColor = styles.sidebarLinkActive.backgroundColor;

const avatarTooltips = !optionItem.isChatRoom && !optionItem.isArchivedRoom ? _.pluck(optionItem.displayNamesWithTooltips, 'tooltip') : undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

Now we have shouldShowTooltip prop. Please add that logic
shouldShowTooltip={!optionItem.isChatRoom && !optionItem.isArchivedRoom}

const hasBrickError = optionItem.brickRoadIndicator === CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR;
const shouldShowGreenDotIndicator = !hasBrickError && (optionItem.isUnreadWithMention || (optionItem.hasOutstandingIOU && !optionItem.isIOUReportOwner));

Expand Down Expand Up @@ -138,7 +137,7 @@ const OptionRowLHN = (props) => {
props.isFocused ? StyleUtils.getBackgroundAndBorderStyle(focusedBackgroundColor) : undefined,
hovered && !props.isFocused ? StyleUtils.getBackgroundAndBorderStyle(hoveredBackgroundColor) : undefined,
]}
avatarTooltips={optionItem.isPolicyExpenseChat ? [optionItem.subtitle] : avatarTooltips}
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB but we used to show 'Workspace' instead of the workspace's name.

Screenshot from 2023-05-17 20-45-24
Screenshot from 2023-05-17 20-45-16

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@JmillsExpensify @shawnborton is Showing Workspace the desire behavior here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm what do we do for users? I feel like we stay consistent and just always show the room title?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for users we show the login email

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting... I lean towards just using the room title, or basically whatever the text to the right of the avatar or the chat header says?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, I think this change is fine in that case. Also, I think rooms don't use tooltips currently, so this would only be for Workspace chats.

shouldShowTooltip={!optionItem.isChatRoom && !optionItem.isArchivedRoom}
/>
))}
<View style={contentContainerStyles}>
Expand Down
24 changes: 13 additions & 11 deletions src/components/MultipleAvatars.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ const propTypes = {
// eslint-disable-next-line react/forbid-prop-types
secondAvatarStyle: PropTypes.arrayOf(PropTypes.object),

/** Tooltip for the Avatar */
avatarTooltips: PropTypes.arrayOf(PropTypes.string),

/** A fallback avatar icon to display when there is an error on loading avatar from remote URL. */
fallbackIcon: PropTypes.func,

Expand All @@ -44,28 +41,32 @@ const propTypes = {
/** Whether avatars are displayed within a reportAction */
isInReportAction: PropTypes.bool,

/** Whether avatars are displayed within an IOUAction */
/** Whether to show the toolip text */
shouldShowTooltip: PropTypes.bool,

/** Whether avatars are displayed with the highlighted background color instead of the app background color. This is primarily the case for IOU previews. */
shouldUseCardBackground: PropTypes.bool,
};

const defaultProps = {
icons: [],
size: CONST.AVATAR_SIZE.DEFAULT,
secondAvatarStyle: [StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)],
avatarTooltips: [],
fallbackIcon: undefined,
shouldStackHorizontally: false,
isHovered: false,
isPressed: false,
isFocusMode: false,
isInReportAction: false,
shouldShowTooltip: true,
shouldUseCardBackground: false,
};

const MultipleAvatars = (props) => {
let avatarContainerStyles = props.size === CONST.AVATAR_SIZE.SMALL ? [styles.emptyAvatarSmall, styles.emptyAvatarMarginSmall] : [styles.emptyAvatar, styles.emptyAvatarMargin];
const singleAvatarStyles = props.size === CONST.AVATAR_SIZE.SMALL ? styles.singleAvatarSmall : styles.singleAvatar;
const secondAvatarStyles = [props.size === CONST.AVATAR_SIZE.SMALL ? styles.secondAvatarSmall : styles.secondAvatar, ...props.secondAvatarStyle];
const tooltipTexts = props.shouldShowTooltip ? _.pluck(props.icons, 'name') : [];

if (!props.icons.length) {
return null;
Expand All @@ -74,7 +75,7 @@ const MultipleAvatars = (props) => {
if (props.icons.length === 1 && !props.shouldStackHorizontally) {
return (
<View style={avatarContainerStyles}>
<Tooltip text={props.avatarTooltips[0]}>
<Tooltip text={tooltipTexts[0]}>
<Avatar
source={props.icons[0].source}
size={props.size}
Expand Down Expand Up @@ -113,7 +114,7 @@ const MultipleAvatars = (props) => {
{_.map([...props.icons].splice(0, 4), (icon, index) => (
<Tooltip
key={`stackedAvatars-${index}`}
text={props.avatarTooltips[index]}
text={tooltipTexts[index]}
absolute
>
<View
Expand Down Expand Up @@ -142,7 +143,8 @@ const MultipleAvatars = (props) => {
))}
{props.icons.length > 4 && (
<Tooltip
text={props.avatarTooltips.slice(3).join(', ')}
// We only want to cap tooltips to only the first 10 users or so since some reports have hundreds of users, causing performance to degrade.
text={tooltipTexts.slice(3, 10).join(', ')}
absolute
>
<View
Expand Down Expand Up @@ -174,7 +176,7 @@ const MultipleAvatars = (props) => {
) : (
<View style={singleAvatarStyles}>
<Tooltip
text={props.avatarTooltips[0]}
text={tooltipTexts[0]}
absolute
>
{/* View is necessary for tooltip to show for multiple avatars in LHN */}
Expand All @@ -192,7 +194,7 @@ const MultipleAvatars = (props) => {
<View style={secondAvatarStyles}>
{props.icons.length === 2 ? (
<Tooltip
text={props.avatarTooltips[1]}
text={tooltipTexts[1]}
absolute
>
<View>
Expand All @@ -208,7 +210,7 @@ const MultipleAvatars = (props) => {
</Tooltip>
) : (
<Tooltip
text={props.avatarTooltips.slice(1).join(', ')}
text={tooltipTexts.slice(1).join(', ')}
absolute
>
<View style={[singleAvatarStyles, styles.alignItemsCenter, styles.justifyContentCenter]}>
Expand Down
4 changes: 1 addition & 3 deletions src/components/OptionRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ class OptionRow extends Component {

// We only create tooltips for the first 10 users or so since some reports have hundreds of users, causing performance to degrade.
const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips((this.props.option.participantsList || []).slice(0, 10), isMultipleParticipant);
const avatarTooltips = this.props.showTitleTooltip && !this.props.option.isChatRoom && !this.props.option.isArchivedRoom ? _.pluck(displayNamesWithTooltips, 'tooltip') : undefined;

let subscriptColor = themeColors.appBG;
if (this.props.optionIsFocused) {
subscriptColor = focusedBackgroundColor;
Expand Down Expand Up @@ -197,7 +195,7 @@ class OptionRow extends Component {
this.props.optionIsFocused ? StyleUtils.getBackgroundAndBorderStyle(focusedBackgroundColor) : undefined,
hovered && !this.props.optionIsFocused ? StyleUtils.getBackgroundAndBorderStyle(hoveredBackgroundColor) : undefined,
]}
avatarTooltips={this.props.option.isPolicyExpenseChat ? [this.props.option.subtitle] : avatarTooltips}
shouldShowTooltip={this.props.showTitleTooltip && !this.props.option.isChatRoom && !this.props.option.isArchivedRoom}
/>
))}
<View style={contentContainerStyles}>
Expand Down
1 change: 0 additions & 1 deletion src/components/ReportActionItem/IOUPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ const IOUPreview = (props) => {
size="small"
isHovered={props.isHovered}
shouldUseCardBackground
avatarTooltips={participantEmails}
/>
</View>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Tooltip/tooltipPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const propTypes = {
/** Enable support for the absolute positioned native(View|Text) children. It will only work for single native child */
absolute: PropTypes.bool,

/** The text to display in the tooltip. */
/** The text to display in the tooltip. If text is ommitted, only children will be rendered. */
text: PropTypes.string,

/** Maximum number of lines to show in tooltip */
Expand Down
3 changes: 1 addition & 2 deletions src/pages/home/HeaderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ const HeaderView = (props) => {
}
const shouldShowThreeDotsButton = !!threeDotMenuItems.length;

const avatarTooltip = isChatRoom ? undefined : _.pluck(displayNamesWithTooltips, 'tooltip');
const shouldShowSubscript = isPolicyExpenseChat && !props.report.isOwnPolicyExpenseChat && !ReportUtils.isArchivedRoom(props.report) && !isTaskReport;
const icons = ReportUtils.getIcons(reportHeaderData, props.personalDetails);
const brickRoadIndicator = ReportUtils.hasReportNameError(props.report) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : '';
Expand Down Expand Up @@ -157,7 +156,7 @@ const HeaderView = (props) => {
) : (
<MultipleAvatars
icons={icons}
avatarTooltips={avatarTooltip}
shouldShowTooltip={!isChatRoom}
/>
)}
<View style={[styles.flex1, styles.flexColumn]}>
Expand Down
2 changes: 0 additions & 2 deletions src/pages/home/report/ReportActionItemThread.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import {View, Pressable, Text} from 'react-native';
import PropTypes from 'prop-types';
import _ from 'underscore';
import styles from '../../../styles/styles';
import * as Report from '../../../libs/actions/Report';
import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize';
Expand Down Expand Up @@ -49,7 +48,6 @@ const ReportActionItemThread = (props) => {
size={CONST.AVATAR_SIZE.SMALL}
icons={props.icons}
shouldStackHorizontally
avatarTooltips={_.map(props.icons, (icon) => icon.name)}
isHovered={props.isHovered}
isInReportAction
/>
Expand Down
7 changes: 0 additions & 7 deletions src/pages/workspace/WorkspaceInviteMessagePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import PropTypes from 'prop-types';
import {Pressable, View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import Str from 'expensify-common/lib/str';
import lodashGet from 'lodash/get';
import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize';
import ScreenWrapper from '../../components/ScreenWrapper';
Expand Down Expand Up @@ -114,11 +113,6 @@ class WorkspaceInviteMessagePage extends React.Component {
});
}

getAvatarTooltips() {
const filteredPersonalDetails = _.pick(this.props.personalDetails, this.props.invitedMembersDraft);
return _.map(filteredPersonalDetails, (personalDetail) => Str.removeSMSDomain(personalDetail.login));
}

sendInvitation() {
Policy.addMembersToWorkspace(this.props.invitedMembersDraft, this.state.welcomeNote, this.props.route.params.policyID, this.props.betas);
Policy.setWorkspaceInviteMembersDraft(this.props.route.params.policyID, []);
Expand Down Expand Up @@ -186,7 +180,6 @@ class WorkspaceInviteMessagePage extends React.Component {
icons={OptionsListUtils.getAvatarsForLogins(this.props.invitedMembersDraft, this.props.personalDetails)}
shouldStackHorizontally
secondAvatarStyle={[styles.secondAvatarInline]}
avatarTooltips={this.getAvatarTooltips()}
/>
</View>
<View style={[styles.mb5]}>
Expand Down