forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-tab-container.js
More file actions
86 lines (75 loc) · 2.51 KB
/
github-tab-container.js
File metadata and controls
86 lines (75 loc) · 2.51 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
import React from 'react';
import PropTypes from 'prop-types';
import yubikiri from 'yubikiri';
import {GithubLoginModelPropType, RefHolderPropType} from '../prop-types';
import OperationStateObserver, {PUSH, PULL, FETCH} from '../models/operation-state-observer';
import GitHubTabController from '../controllers/github-tab-controller';
import ObserveModel from '../views/observe-model';
import RemoteSet from '../models/remote-set';
import BranchSet from '../models/branch-set';
export default class GitHubTabContainer extends React.Component {
static propTypes = {
workspace: PropTypes.object.isRequired,
repository: PropTypes.object,
loginModel: GithubLoginModelPropType.isRequired,
rootHolder: RefHolderPropType.isRequired,
}
state = {};
static getDerivedStateFromProps(props, state) {
if (props.repository !== state.lastRepository) {
return {
lastRepository: props.repository,
remoteOperationObserver: new OperationStateObserver(props.repository, PUSH, PULL, FETCH),
};
}
return null;
}
fetchRepositoryData = repository => {
return yubikiri({
workingDirectory: repository.getWorkingDirectoryPath(),
allRemotes: repository.getRemotes(),
branches: repository.getBranches(),
selectedRemoteName: repository.getConfig('atomGithub.currentRemote'),
aheadCount: async query => {
const branches = await query.branches;
const currentBranch = branches.getHeadBranch();
return repository.getAheadCount(currentBranch.getName());
},
pushInProgress: repository.getOperationStates().isPushInProgress(),
});
}
render() {
return (
<ObserveModel model={this.props.repository} fetchData={this.fetchRepositoryData}>
{this.renderRepositoryData}
</ObserveModel>
);
}
renderRepositoryData = data => {
if (!data || this.props.repository.isLoading()) {
return (
<GitHubTabController
{...this.props}
remoteOperationObserver={this.state.remoteOperationObserver}
allRemotes={new RemoteSet()}
branches={new BranchSet()}
aheadCount={0}
pushInProgress={false}
isLoading={true}
/>
);
}
if (!this.props.repository.isPresent()) {
// TODO include a better message here.
return null;
}
return (
<GitHubTabController
{...data}
{...this.props}
remoteOperationObserver={this.state.remoteOperationObserver}
isLoading={false}
/>
);
}
}