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 {
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 const propertiesJson = JSON.parse(JSON.stringify(this.props.loopCache.getGlobalProperties()));
54 loopCache: this.props.loopCache,
55 temporaryPropertiesJson: propertiesJson,
57 key: this.getInitialKeyValue(propertiesJson)
60 getInitialKeyValue(temporaryPropertiesJson) {
61 const deployJsonList = temporaryPropertiesJson["dcaeDeployParameters"];
63 Object.keys(deployJsonList)
64 .filter((obj) => Object.keys(deployJsonList).indexOf(obj) === 0)
70 componentWillReceiveProps(newProps) {
72 loopName: newProps.loopCache.getLoopName(),
78 this.setState({ show: false });
79 this.props.history.push('/');
83 const loopName = this.props.loopCache.getLoopName();
84 // save the global propserties
85 LoopService.updateGlobalProperties(loopName, this.state.temporaryPropertiesJson).then(resp => {
86 LoopActionService.performAction(loopName, "deploy").then(pars => {
87 this.props.showAlert("Action deploy successfully performed");
88 // refresh status and update loop logs
89 this.refreshStatus(loopName);
92 this.props.showAlert("Action deploy failed");
93 // refresh status and update loop logs
94 this.refreshStatus(loopName);
97 this.setState({ show: false });
98 this.props.history.push('/');
101 refreshStatus(loopName) {
102 LoopActionService.refreshStatus(loopName).then(data => {
103 this.props.updateLoopFunction(data);
106 this.props.showAlert("Refresh status failed");
109 handleChange(event) {
110 let deploymentParam = this.state.temporaryPropertiesJson["dcaeDeployParameters"];
111 deploymentParam[this.state.key][event.target.name] = event.target.value;
113 this.setState({temporaryPropertiesJson:{dcaeDeployParameters: deploymentParam}});
115 renderDeployParamTabs() {
116 if (typeof (this.state.temporaryPropertiesJson) === "undefined") {
120 const deployJsonList = this.state.temporaryPropertiesJson["dcaeDeployParameters"];
122 Object.keys(deployJsonList).map((item,key) =>
123 indents.push(<Tab eventKey={item} title={item}>
124 {this.renderDeployParam(deployJsonList[item])}
129 renderDeployParam(deployJson) {
131 Object.keys(deployJson).map((item,key) =>
132 indents.push(<FormStyled>
133 <Form.Label>{item}</Form.Label>
134 <Form.Control type="text" name={item} onChange={this.handleChange} defaultValue={deployJson[item]}></Form.Control>
140 <ModalStyled size="lg" show={this.state.show} onHide={this.handleClose} >
141 <Modal.Header closeButton>
142 <Modal.Title>Deployment parameters</Modal.Title>
144 <Tabs id="controlled-tab-example" activeKey={this.state.key} onSelect={key => this.setState({ key })}>
145 {this.renderDeployParamTabs()}
148 <Button variant="secondary" type="null" onClick={this.handleClose}>Cancel</Button>
149 <Button variant="primary" type="submit" onClick={this.handleSave}>Deploy</Button>