From ea2969fd3bbfe52cbe4f41546dd40d68321c233b Mon Sep 17 00:00:00 2001 From: sebdet Date: Thu, 25 Feb 2021 13:58:36 +0100 Subject: Add "delete policy" feature in UI Add delete policy functionality (call to backend) + insert Policies array in a tabs for future policy create operation + Ask column names during export of the test db Issue-ID: POLICY-2929 Signed-off-by: sebdet Change-Id: I4108c9fa2b986cc5aff11b8710bc6ad722c52f46 Signed-off-by: sebdet --- ui-react/src/api/PolicyService.js | 81 ++++++++++------ .../components/dialogs/Policy/ViewAllPolicies.js | 102 ++++++++++++--------- 2 files changed, 115 insertions(+), 68 deletions(-) (limited to 'ui-react') diff --git a/ui-react/src/api/PolicyService.js b/ui-react/src/api/PolicyService.js index 16cc1f322..a77a8bdb0 100644 --- a/ui-react/src/api/PolicyService.js +++ b/ui-react/src/api/PolicyService.js @@ -26,19 +26,22 @@ export default class PolicyService { method: 'GET', credentials: 'same-origin' }) - .then(function (response) { - console.debug("getPoliciesList response received: ", response.status); - if (response.ok) { - return response.json(); - } else { - console.error("getPoliciesList query failed"); - return {}; - } - }) - .catch(function (error) { - console.error("getPoliciesList error received", error); - return {}; - }); + .then(function(response) { + console.debug("getPoliciesList response received: ", response.status); + if (response.ok) { + console.info("getPoliciesList query successful"); + return response.json(); + } else { + return response.text().then(responseBody => { + throw new Error("HTTP " + response.status + "," + responseBody); + }) + } + }) + .catch(function(error) { + console.error("getPoliciesList error occurred ", error); + alert("getPoliciesList error occurred " + error); + return ""; + }) } static createNewPolicy(policyModelType, policyModelVersion, policyJson) { return fetch(window.location.pathname + 'restservices/clds/v2/policies/' + policyModelType + '/' + policyModelVersion, { @@ -49,18 +52,44 @@ export default class PolicyService { }, body: JSON.stringify(policyJson) }) - .then(function (response) { - console.debug("createNewPolicy response received: ", response.status); - if (response.ok) { - return response.text; - } else { - console.error("createNewPolicy query failed"); - return ""; - } - }) - .catch(function (error) { - console.error("createNewPolicy error received", error); - throw new Error(error) - }); + .then(function (response) { + console.debug("createNewPolicy response received: ", response.status); + if (response.ok) { + console.info("createNewPolicy query successful"); + return response.text(); + } else { + return response.text().then(responseBody => { + throw new Error("HTTP " + response.status + "," + responseBody); + }) + } + }) + .catch(function (error) { + console.error("createNewPolicy error occurred ", error); + alert ("createNewPolicy error occurred " + error); + return ""; + }); + } + static deletePolicy(policyModelType, policyModelVersion, policyName, policyVersion) { + return fetch(window.location.pathname + 'restservices/clds/v2/policies/' + policyModelType + '/' + + policyModelVersion + '/' + policyName + '/' + policyVersion, { + method: 'DELETE', + credentials: 'same-origin' + }) + .then(function (response) { + console.debug("deletePolicy response received: ", response.status); + if (response.ok) { + console.info("deletePolicy query successful"); + return response.text(); + } else { + return response.text().then(responseBody => { + throw new Error("HTTP " + response.status + "," + responseBody); + }) + } + }) + .catch(function (error) { + console.error("deletePolicy error occurred ", error); + alert ("deletePolicy error occurred " + error); + return ""; + }); } } diff --git a/ui-react/src/components/dialogs/Policy/ViewAllPolicies.js b/ui-react/src/components/dialogs/Policy/ViewAllPolicies.js index dfebc51d8..b159584dd 100644 --- a/ui-react/src/components/dialogs/Policy/ViewAllPolicies.js +++ b/ui-react/src/components/dialogs/Policy/ViewAllPolicies.js @@ -49,9 +49,11 @@ import Select from 'react-select'; import JSONEditor from '@json-editor/json-editor'; import OnapUtils from '../../../utils/OnapUtils'; import Alert from 'react-bootstrap/Alert'; +import Tabs from 'react-bootstrap/Tabs'; +import Tab from 'react-bootstrap/Tab'; const DivWhiteSpaceStyled = styled.div` - white-space: pre; + white-space: pre; ` const ModalStyled = styled(Modal)` @@ -259,7 +261,22 @@ export default class ViewAllPolicies extends React.Component { } handleDeletePolicy(event, rowData) { - return null; + PolicyService.deletePolicy(rowData["type"], rowData["type_version"], rowData["name"],rowData["version"]).then( + respPolicyDeletion => { + if (respPolicyDeletion === "") { + //it indicates a failure + this.setState({ + showFailAlert: true, + showMessage: 'Policy Deletion Failure' + }); + } else { + this.setState({ + showSuccessAlert: true, + showMessage: 'Policy successfully Deleted' + }); + } + } + ) } customValidation(editorData) { @@ -324,53 +341,54 @@ export default class ViewAllPolicies extends React.Component { - - - } - label="Group by prefix" - /> - {this.handleOnRowClick(rowData)}} - options={{ - grouping: true, - exportButton: true, - headerStyle:rowHeaderStyle, - rowStyle: rowData => ({ - backgroundColor: (this.state.selectedRowId !== -1 && this.state.selectedRowId === rowData.tableData.id) ? '#EEE' : '#FFF' - }) - }} - actions={[ - { - icon: forwardRef((props, ref) => ), - tooltip: 'Delete Policy', - onClick: (event, rowData) => this.handleDeletePolicy(event, rowData) - } - ]} - /> + this.setState({ key, selectedRowData: {} })}> + + + } + label="Group by prefix" + /> + {this.handleOnRowClick(rowData)}} + options={{ + grouping: true, + exportButton: true, + headerStyle:rowHeaderStyle, + rowStyle: rowData => ({ + backgroundColor: (this.state.selectedRowId !== -1 && this.state.selectedRowId === rowData.tableData.id) ? '#EEE' : '#FFF' + }) + }} + actions={[ + { + icon: forwardRef((props, ref) => ), + tooltip: 'Delete Policy', + onClick: (event, rowData) => this.handleDeletePolicy(event, rowData) + } + ]} + /> + + +
Policy Properties Editor
- - - {this.state.showMessage} - - - - - {this.state.showMessage} - - - + + {this.state.showMessage} + + + + + {this.state.showMessage} + + -- cgit 1.2.3-korg