2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
23 import React from 'react';
24 import LoopActionService from '../../api/LoopActionService';
25 import LoopService from '../../api/LoopService';
26 import Button from 'react-bootstrap/Button';
27 import Modal from 'react-bootstrap/Modal';
28 import Form from 'react-bootstrap/Form';
29 import styled from 'styled-components';
31 const ModalStyled = styled(Modal)`
32 background-color: transparent;
34 const FormStyled = styled(Form.Group)`
35 padding: .25rem 1.5rem;
37 export default class DeployLoop extends React.Component {
39 loopCache: this.props.loopCache,
40 temporaryPropertiesJson: JSON.parse(JSON.stringify(this.props.loopCache.getGlobalProperties())),
43 constructor(props, context) {
44 super(props, context);
46 this.handleSave = this.handleSave.bind(this);
47 this.handleClose = this.handleClose.bind(this);
48 this.handleChange = this.handleChange.bind(this);
49 this.refreshStatus = this.refreshStatus.bind(this);
50 this.renderDeployParam = this.renderDeployParam.bind(this);
52 componentWillReceiveProps(newProps) {
54 loopName: newProps.loopCache.getLoopName(),
59 this.props.history.push('/');
62 const loopName = this.props.loopCache.getLoopName();
63 // save the global propserties
64 LoopService.updateGlobalProperties(loopName, this.state.temporaryPropertiesJson).then(resp => {
65 this.setState({ show: false });
67 console.log("Perform action: deploy");
68 LoopActionService.performAction(loopName, "deploy").then(pars => {
69 alert("Action deploy successfully performed");
70 // refresh status and update loop logs
71 this.refreshStatus(loopName);
74 alert("Action deploy failed");
75 // refresh status and update loop logs
76 this.refreshStatus(loopName);
81 refreshStatus(loopName) {
82 LoopActionService.refreshStatus(loopName).then(data => {
83 this.props.updateLoopFunction(data);
84 this.props.history.push('/');
87 alert("Refresh status failed");
88 this.props.history.push('/');
92 let deploymentParam = this.state.temporaryPropertiesJson["dcaeDeployParameters"];
93 deploymentParam[event.target.name] = event.target.value;
95 this.setState({temporaryPropertiesJson:{dcaeDeployParameters: deploymentParam}});
98 if (typeof (this.state.temporaryPropertiesJson) === "undefined") {
102 const deployJson = this.state.temporaryPropertiesJson["dcaeDeployParameters"];
104 Object.keys(deployJson).map((item,key) =>
105 indents.push(<FormStyled>
106 <Form.Label>{item}</Form.Label>
107 <Form.Control type="text" name={item} onChange={this.handleChange} defaultValue={deployJson[item]}></Form.Control>
116 <ModalStyled size="lg" show={this.state.show} onHide={this.handleClose} >
117 <Modal.Header closeButton>
118 <Modal.Title>Deployment parameters</Modal.Title>
120 {this.renderDeployParam()}
122 <Button variant="secondary" type="null" onClick={this.handleClose}>Cancel</Button>
123 <Button variant="primary" type="submit" onClick={this.handleSave}>Deploy</Button>