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 --- 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 +- 24 files changed, 460 insertions(+), 538 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') 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: - + + + - - -