1
|
|
|
const React = require('react'); |
2
|
|
|
const ReactRedux = require('react-redux'); |
3
|
|
|
const BuildStatus = require('../components/BuildStatus.jsx'); |
4
|
|
|
|
5
|
|
|
const _ = require('underscore'); |
6
|
|
|
const actions = require('../_actions.js'); |
7
|
|
|
const deployStates = require('../constants/deployment.js'); |
8
|
|
|
|
9
|
|
|
const UpcomingDeployments = function(props) { |
10
|
|
|
let errorRow = null; |
11
|
|
|
|
12
|
|
|
if (props.error) { |
13
|
|
|
errorRow = ( |
14
|
|
|
<tr className="danger"> |
15
|
|
|
<td colSpan="5"> |
16
|
|
|
{props.error} |
17
|
|
|
</td> |
18
|
|
|
</tr> |
19
|
|
|
); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
if (props.list.length === 0 && errorRow === null) { |
23
|
|
|
return null; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
return ( |
27
|
|
|
<div className="fade-in"> |
28
|
|
|
<h4>Upcoming</h4> |
29
|
|
|
<div className="table-responsive"> |
30
|
|
|
<table className="table table-clickable table-centered-columns table-striped table-hover"> |
31
|
|
|
<thead> |
32
|
|
|
<tr> |
33
|
|
|
<th>Request date</th> |
34
|
|
|
<th>Build details</th> |
35
|
|
|
<th>Requested by</th> |
36
|
|
|
<th>Approval</th> |
37
|
|
|
<th>Status</th> |
38
|
|
|
</tr> |
39
|
|
|
</thead> |
40
|
|
|
<tbody> |
41
|
|
|
{errorRow} |
42
|
|
|
{ |
43
|
|
|
Object.keys(props.list).map(function(i) { |
44
|
|
|
const row = props.list[i]; |
45
|
|
|
|
46
|
|
|
let approver = null; |
47
|
|
|
let deployer = null; |
48
|
|
|
if (row.deployer) { |
49
|
|
|
deployer = row.deployer.name; |
50
|
|
|
} |
51
|
|
|
if (row.approver) { |
52
|
|
|
approver = row.approver.name; |
53
|
|
|
} else if (deployStates.isApproved(row.state)) { |
54
|
|
|
approver = ( |
55
|
|
|
<span className="bypassed">Bypassed</span> |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return ( |
60
|
|
|
<tr className={"fade-in status-" + row.state} onClick={() => props.onItemClick(row.id)} key={i}> |
|
|
|
|
61
|
|
|
<td>{row.date_requested_nice ? row.date_requested_nice : "-"}</td> |
62
|
|
|
<td><BuildStatus deployment={row} /></td> |
63
|
|
|
<td>{deployer}</td> |
64
|
|
|
<td className="deploy-approver">{approver}</td> |
65
|
|
|
<td className="deploy-status"><span className="deploy-status-text">{row.state}</span></td> |
|
|
|
|
66
|
|
|
</tr> |
67
|
|
|
); |
68
|
|
|
}) |
69
|
|
|
} |
70
|
|
|
</tbody> |
71
|
|
|
</table> |
72
|
|
|
</div> |
73
|
|
|
</div> |
74
|
|
|
); |
75
|
|
|
}; |
76
|
|
|
|
77
|
|
|
const mapStateToProps = function(state) { |
78
|
|
|
|
79
|
|
|
// try to find the current build in the list of all deployments |
80
|
|
|
let upcomingList = []; |
81
|
|
|
if (typeof state.deployment.list === "object") { |
82
|
|
|
upcomingList = _.filter(state.deployment.list, function(deploy) { |
83
|
|
|
switch (deploy.state) { |
84
|
|
|
case undefined: |
85
|
|
|
case deployStates.STATE_COMPLETED: |
86
|
|
|
case deployStates.STATE_INVALID: |
87
|
|
|
case deployStates.STATE_FAILED: |
88
|
|
|
case deployStates.STATE_DELETED: |
89
|
|
|
return false; |
90
|
|
|
default: |
91
|
|
|
return true; |
92
|
|
|
} |
93
|
|
|
}); |
94
|
|
|
} |
95
|
|
|
upcomingList.sort(function(a, b) { |
96
|
|
|
return Date.parse(b.date_created) - Date.parse(a.date_created); |
97
|
|
|
}); |
98
|
|
|
|
99
|
|
|
return { |
100
|
|
|
list: upcomingList |
101
|
|
|
}; |
102
|
|
|
}; |
103
|
|
|
|
104
|
|
|
const mapDispatchToProps = function() { |
105
|
|
|
return { |
106
|
|
|
onItemClick: function(id) { |
107
|
|
|
actions.history.push('/deployment/' + id.toString()); |
108
|
|
|
} |
109
|
|
|
}; |
110
|
|
|
}; |
111
|
|
|
|
112
|
|
|
module.exports = ReactRedux.connect(mapStateToProps, mapDispatchToProps)(UpcomingDeployments); |
113
|
|
|
|