This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
/
review-summaries-accumulator.js
110 lines (102 loc) · 2.72 KB
/
review-summaries-accumulator.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
import React from 'react';
import PropTypes from 'prop-types';
import {graphql, createPaginationContainer} from 'react-relay';
import {PAGE_SIZE, PAGINATION_WAIT_TIME_MS} from '../../helpers';
import {RelayConnectionPropType} from '../../prop-types';
import Accumulator from './accumulator';
class ReviewSummariesAccumulator extends React.Component {
static propTypes = {
// Relay props
relay: PropTypes.shape({
hasMore: PropTypes.func.isRequired,
loadMore: PropTypes.func.isRequired,
isLoading: PropTypes.func.isRequired,
}).isRequired,
pullRequest: PropTypes.shape({
reviews: RelayConnectionPropType(
PropTypes.object,
),
}),
// Render prop. Called with (error or null, array of all reviews, loading)
children: PropTypes.func,
// Non-render callback prop. Called with (error or null, array of all reviews, loading)
handleResults: PropTypes.func,
}
render() {
const resultBatch = this.props.pullRequest.reviews.edges.map(edge => edge.node);
return (
<Accumulator
relay={this.props.relay}
resultBatch={resultBatch}
handleResults={this.props.handleResults}
pageSize={PAGE_SIZE}
waitTimeMs={PAGINATION_WAIT_TIME_MS}>
{this.props.children}
</Accumulator>
);
}
}
export default createPaginationContainer(ReviewSummariesAccumulator, {
pullRequest: graphql`
fragment reviewSummariesAccumulator_pullRequest on PullRequest
@argumentDefinitions(
reviewCount: {type: "Int!"}
reviewCursor: {type: "String"},
) {
url
reviews(
first: $reviewCount
after: $reviewCursor
) @connection(key: "ReviewSummariesAccumulator_reviews") {
pageInfo {
hasNextPage
endCursor
}
edges {
cursor
node {
id
body
state
submittedAt
author {
login
avatarUrl
}
}
}
}
}
`,
}, {
direction: 'forward',
getConnectionFromProps(props) {
return props.pullRequest.reviews;
},
getFragmentVariables(prevVars, totalCount) {
return {...prevVars, totalCount};
},
getVariables(props, {count, cursor}) {
return {
url: props.pullRequest.url,
reviewCount: count,
reviewCursor: cursor,
};
},
query: graphql`
query reviewSummariesAccumulatorQuery(
$url: URI!
$reviewCount: Int!
$reviewCursor: String
) {
resource(url: $url) {
... on PullRequest {
...reviewSummariesAccumulator_pullRequest @arguments(
reviewCount: $reviewCount
reviewCursor: $reviewCursor
)
}
}
}
`,
});