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 Tabs from 'react-bootstrap/Tabs';
30 import Tab from 'react-bootstrap/Tab';
31 import styled from 'styled-components';
33 const ModalStyled = styled(Modal)`
34 background-color: transparent;
36 const FormStyled = styled(Form.Group)`
37 padding: .25rem 1.5rem;
39 export default class DeployLoopModal extends React.Component {
41 loopCache: this.props.loopCache,
42 temporaryPropertiesJson: JSON.parse(JSON.stringify(this.props.loopCache.getGlobalProperties())),
45 constructor(props, context) {
46 super(props, context);
48 this.handleSave = this.handleSave.bind(this);
49 this.handleClose = this.handleClose.bind(this);
50 this.handleChange = this.handleChange.bind(this);
51 this.refreshStatus = this.refreshStatus.bind(this);
52 this.renderDeployParam = this.renderDeployParam.bind(this);
54 componentWillReceiveProps(newProps) {
56 loopName: newProps.loopCache.getLoopName(),
61 const deployJsonList = this.state.temporaryPropertiesJson["dcaeDeployParameters"];
62 Object.keys(deployJsonList)
63 .filter((obj) => Object.keys(deployJsonList).indexOf(obj) === 0)
65 this.setState({key: obj})
69 this.props.history.push('/');
72 const loopName = this.props.loopCache.getLoopName();
73 // save the global propserties
74 LoopService.updateGlobalProperties(loopName, this.state.temporaryPropertiesJson).then(resp => {
75 this.setState({ show: false });
77 LoopActionService.performAction(loopName, "deploy").then(pars => {
78 this.props.showAlert("Action deploy successfully performed");
79 // refresh status and update loop logs
80 this.refreshStatus(loopName);
83 this.props.showAlert("Action deploy failed");
84 // refresh status and update loop logs
85 this.refreshStatus(loopName);
90 refreshStatus(loopName) {
91 LoopActionService.refreshStatus(loopName).then(data => {
92 this.props.updateLoopFunction(data);
93 this.props.history.push('/');
96 this.props.showAlert("Refresh status failed");
97 this.props.history.push('/');
100 handleChange(event) {
101 let deploymentParam = this.state.temporaryPropertiesJson["dcaeDeployParameters"];
102 deploymentParam[this.state.key][event.target.name] = event.target.value;
104 this.setState({temporaryPropertiesJson:{dcaeDeployParameters: deploymentParam}});
106 renderDeployParamTabs() {
107 if (typeof (this.state.temporaryPropertiesJson) === "undefined") {
111 const deployJsonList = this.state.temporaryPropertiesJson["dcaeDeployParameters"];
113 Object.keys(deployJsonList).map((item,key) =>
114 indents.push(<Tab eventKey={item} title={item}>
115 {this.renderDeployParam(deployJsonList[item])}
121 renderDeployParam(deployJson) {
123 Object.keys(deployJson).map((item,key) =>
124 indents.push(<FormStyled>
125 <Form.Label>{item}</Form.Label>
126 <Form.Control type="text" name={item} onChange={this.handleChange} defaultValue={deployJson[item]}></Form.Control>
132 <ModalStyled size="lg" show={this.state.show} onHide={this.handleClose} >
133 <Modal.Header closeButton>
134 <Modal.Title>Deployment parameters</Modal.Title>
136 <Tabs id="controlled-tab-example" activeKey={this.state.key} onSelect={key => this.setState({ key })}>
137 {this.renderDeployParamTabs()}
140 <Button variant="secondary" type="null" onClick={this.handleClose}>Cancel</Button>
141 <Button variant="primary" type="submit" onClick={this.handleSave}>Deploy</Button>