Skip to content

fix: Fix tooltip if either release commits has no author, or if an author's name/email of a commit contains just whitespace. #13707

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
merged 1 commit into from
Jun 17, 2019
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
2 changes: 2 additions & 0 deletions src/sentry/static/sentry/app/components/avatar/userAvatar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class UserAvatar extends React.Component {
tooltip={
typeof renderTooltip === 'function'
? renderTooltip(user)
: props.tooltip
Copy link
Member Author

Choose a reason for hiding this comment

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

@markstory @billyvg The tooltip prop wasn't properly forwarded from here

So, I'm fixing that here in case this component was consumed with a tooltip prop.

? props.tooltip
: userDisplayName(user)
}
title={user.name || user.email || user.username || ''}
Expand Down
15 changes: 13 additions & 2 deletions src/sentry/static/sentry/app/utils/formatters.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import {get} from 'lodash';

import {t} from 'app/locale';

export function userDisplayName(user) {
let displayName = user.name;
if (user.email && user.email !== user.name) {
let displayName = String(get(user, 'name', t('Unknown author'))).trim();

if (displayName.length <= 0) {
displayName = t('Unknown author');
}

const email = String(get(user, 'email', '')).trim();

if (email.length > 0 && email !== displayName) {
displayName += ' (' + user.email + ')';
}
return displayName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,7 @@ class CommitAuthorStats extends React.Component {
return (
<PanelItem key={i} p={1} align="center">
<Flex>
<Avatar
user={author}
size={20}
hasTooltip
tooltip={`${author.name} ${author.email}`}
/>
<Avatar user={author} size={20} hasTooltip />
Copy link
Member Author

Choose a reason for hiding this comment

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

@markstory I'm removing tooltip here since it wasn't being used or forwarded at all. I've fixed that in this PR.

In addition, I removed it overall since the fallback tooltip that uses userDisplayName() seems better.

</Flex>
<Flex flex="1" px={1}>
<CommitBar
Expand Down
29 changes: 29 additions & 0 deletions tests/js/spec/helpers/formatters.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,34 @@ describe('formatters', function() {
})
).toEqual('user (foo@bar.com)');
});

it('should show unknown author with email, if email is only provided', function() {
expect(
userDisplayName({
email: 'foo@bar.com',
})
).toEqual('Unknown author (foo@bar.com)');
});

it('should show unknown author, if author or email is just whitespace', function() {
Copy link
Member Author

@dashed dashed Jun 17, 2019

Choose a reason for hiding this comment

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

I don't have a strong opinion on this. If an author name is intentionally whitespace, I can adjust the userDisplayName() to display it.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think explicit whitespace is a use case we need to afford.

expect(
userDisplayName({
// eslint-disable-next-line quotes
name: `\t\n `,
})
).toEqual('Unknown author');

expect(
userDisplayName({
// eslint-disable-next-line quotes
email: `\t\n `,
})
).toEqual('Unknown author');
});

it('should show unknown author, if user object is either not an object or incomplete', function() {
expect(userDisplayName()).toEqual('Unknown author');
expect(userDisplayName({})).toEqual('Unknown author');
});
});
});