From d52c0e31c2232e3ad14c8fc0a9240cb7dfddfda0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gr=C3=A9goire=20Aubert?= Date: Tue, 22 May 2018 14:31:19 +0200 Subject: [PATCH] SONAR-10692 Don't break the issues page if a user is missing --- .../src/main/js/components/issue/components/IssueAssign.js | 4 ++-- .../js/components/issue/components/IssueCommentLine.js | 7 ++++--- .../main/js/components/issue/popups/SimilarIssuesPopup.js | 4 ++-- server/sonar-web/src/main/js/components/ui/Avatar.js | 5 ++++- .../src/main/js/components/ui/__tests__/Avatar-test.js | 7 +++++++ .../ui/__tests__/__snapshots__/Avatar-test.js.snap | 2 ++ 6 files changed, 21 insertions(+), 8 deletions(-) diff --git a/server/sonar-web/src/main/js/components/issue/components/IssueAssign.js b/server/sonar-web/src/main/js/components/issue/components/IssueAssign.js index ba6e67dda76..3f9ed2a47df 100644 --- a/server/sonar-web/src/main/js/components/issue/components/IssueAssign.js +++ b/server/sonar-web/src/main/js/components/issue/components/IssueAssign.js @@ -52,13 +52,13 @@ export default class IssueAssign extends React.PureComponent { )} - {issue.assignee ? issue.assigneeName : translate('unassigned')} + {issue.assignee ? issue.assigneeName || issue.assignee : translate('unassigned')} ); diff --git a/server/sonar-web/src/main/js/components/issue/components/IssueCommentLine.js b/server/sonar-web/src/main/js/components/issue/components/IssueCommentLine.js index f6c73044282..462f89f30c3 100644 --- a/server/sonar-web/src/main/js/components/issue/components/IssueCommentLine.js +++ b/server/sonar-web/src/main/js/components/issue/components/IssueCommentLine.js @@ -79,16 +79,17 @@ export default class IssueCommentLine extends React.PureComponent { render() { const { comment } = this.props; + const authorName = comment.authorName || comment.author; return (
-
+
- {comment.authorName} + {authorName}
- {issue.assigneeName} + {issue.assigneeName || issue.assignee} ) : ( translate('unassigned') diff --git a/server/sonar-web/src/main/js/components/ui/Avatar.js b/server/sonar-web/src/main/js/components/ui/Avatar.js index 448fb782f4b..62e6b1b68d9 100644 --- a/server/sonar-web/src/main/js/components/ui/Avatar.js +++ b/server/sonar-web/src/main/js/components/ui/Avatar.js @@ -52,7 +52,7 @@ class Avatar extends React.PureComponent { gravatarServerUrl: PropTypes.string.isRequired, email: PropTypes.string, hash: PropTypes.string, - name: PropTypes.string.isRequired, + name: PropTypes.string, size: PropTypes.number.isRequired, className: PropTypes.string }; @@ -91,6 +91,9 @@ class Avatar extends React.PureComponent { render() { if (!this.props.enableGravatar) { + if (!this.props.name) { + return null; + } return this.renderFallback(); } diff --git a/server/sonar-web/src/main/js/components/ui/__tests__/Avatar-test.js b/server/sonar-web/src/main/js/components/ui/__tests__/Avatar-test.js index 044e07240b1..4b0aba8018f 100644 --- a/server/sonar-web/src/main/js/components/ui/__tests__/Avatar-test.js +++ b/server/sonar-web/src/main/js/components/ui/__tests__/Avatar-test.js @@ -55,3 +55,10 @@ it('falls back to dummy avatar', () => { ); expect(avatar).toMatchSnapshot(); }); + +it('do not fail when name is missing', () => { + const avatar = shallow( + + ); + expect(avatar).toMatchSnapshot(); +}); diff --git a/server/sonar-web/src/main/js/components/ui/__tests__/__snapshots__/Avatar-test.js.snap b/server/sonar-web/src/main/js/components/ui/__tests__/__snapshots__/Avatar-test.js.snap index d51b5ecabcb..6ea16cecc3f 100644 --- a/server/sonar-web/src/main/js/components/ui/__tests__/__snapshots__/Avatar-test.js.snap +++ b/server/sonar-web/src/main/js/components/ui/__tests__/__snapshots__/Avatar-test.js.snap @@ -1,5 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`do not fail when name is missing 1`] = `null`; + exports[`falls back to dummy avatar 1`] = `