-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Only render UserDetailsTooltip
on web
#21807
Merged
roryabraham
merged 6 commits into
Expensify:main
from
margelo:perf/remove-userdetailstooltip-mobile
Jul 11, 2023
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0c70ad8
Only render UserDetailsTooltip on web
hannojg 8ba1551
Merge branch 'main' of github.com:margelo/expensify-app-fork into per…
hannojg afeba44
update with changes from `main`
hannojg 457da56
use localize hook
hannojg 2ac340e
Merge branch 'main' of github.com:margelo/expensify-app-fork into per…
hannojg 1183cd7
fix prop types
hannojg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,17 @@ | ||
import React, {useCallback} from 'react'; | ||
import {View, Text} from 'react-native'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import Str from 'expensify-common/lib/str'; | ||
import lodashGet from 'lodash/get'; | ||
import _ from 'underscore'; | ||
import Avatar from '../Avatar'; | ||
import Tooltip from '../Tooltip'; | ||
import {propTypes, defaultProps} from './userDetailsTooltipPropTypes'; | ||
import styles from '../../styles/styles'; | ||
import ONYXKEYS from '../../ONYXKEYS'; | ||
import withLocalize from '../withLocalize'; | ||
import compose from '../../libs/compose'; | ||
import * as UserUtils from '../../libs/UserUtils'; | ||
import CONST from '../../CONST'; | ||
import * as LocalePhoneNumber from '../../libs/LocalePhoneNumber'; | ||
import PropTypes from 'prop-types'; | ||
|
||
function UserDetailsTooltip(props) { | ||
const userDetails = lodashGet(props.personalDetailsList, props.accountID, props.fallbackUserDetails); | ||
let userDisplayName = userDetails.displayName ? userDetails.displayName.trim() : ''; | ||
let userLogin = (userDetails.login || '').trim() && !_.isEqual(userDetails.login, userDetails.displayName) ? Str.removeSMSDomain(userDetails.login) : ''; | ||
let userAvatar = userDetails.avatar; | ||
let userAccountID = props.accountID; | ||
const propTypes = { | ||
/** Children to wrap with Tooltip. */ | ||
children: PropTypes.node.isRequired, | ||
}; | ||
|
||
// We replace the actor's email, name, and avatar with the Copilot manually for now. This will be improved upon when | ||
// the Copilot feature is implemented. | ||
if (props.delegateAccountID) { | ||
const delegateUserDetails = lodashGet(props.personalDetailsList, props.delegateAccountID, {}); | ||
const delegateUserDisplayName = delegateUserDetails.displayName ? delegateUserDetails.displayName.trim() : ''; | ||
userDisplayName = `${delegateUserDisplayName} (${props.translate('reportAction.asCopilot')} ${userDisplayName})`; | ||
userLogin = delegateUserDetails.login; | ||
userAvatar = delegateUserDetails.avatar; | ||
userAccountID = props.delegateAccountID; | ||
} | ||
|
||
let title = String(userDisplayName).trim() ? userDisplayName : ''; | ||
const subtitle = (userLogin || '').trim() && !_.isEqual(LocalePhoneNumber.formatPhoneNumber(userLogin || ''), userDisplayName) ? Str.removeSMSDomain(userLogin) : ''; | ||
if (props.icon && props.icon.type === CONST.ICON_TYPE_WORKSPACE) { | ||
title = props.icon.name; | ||
} | ||
const renderTooltipContent = useCallback( | ||
() => ( | ||
<View style={[styles.alignItemsCenter, styles.ph2, styles.pv2]}> | ||
<View style={styles.emptyAvatar}> | ||
<Avatar | ||
containerStyles={[styles.actionAvatar]} | ||
source={props.icon ? props.icon.source : UserUtils.getAvatar(userAvatar, userAccountID)} | ||
type={props.icon ? props.icon.type : CONST.ICON_TYPE_AVATAR} | ||
name={props.icon ? props.icon.name : userLogin} | ||
/> | ||
</View> | ||
<Text style={[styles.mt2, styles.textMicroBold, styles.textReactionSenders, styles.textAlignCenter]}>{title}</Text> | ||
<Text style={[styles.textMicro, styles.fontColorReactionLabel, styles.breakWord, styles.textAlignCenter]}>{subtitle}</Text> | ||
</View> | ||
), | ||
[props.icon, userAvatar, userAccountID, userLogin, title, subtitle], | ||
); | ||
|
||
if (!props.icon && !userDisplayName && !userLogin) { | ||
return props.children; | ||
} | ||
|
||
return ( | ||
<Tooltip | ||
renderTooltipContent={renderTooltipContent} | ||
renderTooltipContentKey={[userDisplayName, userLogin]} | ||
> | ||
{props.children} | ||
</Tooltip> | ||
); | ||
} | ||
/** | ||
* @param {propTypes} props | ||
* @returns {ReactNodeLike} | ||
*/ | ||
const UserDetailsTooltip = (props) => props.children; | ||
|
||
UserDetailsTooltip.propTypes = propTypes; | ||
UserDetailsTooltip.defaultProps = defaultProps; | ||
UserDetailsTooltip.displayName = 'UserDetailsTooltip'; | ||
|
||
export default compose( | ||
withLocalize, | ||
withOnyx({ | ||
personalDetailsList: { | ||
key: ONYXKEYS.PERSONAL_DETAILS_LIST, | ||
}, | ||
}), | ||
)(UserDetailsTooltip); | ||
export default UserDetailsTooltip; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import React, {useCallback} from 'react'; | ||
import {View, Text} from 'react-native'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import Str from 'expensify-common/lib/str'; | ||
import lodashGet from 'lodash/get'; | ||
import _ from 'underscore'; | ||
import Avatar from '../Avatar'; | ||
import Tooltip from '../Tooltip'; | ||
import {propTypes, defaultProps} from './userDetailsTooltipPropTypes'; | ||
import styles from '../../styles/styles'; | ||
import ONYXKEYS from '../../ONYXKEYS'; | ||
import * as UserUtils from '../../libs/UserUtils'; | ||
import CONST from '../../CONST'; | ||
import * as LocalePhoneNumber from '../../libs/LocalePhoneNumber'; | ||
import useLocalize from '../../hooks/useLocalize'; | ||
|
||
function UserDetailsTooltip(props) { | ||
const localize = useLocalize(); | ||
|
||
const userDetails = lodashGet(props.personalDetailsList, props.accountID, props.fallbackUserDetails); | ||
let userDisplayName = userDetails.displayName ? userDetails.displayName.trim() : ''; | ||
let userLogin = (userDetails.login || '').trim() && !_.isEqual(userDetails.login, userDetails.displayName) ? Str.removeSMSDomain(userDetails.login) : ''; | ||
let userAvatar = userDetails.avatar; | ||
let userAccountID = props.accountID; | ||
|
||
// We replace the actor's email, name, and avatar with the Copilot manually for now. This will be improved upon when | ||
// the Copilot feature is implemented. | ||
if (props.delegateAccountID) { | ||
const delegateUserDetails = lodashGet(props.personalDetailsList, props.delegateAccountID, {}); | ||
const delegateUserDisplayName = delegateUserDetails.displayName ? delegateUserDetails.displayName.trim() : ''; | ||
userDisplayName = `${delegateUserDisplayName} (${localize.translate('reportAction.asCopilot')} ${userDisplayName})`; | ||
userLogin = delegateUserDetails.login; | ||
userAvatar = delegateUserDetails.avatar; | ||
userAccountID = props.delegateAccountID; | ||
} | ||
|
||
let title = String(userDisplayName).trim() ? userDisplayName : ''; | ||
const subtitle = (userLogin || '').trim() && !_.isEqual(LocalePhoneNumber.formatPhoneNumber(userLogin || ''), userDisplayName) ? Str.removeSMSDomain(userLogin) : ''; | ||
if (props.icon && props.icon.type === CONST.ICON_TYPE_WORKSPACE) { | ||
title = props.icon.name; | ||
} | ||
const renderTooltipContent = useCallback( | ||
() => ( | ||
<View style={[styles.alignItemsCenter, styles.ph2, styles.pv2]}> | ||
<View style={styles.emptyAvatar}> | ||
<Avatar | ||
containerStyles={[styles.actionAvatar]} | ||
source={props.icon ? props.icon.source : UserUtils.getAvatar(userAvatar, userAccountID)} | ||
type={props.icon ? props.icon.type : CONST.ICON_TYPE_AVATAR} | ||
name={props.icon ? props.icon.name : userLogin} | ||
/> | ||
</View> | ||
<Text style={[styles.mt2, styles.textMicroBold, styles.textReactionSenders, styles.textAlignCenter]}>{title}</Text> | ||
<Text style={[styles.textMicro, styles.fontColorReactionLabel]}>{subtitle}</Text> | ||
</View> | ||
), | ||
[props.icon, userAvatar, userAccountID, userLogin, title, subtitle], | ||
); | ||
|
||
if (!props.icon && !userDisplayName && !userLogin) { | ||
return props.children; | ||
} | ||
|
||
return ( | ||
<Tooltip | ||
renderTooltipContent={renderTooltipContent} | ||
renderTooltipContentKey={[userDisplayName, userLogin]} | ||
> | ||
{props.children} | ||
</Tooltip> | ||
); | ||
} | ||
|
||
UserDetailsTooltip.propTypes = propTypes; | ||
UserDetailsTooltip.defaultProps = defaultProps; | ||
UserDetailsTooltip.displayName = 'UserDetailsTooltip'; | ||
|
||
export default withOnyx({ | ||
personalDetailsList: { | ||
key: ONYXKEYS.PERSONAL_DETAILS_LIST, | ||
}, | ||
})(UserDetailsTooltip); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hannojg Do you recall why we had to add
renderTooltipContentKey
? (Coming from #22840)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that was already there when i made the changes, so no clue, sorry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops sorry my bad, the merge with main commit tricked me 😅. This was added in #22246.