1
|
|
|
const React = require("react"); |
2
|
|
|
const ReactRedux = require('react-redux'); |
3
|
|
|
|
4
|
|
|
const Dropdown = require('../components/Dropdown.jsx'); |
5
|
|
|
const RequestApproval = require('./buttons/RequestApproval.jsx'); |
6
|
|
|
const Bypass = require('./buttons/Bypass.jsx'); |
7
|
|
|
|
8
|
|
|
const actions = require('../_actions.js'); |
9
|
|
|
const constants = require('../constants/deployment.js'); |
10
|
|
|
|
11
|
|
|
function Approval(props) { |
12
|
|
|
var sentTime = null; |
13
|
|
|
if (props.date_requested_nice) { |
14
|
|
|
sentTime = "Sent: " + props.date_requested_nice; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
let error = null; |
18
|
|
|
if (props.error) { |
19
|
|
|
error = ( |
20
|
|
|
<div className="alert alert-danger"> |
21
|
|
|
<div className=""> |
22
|
|
|
{props.error} |
23
|
|
|
</div> |
24
|
|
|
</div> |
25
|
|
|
); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
return ( |
29
|
|
|
<div className="section"> |
30
|
|
|
{error} |
31
|
|
|
<header id="2">Approval</header> |
32
|
|
|
<p> |
33
|
|
|
Send a request to deploy this release. Once approved, team members will have the ability to deploy this release.<br /> |
|
|
|
|
34
|
|
|
Only one request can be active at a time, although approval can also be granted by others with the same permissions, e.g. Release managers. |
|
|
|
|
35
|
|
|
</p> |
36
|
|
|
<div> |
37
|
|
|
<div className="form-group"> |
38
|
|
|
<label htmlFor="approver">Request approval from</label> |
39
|
|
|
<Dropdown |
40
|
|
|
name="approver" |
41
|
|
|
options={props.approvers} |
42
|
|
|
value={props.approver_id} |
43
|
|
|
onSelect={props.onApproverSelect} |
44
|
|
|
disabled={props.disabled} |
45
|
|
|
/> |
46
|
|
|
</div> |
47
|
|
|
<div> |
48
|
|
|
{sentTime} |
49
|
|
|
</div> |
50
|
|
|
<div> |
51
|
|
|
<RequestApproval /> <Bypass /> |
52
|
|
|
</div> |
53
|
|
|
</div> |
54
|
|
|
</div> |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
function isDisabled(deployState) { |
59
|
|
|
if (constants.isApproved(deployState)) { |
60
|
|
|
return true; |
61
|
|
|
} |
62
|
|
|
if (constants.isRejected(deployState)) { |
63
|
|
|
return true; |
64
|
|
|
} |
65
|
|
|
if (constants.isQueued(deployState)) { |
66
|
|
|
return true; |
67
|
|
|
} |
68
|
|
|
return false; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
const mapStateToProps = function(state) { |
72
|
|
|
const approvers = []; |
73
|
|
|
Object.keys(state.environment.approvers).forEach(function(id) { |
74
|
|
|
const approver = state.environment.approvers[id]; |
75
|
|
|
approvers.push({ |
76
|
|
|
id: approver.id, |
77
|
|
|
title: approver.email + ' - ' + approver.role |
78
|
|
|
}); |
79
|
|
|
}); |
80
|
|
|
|
81
|
|
|
const current = state.deployment.list[state.deployment.current_id] || {}; |
82
|
|
|
return { |
83
|
|
|
disabled: isDisabled(current.state), |
84
|
|
|
date_requested_nice: current.date_requested_nice, |
85
|
|
|
approvers: approvers, |
86
|
|
|
approver_id: current.approver_id, |
87
|
|
|
error: state.approval.error |
88
|
|
|
}; |
89
|
|
|
}; |
90
|
|
|
|
91
|
|
|
const mapDispatchToProps = function(dispatch) { |
92
|
|
|
return { |
93
|
|
|
onApproverSelect: function(id) { |
94
|
|
|
dispatch(actions.setApprover(id)); |
95
|
|
|
} |
96
|
|
|
}; |
97
|
|
|
}; |
98
|
|
|
|
99
|
|
|
module.exports = ReactRedux.connect(mapStateToProps, mapDispatchToProps)(Approval); |
100
|
|
|
|