Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit f934a46

Browse files
lift login handling from remote container to github tab controller
1 parent 82e6c50 commit f934a46

File tree

3 files changed

+58
-31
lines changed

3 files changed

+58
-31
lines changed

lib/containers/remote-container.js

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ export default class RemoteContainer extends React.Component {
1919
// Connection
2020
loginModel: PropTypes.object.isRequired,
2121
endpoint: EndpointPropType.isRequired,
22+
fetchToken: PropTypes.func.isRequired,
23+
handleLogin: PropTypes.func.isRequired,
24+
handleLogout: PropTypes.func.isRequired,
25+
handleTokenRetry: PropTypes.func.isRequired,
2226

2327
// Repository attributes
2428
remoteOperationObserver: OperationStateObserverPropType.isRequired,
@@ -34,13 +38,9 @@ export default class RemoteContainer extends React.Component {
3438
onPushBranch: PropTypes.func.isRequired,
3539
}
3640

37-
fetchToken = loginModel => {
38-
return loginModel.getToken(this.props.endpoint.getLoginAccount());
39-
}
40-
4141
render() {
4242
return (
43-
<ObserveModel model={this.props.loginModel} fetchData={this.fetchToken}>
43+
<ObserveModel model={this.props.loginModel} fetchData={this.props.fetchToken}>
4444
{this.renderWithToken}
4545
</ObserveModel>
4646
);
@@ -55,20 +55,20 @@ export default class RemoteContainer extends React.Component {
5555
return (
5656
<QueryErrorView
5757
error={token}
58-
retry={this.handleTokenRetry}
59-
login={this.handleLogin}
60-
logout={this.handleLogout}
58+
retry={this.props.handleTokenRetry}
59+
login={this.props.handleLogin}
60+
logout={this.props.handleLogout}
6161
/>
6262
);
6363
}
6464

6565
if (token === UNAUTHENTICATED) {
66-
return <GithubLoginView onLogin={this.handleLogin} />;
66+
return <GithubLoginView onLogin={this.props.handleLogin} />;
6767
}
6868

6969
if (token === INSUFFICIENT) {
7070
return (
71-
<GithubLoginView onLogin={this.handleLogin}>
71+
<GithubLoginView onLogin={this.props.handleLogin}>
7272
<p>
7373
Your token no longer has sufficient authorizations. Please re-authenticate and generate a new one.
7474
</p>
@@ -108,9 +108,9 @@ export default class RemoteContainer extends React.Component {
108108
return (
109109
<QueryErrorView
110110
error={error}
111-
login={this.handleLogin}
111+
login={this.props.handleLogin}
112112
retry={retry}
113-
logout={this.handleLogout}
113+
logout={this.props.handleLogout}
114114
/>
115115
);
116116
}
@@ -140,16 +140,4 @@ export default class RemoteContainer extends React.Component {
140140
/>
141141
);
142142
}
143-
144-
handleLogin = token => {
145-
incrementCounter('github-login');
146-
this.props.loginModel.setToken(this.props.endpoint.getLoginAccount(), token);
147-
}
148-
149-
handleLogout = () => {
150-
incrementCounter('github-logout');
151-
this.props.loginModel.removeToken(this.props.endpoint.getLoginAccount());
152-
}
153-
154-
handleTokenRetry = () => this.props.loginModel.didUpdate();
155143
}

lib/controllers/github-tab-controller.js

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,32 @@ export default class GitHubTabController extends React.Component {
3232
const gitHubRemotes = this.props.allRemotes.filter(remote => remote.isGithubRepo());
3333
const currentBranch = this.props.branches.getHeadBranch();
3434

35-
let currentRemote = gitHubRemotes.withName(this.props.selectedRemoteName);
35+
this.currentRemote = gitHubRemotes.withName(this.props.selectedRemoteName);
3636
let manyRemotesAvailable = false;
37-
if (!currentRemote.isPresent() && gitHubRemotes.size() === 1) {
38-
currentRemote = Array.from(gitHubRemotes)[0];
39-
} else if (!currentRemote.isPresent() && gitHubRemotes.size() > 1) {
37+
if (!this.currentRemote.isPresent() && gitHubRemotes.size() === 1) {
38+
this.currentRemote = Array.from(gitHubRemotes)[0];
39+
} else if (!this.currentRemote.isPresent() && gitHubRemotes.size() > 1) {
4040
manyRemotesAvailable = true;
4141
}
4242

4343
return (
4444
<GitHubTabView
45+
// Connection
46+
loginModel={this.props.loginModel}
47+
fetchToken={this.fetchToken}
48+
handleTokenRetry={this.handleTokenRetry}
49+
handleLogin={this.handleLogin}
50+
handleLogout={this.handleLogout}
51+
4552
workspace={this.props.workspace}
4653
remoteOperationObserver={this.props.remoteOperationObserver}
47-
loginModel={this.props.loginModel}
4854
rootHolder={this.props.rootHolder}
4955

5056
workingDirectory={this.props.workingDirectory || this.props.currentWorkDir}
5157
branches={this.props.branches}
5258
currentBranch={currentBranch}
5359
remotes={gitHubRemotes}
54-
currentRemote={currentRemote}
60+
currentRemote={this.currentRemote}
5561
repository={this.props.repository}
5662
manyRemotesAvailable={manyRemotesAvailable}
5763
aheadCount={this.props.aheadCount}
@@ -78,4 +84,26 @@ export default class GitHubTabController extends React.Component {
7884
e.preventDefault();
7985
return this.props.repository.setConfig('atomGithub.currentRemote', remote.getName());
8086
}
87+
88+
fetchToken = loginModel => {
89+
if (this.currentRemote.isPresent()) {
90+
return loginModel.getToken(this.currentRemote.getEndpoint().getLoginAccount());
91+
}
92+
}
93+
94+
handleLogin = token => {
95+
if (this.currentRemote.isPresent()) {
96+
incrementCounter('github-login');
97+
this.props.loginModel.setToken(this.currentRemote.getEndpoint().getLoginAccount(), token);
98+
}
99+
}
100+
101+
handleLogout = () => {
102+
if (this.currentRemote.isPresent()) {
103+
incrementCounter('github-logout');
104+
this.props.loginModel.removeToken(this.currentRemote.getEndpoint().getLoginAccount());
105+
}
106+
}
107+
108+
handleTokenRetry = () => this.props.loginModel.didUpdate();
81109
}

lib/views/github-tab-view.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@ import RemoteContainer from '../containers/remote-container';
1212

1313
export default class GitHubTabView extends React.Component {
1414
static propTypes = {
15+
// Connection
16+
loginModel: PropTypes.object.isRequired,
17+
fetchToken: PropTypes.func.isRequired,
18+
handleLogin: PropTypes.func.isRequired,
19+
handleLogout: PropTypes.func.isRequired,
20+
handleTokenRetry: PropTypes.func.isRequired,
21+
1522
repository: PropTypes.object.isRequired,
1623
workspace: PropTypes.object.isRequired,
1724
remoteOperationObserver: OperationStateObserverPropType.isRequired,
18-
loginModel: GithubLoginModelPropType.isRequired,
1925
rootHolder: RefHolderPropType.isRequired,
2026

2127
workingDirectory: PropTypes.string,
@@ -55,8 +61,13 @@ export default class GitHubTabView extends React.Component {
5561
// Single, chosen or unambiguous remote
5662
return (
5763
<RemoteContainer
64+
// Connection
5865
loginModel={this.props.loginModel}
5966
endpoint={this.props.currentRemote.getEndpoint()}
67+
fetchToken={this.props.fetchToken}
68+
handleTokenRetry={this.props.handleTokenRetry}
69+
handleLogin={this.props.handleLogin}
70+
handleLogout={this.props.handleLogout}
6071

6172
remoteOperationObserver={this.props.remoteOperationObserver}
6273
pushInProgress={this.props.pushInProgress}

0 commit comments

Comments
 (0)