diff options
Diffstat (limited to 'ui-react/src')
-rw-r--r-- | ui-react/src/LoopUI.js | 2 | ||||
-rw-r--r-- | ui-react/src/api/LoopCache.js | 8 | ||||
-rw-r--r-- | ui-react/src/api/LoopCache.test.js | 25 | ||||
-rw-r--r-- | ui-react/src/api/LoopCache_mokeLoopJsonCache.json | 3 | ||||
-rw-r--r-- | ui-react/src/api/LoopService.js | 23 | ||||
-rw-r--r-- | ui-react/src/components/dialogs/Loop/DeployLoopModal.js | 36 | ||||
-rw-r--r-- | ui-react/src/components/dialogs/OperationalPolicy/OperationalPolicyModal.js | 30 | ||||
-rw-r--r-- | ui-react/src/components/dialogs/OperationalPolicy/OperationalPolicyModal.test.js | 21 |
8 files changed, 124 insertions, 24 deletions
diff --git a/ui-react/src/LoopUI.js b/ui-react/src/LoopUI.js index 58fbce635..eb4ff6a50 100644 --- a/ui-react/src/LoopUI.js +++ b/ui-react/src/LoopUI.js @@ -252,7 +252,7 @@ export default class LoopUI extends React.Component { <Route path="/viewToscaPolicyModal" render={(routeProps) => (<ViewToscaPolicyModal {...routeProps} />)} /> <Route path="/viewBlueprintMicroServiceTemplatesModal" render={(routeProps) => (<ViewBlueprintMicroServiceTemplatesModal {...routeProps} />)} /> <Route path="/operationalPolicyModal" - render={(routeProps) => (<OperationalPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop} showAlert={this.showAlert}/>)} /> + render={(routeProps) => (<OperationalPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} /> <Route path="/configurationPolicyModal/:componentName" render={(routeProps) => (<ConfigurationPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} /> <Route path="/openLoop" render={(routeProps) => (<OpenLoopModal {...routeProps} loadLoopFunction={this.loadLoop} />)} /> <Route path="/loopProperties" render={(routeProps) => (<LoopPropertiesModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} /> diff --git a/ui-react/src/api/LoopCache.js b/ui-react/src/api/LoopCache.js index 95eb9310e..c73ed62b5 100644 --- a/ui-react/src/api/LoopCache.js +++ b/ui-react/src/api/LoopCache.js @@ -53,13 +53,19 @@ export default class LoopCache { } getOperationalPolicyJsonSchema() { - return this.loopJsonCache["operationalPolicySchema"]; + return this.loopJsonCache["operationalPolicies"]["0"]["jsonRepresentation"]; } getOperationalPolicies() { return this.loopJsonCache["operationalPolicies"]; } + getOperationalPoliciesNoJsonSchema() { + var operationalPolicies = JSON.parse(JSON.stringify(this.loopJsonCache["operationalPolicies"])); + delete operationalPolicies[0]["jsonRepresentation"]; + return operationalPolicies; + } + getGlobalProperties() { return this.loopJsonCache["globalPropertiesJson"]; } diff --git a/ui-react/src/api/LoopCache.test.js b/ui-react/src/api/LoopCache.test.js index f67bc0aa0..471fa4d71 100644 --- a/ui-react/src/api/LoopCache.test.js +++ b/ui-react/src/api/LoopCache.test.js @@ -49,13 +49,36 @@ describe('Verify LoopCache functions', () => { "operational_policy": { "controlLoop": {}, "policies": [] + } + }, + "jsonRepresentation": { + "schema": {} + } + }]; + expect(loopCache.getOperationalPolicies()).toStrictEqual(opPolicy); + }); + it('getOperationalPoliciesNoJsonSchema', () => { + const opPolicy = [{ + "name": "OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca", + "configurationsJson": { + "guard_policies": {}, + "operational_policy": { + "controlLoop": {}, + "policies": [] } } }]; - expect(loopCache.getOperationalPolicies()).toStrictEqual(opPolicy); + expect(loopCache.getOperationalPoliciesNoJsonSchema()).toStrictEqual(opPolicy); }); + it('getOperationalPolicyJsonSchema', () => { + const jsonSchema = { + "schema": {} + }; + + expect(loopCache.getOperationalPolicyJsonSchema()).toStrictEqual(jsonSchema); + }); it('getGlobalProperties', () => { const globelProp = { "dcaeDeployParameters": { diff --git a/ui-react/src/api/LoopCache_mokeLoopJsonCache.json b/ui-react/src/api/LoopCache_mokeLoopJsonCache.json index c84b5b691..087ab5d45 100644 --- a/ui-react/src/api/LoopCache_mokeLoopJsonCache.json +++ b/ui-react/src/api/LoopCache_mokeLoopJsonCache.json @@ -93,6 +93,9 @@ "controlLoop": {}, "policies": [] } + }, + "jsonRepresentation": { + "schema": {} } } ], diff --git a/ui-react/src/api/LoopService.js b/ui-react/src/api/LoopService.js index e2e234821..ead2cf80c 100644 --- a/ui-react/src/api/LoopService.js +++ b/ui-react/src/api/LoopService.js @@ -152,4 +152,27 @@ export default class LoopService { return ""; }); } + + static refreshOpPolicyJson(loopName) { + return fetch('/restservices/clds/v2/loop/refreshOpPolicyJsonSchema/' + loopName, { + method: 'PUT', + headers: { + "Content-Type": "application/json" + }, + credentials: 'same-origin' + }) + .then(function (response) { + console.debug("Refresh Operational Policy Json Schema response received: ", response.status); + if (response.ok) { + return response.json(); + } else { + console.error("Refresh Operational Policy Json Schema query failed"); + return {}; + } + }) + .catch(function (error) { + console.error("Refresh Operational Policy Json Schema error received", error); + return {}; + }); + } } diff --git a/ui-react/src/components/dialogs/Loop/DeployLoopModal.js b/ui-react/src/components/dialogs/Loop/DeployLoopModal.js index 9c9a16feb..6468e9f9e 100644 --- a/ui-react/src/components/dialogs/Loop/DeployLoopModal.js +++ b/ui-react/src/components/dialogs/Loop/DeployLoopModal.js @@ -37,11 +37,9 @@ const FormStyled = styled(Form.Group)` padding: .25rem 1.5rem; ` export default class DeployLoopModal extends React.Component { - state = { - loopCache: this.props.loopCache, - temporaryPropertiesJson: JSON.parse(JSON.stringify(this.props.loopCache.getGlobalProperties())), - show: true - }; + + + constructor(props, context) { super(props, context); @@ -50,6 +48,24 @@ export default class DeployLoopModal extends React.Component { this.handleChange = this.handleChange.bind(this); this.refreshStatus = this.refreshStatus.bind(this); this.renderDeployParam = this.renderDeployParam.bind(this); + + const propertiesJson = JSON.parse(JSON.stringify(this.props.loopCache.getGlobalProperties())); + this.state = { + loopCache: this.props.loopCache, + temporaryPropertiesJson: propertiesJson, + show: true, + key: this.getInitialKeyValue(propertiesJson) + }; + } + getInitialKeyValue(temporaryPropertiesJson) { + const deployJsonList = temporaryPropertiesJson["dcaeDeployParameters"]; + let initialKey; + Object.keys(deployJsonList) + .filter((obj) => Object.keys(deployJsonList).indexOf(obj) === 0) + .map(obj => + initialKey = obj + ); + return initialKey; } componentWillReceiveProps(newProps) { this.setState({ @@ -57,14 +73,7 @@ export default class DeployLoopModal extends React.Component { show: true }); } - componentDidMount() { - const deployJsonList = this.state.temporaryPropertiesJson["dcaeDeployParameters"]; - Object.keys(deployJsonList) - .filter((obj) => Object.keys(deployJsonList).indexOf(obj) === 0) - .map(obj => - this.setState({key: obj}) - ); - } + handleClose(){ this.props.history.push('/'); } @@ -117,7 +126,6 @@ export default class DeployLoopModal extends React.Component { ); return indents; } - renderDeployParam(deployJson) { var indents = []; Object.keys(deployJson).map((item,key) => diff --git a/ui-react/src/components/dialogs/OperationalPolicy/OperationalPolicyModal.js b/ui-react/src/components/dialogs/OperationalPolicy/OperationalPolicyModal.js index 5c5f0241a..dc7c0a489 100644 --- a/ui-react/src/components/dialogs/OperationalPolicy/OperationalPolicyModal.js +++ b/ui-react/src/components/dialogs/OperationalPolicy/OperationalPolicyModal.js @@ -25,6 +25,7 @@ import React from 'react' import Button from 'react-bootstrap/Button'; import Modal from 'react-bootstrap/Modal'; import styled from 'styled-components'; +import LoopCache from '../../../api/LoopCache'; import LoopService from '../../../api/LoopService'; import JSONEditor from '@json-editor/json-editor'; @@ -45,6 +46,7 @@ export default class OperationalPolicyModal extends React.Component { this.handleClose = this.handleClose.bind(this); this.handleSave = this.handleSave.bind(this); this.renderJsonEditor = this.renderJsonEditor.bind(this); + this.handleRefresh = this.handleRefresh.bind(this); this.setDefaultJsonEditorOptions(); } @@ -114,7 +116,7 @@ export default class OperationalPolicyModal extends React.Component { console.error("NO Operational policy schema found"); return; } - var operationalPoliciesData = this.state.loopCache.getOperationalPolicies(); + var operationalPoliciesData = this.state.loopCache.getOperationalPoliciesNoJsonSchema(); this.setState({ jsonEditor: new JSONEditor(document.getElementById("editor"), @@ -122,6 +124,25 @@ export default class OperationalPolicyModal extends React.Component { }) } + handleRefresh() { + LoopService.refreshOpPolicyJson(this.state.loopCache.getLoopName()).then(data => { + var newLoopCache = new LoopCache(data); + var schema_json = newLoopCache.getOperationalPolicyJsonSchema(); + var operationalPoliciesData = newLoopCache.getOperationalPoliciesNoJsonSchema(); + document.getElementById("editor").innerHTML = ""; + this.setState({ + loopCache: newLoopCache, + jsonEditor: new JSONEditor(document.getElementById("editor"), + { schema: schema_json.schema, startval: operationalPoliciesData }) + }) + this.props.updateLoopFunction(data); + + }) + .catch(error => { + console.error("Error while refreshing the Operational Policy Json Representation"); + }); + } + render() { return ( <ModalStyled size="xl" show={this.state.show} onHide={this.handleClose}> @@ -135,10 +156,13 @@ export default class OperationalPolicyModal extends React.Component { <Modal.Footer> <Button variant="secondary" onClick={this.handleClose}> Close - </Button> + </Button> + <Button variant="secondary" onClick={this.handleRefresh}> + Refresh + </Button> <Button variant="primary" onClick={this.handleSave}> Save Changes - </Button> + </Button> </Modal.Footer> </ModalStyled> diff --git a/ui-react/src/components/dialogs/OperationalPolicy/OperationalPolicyModal.test.js b/ui-react/src/components/dialogs/OperationalPolicy/OperationalPolicyModal.test.js index 9c7da3108..c10c6ff0a 100644 --- a/ui-react/src/components/dialogs/OperationalPolicy/OperationalPolicyModal.test.js +++ b/ui-react/src/components/dialogs/OperationalPolicy/OperationalPolicyModal.test.js @@ -46,9 +46,9 @@ describe('Verify OperationalPolicyModal', () => { "controlLoop": {}, "policies": [] } - } - }], - "operationalPolicySchema": {"schema": {}} + }, + "jsonRepresentation" : {"schema": {}} + }] }); const historyMock = { push: jest.fn() }; const flushPromises = () => new Promise(setImmediate); @@ -57,7 +57,7 @@ describe('Verify OperationalPolicyModal', () => { const handleClose = jest.spyOn(OperationalPolicyModal.prototype,'handleClose'); const component = mount(<OperationalPolicyModal history={historyMock} loopCache={loopCache}/>) - component.find('[variant="secondary"]').prop('onClick')(); + component.find('[variant="secondary"]').get(0).props.onClick(); expect(handleClose).toHaveBeenCalledTimes(1); expect(component.state('show')).toEqual(false); @@ -78,4 +78,17 @@ describe('Verify OperationalPolicyModal', () => { expect(component.state('show')).toEqual(false); expect(historyMock.push.mock.calls[0]).toEqual([ '/']); }); + + it('Test handleRefresh', async () => { + const updateLoopFunction = jest.fn(); + const handleRefresh = jest.spyOn(OperationalPolicyModal.prototype,'handleRefresh'); + const component = mount(<OperationalPolicyModal loopCache={loopCache} updateLoopFunction={updateLoopFunction} />) + + component.find('[variant="secondary"]').get(1).props.onClick(); + await flushPromises(); + component.update(); + + expect(handleRefresh).toHaveBeenCalledTimes(1); + expect(component.state('show')).toEqual(true); + }); });
\ No newline at end of file |