forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathissueish-searches-controller.js
More file actions
130 lines (115 loc) · 4.07 KB
/
issueish-searches-controller.js
File metadata and controls
130 lines (115 loc) · 4.07 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import React from 'react';
import PropTypes from 'prop-types';
import {shell} from 'electron';
import {
RemotePropType, RemoteSetPropType, BranchSetPropType, OperationStateObserverPropType, EndpointPropType,
} from '../prop-types';
import Search from '../models/search';
import IssueishSearchContainer from '../containers/issueish-search-container';
import CurrentPullRequestContainer from '../containers/current-pull-request-container';
import IssueishDetailItem from '../items/issueish-detail-item';
import ReviewsItem from '../items/reviews-item';
import {addEvent} from '../reporter-proxy';
export default class IssueishSearchesController extends React.Component {
static propTypes = {
// Relay payload
repository: PropTypes.shape({
id: PropTypes.string.isRequired,
defaultBranchRef: PropTypes.shape({
prefix: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
}),
}),
// Connection
endpoint: EndpointPropType.isRequired,
token: PropTypes.string.isRequired,
// Atom environment
workspace: PropTypes.object.isRequired,
// Repository model attributes
remoteOperationObserver: OperationStateObserverPropType.isRequired,
workingDirectory: PropTypes.string,
remote: RemotePropType.isRequired,
remotes: RemoteSetPropType.isRequired,
branches: BranchSetPropType.isRequired,
aheadCount: PropTypes.number,
pushInProgress: PropTypes.bool.isRequired,
// Actions
onCreatePr: PropTypes.func.isRequired,
}
state = {};
static getDerivedStateFromProps(props) {
return {
searches: [
Search.inRemote(props.remote, 'Open pull requests', 'type:pr state:open'),
],
};
}
render() {
return (
<div className="github-IssueishSearch">
<CurrentPullRequestContainer
repository={this.props.repository}
token={this.props.token}
endpoint={this.props.endpoint}
remoteOperationObserver={this.props.remoteOperationObserver}
remote={this.props.remote}
remotes={this.props.remotes}
branches={this.props.branches}
aheadCount={this.props.aheadCount}
pushInProgress={this.props.pushInProgress}
workspace={this.props.workspace}
workingDirectory={this.props.workingDirectory}
onOpenIssueish={this.onOpenIssueish}
onOpenReviews={this.onOpenReviews}
onCreatePr={this.props.onCreatePr}
/>
{this.state.searches.map(search => (
<IssueishSearchContainer
key={search.getName()}
token={this.props.token}
endpoint={this.props.endpoint}
search={search}
remoteOperationObserver={this.props.remoteOperationObserver}
onOpenIssueish={this.onOpenIssueish}
onOpenSearch={this.onOpenSearch}
onOpenReviews={this.onOpenReviews}
/>
))}
</div>
);
}
onOpenReviews = issueish => {
const uri = ReviewsItem.buildURI({
host: this.props.endpoint.getHost(),
owner: this.props.remote.getOwner(),
repo: this.props.remote.getRepo(),
number: issueish.getNumber(),
workdir: this.props.workingDirectory,
});
return this.props.workspace.open(uri).then(() => {
addEvent('open-reviews-tab', {package: 'github', from: this.constructor.name});
});
}
onOpenIssueish = issueish => {
return this.props.workspace.open(
IssueishDetailItem.buildURI({
host: this.props.endpoint.getHost(),
owner: this.props.remote.getOwner(),
repo: this.props.remote.getRepo(),
number: issueish.getNumber(),
workdir: this.props.workingDirectory,
}),
{pending: true, searchAllPanes: true},
).then(() => {
addEvent('open-issueish-in-pane', {package: 'github', from: 'issueish-list'});
});
}
onOpenSearch = search => {
const searchURL = search.getWebURL(this.props.remote);
return new Promise((resolve, reject) => {
shell.openExternal(searchURL, {}, err => {
if (err) { reject(err); } else { resolve(); }
});
});
}
}