From c65613938d30565d4dc913fbf2d48002390119d3 Mon Sep 17 00:00:00 2001 From: xuegao Date: Tue, 21 Apr 2020 13:39:50 +0200 Subject: Prevent adding same type of Op policy Add the logic to prevent user adding the same type of Operational Policy Issue-ID: CLAMP-828 Change-Id: Iec6774ec7a9494740f7aed0873165ba073d73e45 Signed-off-by: xuegao --- .../src/components/dialogs/Loop/ModifyLoopModal.js | 27 ++++++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'ui-react/src/components/dialogs') diff --git a/ui-react/src/components/dialogs/Loop/ModifyLoopModal.js b/ui-react/src/components/dialogs/Loop/ModifyLoopModal.js index 42c03daca..4c6b6a729 100644 --- a/ui-react/src/components/dialogs/Loop/ModifyLoopModal.js +++ b/ui-react/src/components/dialogs/Loop/ModifyLoopModal.js @@ -37,7 +37,7 @@ import Search from '@material-ui/icons/Search'; import LoopService from '../../../api/LoopService'; import Tabs from 'react-bootstrap/Tabs'; import Tab from 'react-bootstrap/Tab'; - +import Alert from 'react-bootstrap/Alert'; const ModalStyled = styled(Modal)` background-color: transparent; @@ -65,6 +65,7 @@ export default class ModifyLoopModal extends React.Component { toscaPolicyModelsData: [], selectedPolicyModelsData: [], key: 'add', + showFailAlert: false, toscaColumns: [ { title: "#", field: "index", render: rowData => rowData.tableData.id + 1, cellStyle: cellStyle, @@ -160,10 +161,25 @@ export default class ModifyLoopModal extends React.Component { this.props.history.push('/'); } + renderAlert() { + return ( +
+ + {this.state.showMessage} + +
+ ); + } + handleAdd() { - LoopService.addOperationalPolicyType(this.state.loopCache.getLoopName(),this.state.selectedRowData.policyModelType,this.state.selectedRowData.version); - this.props.loadLoopFunction(this.state.loopCache.getLoopName()); - this.handleClose(); + LoopService.addOperationalPolicyType(this.state.loopCache.getLoopName(),this.state.selectedRowData.policyModelType,this.state.selectedRowData.version) + .then(pars => { + this.props.loadLoopFunction(this.state.loopCache.getLoopName()); + this.handleClose(); + }) + .catch(error => { + this.setState({ showFailAlert: true, showMessage: "Adding failed with error: " + error.message}); + }); } handleRemove() { @@ -192,13 +208,14 @@ export default class ModifyLoopModal extends React.Component { rowStyle: rowData => ({ backgroundColor: (this.state.selectedRowData !== {} && this.state.selectedRowData.tableData !== undefined && this.state.selectedRowData.tableData.id === rowData.tableData.id) ? '#EEE' : '#FFF' - }) + }) }} />
+ {this.renderAlert()} -- cgit 1.2.3-korg