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

Commit 08166bb

Browse files
committed
Render login or error views from GithubTabView
1 parent b75a24d commit 08166bb

File tree

2 files changed

+82
-37
lines changed

2 files changed

+82
-37
lines changed

lib/views/github-tab-view.js

Lines changed: 51 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,29 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33

44
import {
5-
GithubLoginModelPropType, RefHolderPropType, RemoteSetPropType, RemotePropType, BranchSetPropType, BranchPropType,
5+
TokenPropType, EndpointPropType, RefHolderPropType,
6+
RemoteSetPropType, RemotePropType, BranchSetPropType, BranchPropType,
67
RefresherPropType,
78
} from '../prop-types';
89
import LoadingView from './loading-view';
10+
import QueryErrorView from '../views/query-error-view';
11+
import GithubLoginView from '../views/github-login-view';
912
import RemoteSelectorView from './remote-selector-view';
1013
import GithubTabHeaderContainer from '../containers/github-tab-header-container';
11-
import GithubTabHeaderController from '../controllers/github-tab-header-controller';
1214
import GitHubBlankNoLocal from './github-blank-nolocal';
1315
import GitHubBlankUninitialized from './github-blank-uninitialized';
1416
import GitHubBlankNoRemote from './github-blank-noremote';
1517
import RemoteContainer from '../containers/remote-container';
16-
import {nullAuthor} from '../models/author';
18+
import {UNAUTHENTICATED, INSUFFICIENT} from '../shared/keytar-strategy';
1719

