-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
ref(ui): Simplify badges implementation #68946
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
Merged
evanpurkhiser
merged 2 commits into
master
from
evanpurkhiser/ref-ui-simplify-badges-implementation
Apr 16, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,21 +1,14 @@ | ||
import styled from '@emotion/styled'; | ||
import omit from 'lodash/omit'; | ||
|
||
import UserAvatar from 'sentry/components/avatar/userAvatar'; | ||
import type {LinkProps} from 'sentry/components/links/link'; | ||
import Link from 'sentry/components/links/link'; | ||
import {space} from 'sentry/styles/space'; | ||
import type {AvatarUser, Member} from 'sentry/types'; | ||
import useOrganization from 'sentry/utils/useOrganization'; | ||
|
||
import UserBadge, {type UserBadgeProps} from './userBadge'; | ||
|
||
export interface MemberBadgeProps { | ||
export interface MemberBadgeProps extends Omit<UserBadgeProps, 'user'> { | ||
member: Member; | ||
avatarSize?: React.ComponentProps<typeof UserAvatar>['size']; | ||
className?: string; | ||
displayEmail?: string; | ||
displayName?: React.ReactNode; | ||
hideEmail?: boolean; | ||
orgId?: string; | ||
useLink?: boolean; | ||
/** | ||
* Do not link to the members page | ||
*/ | ||
disableLink?: boolean; | ||
} | ||
|
||
function getMemberUser(member: Member): AvatarUser { | ||
|
@@ -32,82 +25,16 @@ function getMemberUser(member: Member): AvatarUser { | |
}; | ||
} | ||
|
||
function MemberBadge({ | ||
avatarSize = 24, | ||
useLink = true, | ||
hideEmail = false, | ||
displayName, | ||
displayEmail, | ||
member, | ||
orgId, | ||
className, | ||
}: MemberBadgeProps) { | ||
function MemberBadge({member, disableLink, ...props}: MemberBadgeProps) { | ||
const user = getMemberUser(member); | ||
const title = | ||
displayName || | ||
user.name || | ||
user.email || | ||
user.username || | ||
user.ipAddress || | ||
// Because this can be used to render EventUser models, or User *interface* | ||
// objects from serialized Event models. we try both ipAddress and ip_address. | ||
user.ip_address; | ||
|
||
return ( | ||
<StyledUserBadge className={className}> | ||
<StyledAvatar user={user} size={avatarSize} /> | ||
<StyledNameAndEmail> | ||
<StyledName | ||
useLink={useLink && !!orgId} | ||
hideEmail={hideEmail} | ||
to={(member && orgId && `/settings/${orgId}/members/${member.id}/`) || ''} | ||
> | ||
{title} | ||
</StyledName> | ||
{!hideEmail && <StyledEmail>{displayEmail || user.email}</StyledEmail>} | ||
</StyledNameAndEmail> | ||
</StyledUserBadge> | ||
); | ||
} | ||
const org = useOrganization({allowNull: true}); | ||
|
||
const StyledUserBadge = styled('div')` | ||
display: flex; | ||
align-items: center; | ||
`; | ||
const membersUrl = | ||
member && org && !disableLink | ||
? `/settings/${org.slug}/members/${member.id}/` | ||
: undefined; | ||
|
||
const StyledNameAndEmail = styled('div')` | ||
flex-shrink: 1; | ||
min-width: 0; | ||
line-height: 1; | ||
`; | ||
|
||
const StyledEmail = styled('div')` | ||
font-size: 0.875em; | ||
margin-top: ${space(0.25)}; | ||
color: ${p => p.theme.gray300}; | ||
${p => p.theme.overflowEllipsis}; | ||
`; | ||
|
||
interface NameProps { | ||
hideEmail: boolean; | ||
to: LinkProps['to']; | ||
useLink: boolean; | ||
children?: React.ReactNode; | ||
return <UserBadge to={membersUrl} user={user} {...props} />; | ||
Comment on lines
+32
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is amazing |
||
} | ||
|
||
const StyledName = styled(({useLink, to, ...props}: NameProps) => { | ||
const forwardProps = omit(props, 'hideEmail'); | ||
return useLink ? <Link to={to} {...forwardProps} /> : <span {...forwardProps} />; | ||
})` | ||
font-weight: ${(p: NameProps) => (p.hideEmail ? 'inherit' : 'bold')}; | ||
line-height: 1.15em; | ||
${p => p.theme.overflowEllipsis}; | ||
`; | ||
|
||
const StyledAvatar = styled(UserAvatar)` | ||
min-width: ${space(3)}; | ||
min-height: ${space(3)}; | ||
margin-right: ${space(1)}; | ||
`; | ||
|
||
export default MemberBadge; |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
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.
Idk if this is properly replacing the margin-right that StyledAvatar had before.
The problem I'm seeing is that the replay breadcrumbItem has no spacing now:

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.
Should look like this:

from https://sentry.sentry.io/replays/6745a47f9add410198126dd92a43983e/?query=&referrer=%2Freplays%2F&statsPeriod=14d&yAxis=count%28%29
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.
waiting to see the combo with #69009, will return to look again!
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.
this will have a merge conflict once #69009 merges