From fb4b25f6827accf6f975f9ca9a7aaee08d335c2f Mon Sep 17 00:00:00 2001 From: xuegao Date: Wed, 11 Mar 2020 11:22:15 +0100 Subject: Add remove op policy option Update the UI and backend code to be able to remove op policy for loop instances. Issue-ID: CLAMP-648 Change-Id: Ib3eab4977fe4f1b85e11f2373263197009bbc3e1 Signed-off-by: xuegao --- .../src/components/dialogs/Loop/ModifyLoopModal.js | 98 ++++++++++++++++------ 1 file changed, 71 insertions(+), 27 deletions(-) (limited to 'ui-react/src/components/dialogs/Loop/ModifyLoopModal.js') diff --git a/ui-react/src/components/dialogs/Loop/ModifyLoopModal.js b/ui-react/src/components/dialogs/Loop/ModifyLoopModal.js index 4cd21fdb..7c16b786 100644 --- a/ui-react/src/components/dialogs/Loop/ModifyLoopModal.js +++ b/ui-react/src/components/dialogs/Loop/ModifyLoopModal.js @@ -35,6 +35,8 @@ import FirstPage from '@material-ui/icons/FirstPage'; import LastPage from '@material-ui/icons/LastPage'; import Search from '@material-ui/icons/Search'; import LoopService from '../../../api/LoopService'; +import Tabs from 'react-bootstrap/Tabs'; +import Tab from 'react-bootstrap/Tab'; const ModalStyled = styled(Modal)` @@ -61,6 +63,8 @@ export default class ModifyLoopModal extends React.Component { content: 'Please select Tosca model to view the details', selectedRowData: {}, toscaPolicyModelsData: [], + selectedPolicyModelsData: [], + key: 'add', toscaColumns: [ { title: "#", field: "index", render: rowData => rowData.tableData.id + 1, cellStyle: cellStyle, @@ -105,11 +109,12 @@ export default class ModifyLoopModal extends React.Component { constructor(props, context) { super(props, context); this.handleClose = this.handleClose.bind(this); - this.getPolicyToscaModels = this.getToscaPolicyModels.bind(this); + this.initializeToscaPolicyModelsInfo = this.initializeToscaPolicyModelsInfo.bind(this); this.handleYamlContent = this.handleYamlContent.bind(this); this.getToscaPolicyModelYaml = this.getToscaPolicyModelYaml.bind(this); this.handleAdd = this.handleAdd.bind(this); - this.getToscaPolicyModels(); + this.handleRemove = this.handleRemove.bind(this); + this.initializeToscaPolicyModelsInfo(); } componentWillReceiveProps(newProps) { @@ -119,9 +124,16 @@ export default class ModifyLoopModal extends React.Component { }); } - getToscaPolicyModels() { - PolicyToscaService.getToscaPolicyModels().then(allToscaModels => { - this.setState({ toscaPolicyModelsData: allToscaModels}); + initializeToscaPolicyModelsInfo() { + var operationalPolicies = this.state.loopCache.getOperationalPolicies(); + var selectedPolicyModels = []; + for (var policy in operationalPolicies) { + selectedPolicyModels.push(operationalPolicies[policy]["policyModel"]); + } + + PolicyToscaService.getToscaPolicyModels().then(allToscaModels => { + this.setState({ toscaPolicyModelsData: allToscaModels, + selectedPolicyModelsData: selectedPolicyModels}); }); } @@ -149,38 +161,70 @@ export default class ModifyLoopModal extends React.Component { } handleAdd() { - LoopService.addOperationalPolicyType(this.state.loopCache.getLoopName(),this.state.selectedRowData.policyModelType,this.state.selectedRowData.version); - this.handleClose(); - this.props.loadLoopFunction(this.state.loopCache.getLoopName()); + LoopService.addOperationalPolicyType(this.state.loopCache.getLoopName(),this.state.selectedRowData.policyModelType,this.state.selectedRowData.version); + this.handleClose(); + this.props.loadLoopFunction(this.state.loopCache.getLoopName()); + } + + handleRemove() { + LoopService.removeOperationalPolicyType(this.state.loopCache.getLoopName(),this.state.selectedRowData.policyModelType,this.state.selectedRowData.version); + this.handleClose(); + this.props.loadLoopFunction(this.state.loopCache.getLoopName()); } render() { return ( + Modify Loop Operational Policies - - {this.getToscaPolicyModelYaml(rowData.policyModelType, rowData.version);this.setState({selectedRowData: rowData})}} - options={{ - headerStyle: rowHeaderStyle, - rowStyle: rowData => ({ - backgroundColor: (this.state.selectedRowData !== {} && this.state.selectedRowData.id === rowData.tableData.id) ? '#EEE' : '#FFF' - }) - }} - /> -
- -
-
+ this.setState({ key, selectedRowData: {} })}> + + + {this.getToscaPolicyModelYaml(rowData.policyModelType, rowData.version);this.setState({selectedRowData: rowData})}} + options={{ + headerStyle: rowHeaderStyle, + rowStyle: rowData => ({ + backgroundColor: (this.state.selectedRowData !== {} && this.state.selectedRowData.tableData !== undefined + && this.state.selectedRowData.tableData.id === rowData.tableData.id) ? '#EEE' : '#FFF' + }) + }} + /> +
+ +
+
+
+ + + {this.setState({selectedRowData: rowData})}} + options={{ + headerStyle: rowHeaderStyle, + rowStyle: rowData => ({ + backgroundColor: (this.state.selectedRowData !== {} && this.state.selectedRowData.tableData !== undefined + && this.state.selectedRowData.tableData.id === rowData.tableData.id) ? '#EEE' : '#FFF' + }) + }} + /> + + +
- + + +
); } -- cgit