1
|
|
|
const React = require('react'); |
2
|
|
|
const ReactRedux = require('react-redux'); |
3
|
|
|
const Pagination = require('react-bootstrap/lib/Pagination'); |
4
|
|
|
const BuildStatus = require('../components/BuildStatus.jsx'); |
5
|
|
|
const LoadingBar = require('../components/LoadingBar.jsx'); |
6
|
|
|
|
7
|
|
|
const _ = require('underscore'); |
8
|
|
|
const actions = require('../_actions.js'); |
9
|
|
|
const deployStates = require('../constants/deployment.js'); |
10
|
|
|
|
11
|
|
|
const DeployHistory = function(props) { |
12
|
|
|
let errorRow = null; |
13
|
|
|
let pagination = null; |
14
|
|
|
|
15
|
|
|
if (props.error) { |
16
|
|
|
errorRow = ( |
17
|
|
|
<tr className="danger"> |
18
|
|
|
<td colSpan="5"> |
19
|
|
|
{props.error} |
20
|
|
|
</td> |
21
|
|
|
</tr> |
22
|
|
|
); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
if (props.total_pages > 1) { |
26
|
|
|
pagination = ( |
27
|
|
|
<div className="text-center"> |
28
|
|
|
<nav> |
29
|
|
|
<Pagination |
30
|
|
|
first |
31
|
|
|
last |
32
|
|
|
maxButtons={6} |
33
|
|
|
items={props.total_pages} |
34
|
|
|
activePage={props.current_page} |
35
|
|
|
onSelect={props.onPageClick} |
36
|
|
|
/> |
37
|
|
|
</nav> |
38
|
|
|
</div> |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
return ( |
43
|
|
|
<div className="fade-in"> |
44
|
|
|
<h4>History</h4> |
45
|
|
|
<div className="table-responsive"> |
46
|
|
|
<table className="table table-clickable table-centered-columns table-striped table-hover"> |
47
|
|
|
<thead> |
48
|
|
|
<tr> |
49
|
|
|
<th>Deploy date</th> |
50
|
|
|
<th>Build details</th> |
51
|
|
|
<th>Approval</th> |
52
|
|
|
<th>Deployed by</th> |
53
|
|
|
<th>Status</th> |
54
|
|
|
</tr> |
55
|
|
|
</thead> |
56
|
|
|
<tbody> |
57
|
|
|
{errorRow} |
58
|
|
|
{ |
59
|
|
|
Object.keys(props.list).map(function(i) { |
60
|
|
|
const row = props.list[i]; |
61
|
|
|
const state = row.is_current_build ? 'Current' : row.state; |
62
|
|
|
return ( |
63
|
|
|
<tr className={"fade-in status-" + state} onClick={() => props.onItemClick(row.id)} key={i}> |
|
|
|
|
64
|
|
|
<td>{row.date_started_nice}</td> |
65
|
|
|
<td><BuildStatus deployment={row} /></td> |
66
|
|
|
<td>{row.approver ? row.approver.name : <span className="bypassed">Bypassed</span>}</td> |
|
|
|
|
67
|
|
|
<td>{row.deployer ? row.deployer.name : null}</td> |
68
|
|
|
<td className="deploy-status"><span className="deploy-status-text">{state}</span></td> |
|
|
|
|
69
|
|
|
</tr> |
70
|
|
|
); |
71
|
|
|
}) |
72
|
|
|
} |
73
|
|
|
</tbody> |
74
|
|
|
</table> |
75
|
|
|
<LoadingBar show={props.is_loading} /> |
76
|
|
|
</div> |
77
|
|
|
{pagination} |
78
|
|
|
</div> |
79
|
|
|
); |
80
|
|
|
}; |
81
|
|
|
|
82
|
|
|
const mapStateToProps = function(state) { |
83
|
|
|
|
84
|
|
|
// try to find the current build in the list of all deployments |
85
|
|
|
let historyList = {}; |
86
|
|
|
let numDeployments = 0; |
87
|
|
|
if (typeof state.deployment.list === "object") { |
88
|
|
|
historyList = _.filter(state.deployment.list, function(deploy) { |
89
|
|
|
switch (deploy.state) { |
90
|
|
|
case deployStates.STATE_COMPLETED: |
91
|
|
|
case deployStates.STATE_INVALID: |
92
|
|
|
case deployStates.STATE_FAILED: |
93
|
|
|
numDeployments += 1; |
94
|
|
|
return true; |
95
|
|
|
default: |
96
|
|
|
return false; |
97
|
|
|
} |
98
|
|
|
}); |
99
|
|
|
} |
100
|
|
|
historyList.sort(function(a, b) { |
101
|
|
|
return Date.parse(b.date_started) - Date.parse(a.date_started); |
102
|
|
|
}); |
103
|
|
|
|
104
|
|
|
const perPage = 10; |
105
|
|
|
// only show paginated result, recalc |
106
|
|
|
const start = (state.deployment.current_page - 1) * perPage; |
107
|
|
|
const end = start + perPage; |
108
|
|
|
const totalPages = Math.ceil(numDeployments / perPage); |
109
|
|
|
|
110
|
|
|
const paginatedList = {}; |
111
|
|
|
let pos = 0; |
112
|
|
|
Object.keys(historyList).forEach(function(key) { |
113
|
|
|
if (pos >= start && pos < end) { |
114
|
|
|
paginatedList[key] = historyList[key]; |
115
|
|
|
} |
116
|
|
|
pos++; |
|
|
|
|
117
|
|
|
}); |
118
|
|
|
|
119
|
|
|
return { |
120
|
|
|
list: paginatedList, |
121
|
|
|
page_length: perPage, |
122
|
|
|
total_pages: totalPages, |
123
|
|
|
current_page: state.deployment.current_page, |
124
|
|
|
error: state.deployment.history_error, |
125
|
|
|
is_loading: state.deployment.history_is_loading |
126
|
|
|
|
127
|
|
|
}; |
128
|
|
|
}; |
129
|
|
|
|
130
|
|
|
const mapDispatchToProps = function(dispatch) { |
131
|
|
|
return { |
132
|
|
|
onItemClick: function(id) { |
133
|
|
|
actions.history.push('/deployment/' + id.toString()); |
134
|
|
|
}, |
135
|
|
|
onPageClick: function(page) { |
136
|
|
|
dispatch(actions.setDeployHistoryPage(page)); |
137
|
|
|
} |
138
|
|
|
}; |
139
|
|
|
}; |
140
|
|
|
|
141
|
|
|
module.exports = ReactRedux.connect(mapStateToProps, mapDispatchToProps)(DeployHistory); |
142
|
|
|
|