From f6276b3b6fecce2b160ed8bdc62a3e87439249e4 Mon Sep 17 00:00:00 2001 From: Grégoire Aubert Date: Fri, 18 Aug 2017 17:47:37 +0200 Subject: SONAR-9385 SONAR-9436 Replace moment with react-intl --- .../components/issue/components/IssueChangelog.js | 27 ++++---- .../issue/components/IssueCommentLine.js | 4 +- .../components/__tests__/IssueChangelog-test.js | 5 -- .../components/__tests__/IssueCommentLine-test.js | 2 - .../__snapshots__/IssueChangelog-test.js.snap | 72 ++++++++++++++-------- .../__snapshots__/IssueCommentLine-test.js.snap | 21 ++++--- .../js/components/issue/popups/ChangelogPopup.js | 6 +- .../issue/popups/__tests__/ChangelogPopup-test.js | 2 - .../__snapshots__/ChangelogPopup-test.js.snap | 8 ++- 9 files changed, 87 insertions(+), 60 deletions(-) (limited to 'server/sonar-web/src/main/js/components/issue') diff --git a/server/sonar-web/src/main/js/components/issue/components/IssueChangelog.js b/server/sonar-web/src/main/js/components/issue/components/IssueChangelog.js index 721c83ff7e4..404e395479a 100644 --- a/server/sonar-web/src/main/js/components/issue/components/IssueChangelog.js +++ b/server/sonar-web/src/main/js/components/issue/components/IssueChangelog.js @@ -19,9 +19,11 @@ */ // @flow import React from 'react'; -import moment from 'moment'; +import { FormattedRelative } from 'react-intl'; import BubblePopupHelper from '../../../components/common/BubblePopupHelper'; import ChangelogPopup from '../popups/ChangelogPopup'; +import DateTimeFormatter from '../../../components/intl/DateTimeFormatter'; +import Tooltip from '../../../components/controls/Tooltip'; /*:: import type { Issue } from '../types'; */ /*:: @@ -47,22 +49,25 @@ export default class IssueChangelog extends React.PureComponent { }; render() { - const momentCreationDate = moment(this.props.creationDate); return ( }> - + } + placement="left" + mouseEnterDelay={0.5}> + + ); } 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 54836503b39..51865ad5850 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 @@ -19,7 +19,7 @@ */ // @flow import React from 'react'; -import moment from 'moment'; +import { FormattedRelative } from 'react-intl'; import Avatar from '../../../components/ui/Avatar'; import BubblePopupHelper from '../../../components/common/BubblePopupHelper'; import CommentDeletePopup from '../popups/CommentDeletePopup'; @@ -98,7 +98,7 @@ export default class IssueCommentLine extends React.PureComponent { tabIndex={0} />
- ({moment(comment.createdAt).fromNow()}) +
{comment.updatable && diff --git a/server/sonar-web/src/main/js/components/issue/components/__tests__/IssueChangelog-test.js b/server/sonar-web/src/main/js/components/issue/components/__tests__/IssueChangelog-test.js index 446dc8bcea4..65c2c001f3a 100644 --- a/server/sonar-web/src/main/js/components/issue/components/__tests__/IssueChangelog-test.js +++ b/server/sonar-web/src/main/js/components/issue/components/__tests__/IssueChangelog-test.js @@ -28,11 +28,6 @@ const issue = { creationDate: '2017-03-01T09:36:01+0100' }; -jest.mock('moment', () => () => ({ - format: () => 'March 1, 2017 9:36 AM', - fromNow: () => 'a month ago' -})); - it('should render correctly', () => { const element = shallow( () => ({ fromNow: () => 'a month ago' })); - it('should render correctly a comment that is not updatable', () => { const element = shallow( - + + + + + + `; @@ -62,19 +74,31 @@ exports[`should render correctly 1`] = ` position="bottomright" togglePopup={[Function]} > - + + + + + + `; diff --git a/server/sonar-web/src/main/js/components/issue/components/__tests__/__snapshots__/IssueCommentLine-test.js.snap b/server/sonar-web/src/main/js/components/issue/components/__tests__/__snapshots__/IssueCommentLine-test.js.snap index 9d4ea6fa3aa..a3b7b63d015 100644 --- a/server/sonar-web/src/main/js/components/issue/components/__tests__/__snapshots__/IssueCommentLine-test.js.snap +++ b/server/sonar-web/src/main/js/components/issue/components/__tests__/__snapshots__/IssueCommentLine-test.js.snap @@ -42,9 +42,10 @@ exports[`should open the right popups when the buttons are clicked 3`] = `
- ( - a month ago - ) +
- ( - a month ago - ) +
- ( - a month ago - ) +
- {moment(issue.creationDate).format('LLL')} + {author ? `${translate('created_by')} ${author}` : translate('created')} @@ -96,7 +96,7 @@ export default class ChangelogPopup extends React.PureComponent { {this.state.changelogs.map((item, idx) => - {moment(item.creationDate).format('LLL')} + {item.userName && diff --git a/server/sonar-web/src/main/js/components/issue/popups/__tests__/ChangelogPopup-test.js b/server/sonar-web/src/main/js/components/issue/popups/__tests__/ChangelogPopup-test.js index 35d5c05b5f2..6c4f9d5977e 100644 --- a/server/sonar-web/src/main/js/components/issue/popups/__tests__/ChangelogPopup-test.js +++ b/server/sonar-web/src/main/js/components/issue/popups/__tests__/ChangelogPopup-test.js @@ -21,8 +21,6 @@ import { shallow } from 'enzyme'; import React from 'react'; import ChangelogPopup from '../ChangelogPopup'; -jest.mock('moment', () => () => ({ format: () => 'March 1, 2017 9:36 AM' })); - it('should render the changelog popup correctly', () => { const element = shallow( - March 1, 2017 9:36 AM + - March 1, 2017 9:36 AM +