This repository was archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 410
Expand file tree
/
Copy pathgithub-tab-header-container.js
More file actions
102 lines (87 loc) · 2.85 KB
/
github-tab-header-container.js
File metadata and controls
102 lines (87 loc) · 2.85 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
import React from 'react';
import PropTypes from 'prop-types';
import {QueryRenderer, graphql} from 'react-relay';
import {EndpointPropType, TokenPropType} from '../prop-types';
import RelayNetworkLayerManager from '../relay-network-layer-manager';
import {UNAUTHENTICATED, INSUFFICIENT} from '../shared/keytar-strategy';
import Author, {nullAuthor} from '../models/author';
import GithubTabHeaderController from '../controllers/github-tab-header-controller';
export default class GithubTabHeaderContainer extends React.Component {
static propTypes = {
// Connection
endpoint: EndpointPropType.isRequired,
token: TokenPropType,
// Workspace
currentWorkDir: PropTypes.string,
contextLocked: PropTypes.bool.isRequired,
changeWorkingDirectory: PropTypes.func.isRequired,
setContextLock: PropTypes.func.isRequired,
getCurrentWorkDirs: PropTypes.func.isRequired,
// Event Handlers
onDidChangeWorkDirs: PropTypes.func,
}
render() {
if (
this.props.token == null
|| this.props.token instanceof Error
|| this.props.token === UNAUTHENTICATED
|| this.props.token === INSUFFICIENT
) {
return this.renderNoResult();
}
const environment = RelayNetworkLayerManager.getEnvironmentForHost(this.props.endpoint, this.props.token);
const query = graphql`
query githubTabHeaderContainerQuery {
viewer {
name,
email,
avatarUrl,
login
}
}
`;
return (
<QueryRenderer
environment={environment}
variables={{}}
query={query}
render={this.renderWithResult}
/>
);
}
renderWithResult = ({error, props}) => {
if (error || props === null) {
return this.renderNoResult();
}
// eslint-disable-next-line react/prop-types
const {email, name, avatarUrl, login} = props.viewer;
return (
<GithubTabHeaderController
user={new Author(email, name, login, false, avatarUrl)}
// Workspace
currentWorkDir={this.props.currentWorkDir}
contextLocked={this.props.contextLocked}
getCurrentWorkDirs={this.props.getCurrentWorkDirs}
changeWorkingDirectory={this.props.changeWorkingDirectory}
setContextLock={this.props.setContextLock}
// Event Handlers
onDidChangeWorkDirs={this.props.onDidChangeWorkDirs}
/>
);
}
renderNoResult() {
return (
<GithubTabHeaderController
user={nullAuthor}
// Workspace
currentWorkDir={this.props.currentWorkDir}
contextLocked={this.props.contextLocked}
changeWorkingDirectory={this.props.changeWorkingDirectory}
setContextLock={this.props.setContextLock}
getCurrentWorkDirs={this.props.getCurrentWorkDirs}
// Event Handlers
onDidChangeWorkDirs={this.props.onDidChangeWorkDirs}
/>
);
}
}