forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub-tab-view.js
186 lines (164 loc) · 5.79 KB
/
github-tab-view.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import React from 'react';
import PropTypes from 'prop-types';
import {
TokenPropType, EndpointPropType, RefHolderPropType,
RemoteSetPropType, RemotePropType, BranchSetPropType, BranchPropType,
RefresherPropType,
} from '../prop-types';
import LoadingView from './loading-view';
import QueryErrorView from '../views/query-error-view';
import GithubLoginView from '../views/github-login-view';
import RemoteSelectorView from './remote-selector-view';
import GithubTabHeaderContainer from '../containers/github-tab-header-container';
import GitHubBlankNoLocal from './github-blank-nolocal';
import GitHubBlankUninitialized from './github-blank-uninitialized';
import GitHubBlankNoRemote from './github-blank-noremote';
import RemoteContainer from '../containers/remote-container';
import {UNAUTHENTICATED, INSUFFICIENT} from '../shared/keytar-strategy';
export default class GitHubTabView extends React.Component {
static propTypes = {
refresher: RefresherPropType.isRequired,
rootHolder: RefHolderPropType.isRequired,
// Connection
endpoint: EndpointPropType.isRequired,
token: TokenPropType,
// Workspace
workspace: PropTypes.object.isRequired,
workingDirectory: PropTypes.string,
getCurrentWorkDirs: PropTypes.func.isRequired,
changeWorkingDirectory: PropTypes.func.isRequired,
contextLocked: PropTypes.bool.isRequired,
setContextLock: PropTypes.func.isRequired,
repository: PropTypes.object.isRequired,
// Remotes
remotes: RemoteSetPropType.isRequired,
currentRemote: RemotePropType.isRequired,
manyRemotesAvailable: PropTypes.bool.isRequired,
isLoading: PropTypes.bool.isRequired,
branches: BranchSetPropType.isRequired,
currentBranch: BranchPropType.isRequired,
aheadCount: PropTypes.number,
pushInProgress: PropTypes.bool.isRequired,
// Event Handlers
handleLogin: PropTypes.func.isRequired,
handleLogout: PropTypes.func.isRequired,
handleTokenRetry: PropTypes.func.isRequired,
handleWorkDirSelect: PropTypes.func,
handlePushBranch: PropTypes.func.isRequired,
handleRemoteSelect: PropTypes.func.isRequired,
onDidChangeWorkDirs: PropTypes.func.isRequired,
openCreateDialog: PropTypes.func.isRequired,
openBoundPublishDialog: PropTypes.func.isRequired,
openCloneDialog: PropTypes.func.isRequired,
openGitTab: PropTypes.func.isRequired,
}
render() {
return (
<div className="github-GitHub" ref={this.props.rootHolder.setter}>
{this.renderHeader()}
<div className="github-GitHub-content">
{this.renderRemote()}
</div>
</div>
);
}
renderRemote() {
if (this.props.token === null) {
return <LoadingView />;
}
if (this.props.token === UNAUTHENTICATED) {
return <GithubLoginView onLogin={this.props.handleLogin} />;
}
if (this.props.token === INSUFFICIENT) {
return (
<GithubLoginView onLogin={this.props.handleLogin}>
<p>
Your token no longer has sufficient authorizations. Please re-authenticate and generate a new one.
</p>
</GithubLoginView>
);
}
if (this.props.token instanceof Error) {
return (
<QueryErrorView
error={this.props.token}
retry={this.props.handleTokenRetry}
login={this.props.handleLogin}
logout={this.props.handleLogout}
/>
);
}
if (this.props.isLoading) {
return <LoadingView />;
}
if (this.props.repository.isAbsent() || this.props.repository.isAbsentGuess()) {
return (
<GitHubBlankNoLocal
openCreateDialog={this.props.openCreateDialog}
openCloneDialog={this.props.openCloneDialog}
/>
);
}
if (this.props.repository.isEmpty()) {
return (
<GitHubBlankUninitialized
openBoundPublishDialog={this.props.openBoundPublishDialog}
openGitTab={this.props.openGitTab}
/>
);
}
if (this.props.currentRemote.isPresent()) {
// Single, chosen or unambiguous remote
return (
<RemoteContainer
// Connection
endpoint={this.props.currentRemote.getEndpoint()}
token={this.props.token}
// Repository attributes
refresher={this.props.refresher}
pushInProgress={this.props.pushInProgress}
workingDirectory={this.props.workingDirectory}
workspace={this.props.workspace}
remote={this.props.currentRemote}
remotes={this.props.remotes}
branches={this.props.branches}
aheadCount={this.props.aheadCount}
// Action methods
handleLogin={this.props.handleLogin}
handleLogout={this.props.handleLogout}
onPushBranch={() => this.props.handlePushBranch(this.props.currentBranch, this.props.currentRemote)}
/>
);
}
if (this.props.manyRemotesAvailable) {
// No chosen remote, multiple remotes hosted on GitHub instances
return (
<RemoteSelectorView
remotes={this.props.remotes}
currentBranch={this.props.currentBranch}
selectRemote={this.props.handleRemoteSelect}
/>
);
}
return (
<GitHubBlankNoRemote openBoundPublishDialog={this.props.openBoundPublishDialog} />
);
}
renderHeader() {
return (
<GithubTabHeaderContainer
// Connection
endpoint={this.props.endpoint}
token={this.props.token}
// Workspace
currentWorkDir={this.props.workingDirectory}
contextLocked={this.props.contextLocked}
changeWorkingDirectory={this.props.changeWorkingDirectory}
setContextLock={this.props.setContextLock}
getCurrentWorkDirs={this.props.getCurrentWorkDirs}
// Event Handlers
onDidChangeWorkDirs={this.props.onDidChangeWorkDirs}
/>
);
}
}