Merge "Fix the stage builds"
[clamp.git] / ui-react / src / components / dialogs / Loop / DeployLoopModal.js
index 9c9a16f..d034ee5 100644 (file)
@@ -37,11 +37,9 @@ const FormStyled = styled(Form.Group)`
        padding: .25rem 1.5rem;
 `
 export default class DeployLoopModal extends React.Component {
-       state = {
-               loopCache: this.props.loopCache,
-               temporaryPropertiesJson: JSON.parse(JSON.stringify(this.props.loopCache.getGlobalProperties())),
-               show: true
-       };
+
+
+               
        constructor(props, context) {
                super(props, context);
 
@@ -50,6 +48,24 @@ export default class DeployLoopModal extends React.Component {
                this.handleChange = this.handleChange.bind(this);
                this.refreshStatus = this.refreshStatus.bind(this);
                this.renderDeployParam = this.renderDeployParam.bind(this);
+
+               const propertiesJson = JSON.parse(JSON.stringify(this.props.loopCache.getGlobalProperties()));
+               this.state = {
+                       loopCache: this.props.loopCache,
+                       temporaryPropertiesJson: propertiesJson,
+                       show: true,
+                       key: this.getInitialKeyValue(propertiesJson)
+               };
+       }
+       getInitialKeyValue(temporaryPropertiesJson) {
+               const deployJsonList = temporaryPropertiesJson["dcaeDeployParameters"];
+               let initialKey;
+               Object.keys(deployJsonList)
+                       .filter((obj) => Object.keys(deployJsonList).indexOf(obj) === 0)
+                       .map(obj =>
+                               initialKey = obj
+               );
+               return initialKey;
        }
        componentWillReceiveProps(newProps) {
                this.setState({
@@ -57,23 +73,16 @@ export default class DeployLoopModal extends React.Component {
                        show: true
                });
        }
-       componentDidMount() {
-               const deployJsonList = this.state.temporaryPropertiesJson["dcaeDeployParameters"];
-               Object.keys(deployJsonList)
-                       .filter((obj) => Object.keys(deployJsonList).indexOf(obj) === 0)
-                       .map(obj =>
-                               this.setState({key: obj})
-               );
-       }
+
        handleClose(){
+               this.setState({ show: false });
                this.props.history.push('/');
        }
+
        handleSave() {
                const loopName = this.props.loopCache.getLoopName();
                // save the global propserties
                LoopService.updateGlobalProperties(loopName, this.state.temporaryPropertiesJson).then(resp => {
-                       this.setState({ show: false });
-
                        LoopActionService.performAction(loopName, "deploy").then(pars => {
                                this.props.showAlert("Action deploy successfully performed");
                                // refresh status and update loop logs
@@ -85,16 +94,16 @@ export default class DeployLoopModal extends React.Component {
                                this.refreshStatus(loopName);
                        });
                });
+               this.setState({ show: false });
+               this.props.history.push('/');
        }
 
        refreshStatus(loopName) {
                LoopActionService.refreshStatus(loopName).then(data => {
                        this.props.updateLoopFunction(data);
-                       this.props.history.push('/');
                })
                .catch(error => {
                        this.props.showAlert("Refresh status failed");
-                       this.props.history.push('/');
                });
        }
        handleChange(event) {
@@ -117,7 +126,6 @@ export default class DeployLoopModal extends React.Component {
                );
                return indents;
        }
-
        renderDeployParam(deployJson) {
                var indents = [];
                Object.keys(deployJson).map((item,key) =>