-
Notifications
You must be signed in to change notification settings - Fork 188
/
NewHeader.jsx
131 lines (121 loc) · 4.33 KB
/
NewHeader.jsx
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import React from 'react';
import { Link } from 'react-router';
import classNames from 'classnames';
import NewColorDropdown from './NewColorDropdown';
import NewTasksDropdown from './NewTasksDropdown';
import { connect } from 'react-redux';
import { switchViewMode } from '../../actions/log';
import { jumpAllToTop, jumpAllToBottom, setColor, toggleTailerGroup } from '../../actions/tailer';
class NewHeader extends React.Component {
renderBreadcrumbs() {
if (this.props.paths.length > 1) {
return (<li>(multiple paths)</li>);
} else if (this.props.paths.length === 1) {
return this.props.paths[0].split('/').map((subpath, key) => {
if (subpath === '$TASK_ID') {
return <li key={key}><span className="label label-info">Task ID</span></li>;
}
return <li key={key}>{subpath}</li>;
});
}
}
renderAnchorButtons() {
return (this.props.tailerGroupCount > 1) && (
<span>
<a className="btn btn-default btn-sm tail-bottom-button" onClick={this.props.jumpAllToBottom} title="Scroll All to Bottom">
<span className="glyphicon glyphicon-chevron-down"></span>
</a>
<a className="btn btn-default btn-sm tail-top-button" onClick={this.props.jumpAllToTop} title="Scroll All to Top">
<span className="glyphicon glyphicon-chevron-up"></span>
</a>
</span>
);
}
renderRequestLink() {
if (this.props.requestIds.length > 1) {
return (<li>
(multiple requests)
</li>);
} else if (this.props.requestIds.length === 1) {
return (<li>
Request
<Link to={`request/${this.props.requestIds[0]}`}>
{this.props.requestIds[0]}
</Link>
</li>);
}
}
renderTasksDropdown() {
if (this.props.requestIds.length === 1 && this.props.paths.length === 1) {
return (<NewTasksDropdown
ready={this.props.ready}
runningTasks={this.props.runningTasks}
visibleTasks={this.props.taskIds}
onToggle={(taskId) => this.props.toggleTailerGroup(taskId, this.props.paths[0])}
/>);
}
}
renderSwitchToOldTailer() {
if ((this.props.tailerGroupCount === 1)) {
return (<Link to={`/task/${this.props.taskIds[0]}/old-tail/${this.props.paths[0]}`}>
<button type="button" className="btn btn-sm btn-default">Back to old tailer</button>
</Link>);
} else if ((this.props.tailerGroupCount > 1)) {
return (<Link to={`/request/${this.props.requestIds[0]}/old-tail/${this.props.paths[0]}`}>
<button type="button" className="btn btn-sm btn-default">Back to old tailer</button>
</Link>);
}
}
render() {
if (!this.props.ready) {
return (<div>Loading...</div>);
}
return (
<div className="tail-header">
<div className="row">
<div className="col-md-3">
<ul className="breadcrumb breadcrumb-request">
{this.renderRequestLink()}
</ul>
</div>
<div className="col-md-6">
<ul className="breadcrumb">
{this.renderBreadcrumbs()}
</ul>
</div>
<div className="col-md-3 hidden-xs tail-buttons">
{this.renderSwitchToOldTailer()}
{this.renderTasksDropdown()}
<NewColorDropdown activeColor={this.props.activeColor} onSetColor={this.props.setColor} />
{this.renderAnchorButtons()}
</div>
</div>
</div>
);
}
}
NewHeader.propTypes = {
//requestIds: React.PropTypes.string,
//paths: React.PropTypes.string.isRequired,
viewMode: React.PropTypes.string.isRequired,
tailerGroupCount: React.PropTypes.number.isRequired,
switchViewMode: React.PropTypes.func.isRequired,
jumpAllToTop: React.PropTypes.func.isRequired,
jumpAllToBottom: React.PropTypes.func.isRequired,
};
export default connect((state) => ({
tailerGroupCount: state.tailerView.tailerGroups.length,
taskIds: state.tailerView.taskIds,
requestIds: state.tailerView.requestIds,
paths: state.tailerView.paths,
viewMode: state.tailerView.viewMode,
ready: state.tailerView.ready,
activeColor: state.tailerView.color,
runningTasks: state.tailerView.requestIds.length > 0 && state.api.activeTasksForRequest[state.tailerView.requestIds[0]].data
}), {
switchViewMode,
jumpAllToTop,
jumpAllToBottom,
setColor,
toggleTailerGroup,
})(NewHeader);