Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 30bc7ce

Browse files
committed
PullRequestReviewCommentsView > PullRequestReviewCommentThreadView
Rework PullRequestReviewCommentsView to render a single comment thread at a time. Rename it to PullRequestReviewCommentThreadView which is a mouthful, but a more accurate description of what it does.
1 parent 9bec06a commit 30bc7ce

File tree

2 files changed

+54
-60
lines changed

2 files changed

+54
-60
lines changed

lib/views/pr-review-comments-view.js renamed to lib/views/pr-review-comment-thread-view.js

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,55 +10,51 @@ import Octicon from '../atom/octicon';
1010
import GithubDotcomMarkdown from './github-dotcom-markdown';
1111
import Timeago from './timeago';
1212

13-
export default class PullRequestCommentsView extends React.Component {
13+
export default class PullRequestReviewCommentThreadView extends React.Component {
1414
static propTypes = {
15-
commentThreads: PropTypes.arrayOf(PropTypes.shape({
15+
commentThread: PropTypes.shape({
1616
rootCommentId: PropTypes.string.isRequired,
1717
comments: PropTypes.arrayOf(PropTypes.object).isRequired,
18-
})),
18+
}),
1919
getBufferRowForDiffPosition: PropTypes.func.isRequired,
2020
switchToIssueish: PropTypes.func.isRequired,
2121
isPatchVisible: PropTypes.func.isRequired,
2222
}
2323

2424
render() {
25-
return [...this.props.commentThreads].map(({rootCommentId, comments}) => {
26-
const rootComment = comments[0];
27-
if (!rootComment.position) {
28-
return null;
29-
}
25+
const {rootCommentId, comments} = this.props.commentThread;
26+
const rootComment = comments[0];
27+
if (!rootComment.position) {
28+
return null;
29+
}
3030

31-
// if file patch is collapsed or too large, do not render the comments
32-
if (!this.props.isPatchVisible(rootComment.path)) {
33-
return null;
34-
}
31+
// if file patch is collapsed or too large, do not render the comments
32+
if (!this.props.isPatchVisible(rootComment.path)) {
33+
return null;
34+
}
3535

36-
const nativePath = toNativePathSep(rootComment.path);
37-
const row = this.props.getBufferRowForDiffPosition(nativePath, rootComment.position);
38-
const point = new Point(row, 0);
39-
const range = new Range(point, point);
40-
return (
41-
<Marker key={`pr-comment-${rootCommentId}`} bufferRange={range} invalidate="never">
42-
<Decoration type="block" position="after" className="github-PrCommentThread">
43-
{comments.map(comment => {
44-
return (
45-
<PullRequestCommentView
46-
key={comment.id}
47-
comment={comment}
48-
switchToIssueish={this.props.switchToIssueish}
49-
/>
50-
);
51-
})}
52-
</Decoration>
53-
</Marker>
54-
);
55-
});
36+
const nativePath = toNativePathSep(rootComment.path);
37+
const row = this.props.getBufferRowForDiffPosition(nativePath, rootComment.position);
38+
const point = new Point(row, 0);
39+
const range = new Range(point, point);
40+
return (
41+
<Marker key={`pr-comment-${rootCommentId}`} bufferRange={range} invalidate="never">
42+
<Decoration type="block" position="after" className="github-PrCommentThread">
43+
{comments.map(comment => (
44+
<PullRequestCommentView
45+
key={comment.id}
46+
comment={comment}
47+
switchToIssueish={this.props.switchToIssueish}
48+
/>
49+
))}
50+
</Decoration>
51+
</Marker>
52+
);
5653
}
5754
}
5855

5956
export class PullRequestCommentView extends React.Component {
6057
static propTypes = {
61-
switchToIssueish: PropTypes.func.isRequired,
6258
comment: PropTypes.shape({
6359
author: PropTypes.shape({
6460
avatarUrl: PropTypes.string,
@@ -69,6 +65,7 @@ export class PullRequestCommentView extends React.Component {
6965
createdAt: PropTypes.string.isRequired,
7066
isMinimized: PropTypes.bool.isRequired,
7167
}).isRequired,
68+
switchToIssueish: PropTypes.func.isRequired,
7269
}
7370

7471
render() {

test/views/pr-comments-view.test.js renamed to test/views/pr-review-comment-thread-view.test.js

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,21 @@ import {shallow} from 'enzyme';
33

44
import {multiFilePatchBuilder} from '../builder/patch';
55
import {pullRequestBuilder} from '../builder/pr';
6-
import PullRequestCommentsView, {PullRequestCommentView} from '../../lib/views/pr-review-comments-view';
7-
8-
describe('PullRequestCommentsView', function() {
9-
function buildApp(multiFilePatch, pullRequest, overrideProps) {
10-
const relay = {
11-
hasMore: () => {},
12-
loadMore: () => {},
13-
isLoading: () => {},
14-
};
6+
import PullRequestReviewCommentThreadView, {PullRequestCommentView} from '../../lib/views/pr-review-comment-thread-view';
7+
8+
describe('PullRequestReviewCommentThreadView', function() {
9+
function buildApp(multiFilePatch, commentThread, overrideProps = {}) {
1510
return shallow(
16-
<PullRequestCommentsView
17-
isPatchVisible={sinon.stub().returns(true)}
18-
getBufferRowForDiffPosition={multiFilePatch.getBufferRowForDiffPosition} reviews={pullRequest.reviews}
19-
commentThreads={pullRequest.commentThreads}
20-
relay={relay}
11+
<PullRequestReviewCommentThreadView
12+
isPatchVisible={() => true}
13+
getBufferRowForDiffPosition={multiFilePatch.getBufferRowForDiffPosition}
14+
commentThread={commentThread}
2115
switchToIssueish={() => {}}
2216
{...overrideProps}
2317
/>,
2418
);
2519
}
20+
2621
it('adjusts the position for comments after hunk headers', function() {
2722
const {multiFilePatch} = multiFilePatchBuilder()
2823
.addFilePatch(fp => {
@@ -48,11 +43,14 @@ describe('PullRequestCommentsView', function() {
4843
})
4944
.build();
5045

51-
const wrapper = buildApp(multiFilePatch, pr, {});
46+
const wrapper0 = buildApp(multiFilePatch, pr.commentThreads[0]);
47+
assert.deepEqual(wrapper0.find('Marker').prop('bufferRange').serialize(), [[1, 0], [1, 0]]);
5248

53-
assert.deepEqual(wrapper.find('Marker').at(0).prop('bufferRange').serialize(), [[1, 0], [1, 0]]);
54-
assert.deepEqual(wrapper.find('Marker').at(1).prop('bufferRange').serialize(), [[12, 0], [12, 0]]);
55-
assert.deepEqual(wrapper.find('Marker').at(2).prop('bufferRange').serialize(), [[20, 0], [20, 0]]);
49+
const wrapper1 = buildApp(multiFilePatch, pr.commentThreads[1]);
50+
assert.deepEqual(wrapper1.find('Marker').prop('bufferRange').serialize(), [[12, 0], [12, 0]]);
51+
52+
const wrapper2 = buildApp(multiFilePatch, pr.commentThreads[2]);
53+
assert.deepEqual(wrapper2.find('Marker').prop('bufferRange').serialize(), [[20, 0], [20, 0]]);
5654
});
5755

5856
it('does not render comment if patch is too large or collapsed', function() {
@@ -64,9 +62,8 @@ describe('PullRequestCommentsView', function() {
6462
})
6563
.build();
6664

67-
const wrapper = buildApp(multiFilePatch, pr, {isPatchVisible: () => { return false; }});
68-
const comments = wrapper.find('PullRequestCommentView');
69-
assert.lengthOf(comments, 0);
65+
const wrapper = buildApp(multiFilePatch, pr.commentThreads[0], {isPatchVisible: () => false});
66+
assert.isFalse(wrapper.exists('PullRequestCommentView'));
7067
});
7168

7269
it('does not render comment if position is null', function() {
@@ -88,11 +85,11 @@ describe('PullRequestCommentsView', function() {
8885
})
8986
.build();
9087

91-
const wrapper = buildApp(multiFilePatch, pr, {});
88+
const wrapper = buildApp(multiFilePatch, pr.commentThreads[0]);
9289

9390
const comments = wrapper.find('PullRequestCommentView');
9491
assert.lengthOf(comments, 1);
95-
assert.strictEqual(comments.at(0).prop('comment').body, 'one');
92+
assert.strictEqual(comments.prop('comment').body, 'one');
9693
});
9794
});
9895

@@ -132,7 +129,7 @@ describe('PullRequestCommentView', function() {
132129
assert.strictEqual(avatar.getElement('src').props.src, avatarUrl);
133130
assert.strictEqual(avatar.getElement('alt').props.alt, login);
134131

135-
assert.isTrue(wrapper.text().includes(`${login} commented`));
132+
assert.include(wrapper.text(), `${login} commented`);
136133

137134
const a = wrapper.find('.github-PrComment-timeAgo');
138135
assert.strictEqual(a.getElement('href').props.href, commentUrl);
@@ -147,12 +144,12 @@ describe('PullRequestCommentView', function() {
147144

148145
it('contains the text `someone commented` for null authors', function() {
149146
const wrapper = shallow(buildApp({author: null}));
150-
assert.isTrue(wrapper.text().includes('someone commented'));
147+
assert.include(wrapper.text(), 'someone commented');
151148
});
152149

153150
it('hides minimized comment', function() {
154151
const wrapper = shallow(buildApp({isMinimized: true}));
155-
assert.isTrue(wrapper.find('.github-PrComment-hidden').exists());
156-
assert.isFalse(wrapper.find('.github-PrComment-header').exists());
152+
assert.isTrue(wrapper.exists('.github-PrComment-hidden'));
153+
assert.isFalse(wrapper.exists('.github-PrComment-header'));
157154
});
158155
});

0 commit comments

Comments
 (0)