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 --- .../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 +++++++++- 4 files changed, 67 insertions(+), 14 deletions(-) (limited to 'ui-react/src/components/dialogs/Loop') diff --git a/ui-react/src/components/dialogs/Loop/CreateLoopModal.js b/ui-react/src/components/dialogs/Loop/CreateLoopModal.js index d6c5e357..e3820779 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 4e8d9782..7c98fab4 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 208c947c..f362cfaa 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 9e722241..1aa0b5ae 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`] = ` + + + -- cgit