aboutsummaryrefslogtreecommitdiffstats
path: root/runtime/ui-react/src/components/dialogs/Policy/PolicyDeploymentEditor.js
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/ui-react/src/components/dialogs/Policy/PolicyDeploymentEditor.js')
-rw-r--r--runtime/ui-react/src/components/dialogs/Policy/PolicyDeploymentEditor.js248
1 files changed, 125 insertions, 123 deletions
diff --git a/runtime/ui-react/src/components/dialogs/Policy/PolicyDeploymentEditor.js b/runtime/ui-react/src/components/dialogs/Policy/PolicyDeploymentEditor.js
index 57d61600a..de29947fe 100644
--- a/runtime/ui-react/src/components/dialogs/Policy/PolicyDeploymentEditor.js
+++ b/runtime/ui-react/src/components/dialogs/Policy/PolicyDeploymentEditor.js
@@ -32,145 +32,147 @@ import Checkbox from '@material-ui/core/Checkbox';
import FormControlLabel from '@material-ui/core/FormControlLabel';
const DivWhiteSpaceStyled = styled.div`
- white-space: pre;
+ white-space: pre;
`
const PanelDiv = styled.div`
- text-align: justify;
- font-size: ${props => props.theme.policyEditorFontSize};
- background-color: ${props => props.theme.loopViewerBackgroundColor};
+ text-align: justify;
+ font-size: ${ props => props.theme.policyEditorFontSize };
+ background-color: ${ props => props.theme.loopViewerBackgroundColor };
`
export default class PolicyDeploymentEditor extends React.Component {
- state = {
- policyData: this.props.policyData,
- showSuccessAlert: false,
- showFailAlert: false,
- checkboxesState: this.createPdpStructure(this.props.policyData),
- checkboxesInitialState: this.createPdpStructure(this.props.policyData),
- };
+ state = {
+ policyData: this.props.policyData,
+ showSuccessAlert: false,
+ showFailAlert: false,
+ checkboxesState: this.createPdpStructure(this.props.policyData),
+ checkboxesInitialState: this.createPdpStructure(this.props.policyData),
+ };
- constructor(props, context) {
- super(props, context);
- this.handleClose = this.handleClose.bind(this);
- this.handleUpdatePdpDeployment = this.handleUpdatePdpDeployment.bind(this);
- this.disableAlert = this.disableAlert.bind(this);
- this.renderPdpDeploymentCheckboxes = this.renderPdpDeploymentCheckboxes.bind(this);
- this.createPdpStructure = this.createPdpStructure.bind(this);
- this.handleCheckboxChange = this.handleCheckboxChange.bind(this);
- this.createPdpGroupOperations = this.createPdpGroupOperations.bind(this);
- }
+ constructor(props, context) {
+ super(props, context);
+ this.handleClose = this.handleClose.bind(this);
+ this.handleUpdatePdpDeployment = this.handleUpdatePdpDeployment.bind(this);
+ this.disableAlert = this.disableAlert.bind(this);
+ this.renderPdpDeploymentCheckboxes = this.renderPdpDeploymentCheckboxes.bind(this);
+ this.createPdpStructure = this.createPdpStructure.bind(this);
+ this.handleCheckboxChange = this.handleCheckboxChange.bind(this);
+ this.createPdpGroupOperations = this.createPdpGroupOperations.bind(this);
+ }
- handleClose() {
- this.setState({ show: false });
+ handleClose() {
+ this.setState({ show: false });
- }
+ }
- disableAlert() {
- this.setState ({ showSuccessAlert: false, showFailAlert: false });
- }
+ disableAlert() {
+ this.setState({ showSuccessAlert: false, showFailAlert: false });
+ }
- createPdpGroupOperations(initialStates, newStates) {
- let commandsArray = [];
- initialStates.forEach(initElem => {
- let newStateFound = newStates.find(newElement => newElement.name === initElem.name);
- if (initElem.value !== newStateFound.value) {
- let newPdpGroupsArray = newStateFound.name.split("/");
- let operation = "POST/";
- if (initElem.value) {
- operation = "DELETE/";
- }
- commandsArray.push(operation + newPdpGroupsArray[0] + "/"+newPdpGroupsArray[1] + "/"
- +this.state.policyData.name + "/" + this.state.policyData.version);
- }
- });
- return commandsArray.length > 0 ? {"PdpActions":commandsArray} : undefined;
- }
+ createPdpGroupOperations(initialStates, newStates) {
+ let commandsArray = [];
+ initialStates.forEach(initElem => {
+ let newStateFound = newStates.find(newElement => newElement.name === initElem.name);
+ if (initElem.value !== newStateFound.value) {
+ let newPdpGroupsArray = newStateFound.name.split("/");
+ let operation = "POST/";
+ if (initElem.value) {
+ operation = "DELETE/";
+ }
+ commandsArray.push(operation + newPdpGroupsArray[0] + "/" + newPdpGroupsArray[1] + "/"
+ + this.state.policyData.name + "/" + this.state.policyData.version);
+ }
+ });
+ return commandsArray.length > 0 ? { "PdpActions": commandsArray } : undefined;
+ }
- handleUpdatePdpDeployment() {
- let operationsList = this.createPdpGroupOperations(this.state.checkboxesInitialState,
- this.state.checkboxesState);
- if (typeof(operationsList) !== "undefined") {
- PolicyService.updatePdpDeployment(operationsList).then(respPdpDeploymentUpdate => {
- if (typeof(respPdpDeploymentUpdate) === "undefined") {
- //it indicates a failure
- this.setState({
- showFailAlert: true,
- showMessage: 'Pdp Deployment update Failure'
- });
- } else {
- this.setState({
- showSuccessAlert: true,
- showMessage: 'Pdp Deployment Update successful'
- });
- this.props.policiesTableUpdateFunction();
- }
- })
- } else {
- this.setState({
- showSuccessAlert: true,
- showMessage: 'Pdp Deployment: Nothing to change'
- });
- }
+ handleUpdatePdpDeployment() {
+ let operationsList = this.createPdpGroupOperations(this.state.checkboxesInitialState,
+ this.state.checkboxesState);
+ if (typeof (operationsList) !== "undefined") {
+ PolicyService.updatePdpDeployment(operationsList).then(respPdpDeploymentUpdate => {
+ if (typeof (respPdpDeploymentUpdate) === "undefined") {
+ //it indicates a failure
+ this.setState({
+ showFailAlert: true,
+ showMessage: 'Pdp Deployment update Failure'
+ });
+ } else {
+ this.setState({
+ showSuccessAlert: true,
+ showMessage: 'Pdp Deployment Update successful'
+ });
+ this.props.policiesTableUpdateFunction();
+ }
+ })
+ } else {
+ this.setState({
+ showSuccessAlert: true,
+ showMessage: 'Pdp Deployment: Nothing to change'
+ });
}
+ }
- createPdpStructure(policyData) {
- // Create map with data for all group/subgroup where the policy is deployed
- let infoPdpMap = new Map();
- if (typeof policyData.pdpGroupInfo !== "undefined") {
- policyData["pdpGroupInfo"].forEach(pdpGroupElem => {
- let pdpGroupName = Object.keys(pdpGroupElem)[0];
- pdpGroupElem[pdpGroupName]["pdpSubgroups"].forEach(pdpSubGroupElem => {
- infoPdpMap.set(pdpGroupName + "/" + pdpSubGroupElem["pdpType"], true);
- });
- });
- }
- // Create the possible values for pdpgroup/subgroup and tick the ones where policy is deployed
- let pdpStates = [];
- if (typeof policyData.supportedPdpGroups !== "undefined") {
- for (const pdpGroup of policyData["supportedPdpGroups"]) {
- let pdpGroupName = Object.keys(pdpGroup)[0];
- for (const pdpSubGroup of Object.values(pdpGroup)[0]) {
- let fullName = pdpGroupName + "/" + pdpSubGroup;
- pdpStates.push({name: fullName,
- value: infoPdpMap.get(fullName) !== undefined});
- }
- }
- }
- return pdpStates;
+ createPdpStructure(policyData) {
+ // Create map with data for all group/subgroup where the policy is deployed
+ let infoPdpMap = new Map();
+ if (typeof policyData.pdpGroupInfo !== "undefined") {
+ policyData["pdpGroupInfo"].forEach(pdpGroupElem => {
+ let pdpGroupName = Object.keys(pdpGroupElem)[0];
+ pdpGroupElem[pdpGroupName]["pdpSubgroups"].forEach(pdpSubGroupElem => {
+ infoPdpMap.set(pdpGroupName + "/" + pdpSubGroupElem["pdpType"], true);
+ });
+ });
}
-
- handleCheckboxChange(event) {
- const checkboxesArray = this.state.checkboxesState;
- checkboxesArray.find(element => element.name === event.target.name).value = event.target.checked;
- this.setState({checkboxesState:checkboxesArray});
+ // Create the possible values for pdpgroup/subgroup and tick the ones where policy is deployed
+ let pdpStates = [];
+ if (typeof policyData.supportedPdpGroups !== "undefined") {
+ for (const pdpGroup of policyData["supportedPdpGroups"]) {
+ let pdpGroupName = Object.keys(pdpGroup)[0];
+ for (const pdpSubGroup of Object.values(pdpGroup)[0]) {
+ let fullName = pdpGroupName + "/" + pdpSubGroup;
+ pdpStates.push({
+ name: fullName,
+ value: infoPdpMap.get(fullName) !== undefined
+ });
+ }
+ }
}
+ return pdpStates;
+ }
- renderPdpDeploymentCheckboxes() {
- return this.state.checkboxesState.map(item => {
- return <FormControlLabel control={<Checkbox checked={item.value} onChange={this.handleCheckboxChange}
- name={item.name} />} label={item.name} />;
- });
- }
+ handleCheckboxChange(event) {
+ const checkboxesArray = this.state.checkboxesState;
+ checkboxesArray.find(element => element.name === event.target.name).value = event.target.checked;
+ this.setState({ checkboxesState: checkboxesArray });
+ }
- render() {
- return (
- <PanelDiv>
- <Alert variant="success" show={this.state.showSuccessAlert} onClose={this.disableAlert} dismissible>
- <DivWhiteSpaceStyled>
- {this.state.showMessage}
- </DivWhiteSpaceStyled>
- </Alert>
- <Alert variant="danger" show={this.state.showFailAlert} onClose={this.disableAlert} dismissible>
- <DivWhiteSpaceStyled>
- {this.state.showMessage}
- </DivWhiteSpaceStyled>
- </Alert>
- <Button variant="secondary" title="Update the policy to the specified PDP Groups/Subgroups"
- onClick={this.handleUpdatePdpDeployment}>Update PDP</Button>
- <FormGroup>{this.renderPdpDeploymentCheckboxes()}</FormGroup>
- </PanelDiv>
- );
- }
- } \ No newline at end of file
+ renderPdpDeploymentCheckboxes() {
+ return this.state.checkboxesState.map(item => {
+ return <FormControlLabel control={ <Checkbox checked={ item.value } onChange={ this.handleCheckboxChange }
+ name={ item.name }/> } label={ item.name }/>;
+ });
+ }
+
+ render() {
+ return (
+ <PanelDiv>
+ <Alert variant="success" show={ this.state.showSuccessAlert } onClose={ this.disableAlert } dismissible>
+ <DivWhiteSpaceStyled>
+ { this.state.showMessage }
+ </DivWhiteSpaceStyled>
+ </Alert>
+ <Alert variant="danger" show={ this.state.showFailAlert } onClose={ this.disableAlert } dismissible>
+ <DivWhiteSpaceStyled>
+ { this.state.showMessage }
+ </DivWhiteSpaceStyled>
+ </Alert>
+ <Button variant="secondary" title="Update the policy to the specified PDP Groups/Subgroups"
+ onClick={ this.handleUpdatePdpDeployment }>Update PDP</Button>
+ <FormGroup>{ this.renderPdpDeploymentCheckboxes() }</FormGroup>
+ </PanelDiv>
+ );
+ }
+}