From: Sébastien Determe Date: Tue, 17 Mar 2020 19:03:08 +0000 (+0000) Subject: Merge "Update policy model UI" X-Git-Tag: 5.0.0~15 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=fdbbb38dfbc907fb0ecbfe69ee53b3e58f04a323;hp=-c;p=clamp.git Merge "Update policy model UI" --- fdbbb38dfbc907fb0ecbfe69ee53b3e58f04a323 diff --combined ui-react/src/components/dialogs/Policy/PolicyModal.js index 428e443c,d78cd6d6..8b49d915 --- a/ui-react/src/components/dialogs/Policy/PolicyModal.js +++ b/ui-react/src/components/dialogs/Policy/PolicyModal.js @@@ -30,7 -30,9 +30,9 @@@ import Select from 'react-select' import Modal from 'react-bootstrap/Modal'; import styled from 'styled-components'; import LoopService from '../../../api/LoopService'; + import LoopCache from '../../../api/LoopCache'; import JSONEditor from '@json-editor/json-editor'; + import Alert from 'react-bootstrap/Alert'; const ModalStyled = styled(Modal)` background-color: transparent; @@@ -49,7 -51,9 +51,9 @@@ export default class PolicyModal extend pdpGroupList: [], pdpSubgroupList: [], chosenPdpGroup: '', - chosenPdpSubgroup: '' + chosenPdpSubgroup: '', + showSucAlert: false, + showFailAlert: false }; constructor(props, context) { @@@ -60,6 -64,8 +64,8 @@@ this.handlePdpGroupChange = this.handlePdpGroupChange.bind(this); this.handlePdpSubgroupChange = this.handlePdpSubgroupChange.bind(this); this.createJsonEditor = this.createJsonEditor.bind(this); + this.handleRefresh = this.handleRefresh.bind(this); + this.disableAlert = this.disableAlert.bind(this); } handleSave() { @@@ -122,7 -128,7 +128,7 @@@ startval: editorData, theme: 'myBootstrap4', object_layout: 'grid', - disable_properties: true, + disable_properties: false, disable_edit_json: false, disable_array_reorder: true, disable_array_delete_last_row: true, @@@ -195,12 -201,67 +201,67 @@@ this.setState({ chosenPdpSubgroup: e.value }); } + handleRefresh() { + var newLoopCache, toscaModel, editorData; + if (this.state.policyInstanceType === 'MICRO-SERVICE-POLICY') { + LoopService.refreshMicroServicePolicyJson(this.state.loopCache.getLoopName(),this.state.policyName).then(data => { + newLoopCache = new LoopCache(data); + toscaModel = newLoopCache.getMicroServiceJsonRepresentationForName(this.state.policyName); + editorData = newLoopCache.getMicroServicePropertiesForName(this.state.policyName); + document.getElementById("editor").innerHTML = ""; + this.setState({ + loopCache: newLoopCache, + jsonEditor: this.createJsonEditor(toscaModel,editorData), + showSucAlert: true, + showMessage: "Successfully refreshed" + }); + }) + .catch(error => { + console.error("Error while refreshing the Operational Policy Json Representation"); + this.setState({ + showFailAlert: true, + showMessage: "Refreshing of UI failed" + }); + }); + } else if (this.state.policyInstanceType === 'OPERATIONAL-POLICY') { + LoopService.refreshOperationalPolicyJson(this.state.loopCache.getLoopName(),this.state.policyName).then(data => { + var newLoopCache = new LoopCache(data); + toscaModel = newLoopCache.getOperationalPolicyJsonRepresentationForName(this.state.policyName); + editorData = newLoopCache.getOperationalPolicyPropertiesForName(this.state.policyName); + document.getElementById("editor").innerHTML = ""; + this.setState({ + loopCache: newLoopCache, + jsonEditor: this.createJsonEditor(toscaModel,editorData), + showSucAlert: true, + showMessage: "Successfully refreshed" + }); + }) + .catch(error => { + console.error("Error while refreshing the Operational Policy Json Representation"); + this.setState({ + showFailAlert: true, + showMessage: "Refreshing of UI failed" + }); + }); + } + } + + disableAlert() { + this.setState ({ showSucAlert: false, showFailAlert: false }); + } + render() { return ( Edit the policy + + {this.state.showMessage} + + + {this.state.showMessage} +
@@@ -220,6 -281,9 +281,9 @@@ +