1820
export default class GitHubTabView extends React.Component {
1921
static propTypes = {
2022
refresher: RefresherPropType.isRequired,
2123
rootHolder: RefHolderPropType.isRequired,
2224

2325
// Connection
24-
loginModel: GithubLoginModelPropType.isRequired,
26+
endpoint: EndpointPropType.isRequired,
27+
token: TokenPropType,
2528

2629
// Workspace
2730
workspace: PropTypes.object.isRequired,
@@ -43,6 +46,9 @@ export default class GitHubTabView extends React.Component {
4346
pushInProgress: PropTypes.bool.isRequired,
4447

4548
// Event Handlers
49+
handleLogin: PropTypes.func.isRequired,
50+
handleLogout: PropTypes.func.isRequired,
51+
handleTokenRetry: PropTypes.func.isRequired,
4652
handleWorkDirSelect: PropTypes.func,
4753
handlePushBranch: PropTypes.func.isRequired,
4854
handleRemoteSelect: PropTypes.func.isRequired,
@@ -65,6 +71,35 @@ export default class GitHubTabView extends React.Component {
6571
}
6672

6773
renderRemote() {
74+
if (this.props.token === null) {
75+
return <LoadingView />;
76+
}
77+
78+
if (this.props.token === UNAUTHENTICATED) {
79+
return <GithubLoginView onLogin={this.props.handleLogin} />;
80+
}
81+
82+
if (this.props.token === INSUFFICIENT) {
83+
return (
84+
<GithubLoginView onLogin={this.props.handleLogin}>
85+
<p>
86+
Your token no longer has sufficient authorizations. Please re-authenticate and generate a new one.
87+
</p>
88+
</GithubLoginView>
89+
);
90+
}
91+
92+
if (this.props.token instanceof Error) {
93+
return (
94+
<QueryErrorView
95+
error={this.props.token}
96+
retry={this.props.handleTokenRetry}
97+
login={this.props.handleLogin}
98+
logout={this.props.handleLogout}
99+
/>
100+
);
101+
}
102+
68103
if (this.props.isLoading) {
69104
return <LoadingView />;
70105
}
@@ -92,22 +127,22 @@ export default class GitHubTabView extends React.Component {
92127
return (
93128
<RemoteContainer
94129
// Connection
95-
loginModel={this.props.loginModel}
96130
endpoint={this.props.currentRemote.getEndpoint()}
131+
token={this.props.token}
97132

98-
// Workspace
99-
workspace={this.props.workspace}
133+
// Repository attributes
134+
refresher={this.props.refresher}
135+
pushInProgress={this.props.pushInProgress}
100136
workingDirectory={this.props.workingDirectory}
101-
102-
// Remote
137+
workspace={this.props.workspace}
103138
remote={this.props.currentRemote}
104139
remotes={this.props.remotes}
105140
branches={this.props.branches}
106141
aheadCount={this.props.aheadCount}
107-
pushInProgress={this.props.pushInProgress}
108-
refresher={this.props.refresher}
109142

110-
// Event Handlers
143+
// Action methods
144+
handleLogin={this.props.handleLogin}
145+
handleLogout={this.props.handleLogout}
111146
onPushBranch={() => this.props.handlePushBranch(this.props.currentBranch, this.props.currentRemote)}
112147
/>
113148
);
@@ -130,29 +165,11 @@ export default class GitHubTabView extends React.Component {
130165
}
131166

132167
renderHeader() {
133-
if (this.props.currentRemote.isPresent()) {
134-
return (
135-
<GithubTabHeaderContainer
136-
// Connection
137-
loginModel={this.props.loginModel}
138-
endpoint={this.props.currentRemote.getEndpoint()}
139-
140-
// Workspace
141-
currentWorkDir={this.props.workingDirectory}
142-
contextLocked={this.props.contextLocked}
143-
changeWorkingDirectory={this.props.changeWorkingDirectory}
144-
setContextLock={this.props.setContextLock}
145-
getCurrentWorkDirs={this.props.getCurrentWorkDirs}
146-
147-
// Event Handlers
148-
// handleWorkDirSelect={e => this.props.changeWorkingDirectory(e.target.value)}
149-
onDidChangeWorkDirs={this.props.onDidChangeWorkDirs}
150-
/>
151-
);
152-
}
153168
return (
154-
<GithubTabHeaderController
155-
user={nullAuthor}
169+
<GithubTabHeaderContainer
170+
// Connection
171+
endpoint={this.props.endpoint}
172+
token={this.props.token}
156173

157174
// Workspace
158175
currentWorkDir={this.props.workingDirectory}

test/views/github-tab-view.test.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import RemoteSet from '../../lib/models/remote-set';
88
import Branch, {nullBranch} from '../../lib/models/branch';
99
import BranchSet from '../../lib/models/branch-set';
1010
import GitHubTabView from '../../lib/views/github-tab-view';
11-
import {InMemoryStrategy} from '../../lib/shared/keytar-strategy';
12-
import GithubLoginModel from '../../lib/models/github-login-model';
11+
import {DOTCOM} from '../../lib/models/endpoint';
1312
import RefHolder from '../../lib/models/ref-holder';
1413
import Refresher from '../../lib/models/refresher';
14+
import {UNAUTHENTICATED, INSUFFICIENT} from '../../lib/shared/keytar-strategy';
1515

1616
import {buildRepository, cloneRepository} from '../helpers';
1717

@@ -34,7 +34,8 @@ describe('GitHubTabView', function() {
3434
refresher={new Refresher()}
3535
rootHolder={new RefHolder()}
3636

37-
loginModel={new GithubLoginModel(InMemoryStrategy)}
37+
endpoint={DOTCOM}
38+
token="1234"
3839

3940
workspace={atomEnv.workspace}
4041
workingDirectory={repo.getWorkingDirectoryPath()}
@@ -52,6 +53,9 @@ describe('GitHubTabView', function() {
5253
currentBranch={nullBranch}
5354
pushInProgress={false}
5455

56+
handleLogin={() => {}}
57+
handleLogout={() => {}}
58+
handleTokenRetry={() => {}}
5559
handleWorkDirSelect={() => {}}
5660
handlePushBranch={() => {}}
5761
handleRemoteSelect={() => {}}
@@ -66,6 +70,30 @@ describe('GitHubTabView', function() {
6670
);
6771
}
6872

73+
it('renders a LoadingView if the token is still loading', function() {
74+
const wrapper = shallow(buildApp({token: null}));
75+
assert.isTrue(wrapper.exists('LoadingView'));
76+
});
77+
78+
it('renders a login view if the token is missing or incorrect', function() {
79+
const wrapper = shallow(buildApp({token: UNAUTHENTICATED}));
80+
assert.isTrue(wrapper.exists('GithubLoginView'));
81+
});
82+
83+
it('renders a login view with a custom message if the token has insufficient scopes', function() {
84+
const wrapper = shallow(buildApp({token: INSUFFICIENT}));
85+
assert.isTrue(wrapper.exists('GithubLoginView'));
86+
assert.isTrue(wrapper.find('GithubLoginView').exists('p'));
87+
});
88+
89+
it('renders an error view if there was an error acquiring the token', function() {
90+
const e = new Error('oh no');
91+
e.rawStack = e.stack;
92+
const wrapper = shallow(buildApp({token: e}));
93+
assert.isTrue(wrapper.exists('QueryErrorView'));
94+
assert.strictEqual(wrapper.find('QueryErrorView').prop('error'), e);
95+
});
96+
6997
it('renders a LoadingView if data is still loading', function() {
7098
const wrapper = shallow(buildApp({isLoading: true}));
7199
assert.isTrue(wrapper.find('LoadingView').exists());

0 commit comments

Comments
 (0)