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 --- .../src/components/dialogs/Loop/CreateLoopModal.js | 133 +++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 ui-react/src/components/dialogs/Loop/CreateLoopModal.js (limited to 'ui-react/src/components/dialogs/Loop/CreateLoopModal.js') diff --git a/ui-react/src/components/dialogs/Loop/CreateLoopModal.js b/ui-react/src/components/dialogs/Loop/CreateLoopModal.js new file mode 100644 index 000000000..d6c5e3579 --- /dev/null +++ b/ui-react/src/components/dialogs/Loop/CreateLoopModal.js @@ -0,0 +1,133 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END============================================ + * =================================================================== + * + */ + +import React from 'react' +import Select from 'react-select'; +import Button from 'react-bootstrap/Button'; +import Modal from 'react-bootstrap/Modal'; +import Form from 'react-bootstrap/Form'; +import Row from 'react-bootstrap/Row'; +import Col from 'react-bootstrap/Col'; +import styled from 'styled-components'; +import LoopService from '../../../api/LoopService'; +import TemplateService from '../../../api/TemplateService'; + +const ModalStyled = styled(Modal)` + background-color: transparent; +` + +export default class CreateLoopModal extends React.Component { + constructor(props, context) { + super(props, context); + + this.getTemplateNames = this.getTemplateNames.bind(this); + this.handleCreate = this.handleCreate.bind(this); + this.handleModelName = this.handleModelName.bind(this); + this.handleClose = this.handleClose.bind(this); + this.handleDropdownListChange = this.handleDropdownListChange.bind(this); + this.state = { + show: true, + chosenTemplateName: '', + modelName: '', + templateNames: [] + }; + } + + componentWillMount() { + this.getTemplateNames(); + } + + handleClose() { + this.setState({ show: false }); + this.props.history.push('/'); + } + + handleDropdownListChange(e) { + this.setState({ chosenTemplateName: e.value }); + } + + getTemplateNames() { + TemplateService.getTemplateNames().then(templateNames => { + 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 -- cgit 1.2.3-korg From 3173d554371bae1eefafc69b2bc9da5543510dd5 Mon Sep 17 00:00:00 2001 From: jingjincs Date: Wed, 4 Mar 2020 09:11:10 +0100 Subject: Update template menu UI Modify View Templates Menu to adopt changes from get template CL API Issue-ID: CLAMP-589 Change-Id: I54d059620e91d0da70e85c62dbb932ee58dd99ab Signed-off-by: xuegao --- ui-react/src/api/TemplateService.js | 17 +++++ .../src/components/dialogs/Loop/CreateLoopModal.js | 32 ++++++-- .../src/components/dialogs/Loop/OpenLoopModal.js | 29 +++++++- .../components/dialogs/Loop/OpenLoopModal.test.js | 6 +- .../Loop/__snapshots__/OpenLoopModal.test.js.snap | 14 +++- .../dialogs/Tosca/ViewLoopTemplatesModal.js | 87 +++++++++++++--------- .../dialogs/Tosca/ViewLoopTemplatesModal.test.js | 26 +------ .../ViewLoopTemplatesModal.test.js.snap | 12 ++- 8 files changed, 143 insertions(+), 80 deletions(-) (limited to 'ui-react/src/components/dialogs/Loop/CreateLoopModal.js') diff --git a/ui-react/src/api/TemplateService.js b/ui-react/src/api/TemplateService.js index 124d29c27..615a87e96 100644 --- a/ui-react/src/api/TemplateService.js +++ b/ui-react/src/api/TemplateService.js @@ -54,6 +54,23 @@ export default class TemplateService { return {}; }); } + + static getBlueprintMicroServiceTemplate(templateName) { + return fetch('/restservices/clds/v2/templates/' + templateName + ' /svgRepresentation', { method: 'GET', credentials: 'same-origin', }) + .then(function (response) { + console.debug("getBlueprintMicroServiceTemplate response received: ", response.status); + if (response.ok) { + return response.text(); + } else { + console.error("getBlueprintMicroServiceTemplates query failed"); + return {}; + } + }) + .catch(function (error) { + console.error("getBlueprintMicroServiceTemplate error received", error); + return {}; + }); + } static getDictionary() { return fetch('restservices/clds/v2/dictionary/', { method: 'GET', credentials: 'same-origin', }) diff --git a/ui-react/src/components/dialogs/Loop/CreateLoopModal.js b/ui-react/src/components/dialogs/Loop/CreateLoopModal.js index d6c5e3579..e38207792 100644 --- a/ui-react/src/components/dialogs/Loop/CreateLoopModal.js +++ b/ui-react/src/components/dialogs/Loop/CreateLoopModal.js @@ -34,6 +34,14 @@ import TemplateService from '../../../api/TemplateService'; const ModalStyled = styled(Modal)` background-color: transparent; ` +const LoopViewSvgDivStyled = styled.div` + overflow: hidden; + background-color: ${props => (props.theme.loopViewerBackgroundColor)}; + border-color: ${props => (props.theme.loopViewerHeaderColor)}; + margin-left: auto; + margin-right:auto; + text-align: center; +` export default class CreateLoopModal extends React.Component { constructor(props, context) { @@ -46,6 +54,7 @@ export default class CreateLoopModal extends React.Component { this.handleDropdownListChange = this.handleDropdownListChange.bind(this); this.state = { show: true, + content: '', chosenTemplateName: '', modelName: '', templateNames: [] @@ -63,6 +72,13 @@ export default class CreateLoopModal extends React.Component { handleDropdownListChange(e) { this.setState({ chosenTemplateName: e.value }); + TemplateService.getBlueprintMicroServiceTemplates(e.value).then(svgXml => { + if (svgXml.length !== 0) { + this.setState({ content: svgXml }) + } else { + this.setState({ content: 'Error1' }) + } + }) } getTemplateNames() { @@ -77,7 +93,7 @@ export default class CreateLoopModal extends React.Component { alert("A model name is required"); return; } - console.info("Create Model " + this.state.modelName + ", Template " + this.state.chosenTemplateName + " is chosen"); + console.debug("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); @@ -92,18 +108,17 @@ export default class CreateLoopModal extends React.Component { .catch(error => { console.debug("Create Loop failed"); }); - } handleModelName = event => { - this.setState({ - modelName: event.target.value - }) + this.setState({ + modelName: event.target.value + }) } render() { return ( - + Create Model @@ -114,6 +129,10 @@ export default class CreateLoopModal extends React.Component { Create - ); } } \ No newline at end of file diff --git a/ui-react/src/components/dialogs/Loop/OpenLoopModal.js b/ui-react/src/components/dialogs/Loop/OpenLoopModal.js index 4e8d97820..7c98fab4d 100644 --- a/ui-react/src/components/dialogs/Loop/OpenLoopModal.js +++ b/ui-react/src/components/dialogs/Loop/OpenLoopModal.js @@ -37,6 +37,14 @@ const ModalStyled = styled(Modal)` const CheckBoxStyled = styled(FormCheck.Input)` margin-left:3rem; ` +const LoopViewSvgDivStyled = styled.div` + overflow: hidden; + background-color: ${props => (props.theme.loopViewerBackgroundColor)}; + border-color: ${props => (props.theme.loopViewerHeaderColor)}; + margin-left: auto; + margin-right:auto; + text-align: center; +` export default class OpenLoopModal extends React.Component { constructor(props, context) { @@ -49,7 +57,8 @@ export default class OpenLoopModal extends React.Component { this.state = { show: true, chosenLoopName: '', - loopNames: [] + loopNames: [], + content:'' }; } @@ -64,6 +73,13 @@ export default class OpenLoopModal extends React.Component { handleDropdownListChange(e) { this.setState({ chosenLoopName: e.value }); + LoopService.getSvg(e.value).then(svgXml => { + if (svgXml.length !== 0) { + this.setState({ content: svgXml }) + } else { + this.setState({ content: 'Error1' }) + } + }); } getLoopNames() { @@ -71,7 +87,9 @@ export default class OpenLoopModal extends React.Component { if (Object.entries(loopNames).length !== 0) { const loopOptions = loopNames.filter(loopName => loopName!=='undefined').map((loopName) => { return { label: loopName, value: loopName } }); this.setState({ loopNames: loopOptions }) + } + }); } @@ -83,7 +101,7 @@ export default class OpenLoopModal extends React.Component { render() { return ( - + Open Model @@ -91,9 +109,14 @@ export default class OpenLoopModal extends React.Component { Model Name - + + + + Read Only diff --git a/ui-react/src/components/dialogs/Loop/OpenLoopModal.test.js b/ui-react/src/components/dialogs/Loop/OpenLoopModal.test.js index 208c947c3..f362cfaa6 100644 --- a/ui-react/src/components/dialogs/Loop/OpenLoopModal.test.js +++ b/ui-react/src/components/dialogs/Loop/OpenLoopModal.test.js @@ -28,12 +28,12 @@ describe('Verify OpenLoopModal', () => { beforeEach(() => { fetch.resetMocks(); - fetch.mockResponseOnce(JSON.stringify([ + fetch.mockResponse(JSON.stringify([ "LOOP_gmtAS_v1_0_ResourceInstanceName1_tca", "LOOP_gmtAS_v1_0_ResourceInstanceName1_tca_3", "LOOP_gmtAS_v1_0_ResourceInstanceName2_tca_2" ])); - }) + }); it('Test the render method', () => { @@ -44,12 +44,12 @@ describe('Verify OpenLoopModal', () => { it('Onchange event', () => { const event = {value: 'LOOP_gmtAS_v1_0_ResourceInstanceName1_tca_3'}; const component = shallow(); - component.find('StateManager').simulate('change', event); component.update(); expect(component.state('chosenLoopName')).toEqual("LOOP_gmtAS_v1_0_ResourceInstanceName1_tca_3"); }); + it('Test handleClose', () => { const historyMock = { push: jest.fn() }; const handleClose = jest.spyOn(OpenLoopModal.prototype,'handleClose'); diff --git a/ui-react/src/components/dialogs/Loop/__snapshots__/OpenLoopModal.test.js.snap b/ui-react/src/components/dialogs/Loop/__snapshots__/OpenLoopModal.test.js.snap index 9e7222415..1aa0b5ae9 100644 --- a/ui-react/src/components/dialogs/Loop/__snapshots__/OpenLoopModal.test.js.snap +++ b/ui-react/src/components/dialogs/Loop/__snapshots__/OpenLoopModal.test.js.snap @@ -4,7 +4,7 @@ exports[`Verify OpenLoopModal Test the render method 1`] = ` + + + diff --git a/ui-react/src/components/dialogs/Tosca/ViewLoopTemplatesModal.js b/ui-react/src/components/dialogs/Tosca/ViewLoopTemplatesModal.js index 89e5697c9..18c444046 100644 --- a/ui-react/src/components/dialogs/Tosca/ViewLoopTemplatesModal.js +++ b/ui-react/src/components/dialogs/Tosca/ViewLoopTemplatesModal.js @@ -38,22 +38,26 @@ import MaterialTable from "material-table"; const ModalStyled = styled(Modal)` background-color: transparent; ` -const TextModal = styled.textarea` -margin-top: 20px; -white-space:pre; -background-color: ${props => props.theme.toscaTextareaBackgroundColor};; -text-align: justify; -font-size: ${props => props.theme.toscaTextareaFontSize};; -width: 100%; -height: 300px; +const LoopViewSvgDivStyled = styled.div` + overflow: hidden; + background-color: ${props => (props.theme.loopViewerBackgroundColor)}; + border-color: ${props => (props.theme.loopViewerHeaderColor)}; + margin-left: auto; + margin-right:auto; + text-align: center; + margin-top: 20px; ` +const SvgContainerDivStyled = styled.div` + border: 1px solid; +` + const cellStyle = { border: '1px solid black' }; const headerStyle = { backgroundColor: '#ddd', border: '2px solid black' }; const rowHeaderStyle = {backgroundColor:'#ddd', fontSize: '15pt', text: 'bold', border: '1px solid black'}; export default class ViewLoopTemplatesModal extends React.Component { state = { - show: true, + show: true, content: 'Please select a loop template to display it', selectedRow: -1, loopTemplateData: [], @@ -97,8 +101,7 @@ export default class ViewLoopTemplatesModal extends React.Component { constructor(props, context) { super(props, context); this.handleClose = this.handleClose.bind(this); - this.getBlueprintMicroServiceTemplates = this.getBlueprintMicroServiceTemplates.bind(this); - this.handleYamlContent = this.handleYamlContent.bind(this); + this.getBlueprintMicroServiceTemplate = this.getBlueprintMicroServiceTemplate.bind(this); this.getBlueprintMicroServiceTemplates(); } @@ -108,11 +111,20 @@ export default class ViewLoopTemplatesModal extends React.Component { }); } - handleYamlContent = event => { - this.setState({ - content: event.target.value - }); - } + getBlueprintMicroServiceTemplate(templateName) { + if (typeof templateName !== "undefined") { + TemplateService.getBlueprintMicroServiceTemplate(templateName).then(svgXml => { + if (svgXml.length !== 0) { + this.setState({ content: svgXml }) + } else { + this.setState({ content: 'Please select a loop template to view the details' }) + + } + }); + } else { + this.setState({ content: 'Please select a loop template to view the details' }) + } + } handleClose() { this.setState({ show: false }); @@ -121,30 +133,31 @@ export default class ViewLoopTemplatesModal extends React.Component { render() { return ( - - - - - + + + + {this.setState({content: rowData.name, selectedRow: rowData.tableData.id})}} + onRowClick={(event, rowData) => {this.getBlueprintMicroServiceTemplate(rowData.name);this.setState({selectedRow: rowData.tableData.id})}} options={{ - headerStyle:rowHeaderStyle, - rowStyle: rowData => ({ - backgroundColor: (this.state.selectedRow !== -1 && this.state.selectedRow === rowData.tableData.id) ? '#EEE' : '#FFF' - }) - }} - /> -
- -
-
- - - + headerStyle:rowHeaderStyle, + rowStyle: rowData => ({ + backgroundColor: (this.state.selectedRow !== -1 && this.state.selectedRow === rowData.tableData.id) ? '#EEE' : '#FFF' + }) + }} + /> + + + + +
+ + +
); } diff --git a/ui-react/src/components/dialogs/Tosca/ViewLoopTemplatesModal.test.js b/ui-react/src/components/dialogs/Tosca/ViewLoopTemplatesModal.test.js index 94d4acdc8..ddfb2a70c 100644 --- a/ui-react/src/components/dialogs/Tosca/ViewLoopTemplatesModal.test.js +++ b/ui-react/src/components/dialogs/Tosca/ViewLoopTemplatesModal.test.js @@ -28,8 +28,7 @@ import { mount } from 'enzyme'; describe('Verify ViewLoopTemplatesModal', () => { beforeEach(() => { fetch.resetMocks(); - } - ); + }); it('Test API Successful', () => { fetch.mockImplementationOnce(() => { @@ -133,29 +132,6 @@ describe('Verify ViewLoopTemplatesModal', () => { const component = mount(); expect(component.find('[className="MuiSelect-icon MuiTablePagination-selectIcon"]')).toBeTruthy(); }); - - it('Test handleYamlContent', () => { - fetch.mockImplementationOnce(() => { - return Promise.resolve({ - ok: true, - status: 200, - json: () => { - return Promise.resolve({ - "index": "1", - "name": "MTCA version 1", - "modelService.serviceDetails.name": "MTCA", - "allowedLoopType" : "CLOSED", - "maximumInstancesAllowed":1, - "updatedDate":"2019-09-06 19:09:42" - }); - } - }); - }); - const yamlContent = 'MTCA version 1'; - const component = shallow(); - component.find('[value="Please select a loop template to display it"]').prop('onChange')({ target: { value: yamlContent }}); - expect(component.state('content')).toEqual(yamlContent); - }); it('Test handleClose', () => { fetch.mockImplementationOnce(() => { diff --git a/ui-react/src/components/dialogs/Tosca/__snapshots__/ViewLoopTemplatesModal.test.js.snap b/ui-react/src/components/dialogs/Tosca/__snapshots__/ViewLoopTemplatesModal.test.js.snap index efec96e94..253820f86 100644 --- a/ui-react/src/components/dialogs/Tosca/__snapshots__/ViewLoopTemplatesModal.test.js.snap +++ b/ui-react/src/components/dialogs/Tosca/__snapshots__/ViewLoopTemplatesModal.test.js.snap @@ -140,12 +140,16 @@ exports[`Verify ViewLoopTemplatesModal Test the tosca model view render method 1 } title="View Blueprint MicroService Templates" /> -
- + -
+ diff --git a/ui-react/src/components/dialogs/Tosca/ViewLoopTemplatesModal.js b/ui-react/src/components/dialogs/Tosca/ViewLoopTemplatesModal.js index c5a91ea26..7cf02f711 100644 --- a/ui-react/src/components/dialogs/Tosca/ViewLoopTemplatesModal.js +++ b/ui-react/src/components/dialogs/Tosca/ViewLoopTemplatesModal.js @@ -38,16 +38,24 @@ import MaterialTable from "material-table"; const ModalStyled = styled(Modal)` background-color: transparent; ` -const LoopViewSvgDivStyled = styled.div` - overflow: hidden; +const LoopViewSvgDivStyled = styled.svg` + overflow-x: scroll; background-color: ${props => (props.theme.loopViewerBackgroundColor)}; border-color: ${props => (props.theme.loopViewerHeaderColor)}; - margin-left: auto; + margin-top: 3em; + margin-left: 2em; margin-right:auto; text-align: center; - margin-top: 20px; + height: 100%; + width: 100%; + display: flex; + flex-direction: row; + align-items: center; + ` const SvgContainerDivStyled = styled.div` + display: flex; + align-items: center; border: 1px solid; ` @@ -133,7 +141,7 @@ export default class ViewLoopTemplatesModal extends React.Component { render() { return ( - + diff --git a/ui-react/src/components/dialogs/Tosca/ViewToscaPolicyModal.js b/ui-react/src/components/dialogs/Tosca/ViewToscaPolicyModal.js index 71f371a6d..d49232f2d 100644 --- a/ui-react/src/components/dialogs/Tosca/ViewToscaPolicyModal.js +++ b/ui-react/src/components/dialogs/Tosca/ViewToscaPolicyModal.js @@ -139,7 +139,7 @@ export default class ViewToscalPolicyModal extends React.Component { render() { return ( - + diff --git a/ui-react/src/components/dialogs/Tosca/__snapshots__/ViewLoopTemplatesModal.test.js.snap b/ui-react/src/components/dialogs/Tosca/__snapshots__/ViewLoopTemplatesModal.test.js.snap index 2926e066e..3f6dc9482 100644 --- a/ui-react/src/components/dialogs/Tosca/__snapshots__/ViewLoopTemplatesModal.test.js.snap +++ b/ui-react/src/components/dialogs/Tosca/__snapshots__/ViewLoopTemplatesModal.test.js.snap @@ -3,6 +3,7 @@ exports[`Verify ViewLoopTemplatesModal Test the tosca model view render method 1`] = ` - (props.theme.loopViewerBackgroundColor)}; border: 1px solid; border-color: ${props => (props.theme.loopViewerHeaderColor)}; + margin-top: 1em; margin-left: auto; margin-right:auto; - text-align: center; + margin-bottom: -3em; + align-items: center; + height: 100%; + width: 100%; ` @@ -101,4 +107,4 @@ class LoopViewSvg extends React.Component { } } -export default withRouter(LoopViewSvg); \ No newline at end of file +export default withRouter(LoopViewSvg); diff --git a/ui-react/src/components/loop_viewer/svg/__snapshots__/LoopSvg.test.js.snap b/ui-react/src/components/loop_viewer/svg/__snapshots__/LoopSvg.test.js.snap index cecfb425a..e05f1c794 100644 --- a/ui-react/src/components/loop_viewer/svg/__snapshots__/LoopSvg.test.js.snap +++ b/ui-react/src/components/loop_viewer/svg/__snapshots__/LoopSvg.test.js.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Verify LoopSvg Test the render method 1`] = ` -No LOOP (SVG)", @@ -12,7 +12,7 @@ exports[`Verify LoopSvg Test the render method 1`] = ` `; exports[`Verify LoopSvg Test the render method no loopName 1`] = ` -No LOOP (SVG)", @@ -23,7 +23,7 @@ exports[`Verify LoopSvg Test the render method no loopName 1`] = ` `; exports[`Verify LoopSvg Test the render method svg not empty 1`] = ` -", -- cgit 1.2.3-korg From c0ec0fc448af1c5d6eacb195e95938c921ba1bce Mon Sep 17 00:00:00 2001 From: sebdet Date: Mon, 18 May 2020 12:31:11 +0200 Subject: Create SVG in UI Remove the SVG generation from the backend and put it in the UI Issue-ID: CLAMP-854 Signed-off-by: sebdet Change-Id: Icfa9e107d83bb244ac3d87300d013555bfa0b037 --- docs/swagger/swagger.pdf | 4 +- .../onap/clamp/loop/template/LoopElementModel.java | 1 + ui-react/src/LoopUI.js | 4 +- ui-react/src/__snapshots__/LoopUI.test.js.snap | 4 +- ui-react/src/__snapshots__/OnapClamp.test.js.snap | 4 +- ui-react/src/api/LoopCache.js | 27 ++- ui-react/src/api/TemplateService.js | 41 +--- .../src/components/dialogs/Loop/CreateLoopModal.js | 74 +++---- .../dialogs/Loop/CreateLoopModal.test.js | 25 +-- .../src/components/dialogs/Loop/OpenLoopModal.js | 45 ++-- .../components/dialogs/Loop/OpenLoopModal.test.js | 12 +- .../__snapshots__/CreateLoopModal.test.js.snap | 11 +- .../Loop/__snapshots__/OpenLoopModal.test.js.snap | 13 +- .../src/components/dialogs/Policy/PolicyModal.js | 91 +++++--- .../components/dialogs/Policy/PolicyModal.test.js | 3 +- .../dialogs/Tosca/ViewLoopTemplatesModal.js | 68 ++---- .../dialogs/Tosca/ViewLoopTemplatesModal.test.js | 3 +- .../ViewLoopTemplatesModal.test.js.snap | 28 +-- .../loop_viewer/svg/LoopComponentConverter.js | 17 -- ui-react/src/components/loop_viewer/svg/LoopSvg.js | 110 ---------- .../src/components/loop_viewer/svg/LoopSvg.test.js | 132 ------------ .../src/components/loop_viewer/svg/SvgGenerator.js | 240 +++++++++++++++++++++ .../svg/__snapshots__/LoopSvg.test.js.snap | 34 --- .../src/components/loop_viewer/svg/example.svg | 1 - ui-react/src/theme/globalStyle.js | 7 +- ui-react/src/utils/OnapConstants.js | 4 +- 26 files changed, 463 insertions(+), 540 deletions(-) delete mode 100644 ui-react/src/components/loop_viewer/svg/LoopComponentConverter.js delete mode 100644 ui-react/src/components/loop_viewer/svg/LoopSvg.js delete mode 100644 ui-react/src/components/loop_viewer/svg/LoopSvg.test.js create mode 100644 ui-react/src/components/loop_viewer/svg/SvgGenerator.js delete mode 100644 ui-react/src/components/loop_viewer/svg/__snapshots__/LoopSvg.test.js.snap delete mode 100644 ui-react/src/components/loop_viewer/svg/example.svg (limited to 'ui-react/src/components/dialogs/Loop/CreateLoopModal.js') diff --git a/docs/swagger/swagger.pdf b/docs/swagger/swagger.pdf index ed429f29e..e5e2bb04e 100644 --- a/docs/swagger/swagger.pdf +++ b/docs/swagger/swagger.pdf @@ -4,8 +4,8 @@ << /Title (Clamp Rest API) /Creator (Asciidoctor PDF 1.5.0.alpha.10, based on Prawn 1.3.0) /Producer (Asciidoctor PDF 1.5.0.alpha.10, based on Prawn 1.3.0) -/CreationDate (D:20200513003949+02'00') -/ModDate (D:20200513003949+02'00') +/CreationDate (D:20200519123507+02'00') +/ModDate (D:20200519123507+02'00') >> endobj 2 0 obj diff --git a/src/main/java/org/onap/clamp/loop/template/LoopElementModel.java b/src/main/java/org/onap/clamp/loop/template/LoopElementModel.java index 35fdf43cd..70cdbe233 100644 --- a/src/main/java/org/onap/clamp/loop/template/LoopElementModel.java +++ b/src/main/java/org/onap/clamp/loop/template/LoopElementModel.java @@ -80,6 +80,7 @@ public class LoopElementModel extends AuditEntity implements Serializable { /** * The type of element. */ + @Expose @Column(nullable = false, name = "loop_element_type") private String loopElementType; diff --git a/ui-react/src/LoopUI.js b/ui-react/src/LoopUI.js index efd02b41f..6522cc3dd 100644 --- a/ui-react/src/LoopUI.js +++ b/ui-react/src/LoopUI.js @@ -29,7 +29,7 @@ import logo from './logo.png'; import { GlobalClampStyle } from './theme/globalStyle.js'; import OnapConstants from './utils/OnapConstants'; -import LoopSvg from './components/loop_viewer/svg/LoopSvg'; +import SvgGenerator from './components/loop_viewer/svg/SvgGenerator'; import LoopLogs from './components/loop_viewer/logs/LoopLogs'; import LoopStatus from './components/loop_viewer/status/LoopStatus'; import UserService from './api/UserService'; @@ -203,7 +203,7 @@ export default class LoopUI extends React.Component { renderLoopViewBody() { return ( - + diff --git a/ui-react/src/__snapshots__/LoopUI.test.js.snap b/ui-react/src/__snapshots__/LoopUI.test.js.snap index ff08f7afb..d8b2e7be5 100644 --- a/ui-react/src/__snapshots__/LoopUI.test.js.snap +++ b/ui-react/src/__snapshots__/LoopUI.test.js.snap @@ -180,7 +180,9 @@ exports[`Verify LoopUI Test the render method 1`] = ` ) - - (props.theme.loopViewerBackgroundColor)}; - border-color: ${props => (props.theme.loopViewerHeaderColor)}; - margin-top: 3em; - margin-left: auto; - margin-right:auto; - margin-bottom: -1em; - text-align: center; - align-items: center; - height: 100%; - width: 100%; -` export default class CreateLoopModal extends React.Component { constructor(props, context) { super(props, context); - this.getTemplateNames = this.getTemplateNames.bind(this); + this.getAllLoopTemplates = this.getAllLoopTemplates.bind(this); this.handleCreate = this.handleCreate.bind(this); this.handleModelName = this.handleModelName.bind(this); this.handleClose = this.handleClose.bind(this); - this.handleDropdownListChange = this.handleDropdownListChange.bind(this); + this.handleDropDownListChange = this.handleDropDownListChange.bind(this); this.state = { show: true, - content: '', chosenTemplateName: '', modelName: '', - templateNames: [] + templateNames: [], + fakeLoopCacheWithTemplate: new LoopCache({}) }; } componentWillMount() { - this.getTemplateNames(); + this.getAllLoopTemplates(); } handleClose() { @@ -77,21 +64,26 @@ export default class CreateLoopModal extends React.Component { this.props.history.push('/'); } - handleDropdownListChange(e) { - this.setState({ chosenTemplateName: e.value }); - TemplateService.getBlueprintMicroServiceTemplateSvg(e.value).then(svgXml => { - if (svgXml.length !== 0) { - this.setState({ content: svgXml }) - } else { - this.setState({ content: 'Error1' }) - } - }) + handleDropDownListChange(e) { + if (typeof e.value !== "undefined") { + this.setState({ + fakeLoopCacheWithTemplate: + new LoopCache({ + "loopTemplate":e.templateObject, + "name": "fakeLoop" + }), + chosenTemplateName: e.value + }) + } else { + this.setState({ fakeLoopCacheWithTemplate: new LoopCache({}) }) + } } - getTemplateNames() { - TemplateService.getTemplateNames().then(templateNames => { - const templateOptions = templateNames.map((templateName) => { return { label: templateName, value: templateName } }); - this.setState({ templateNames: templateOptions }) + getAllLoopTemplates() { + TemplateService.getAllLoopTemplates().then(templatesData => { + const templateOptions = templatesData.map((templateData) => { return { label: templateData.name, value: templateData.name, templateObject: templateData } }); + this.setState({ + templateNames: templateOptions }) }); } @@ -133,17 +125,15 @@ export default class CreateLoopModal extends React.Component { Template Name: - - - Model Preview: - - - - - + + Model Preview: + + + + Model Name: { it('Test the render method', async () => { const flushPromises = () => new Promise(setImmediate); - TemplateService.getTemplateNames = jest.fn().mockImplementation(() => { - return Promise.resolve(["template1","template2"]); + TemplateService.getAllLoopTemplates = jest.fn().mockImplementation(() => { + return Promise.resolve([{"name":"template1"},{"name":"template2"}]); }); const component = shallow(); @@ -39,31 +39,26 @@ describe('Verify CreateLoopModal', () => { await flushPromises(); component.update(); - expect(component.state('templateNames')).toStrictEqual([{"label": "template1", "value": "template1"}, {"label": "template2", "value": "template2"}]); + expect(component.state('templateNames')).toStrictEqual([{"label": "template1", "value": "template1", "templateObject": {"name": "template1"}}, {"label": "template2", "value": "template2","templateObject": {"name": "template2"}}]); }); it('handleDropdownListChange event', async () => { const flushPromises = () => new Promise(setImmediate); - const event = {value: 'template1'}; - TemplateService.getBlueprintMicroServiceTemplateSvg = jest.fn().mockImplementation(() => { - return Promise.resolve(""); - }); const component = shallow(); - component.find('StateManager').simulate('change', event); + component.find('StateManager').simulate('change', {value: 'template1', templateObject: {"name":"template1"} }); await flushPromises(); component.update(); expect(component.state('chosenTemplateName')).toEqual("template1"); - expect(component.state('content')).toEqual("Error1"); - - TemplateService.getBlueprintMicroServiceTemplateSvg = jest.fn().mockImplementation(() => { - return Promise.resolve("svgContentTest"); - }); - component.find('StateManager').simulate('change', {value: 'template2'}); + expect(component.state('fakeLoopCacheWithTemplate').getLoopTemplate()['name']).toEqual("template1"); + expect(component.state('fakeLoopCacheWithTemplate').getLoopName()).toEqual("fakeLoop"); + + component.find('StateManager').simulate('change',{value: 'template2', templateObject: {"name":"template2"} }); await flushPromises(); component.update(); expect(component.state('chosenTemplateName')).toEqual("template2"); - expect(component.state('content')).toEqual("svgContentTest"); + expect(component.state('fakeLoopCacheWithTemplate').getLoopTemplate()['name']).toEqual("template2"); + expect(component.state('fakeLoopCacheWithTemplate').getLoopName()).toEqual("fakeLoop"); }); diff --git a/ui-react/src/components/dialogs/Loop/OpenLoopModal.js b/ui-react/src/components/dialogs/Loop/OpenLoopModal.js index c04883443..7ca90b493 100644 --- a/ui-react/src/components/dialogs/Loop/OpenLoopModal.js +++ b/ui-react/src/components/dialogs/Loop/OpenLoopModal.js @@ -30,6 +30,8 @@ import Col from 'react-bootstrap/Col'; import FormCheck from 'react-bootstrap/FormCheck' import styled from 'styled-components'; import LoopService from '../../../api/LoopService'; +import SvgGenerator from '../../loop_viewer/svg/SvgGenerator'; +import LoopCache from '../../../api/LoopCache'; const ModalStyled = styled(Modal)` background-color: transparent; @@ -37,21 +39,6 @@ const ModalStyled = styled(Modal)` const CheckBoxStyled = styled(FormCheck.Input)` margin-left:3rem; ` -const LoopViewSvgDivStyled = styled.svg` - overflow-x: scroll; - display: flex; - flex-direction: row; - background-color: ${props => (props.theme.loopViewerBackgroundColor)}; - border-color: ${props => (props.theme.loopViewerHeaderColor)}; - margin-top: 2em; - margin-left: auto; - margin-right:auto; - margin-bottom: -3em; - text-align: center; - align-items: center; - height: 100%; - width: 100%; -` export default class OpenLoopModal extends React.Component { constructor(props, context) { @@ -60,13 +47,13 @@ export default class OpenLoopModal extends React.Component { this.getLoopNames = this.getLoopNames.bind(this); this.handleOpen = this.handleOpen.bind(this); this.handleClose = this.handleClose.bind(this); - this.handleDropdownListChange = this.handleDropdownListChange.bind(this); + this.handleDropDownListChange = this.handleDropDownListChange.bind(this); this.showReadOnly = props.showReadOnly ? props.showReadOnly : true; this.state = { show: true, chosenLoopName: '', loopNames: [], - content:'' + loopCacheOpened: new LoopCache({}) }; } @@ -79,14 +66,12 @@ export default class OpenLoopModal extends React.Component { this.props.history.push('/'); } - handleDropdownListChange(e) { - this.setState({ chosenLoopName: e.value }); - LoopService.getSvg(e.value).then(svgXml => { - if (svgXml.length !== 0) { - this.setState({ content: svgXml }) - } else { - this.setState({ content: 'Error1' }) - } + handleDropDownListChange(e) { + LoopService.getLoop(e.value).then(loop => { + this.setState({ + chosenLoopName: e.value, + loopCacheOpened: new LoopCache(loop) + }); }); } @@ -95,9 +80,7 @@ export default class OpenLoopModal extends React.Component { if (Object.entries(loopNames).length !== 0) { const loopOptions = loopNames.filter(loopName => loopName!=='undefined').map((loopName) => { return { label: loopName, value: loopName } }); this.setState({ loopNames: loopOptions }) - } - }); } @@ -117,20 +100,18 @@ export default class OpenLoopModal extends React.Component { Model Name: - + + + - - - + + + + + {this.state.modelInputErrMsg} diff --git a/ui-react/src/components/dialogs/Loop/CreateLoopModal.test.js b/ui-react/src/components/dialogs/Loop/CreateLoopModal.test.js index 5b6ea9e62..1caa22dc7 100644 --- a/ui-react/src/components/dialogs/Loop/CreateLoopModal.test.js +++ b/ui-react/src/components/dialogs/Loop/CreateLoopModal.test.js @@ -29,16 +29,18 @@ import TemplateService from '../../../api/TemplateService'; describe('Verify CreateLoopModal', () => { it('Test the render method', async () => { - const flushPromises = () => new Promise(setImmediate); + const flushPromises = () => new Promise(setImmediate); TemplateService.getAllLoopTemplates = jest.fn().mockImplementation(() => { - return Promise.resolve([{"name":"template1"},{"name":"template2"}]); - }); - - const component = shallow(); + return Promise.resolve([{"name":"template1"},{"name":"template2"}]); + }); + TemplateService.getLoopNames = jest.fn().mockImplementation(() => { + return Promise.resolve([]); + }); + + const component = shallow(); expect(component).toMatchSnapshot(); - await flushPromises(); - component.update(); - + await flushPromises(); + component.update(); expect(component.state('templateNames')).toStrictEqual([{"label": "template1", "value": "template1", "templateObject": {"name": "template1"}}, {"label": "template2", "value": "template2","templateObject": {"name": "template2"}}]); }); @@ -61,17 +63,22 @@ describe('Verify CreateLoopModal', () => { expect(component.state('fakeLoopCacheWithTemplate').getLoopName()).toEqual("fakeLoop"); }); - - - it('handleModelName event', () => { + it('handleModelName event', async () => { + const flushPromises = () => new Promise(setImmediate); + TemplateService.getAllLoopTemplates = jest.fn().mockImplementation(() => { + return Promise.resolve([{"name":"template1"},{"name":"template2"}]); + }); + TemplateService.getLoopNames = jest.fn().mockImplementation(() => { + return Promise.resolve([]); + }); const event = {target: {value : "model1"} }; const component = shallow(); + await flushPromises(); component.find('input').simulate('change', event); component.update(); expect(component.state('modelName')).toEqual("model1"); }); - it('Test handleClose', () => { const historyMock = { push: jest.fn() }; const handleClose = jest.spyOn(CreateLoopModal.prototype,'handleClose'); diff --git a/ui-react/src/components/dialogs/Loop/OpenLoopModal.js b/ui-react/src/components/dialogs/Loop/OpenLoopModal.js index 7ca90b493..b45df6502 100644 --- a/ui-react/src/components/dialogs/Loop/OpenLoopModal.js +++ b/ui-react/src/components/dialogs/Loop/OpenLoopModal.js @@ -48,7 +48,8 @@ export default class OpenLoopModal extends React.Component { this.handleOpen = this.handleOpen.bind(this); this.handleClose = this.handleClose.bind(this); this.handleDropDownListChange = this.handleDropDownListChange.bind(this); - this.showReadOnly = props.showReadOnly ? props.showReadOnly : true; + this.renderSvg = this.renderSvg.bind(this); + this.showReadOnly = props.showReadOnly !== undefined ? props.showReadOnly : true; this.state = { show: true, chosenLoopName: '', @@ -90,6 +91,12 @@ export default class OpenLoopModal extends React.Component { this.props.loadLoopFunction(this.state.chosenLoopName); } + renderSvg() { + return( + + ); + } + render() { return ( @@ -107,7 +114,7 @@ export default class OpenLoopModal extends React.Component { Model Preview: - + {this.renderSvg()} {this.showReadOnly === true ? diff --git a/ui-react/src/components/dialogs/Loop/__snapshots__/CreateLoopModal.test.js.snap b/ui-react/src/components/dialogs/Loop/__snapshots__/CreateLoopModal.test.js.snap index e69b809c7..b05781641 100644 --- a/ui-react/src/components/dialogs/Loop/__snapshots__/CreateLoopModal.test.js.snap +++ b/ui-react/src/components/dialogs/Loop/__snapshots__/CreateLoopModal.test.js.snap @@ -107,6 +107,7 @@ exports[`Verify CreateLoopModal Test the render method 1`] = ` + +
+ + + + + diff --git a/ui-react/src/components/dialogs/Tosca/ViewLoopTemplatesModal.js b/ui-react/src/components/dialogs/Tosca/ViewLoopTemplatesModal.js index 962ab4bda..10473944f 100644 --- a/ui-react/src/components/dialogs/Tosca/ViewLoopTemplatesModal.js +++ b/ui-react/src/components/dialogs/Tosca/ViewLoopTemplatesModal.js @@ -92,6 +92,7 @@ export default class ViewLoopTemplatesModal extends React.Component { constructor(props, context) { super(props, context); this.handleClose = this.handleClose.bind(this); + this.renderSvg = this.renderSvg.bind(this); this.getLoopTemplate = this.getLoopTemplate.bind(this); this.getAllLoopTemplates(); } @@ -120,6 +121,12 @@ export default class ViewLoopTemplatesModal extends React.Component { this.props.history.push('/') } + renderSvg() { + return( + + ) + } + render() { return ( @@ -139,7 +146,7 @@ export default class ViewLoopTemplatesModal extends React.Component { }) }} /> - + {this.renderSvg()} diff --git a/ui-react/src/components/loop_viewer/svg/SvgGenerator.js b/ui-react/src/components/loop_viewer/svg/SvgGenerator.js index 7070455e7..f5f5047ba 100644 --- a/ui-react/src/components/loop_viewer/svg/SvgGenerator.js +++ b/ui-react/src/components/loop_viewer/svg/SvgGenerator.js @@ -28,11 +28,12 @@ import OnapConstant from '../../../utils/OnapConstants'; const DivStyled = styled.div` overflow-x: scroll; + display: flex; width: 100%; height: 100%; ` -const emptySvg = ( No LOOP (SVG) ); +const emptySvg = ( No LOOP (SVG) ); class SvgGenerator extends React.Component { boxWidth = 200; @@ -228,11 +229,14 @@ class SvgGenerator extends React.Component { render() { var allTheElements = this.renderSvg(); var svgWidth = this.boxWidth*allTheElements.length; - var svgHeight = this.boxHeight+100; + var svgHeight = this.boxHeight+50; return ( + - + + {allTheElements} + ); -- cgit 1.2.3-korg