From 8d6b013bc26a5715373fc64901f765fcc96701ca Mon Sep 17 00:00:00 2001 From: sebdet Date: Fri, 12 Mar 2021 19:30:22 +0100 Subject: Add refresh & update libs Add refresh features to the policy list when changing it + update materials-Ui + update Json-editor libs to solve big lag in UI + Remove useless link in the menu + fix issue with build due to mariadb not started yet Issue-ID: POLICY-3131 Signed-off-by: sebdet Change-Id: I9bcb9558f213731a4ea8e20e186fb91c9db1b6f3 (cherry picked from commit b8831e5199aa0fe2bb1de531069d376182b3571d) --- ui-react/package.json | 41 +- ui-react/src/__snapshots__/LoopUI.test.js.snap | 4 +- ui-react/src/__snapshots__/OnapClamp.test.js.snap | 8 +- ui-react/src/api/PolicyService.js | 6 +- .../__snapshots__/CreateLoopModal.test.js.snap | 4 +- .../__snapshots__/DeployLoopModal.test.js.snap | 4 +- .../__snapshots__/LoopPropertiesModal.test.js.snap | 4 +- .../Loop/__snapshots__/OpenLoopModal.test.js.snap | 13 +- .../__snapshots__/ManageDictionaries.test.js.snap | 4 +- .../src/components/dialogs/Policy/PolicyEditor.js | 19 +- .../src/components/dialogs/Policy/PolicyModal.js | 502 +++++++++++---------- .../components/dialogs/Policy/ViewAllPolicies.js | 32 +- .../ViewLoopTemplatesModal.test.js.snap | 5 +- .../__snapshots__/UserInfoModal.test.js.snap | 4 +- .../logs/__snapshots__/LoopLogs.test.js.snap | 4 +- .../status/__snapshots__/LoopStatus.test.js.snap | 4 +- ui-react/src/components/menu/MenuBar.js | 13 +- .../menu/__snapshots__/MenuBar.test.js.snap | 483 ++++++++++++-------- ui-react/src/setupTests.js | 6 +- 19 files changed, 627 insertions(+), 533 deletions(-) (limited to 'ui-react') diff --git a/ui-react/package.json b/ui-react/package.json index 83c9c77a6..8d1104442 100644 --- a/ui-react/package.json +++ b/ui-react/package.json @@ -25,30 +25,31 @@ "src/theme" ], "dependencies": { - "@json-editor/json-editor": "1.4.0-beta.0", - "react": "16.9.0", - "react-dom": "16.9.0", - "react-scripts": "3.1.1", - "react-bootstrap": "1.0.0-beta.14", + "@json-editor/json-editor": "2.5.2", + "@fortawesome/fontawesome-free": "5.15.2", + "react": "17.0.1", + "react-dom": "17.0.1", + "react-scripts": "4.0.3", + "react-bootstrap": "1.5.2", "bootstrap-css-only": "4.3.1", - "styled-components": "4.3.2", - "react-router-dom": "5.0.1", - "@material-ui/core": "4.9.11", - "@material-ui/icons": "4.9.1", - "material-table": "1.57.2", - "react-select": "3.0.8", + "styled-components": "5.2.1", + "react-router-dom": "5.2.0", + "@material-ui/core": "4.11.3", + "@material-ui/icons": "4.11.2", + "material-table": "1.68.1", + "react-select": "4.2.1", "react-uuid": "1.0.2" }, "devDependencies": { - "jest": "24.8.0", - "babel-jest": "24.8.0", - "@babel/preset-env": "7.5.5", - "@babel/preset-react": "7.0.0", - "@babel/plugin-proposal-class-properties": "7.5.5", - "enzyme": "3.10.0", - "enzyme-adapter-react-16": "1.14.0", - "enzyme-to-json": "3.4.0", - "jest-fetch-mock": "2.1.2" + "jest": "26.6.0", + "babel-jest": "26.6.0", + "@babel/preset-env": "7.13.10", + "@babel/preset-react": "7.12.13", + "@babel/plugin-proposal-class-properties": "7.13.0", + "enzyme": "3.11.0", + "enzyme-adapter-react-17-updated": "1.0.2", + "enzyme-to-json": "3.6.1", + "jest-fetch-mock": "3.0.3" }, "browserslist": [ ">0.2%", diff --git a/ui-react/src/__snapshots__/LoopUI.test.js.snap b/ui-react/src/__snapshots__/LoopUI.test.js.snap index c230dbcf6..322c93155 100644 --- a/ui-react/src/__snapshots__/LoopUI.test.js.snap +++ b/ui-react/src/__snapshots__/LoopUI.test.js.snap @@ -4,7 +4,7 @@ exports[`Verify LoopUI Test the render method 1`] = ` - + - + - + `; diff --git a/ui-react/src/api/PolicyService.js b/ui-react/src/api/PolicyService.js index a9f44b2a4..855d44167 100644 --- a/ui-react/src/api/PolicyService.js +++ b/ui-react/src/api/PolicyService.js @@ -40,7 +40,7 @@ export default class PolicyService { .catch(function(error) { console.error("getPoliciesList error occurred ", error); alert("getPoliciesList error occurred " + error); - return ""; + return undefined; }) } static createNewPolicy(policyModelType, policyModelVersion, policyName, policyVersion, policyJson) { @@ -67,7 +67,7 @@ export default class PolicyService { .catch(function (error) { console.error("createNewPolicy error occurred ", error); alert ("createNewPolicy error occurred " + error); - return ""; + return undefined; }); } static deletePolicy(policyModelType, policyModelVersion, policyName, policyVersion) { @@ -90,7 +90,7 @@ export default class PolicyService { .catch(function (error) { console.error("deletePolicy error occurred ", error); alert ("deletePolicy error occurred " + error); - return ""; + return undefined; }); } } 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 b05781641..1ba9dbaf1 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 @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Verify CreateLoopModal Test the render method 1`] = ` - - + `; diff --git a/ui-react/src/components/dialogs/Loop/__snapshots__/DeployLoopModal.test.js.snap b/ui-react/src/components/dialogs/Loop/__snapshots__/DeployLoopModal.test.js.snap index 8d0faa5f7..4779ced0d 100644 --- a/ui-react/src/components/dialogs/Loop/__snapshots__/DeployLoopModal.test.js.snap +++ b/ui-react/src/components/dialogs/Loop/__snapshots__/DeployLoopModal.test.js.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Verify DeployLoopModal Test the render method 1`] = ` - - + `; diff --git a/ui-react/src/components/dialogs/Loop/__snapshots__/LoopPropertiesModal.test.js.snap b/ui-react/src/components/dialogs/Loop/__snapshots__/LoopPropertiesModal.test.js.snap index 233c560ab..3baaa5798 100644 --- a/ui-react/src/components/dialogs/Loop/__snapshots__/LoopPropertiesModal.test.js.snap +++ b/ui-react/src/components/dialogs/Loop/__snapshots__/LoopPropertiesModal.test.js.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Verify LoopPropertiesModal Test the render method 1`] = ` - - + `; 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 477260477..581fd0ec0 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 @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Verify OpenLoopModal Test the render method 1`] = ` - - + Read Only Mode: @@ -140,5 +133,5 @@ exports[`Verify OpenLoopModal Test the render method 1`] = ` Open - + `; diff --git a/ui-react/src/components/dialogs/ManageDictionaries/__snapshots__/ManageDictionaries.test.js.snap b/ui-react/src/components/dialogs/ManageDictionaries/__snapshots__/ManageDictionaries.test.js.snap index 40914aee6..6b583632f 100644 --- a/ui-react/src/components/dialogs/ManageDictionaries/__snapshots__/ManageDictionaries.test.js.snap +++ b/ui-react/src/components/dialogs/ManageDictionaries/__snapshots__/ManageDictionaries.test.js.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Verify ManageDictionaries Test API Successful 1`] = ` - - + `; diff --git a/ui-react/src/components/dialogs/Policy/PolicyEditor.js b/ui-react/src/components/dialogs/Policy/PolicyEditor.js index e329e0c32..f20650e26 100644 --- a/ui-react/src/components/dialogs/Policy/PolicyEditor.js +++ b/ui-react/src/components/dialogs/Policy/PolicyEditor.js @@ -23,7 +23,8 @@ import React from 'react' import PolicyToscaService from '../../../api/PolicyToscaService'; -import JSONEditor from '@json-editor/json-editor'; +import { JSONEditor } from '@json-editor/json-editor/dist/nonmin/jsoneditor.js'; +import "@fortawesome/fontawesome-free/css/all.css" import styled from 'styled-components'; import Button from 'react-bootstrap/Button'; import TextField from '@material-ui/core/TextField'; @@ -32,6 +33,7 @@ import PolicyService from '../../../api/PolicyService'; import OnapUtils from '../../../utils/OnapUtils'; import uuid from 'react-uuid'; +//const JSONEditor = require("@json-editor/json-editor").JSONEditor; const DivWhiteSpaceStyled = styled.div` white-space: pre; ` @@ -41,6 +43,7 @@ const JsonEditorDiv = styled.div` background-color: ${props => props.theme.loopViewerBackgroundColor}; text-align: justify; font-size: ${props => props.theme.policyEditorFontSize}; + border: 1px solid #C0C0C0; ` const PanelDiv = styled.div` margin-top: 20px; @@ -98,7 +101,7 @@ export default class PolicyEditor extends React.Component { console.info("NO validation errors found in policy data"); PolicyService.createNewPolicy(this.state.policyModelType, this.state.policyModelTypeVersion, this.state.policyName, this.state.policyVersion, editorData).then(respPolicyCreation => { - if (respPolicyCreation === "") { + if (typeof(respPolicyCreation) === "undefined") { //it indicates a failure this.setState({ showFailAlert: true, @@ -109,6 +112,7 @@ export default class PolicyEditor extends React.Component { showSuccessAlert: true, showMessage: 'Policy '+ this.state.policyName + '/' + this.state.policyVersion + ' created successfully' }); + this.props.policyUpdateFunction(); } }) } @@ -135,7 +139,7 @@ export default class PolicyEditor extends React.Component { } createJsonEditor(toscaModel, editorData) { - JSONEditor.defaults.themes.myBootstrap4 = JSONEditor.defaults.themes.bootstrap4.extend({ + /*JSONEditor.defaults.themes.myBootstrap4 = JSONEditor.defaults.themes.bootstrap4.extend({ getTab: function(text,tabId) { var liel = document.createElement('li'); liel.classList.add('nav-item'); @@ -149,12 +153,15 @@ export default class PolicyEditor extends React.Component { liel.appendChild(ael); return liel; } - }); + });*/ + return new JSONEditor(document.getElementById(this.state.jsonEditorDivId), { schema: toscaModel, startval: editorData, - theme: 'myBootstrap4', + //theme: 'myBootstrap4', + theme: 'bootstrap4', + iconlib: 'fontawesome5', object_layout: 'grid', disable_properties: false, disable_edit_json: false, @@ -163,7 +170,7 @@ export default class PolicyEditor extends React.Component { disable_array_delete_all_rows: false, array_controls_top: true, keep_oneof_values: false, - collapsed:true, + collapsed: true, show_errors: 'always', display_required_only: false, show_opt_in: false, diff --git a/ui-react/src/components/dialogs/Policy/PolicyModal.js b/ui-react/src/components/dialogs/Policy/PolicyModal.js index 6b1ebe178..2fa0b5432 100644 --- a/ui-react/src/components/dialogs/Policy/PolicyModal.js +++ b/ui-react/src/components/dialogs/Policy/PolicyModal.js @@ -1,8 +1,8 @@ /*- * ============LICENSE_START======================================================= - * ONAP CLAMP + * ONAP POLICY-CLAMP * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights + * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,131 +31,133 @@ 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 { JSONEditor } from '@json-editor/json-editor/dist/jsoneditor.js'; +import "@fortawesome/fontawesome-free/css/all.css" import Alert from 'react-bootstrap/Alert'; import OnapConstant from '../../../utils/OnapConstants'; import OnapUtils from '../../../utils/OnapUtils'; const ModalStyled = styled(Modal)` - background-color: transparent; + background-color: transparent; ` const DivWhiteSpaceStyled = styled.div` - white-space: pre; + white-space: pre; ` export default class PolicyModal extends React.Component { - state = { - show: true, - loopCache: this.props.loopCache, - jsonEditor: null, - policyName: this.props.match.params.policyName, - // This is to indicate whether it's an operational or config policy (in terms of loop instance) - policyInstanceType: this.props.match.params.policyInstanceType, - pdpGroup: null, - pdpGroupList: [], - pdpSubgroupList: [], - chosenPdpGroup: '', - chosenPdpSubgroup: '', - showSucAlert: false, - showFailAlert: false - }; + state = { + show: true, + loopCache: this.props.loopCache, + jsonEditor: null, + policyName: this.props.match.params.policyName, + // This is to indicate whether it's an operational or config policy (in terms of loop instance) + policyInstanceType: this.props.match.params.policyInstanceType, + pdpGroup: null, + pdpGroupList: [], + pdpSubgroupList: [], + chosenPdpGroup: '', + chosenPdpSubgroup: '', + showSucAlert: false, + showFailAlert: false + }; - constructor(props, context) { - super(props, context); - this.handleClose = this.handleClose.bind(this); - this.handleSave = this.handleSave.bind(this); - this.renderJsonEditor = this.renderJsonEditor.bind(this); - 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); - this.renderPdpGroupDropDown = this.renderPdpGroupDropDown.bind(this); - this.renderOpenLoopMessage = this.renderOpenLoopMessage.bind(this); - this.renderModalTitle = this.renderModalTitle.bind(this); - this.readOnly = props.readOnly !== undefined ? props.readOnly : false; - } + constructor(props, context) { + super(props, context); + this.handleClose = this.handleClose.bind(this); + this.handleSave = this.handleSave.bind(this); + this.renderJsonEditor = this.renderJsonEditor.bind(this); + 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); + this.renderPdpGroupDropDown = this.renderPdpGroupDropDown.bind(this); + this.renderOpenLoopMessage = this.renderOpenLoopMessage.bind(this); + this.renderModalTitle = this.renderModalTitle.bind(this); + this.readOnly = props.readOnly !== undefined ? props.readOnly : false; + } - handleSave() { - var editorData = this.state.jsonEditor.getValue(); - var errors = this.state.jsonEditor.validate(); - errors = errors.concat(this.customValidation(editorData, this.state.loopCache.getTemplateName())); + handleSave() { + var editorData = this.state.jsonEditor.getValue(); + var errors = this.state.jsonEditor.validate(); + errors = errors.concat(this.customValidation(editorData, this.state.loopCache.getTemplateName())); - if (errors.length !== 0) { - console.error("Errors detected during policy data validation ", errors); - this.setState({ - showFailAlert: true, - showMessage: 'Errors detected during policy data validation:\n' + OnapUtils.jsonEditorErrorFormatter(errors) - }); - return; - } - else { - console.info("NO validation errors found in policy data"); - if (this.state.policyInstanceType === OnapConstant.microServiceType) { - this.state.loopCache.updateMicroServiceProperties(this.state.policyName, editorData); - this.state.loopCache.updateMicroServicePdpGroup(this.state.policyName, this.state.chosenPdpGroup, this.state.chosenPdpSubgroup); - 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 (this.state.policyInstanceType === OnapConstant.operationalPolicyType) { - this.state.loopCache.updateOperationalPolicyProperties(this.state.policyName, editorData); - this.state.loopCache.updateOperationalPolicyPdpGroup(this.state.policyName, this.state.chosenPdpGroup, this.state.chosenPdpSubgroup); - LoopService.setOperationalPolicyProperties(this.state.loopCache.getLoopName(), this.state.loopCache.getOperationalPolicies()).then(resp => { - this.setState({ show: false }); - this.props.history.push('/'); - this.props.loadLoopFunction(this.state.loopCache.getLoopName()); - }); - } - } - } + if (errors.length !== 0) { + console.error("Errors detected during policy data validation ", errors); + this.setState({ + showFailAlert: true, + showMessage: 'Errors detected during policy data validation:\n' + OnapUtils.jsonEditorErrorFormatter(errors) + }); + return; + } + else { + console.info("NO validation errors found in policy data"); + if (this.state.policyInstanceType === OnapConstant.microServiceType) { + this.state.loopCache.updateMicroServiceProperties(this.state.policyName, editorData); + this.state.loopCache.updateMicroServicePdpGroup(this.state.policyName, this.state.chosenPdpGroup, this.state.chosenPdpSubgroup); + 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 (this.state.policyInstanceType === OnapConstant.operationalPolicyType) { + this.state.loopCache.updateOperationalPolicyProperties(this.state.policyName, editorData); + this.state.loopCache.updateOperationalPolicyPdpGroup(this.state.policyName, this.state.chosenPdpGroup, this.state.chosenPdpSubgroup); + LoopService.setOperationalPolicyProperties(this.state.loopCache.getLoopName(), this.state.loopCache.getOperationalPolicies()).then(resp => { + this.setState({ show: false }); + this.props.history.push('/'); + this.props.loadLoopFunction(this.state.loopCache.getLoopName()); + }); + } + } + } - customValidation(editorData, templateName) { - // method for sub-classes to override with customized validation - return []; - } + customValidation(editorData, templateName) { + // method for sub-classes to override with customized validation + return []; + } - handleClose() { - this.setState({ show: false }); - this.props.history.push('/'); - } + handleClose() { + this.setState({ show: false }); + this.props.history.push('/'); + } - componentDidMount() { - this.renderJsonEditor(); - } + componentDidMount() { + this.renderJsonEditor(); + } - componentDidUpdate() { - if (this.state.showSucAlert === true || this.state.showFailAlert === true) { - let modalElement = document.getElementById("policyModal") - if (modalElement) { - modalElement.scrollTo(0, 0); - } - } - } + componentDidUpdate() { + if (this.state.showSucAlert === true || this.state.showFailAlert === true) { + let modalElement = document.getElementById("policyModal") + if (modalElement) { + modalElement.scrollTo(0, 0); + } + } + } createJsonEditor(toscaModel, editorData) { - JSONEditor.defaults.themes.myBootstrap4 = JSONEditor.defaults.themes.bootstrap4.extend({ - getTab: function(text,tabId) { - var liel = document.createElement('li'); - liel.classList.add('nav-item'); - var ael = document.createElement("a"); - ael.classList.add("nav-link"); - ael.setAttribute("style",'padding:10px;max-width:160px;'); - ael.setAttribute("href", "#" + tabId); - ael.setAttribute('data-toggle', 'tab'); - text.setAttribute("style",'word-wrap:break-word;'); - ael.appendChild(text); - liel.appendChild(ael); - return liel; - } - }); + /*JSONEditor.defaults.themes.myBootstrap4 = JSONEditor.defaults.themes.bootstrap4.extend({ + getTab: function(text,tabId) { + var liel = document.createElement('li'); + liel.classList.add('nav-item'); + var ael = document.createElement("a"); + ael.classList.add("nav-link"); + ael.setAttribute("style",'padding:10px;max-width:160px;'); + ael.setAttribute("href", "#" + tabId); + ael.setAttribute('data-toggle', 'tab'); + text.setAttribute("style",'word-wrap:break-word;'); + ael.appendChild(text); + liel.appendChild(ael); + return liel; + } + });*/ return new JSONEditor(document.getElementById("editor"), { schema: toscaModel, startval: editorData, - theme: 'myBootstrap4', + theme: 'bootstrap4', + iconlib: 'fontawesome5', object_layout: 'grid', disable_properties: false, disable_edit_json: false, @@ -173,147 +175,147 @@ export default class PolicyModal extends React.Component { }) } - renderJsonEditor() { - console.debug("Rendering PolicyModal ", this.state.policyName); - var toscaModel = {}; - var editorData = {}; - var pdpGroupValues = {}; - var chosenPdpGroupValue, chosenPdpSubgroupValue; - if (this.state.policyInstanceType === OnapConstant.microServiceType) { - toscaModel = this.state.loopCache.getMicroServiceJsonRepresentationForName(this.state.policyName); - editorData = this.state.loopCache.getMicroServicePropertiesForName(this.state.policyName); - pdpGroupValues = this.state.loopCache.getMicroServiceSupportedPdpGroup(this.state.policyName); - chosenPdpGroupValue = this.state.loopCache.getMicroServicePdpGroup(this.state.policyName); - chosenPdpSubgroupValue = this.state.loopCache.getMicroServicePdpSubgroup(this.state.policyName); - } else if (this.state.policyInstanceType === OnapConstant.operationalPolicyType) { - toscaModel = this.state.loopCache.getOperationalPolicyJsonRepresentationForName(this.state.policyName); - editorData = this.state.loopCache.getOperationalPolicyPropertiesForName(this.state.policyName); - pdpGroupValues = this.state.loopCache.getOperationalPolicySupportedPdpGroup(this.state.policyName); - chosenPdpGroupValue = this.state.loopCache.getOperationalPolicyPdpGroup(this.state.policyName); - chosenPdpSubgroupValue = this.state.loopCache.getOperationalPolicyPdpSubgroup(this.state.policyName); - } + renderJsonEditor() { + console.debug("Rendering PolicyModal ", this.state.policyName); + var toscaModel = {}; + var editorData = {}; + var pdpGroupValues = {}; + var chosenPdpGroupValue, chosenPdpSubgroupValue; + if (this.state.policyInstanceType === OnapConstant.microServiceType) { + toscaModel = this.state.loopCache.getMicroServiceJsonRepresentationForName(this.state.policyName); + editorData = this.state.loopCache.getMicroServicePropertiesForName(this.state.policyName); + pdpGroupValues = this.state.loopCache.getMicroServiceSupportedPdpGroup(this.state.policyName); + chosenPdpGroupValue = this.state.loopCache.getMicroServicePdpGroup(this.state.policyName); + chosenPdpSubgroupValue = this.state.loopCache.getMicroServicePdpSubgroup(this.state.policyName); + } else if (this.state.policyInstanceType === OnapConstant.operationalPolicyType) { + toscaModel = this.state.loopCache.getOperationalPolicyJsonRepresentationForName(this.state.policyName); + editorData = this.state.loopCache.getOperationalPolicyPropertiesForName(this.state.policyName); + pdpGroupValues = this.state.loopCache.getOperationalPolicySupportedPdpGroup(this.state.policyName); + chosenPdpGroupValue = this.state.loopCache.getOperationalPolicyPdpGroup(this.state.policyName); + chosenPdpSubgroupValue = this.state.loopCache.getOperationalPolicyPdpSubgroup(this.state.policyName); + } - if (toscaModel == null) { - return; - } + if (toscaModel == null) { + return; + } var pdpSubgroupValues = []; - if (typeof(chosenPdpGroupValue) !== "undefined") { - var selectedPdpGroup = pdpGroupValues.filter(entry => (Object.keys(entry)[0] === chosenPdpGroupValue)); - pdpSubgroupValues = selectedPdpGroup[0][chosenPdpGroupValue].map((pdpSubgroup) => { return { label: pdpSubgroup, value: pdpSubgroup } }); - } - this.setState({ - jsonEditor: this.createJsonEditor(toscaModel,editorData), - pdpGroup: pdpGroupValues, - pdpGroupList: pdpGroupValues.map(entry => { - return { label: Object.keys(entry)[0], value: Object.keys(entry)[0] }; - }), - pdpSubgroupList: pdpSubgroupValues, - chosenPdpGroup: chosenPdpGroupValue, - chosenPdpSubgroup: chosenPdpSubgroupValue - }) - } + if (typeof(chosenPdpGroupValue) !== "undefined") { + var selectedPdpGroup = pdpGroupValues.filter(entry => (Object.keys(entry)[0] === chosenPdpGroupValue)); + pdpSubgroupValues = selectedPdpGroup[0][chosenPdpGroupValue].map((pdpSubgroup) => { return { label: pdpSubgroup, value: pdpSubgroup } }); + } + this.setState({ + jsonEditor: this.createJsonEditor(toscaModel,editorData), + pdpGroup: pdpGroupValues, + pdpGroupList: pdpGroupValues.map(entry => { + return { label: Object.keys(entry)[0], value: Object.keys(entry)[0] }; + }), + pdpSubgroupList: pdpSubgroupValues, + chosenPdpGroup: chosenPdpGroupValue, + chosenPdpSubgroup: chosenPdpSubgroupValue + }) + } - handlePdpGroupChange(e) { - var selectedPdpGroup = this.state.pdpGroup.filter(entry => (Object.keys(entry)[0] === e.value)); - const pdpSubgroupValues = selectedPdpGroup[0][e.value].map((pdpSubgroup) => { return { label: pdpSubgroup, value: pdpSubgroup } }); - if (this.state.chosenPdpGroup !== e.value) { - this.setState({ - chosenPdpGroup: e.value, - chosenPdpSubgroup: '', - pdpSubgroupList: pdpSubgroupValues - }); - } - } + handlePdpGroupChange(e) { + var selectedPdpGroup = this.state.pdpGroup.filter(entry => (Object.keys(entry)[0] === e.value)); + const pdpSubgroupValues = selectedPdpGroup[0][e.value].map((pdpSubgroup) => { return { label: pdpSubgroup, value: pdpSubgroup } }); + if (this.state.chosenPdpGroup !== e.value) { + this.setState({ + chosenPdpGroup: e.value, + chosenPdpSubgroup: '', + pdpSubgroupList: pdpSubgroupValues + }); + } + } - handlePdpSubgroupChange(e) { - this.setState({ chosenPdpSubgroup: e.value }); - } + handlePdpSubgroupChange(e) { + this.setState({ chosenPdpSubgroup: e.value }); + } - handleRefresh() { - var newLoopCache, toscaModel, editorData; - if (this.state.policyInstanceType === OnapConstant.microServiceType) { - 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 === OnapConstant.operationalPolicyType) { - 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" - }); - }); - } - } + handleRefresh() { + var newLoopCache, toscaModel, editorData; + if (this.state.policyInstanceType === OnapConstant.microServiceType) { + 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 === OnapConstant.operationalPolicyType) { + 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 }); - } + disableAlert() { + this.setState ({ showSucAlert: false, showFailAlert: false }); + } - renderPdpGroupDropDown() { - if(this.state.policyInstanceType !== OnapConstant.operationalPolicyType || !this.state.loopCache.isOpenLoopTemplate()) { - return ( - - Pdp Group Info - - - - - ); - } - } + renderPdpGroupDropDown() { + if(this.state.policyInstanceType !== OnapConstant.operationalPolicyType || !this.state.loopCache.isOpenLoopTemplate()) { + return ( + + Pdp Group Info + + + + + ); + } + } renderOpenLoopMessage() { - if(this.state.policyInstanceType === OnapConstant.operationalPolicyType && this.state.loopCache.isOpenLoopTemplate()) { - return ( - "Operational Policy cannot be configured as only Open Loop is supported for this Template!" - ); - } + if(this.state.policyInstanceType === OnapConstant.operationalPolicyType && this.state.loopCache.isOpenLoopTemplate()) { + return ( + "Operational Policy cannot be configured as only Open Loop is supported for this Template!" + ); + } } - renderModalTitle() { - return ( - Edit the policy - ); - } + renderModalTitle() { + return ( + Edit the policy + ); + } - renderButton() { - var allElement = [()]; - if(this.state.policyInstanceType !== OnapConstant.operationalPolicyType || !this.state.loopCache.isOpenLoopTemplate()) { + if(this.state.policyInstanceType !== OnapConstant.operationalPolicyType || !this.state.loopCache.isOpenLoopTemplate()) { allElement.push(( )); - } - return allElement; - } + } + return allElement; + } - render() { - return ( - - - {this.renderModalTitle()} - + render() { + return ( + + + {this.renderModalTitle()} + {this.state.showMessage} @@ -344,15 +346,15 @@ export default class PolicyModal extends React.Component { {this.state.showMessage} - - {this.renderOpenLoopMessage()} -
- {this.renderPdpGroupDropDown()} - - - {this.renderButton()} - - - ); - } + + {this.renderOpenLoopMessage()} +
+ {this.renderPdpGroupDropDown()} + + + {this.renderButton()} + + + ); + } } diff --git a/ui-react/src/components/dialogs/Policy/ViewAllPolicies.js b/ui-react/src/components/dialogs/Policy/ViewAllPolicies.js index 1e71bb853..d699f781c 100644 --- a/ui-react/src/components/dialogs/Policy/ViewAllPolicies.js +++ b/ui-react/src/components/dialogs/Policy/ViewAllPolicies.js @@ -40,9 +40,9 @@ import Remove from '@material-ui/icons/Remove'; import SaveAlt from '@material-ui/icons/SaveAlt'; import Search from '@material-ui/icons/Search'; import ViewColumn from '@material-ui/icons/ViewColumn'; -import DescriptionIcon from '@material-ui/icons/Description'; -import SettingsEthernetIcon from '@material-ui/icons/SettingsEthernet'; -import NoteAddIcon from '@material-ui/icons/NoteAdd'; +import DehazeIcon from '@material-ui/icons/Dehaze'; +import ArrowForwardIosIcon from '@material-ui/icons/ArrowForwardIos'; +import AddIcon from '@material-ui/icons/Add'; import FormControlLabel from '@material-ui/core/FormControlLabel'; import Switch from '@material-ui/core/Switch'; import MaterialTable from "material-table"; @@ -188,6 +188,8 @@ export default class ViewAllPolicies extends React.Component { this.handlePrefixGrouping = this.handlePrefixGrouping.bind(this); this.handleDeletePolicy = this.handleDeletePolicy.bind(this); this.disableAlert = this.disableAlert.bind(this); + this.getAllPolicies = this.getAllPolicies.bind(this); + this.getAllToscaModels = this.getAllToscaModels.bind(this); this.getAllPolicies(); this.getAllToscaModels(); } @@ -247,7 +249,7 @@ export default class ViewAllPolicies extends React.Component { handleDeletePolicy(event, rowData) { PolicyService.deletePolicy(rowData["type"], rowData["type_version"], rowData["name"],rowData["version"]).then( respPolicyDeletion => { - if (respPolicyDeletion === "") { + if (typeof(respPolicyDeletion) === "undefined") { //it indicates a failure this.setState({ showFailAlert: true, @@ -259,6 +261,7 @@ export default class ViewAllPolicies extends React.Component { showMessage: 'Policy successfully Deleted' }); } + this.getAllPolicies(); } ) } @@ -292,18 +295,18 @@ export default class ViewAllPolicies extends React.Component { }} detailPanel={[ { - icon: SettingsEthernetIcon, + icon: ArrowForwardIosIcon, tooltip: 'Show Configuration', render: rowData => { return ( - + ) }, }, { - icon: DescriptionIcon, + icon: DehazeIcon, tooltip: 'Show Raw Data', render: rowData => { return ( @@ -352,7 +355,7 @@ export default class ViewAllPolicies extends React.Component { }} detailPanel={[ { - icon: SettingsEthernetIcon, + icon: ArrowForwardIosIcon, tooltip: 'Show Tosca', render: rowData => { return ( @@ -363,7 +366,7 @@ export default class ViewAllPolicies extends React.Component { }, }, { - icon: DescriptionIcon, + icon: DehazeIcon, tooltip: 'Show Raw Data', render: rowData => { return ( @@ -374,24 +377,17 @@ export default class ViewAllPolicies extends React.Component { }, }, { - icon: NoteAddIcon, + icon: AddIcon, tooltip: 'Create a policy from this model', render: rowData => { return ( - + ) }, }, ]} - actions={[ - { - icon: forwardRef((props, ref) => ), - tooltip: 'Delete Tosca Model', - onClick: (event, rowData) => this.handleDeletePolicy(event, rowData) - } - ]} /> 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 ee7b679a5..73f659606 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 @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Verify ViewLoopTemplatesModal Test the tosca model view render method 1`] = ` - Close - + `; diff --git a/ui-react/src/components/dialogs/__snapshots__/UserInfoModal.test.js.snap b/ui-react/src/components/dialogs/__snapshots__/UserInfoModal.test.js.snap index bd05e8635..7c725bc42 100644 --- a/ui-react/src/components/dialogs/__snapshots__/UserInfoModal.test.js.snap +++ b/ui-react/src/components/dialogs/__snapshots__/UserInfoModal.test.js.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Verify UserInfoModal Test the render method full permission 1`] = ` - - + `; diff --git a/ui-react/src/components/loop_viewer/logs/__snapshots__/LoopLogs.test.js.snap b/ui-react/src/components/loop_viewer/logs/__snapshots__/LoopLogs.test.js.snap index 25736d2e9..75b817bab 100644 --- a/ui-react/src/components/loop_viewer/logs/__snapshots__/LoopLogs.test.js.snap +++ b/ui-react/src/components/loop_viewer/logs/__snapshots__/LoopLogs.test.js.snap @@ -5,7 +5,7 @@ exports[`Verify LoopLogs Test the render method 1`] = ` - - + `; diff --git a/ui-react/src/components/loop_viewer/status/__snapshots__/LoopStatus.test.js.snap b/ui-react/src/components/loop_viewer/status/__snapshots__/LoopStatus.test.js.snap index 275933ee8..73da5fff1 100644 --- a/ui-react/src/components/loop_viewer/status/__snapshots__/LoopStatus.test.js.snap +++ b/ui-react/src/components/loop_viewer/status/__snapshots__/LoopStatus.test.js.snap @@ -7,7 +7,7 @@ exports[`Verify LoopStatus Test the render method 1`] = ` DESIGN
- - +
`; diff --git a/ui-react/src/components/menu/MenuBar.js b/ui-react/src/components/menu/MenuBar.js index ae1387912..995db9e16 100644 --- a/ui-react/src/components/menu/MenuBar.js +++ b/ui-react/src/components/menu/MenuBar.js @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * ONAP CLAMP + * ONAP POLICY-CLAMP * ================================================================================ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights * reserved. @@ -87,15 +87,12 @@ export default class MenuBar extends React.Component { return ( - Manage Metadata Dictionaries - View All Policies - View Tosca Models - - Upload Tosca Model - - View All Templates + + Tosca Metadata Dictionaries + + View All Loop Templates Create 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 fd9956ed2..ba19097e5 100644 --- a/ui-react/src/components/menu/__snapshots__/MenuBar.test.js.snap +++ b/ui-react/src/components/menu/__snapshots__/MenuBar.test.js.snap @@ -10,8 +10,10 @@ exports[`Verify MenuBar Test the render method 1`] = ` Object { "$$typeof": Symbol(react.forward_ref), "attrs": Array [], - "componentStyle": ComponentStyle { - "componentId": "sc-bdVaJa", + "componentStyle": e { + "baseHash": 1014106698, + "baseStyle": undefined, + "componentId": "sc-bdfBwQ", "isStatic": false, "rules": Array [ " @@ -40,66 +42,23 @@ exports[`Verify MenuBar Test the render method 1`] = ` } ", ], + "staticRulesId": "", }, - "displayName": "Styled(Link)", "foldedComponentIds": Array [], "render": [Function], - "styledComponentId": "sc-bdVaJa", - "target": [Function], - "toString": [Function], - "warnTooManyClasses": [Function], - "withComponent": [Function], - } - } - disabled={false} - to="/manageDictionaries" - > - Manage Metadata Dictionaries - - - View All Policies + + - View Tosca Models + Tosca Metadata Dictionaries - Upload Tosca Model - - - - - View All Templates + View All Loop Templates