diff options
author | liamfallon <liam.fallon@est.tech> | 2021-11-15 15:22:57 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2021-11-15 16:22:55 +0000 |
commit | 225dcb4d6f801d88094a9512d79c82c4189c07f6 (patch) | |
tree | 3c8d913ebadb9693371a63cce3836ea218f3728e /runtime/ui-react/src/components/dialogs/Policy/PolicyDeploymentEditor.js | |
parent | e3407078474467bc002a06fefb7af4c97d2c3756 (diff) |
Align ui-react file in policy-clamp and policy-gui
When the ui-react code was transferred to policy-gui, the white space
was cleaned up and reformatted. This makes it difficult to track the
real functional changes if any between ui-react in policy-clamp and
policy-gui.
This review brings more white space changes into ui-react in policy-clamp
to make file comparisons easier.
Issue-ID: POLICY-3358
Change-Id: Ie65d5bb664e6f43fe2f8a4342cf679e34ced18b8
Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'runtime/ui-react/src/components/dialogs/Policy/PolicyDeploymentEditor.js')
-rw-r--r-- | runtime/ui-react/src/components/dialogs/Policy/PolicyDeploymentEditor.js | 248 |
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> + ); + } +} |