forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpr-changed-files-container.js
More file actions
115 lines (95 loc) · 3.19 KB
/
pr-changed-files-container.js
File metadata and controls
115 lines (95 loc) · 3.19 KB
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
import React from 'react';
import PropTypes from 'prop-types';
import {CompositeDisposable} from 'event-kit';
import {ItemTypePropType, EndpointPropType} from '../prop-types';
import PullRequestPatchContainer from './pr-patch-container';
import MultiFilePatchController from '../controllers/multi-file-patch-controller';
import LoadingView from '../views/loading-view';
import ErrorView from '../views/error-view';
export default class PullRequestChangedFilesContainer extends React.Component {
static propTypes = {
// Pull request properties
owner: PropTypes.string.isRequired,
repo: PropTypes.string.isRequired,
number: PropTypes.number.isRequired,
// Connection properties
endpoint: EndpointPropType.isRequired,
token: PropTypes.string.isRequired,
// Item context
itemType: ItemTypePropType.isRequired,
// action methods
destroy: PropTypes.func.isRequired,
// Atom environment
workspace: PropTypes.object.isRequired,
commands: PropTypes.object.isRequired,
keymaps: PropTypes.object.isRequired,
tooltips: PropTypes.object.isRequired,
config: PropTypes.object.isRequired,
// local repo as opposed to pull request repo
localRepository: PropTypes.object.isRequired,
workdirPath: PropTypes.string,
// Review comment threads
reviewCommentsLoading: PropTypes.bool.isRequired,
reviewCommentThreads: PropTypes.arrayOf(PropTypes.shape({
thread: PropTypes.object.isRequired,
comments: PropTypes.arrayOf(PropTypes.object).isRequired,
})).isRequired,
// refetch diff on refresh
shouldRefetch: PropTypes.bool.isRequired,
// For opening files changed tab
initChangedFilePath: PropTypes.string,
initChangedFilePosition: PropTypes.number,
onOpenFilesTab: PropTypes.func.isRequired,
}
constructor(props) {
super(props);
this.lastPatch = {
patch: null,
subs: new CompositeDisposable(),
};
}
componentWillUnmount() {
this.lastPatch.subs.dispose();
}
render() {
const patchProps = {
owner: this.props.owner,
repo: this.props.repo,
number: this.props.number,
endpoint: this.props.endpoint,
token: this.props.token,
refetch: this.props.shouldRefetch,
};
return (
<PullRequestPatchContainer {...patchProps}>
{this.renderPatchResult}
</PullRequestPatchContainer>
);
}
renderPatchResult = (error, multiFilePatch) => {
if (error === null && multiFilePatch === null) {
return <LoadingView />;
}
if (error !== null) {
return <ErrorView descriptions={[error]} />;
}
if (multiFilePatch !== this.lastPatch.patch) {
this.lastPatch.subs.dispose();
this.lastPatch = {
subs: new CompositeDisposable(
...multiFilePatch.getFilePatches().map(fp => fp.onDidChangeRenderStatus(() => this.forceUpdate())),
),
patch: multiFilePatch,
};
}
return (
<MultiFilePatchController
multiFilePatch={multiFilePatch}
repository={this.props.localRepository}
reviewCommentsLoading={this.props.reviewCommentsLoading}
reviewCommentThreads={this.props.reviewCommentThreads}
{...this.props}
/>
);
}
}