forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaggregated-reviews-container.js
143 lines (129 loc) · 3.96 KB
/
aggregated-reviews-container.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import React from 'react';
import {Emitter} from 'event-kit';
import {graphql, createRefetchContainer} from 'react-relay';
import PropTypes from 'prop-types';
import {PAGE_SIZE} from '../helpers';
import ReviewSummariesAccumulator from './accumulators/review-summaries-accumulator';
import ReviewThreadsAccumulator from './accumulators/review-threads-accumulator';
export class BareAggregatedReviewsContainer extends React.Component {
static propTypes = {
// Relay response
relay: PropTypes.shape({
refetch: PropTypes.func.isRequired,
}),
// Relay results.
pullRequest: PropTypes.shape({
id: PropTypes.string.isRequired,
}).isRequired,
// Render prop. Called with {errors, summaries, commentThreads, loading}.
children: PropTypes.func.isRequired,
// only fetch summaries when we specify a summariesRenderer
summariesRenderer: PropTypes.func,
// Report errors during refetch
reportRelayError: PropTypes.func.isRequired,
}
constructor(props) {
super(props);
this.emitter = new Emitter();
}
render() {
return (
<ReviewSummariesAccumulator
onDidRefetch={this.onDidRefetch}
pullRequest={this.props.pullRequest}>
{({error: summaryError, summaries, loading: summariesLoading}) => {
return (
<ReviewThreadsAccumulator
onDidRefetch={this.onDidRefetch}
pullRequest={this.props.pullRequest}>
{payload => {
const result = {
errors: [],
refetch: this.refetch,
summaries,
commentThreads: payload.commentThreads,
loading: payload.loading || summariesLoading,
};
if (summaryError) {
result.errors.push(summaryError);
}
result.errors.push(...payload.errors);
return this.props.children(result);
}}
</ReviewThreadsAccumulator>
);
}}
</ReviewSummariesAccumulator>
);
}
refetch = callback => this.props.relay.refetch(
{
prId: this.props.pullRequest.id,
reviewCount: PAGE_SIZE,
reviewCursor: null,
threadCount: PAGE_SIZE,
threadCursor: null,
commentCount: PAGE_SIZE,
commentCursor: null,
},
null,
err => {
if (err) {
this.props.reportRelayError('Unable to refresh reviews', err);
} else {
this.emitter.emit('did-refetch');
}
callback();
},
{force: true},
);
onDidRefetch = callback => this.emitter.on('did-refetch', callback);
}
export default createRefetchContainer(BareAggregatedReviewsContainer, {
pullRequest: graphql`
fragment aggregatedReviewsContainer_pullRequest on PullRequest
@argumentDefinitions(
reviewCount: {type: "Int!"}
reviewCursor: {type: "String"}
threadCount: {type: "Int!"}
threadCursor: {type: "String"}
commentCount: {type: "Int!"}
commentCursor: {type: "String"}
) {
id
...reviewSummariesAccumulator_pullRequest @arguments(
reviewCount: $reviewCount
reviewCursor: $reviewCursor
)
...reviewThreadsAccumulator_pullRequest @arguments(
threadCount: $threadCount
threadCursor: $threadCursor
commentCount: $commentCount
commentCursor: $commentCursor
)
}
`,
}, graphql`
query aggregatedReviewsContainerRefetchQuery
(
$prId: ID!
$reviewCount: Int!
$reviewCursor: String
$threadCount: Int!
$threadCursor: String
$commentCount: Int!
$commentCursor: String
) {
pullRequest: node(id: $prId) {
...prCheckoutController_pullRequest
...aggregatedReviewsContainer_pullRequest @arguments(
reviewCount: $reviewCount
reviewCursor: $reviewCursor
threadCount: $threadCount
threadCursor: $threadCursor
commentCount: $commentCount
commentCursor: $commentCursor
)
}
}
`);