forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-tab-header-view.js
73 lines (64 loc) · 2.26 KB
/
git-tab-header-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
import React from 'react';
import PropTypes from 'prop-types';
import path from 'path';
import {AuthorPropType} from '../prop-types';
import Octicon from '../atom/octicon';
export default class GitTabHeaderView extends React.Component {
static propTypes = {
committer: AuthorPropType.isRequired,
// Workspace
workdir: PropTypes.string,
workdirs: PropTypes.shape({[Symbol.iterator]: PropTypes.func.isRequired}).isRequired,
contextLocked: PropTypes.bool.isRequired,
changingWorkDir: PropTypes.bool.isRequired,
changingLock: PropTypes.bool.isRequired,
// Event Handlers
handleAvatarClick: PropTypes.func,
handleWorkDirSelect: PropTypes.func,
handleLockToggle: PropTypes.func,
}
render() {
const lockIcon = this.props.contextLocked ? 'lock' : 'unlock';
const lockToggleTitle = this.props.contextLocked ?
'Change repository with the dropdown' :
'Follow the active pane item';
return (
<header className="github-Project">
{this.renderCommitter()}
<select className="github-Project-path input-select"
value={this.props.workdir || ''}
onChange={this.props.handleWorkDirSelect}
disabled={this.props.changingWorkDir}>
{this.renderWorkDirs()}
</select>
<button className="github-Project-lock btn btn-small"
onClick={this.props.handleLockToggle}
disabled={this.props.changingLock}
title={lockToggleTitle}>
<Octicon icon={lockIcon} />
</button>
</header>
);
}
renderWorkDirs() {
const workdirs = [];
for (const workdir of this.props.workdirs) {
workdirs.push(<option key={workdir} value={path.normalize(workdir)}>{path.basename(workdir)}</option>);
}
return workdirs;
}
renderCommitter() {
const email = this.props.committer.getEmail();
const avatarUrl = this.props.committer.getAvatarUrl();
const name = this.props.committer.getFullName();
return (
<button className="github-Project-avatarBtn" onClick={this.props.handleAvatarClick}>
<img className="github-Project-avatar"
src={avatarUrl || 'atom://github/img/avatar.svg'}
title={`${name} ${email}`}
alt={`${name}'s avatar`}
/>
</button>
);
}
}