From d2a4df0b62b6a32c42bac45b4bee344016faa8fb Mon Sep 17 00:00:00 2001 From: sebdet Date: Wed, 26 Feb 2020 15:47:30 -0800 Subject: Add Create loop dialog Add create loop dialog and backend part associated (this is based on this PR https://gerrit.onap.org/r/c/clamp/+/102156) Issue-ID: CLAMP-587 Change-Id: I58524bc2d5bfbf5ca5a3acf5c59823df06fd4cd9 Signed-off-by: sebdet --- ui-react/src/LoopUI.js | 3 + ui-react/src/__snapshots__/LoopUI.test.js.snap | 4 + ui-react/src/__snapshots__/OnapClamp.test.js.snap | 4 + ui-react/src/api/LoopService.js | 18 +++ ui-react/src/api/TemplateService.js | 16 +++ .../src/components/dialogs/Loop/CreateLoopModal.js | 133 +++++++++++++++++++++ .../src/components/dialogs/Policy/PolicyModal.js | 8 +- ui-react/src/components/menu/MenuBar.js | 5 +- .../menu/__snapshots__/MenuBar.test.js.snap | 55 ++++++++- 9 files changed, 238 insertions(+), 8 deletions(-) create mode 100644 ui-react/src/components/dialogs/Loop/CreateLoopModal.js (limited to 'ui-react') diff --git a/ui-react/src/LoopUI.js b/ui-react/src/LoopUI.js index 95106702..471e8720 100644 --- a/ui-react/src/LoopUI.js +++ b/ui-react/src/LoopUI.js @@ -37,10 +37,12 @@ import LoopCache from './api/LoopCache'; import LoopActionService from './api/LoopActionService'; import { Route } from 'react-router-dom' +import CreateLoopModal from './components/dialogs/Loop/CreateLoopModal'; import OpenLoopModal from './components/dialogs/Loop/OpenLoopModal'; import ModifyLoopModal from './components/dialogs/Loop/ModifyLoopModal'; import OperationalPolicyModal from './components/dialogs/OperationalPolicy/OperationalPolicyModal'; import ConfigurationPolicyModal from './components/dialogs/ConfigurationPolicy/ConfigurationPolicyModal'; +import PolicyModal from './components/dialogs/Policy/PolicyModal'; import LoopPropertiesModal from './components/dialogs/Loop/LoopPropertiesModal'; import UserInfoModal from './components/dialogs/UserInfoModal'; import LoopService from './api/LoopService'; @@ -257,6 +259,7 @@ export default class LoopUI extends React.Component { render={(routeProps) => ()} /> ()} /> ()} /> + ()} /> ()} /> ()} /> ()} /> diff --git a/ui-react/src/__snapshots__/LoopUI.test.js.snap b/ui-react/src/__snapshots__/LoopUI.test.js.snap index 3d0137c1..7d2c4467 100644 --- a/ui-react/src/__snapshots__/LoopUI.test.js.snap +++ b/ui-react/src/__snapshots__/LoopUI.test.js.snap @@ -28,6 +28,10 @@ exports[`Verify LoopUI Test the render method 1`] = ` path="/configurationPolicyModal/:policyName" render={[Function]} /> + + { + const templateOptions = templateNames.map((templateName) => { return { label: templateName, value: templateName } }); + this.setState({ templateNames: templateOptions }) + }); + } + + handleCreate() { + if (!this.state.modelName) { + alert("A model name is required"); + return; + } + console.info("Create Model " + this.state.modelName + ", Template " + this.state.chosenTemplateName + " is chosen"); + this.setState({ show: false }); + LoopService.createLoop("LOOP_" + this.state.modelName, this.state.chosenTemplateName).then(text => { + console.debug("CreateLoop response received: ", text); + try { + this.props.history.push('/'); + this.props.loadLoopFunction("LOOP_" + this.state.modelName); + } catch(err) { + alert(text); + this.props.history.push('/'); + } + }) + .catch(error => { + console.debug("Create Loop failed"); + }); + + } + + handleModelName = event => { + this.setState({ + modelName: event.target.value + }) + } + + render() { + return ( + + + Create Model + + + + Template Name + + + + + + + + + + + ); + } +} \ No newline at end of file diff --git a/ui-react/src/components/dialogs/Policy/PolicyModal.js b/ui-react/src/components/dialogs/Policy/PolicyModal.js index 75ac2c49..51a6464c 100644 --- a/ui-react/src/components/dialogs/Policy/PolicyModal.js +++ b/ui-react/src/components/dialogs/Policy/PolicyModal.js @@ -61,14 +61,14 @@ export default class PolicyModal extends React.Component { } else { console.info("NO validation errors found in policy data"); - if (policyInstanceType === 'MICRO-SERVICE-POLICY') { + if (this.state.policyInstanceType === 'MICRO-SERVICE-POLICY') { this.state.loopCache.updateMicroServiceProperties(this.state.policyName, editorData[0]); LoopService.setMicroServiceProperties(this.state.loopCache.getLoopName(), this.state.loopCache.getMicroServiceForName(this.state.policyName)).then(resp => { this.setState({ show: false }); this.props.history.push('/'); this.props.loadLoopFunction(this.state.loopCache.getLoopName()); }); - } else if (policyInstanceType === 'OPERATIONAL-POLICY') { + } else if (this.state.policyInstanceType === 'OPERATIONAL-POLICY') { this.state.loopCache.updateOperationalPolicyProperties(editorData); LoopService.setOperationalPolicyProperties(this.state.loopCache.getLoopName(), this.state.loopCache.getOperationalPolicyForName(this.state.policyName)).then(resp => { this.setState({ show: false }); @@ -92,10 +92,10 @@ export default class PolicyModal extends React.Component { console.debug("Rendering PolicyModal ", this.state.policyName); var toscaModel = {}; var editorData = {}; - if (policyInstanceType === 'MICRO-SERVICE-POLICY') { + if (this.state.policyInstanceType === 'MICRO-SERVICE-POLICY') { toscaModel = this.state.loopCache.getMicroServiceJsonRepresentationForName(this.state.policyName); editorData = this.state.loopCache.getMicroServicePropertiesForName(this.state.policyName); - } else if (policyInstanceType === 'OPERATIONAL-POLICY') { + } else if (this.state.policyInstanceType === 'OPERATIONAL-POLICY') { toscaModel = this.state.loopCache.getOperationalPolicyJsonRepresentationForName(this.state.policyName); editorData = this.state.loopCache.getOperationalPolicyPropertiesForName(this.state.policyName); } diff --git a/ui-react/src/components/menu/MenuBar.js b/ui-react/src/components/menu/MenuBar.js index c1a7ac3b..2f13cfe3 100644 --- a/ui-react/src/components/menu/MenuBar.js +++ b/ui-react/src/components/menu/MenuBar.js @@ -95,10 +95,11 @@ export default class MenuBar extends React.Component { View Tosca Models - Open Loop + Create + Open Properties Close - Modify + Modify Refresh Status diff --git a/ui-react/src/components/menu/__snapshots__/MenuBar.test.js.snap b/ui-react/src/components/menu/__snapshots__/MenuBar.test.js.snap index a7e66edd..63d3f654 100644 --- a/ui-react/src/components/menu/__snapshots__/MenuBar.test.js.snap +++ b/ui-react/src/components/menu/__snapshots__/MenuBar.test.js.snap @@ -199,6 +199,57 @@ exports[`Verify MenuBar Test the render method 1`] = ` [Function], "; } +", + ], + }, + "displayName": "Styled(Link)", + "foldedComponentIds": Array [], + "render": [Function], + "styledComponentId": "sc-bdVaJa", + "target": [Function], + "toString": [Function], + "warnTooManyClasses": [Function], + "withComponent": [Function], + } + } + disabled={false} + to="/createLoop" + > + Create + + - Open Loop + Open Modify -- cgit 1.2.3-korg