aboutsummaryrefslogtreecommitdiffstats
path: root/ui-react
diff options
context:
space:
mode:
authorxuegao <xg353y@intl.att.com>2020-04-21 13:39:50 +0200
committerxuegao <xg353y@intl.att.com>2020-04-21 13:39:50 +0200
commitc65613938d30565d4dc913fbf2d48002390119d3 (patch)
tree63cf31d45dad04969c63fdf1f89d3d6deb1c5657 /ui-react
parent8b4027e3e359bba21014dd138da2545d54d117db (diff)
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 <xg353y@intl.att.com>
Diffstat (limited to 'ui-react')
-rw-r--r--ui-react/src/api/LoopService.js13
-rw-r--r--ui-react/src/components/dialogs/Loop/ModifyLoopModal.js27
2 files changed, 28 insertions, 12 deletions
diff --git a/ui-react/src/api/LoopService.js b/ui-react/src/api/LoopService.js
index 698ee28c2..9d3b36983 100644
--- a/ui-react/src/api/LoopService.js
+++ b/ui-react/src/api/LoopService.js
@@ -226,18 +226,17 @@ export default class LoopService {
credentials: 'same-origin'
})
.then(function (response) {
- console.debug("Add Operational Policy response received: ", response.status);
+ console.debug("Add Operational Policy response received: ", response.status);
if (response.ok) {
return response.json();
} else {
- console.error("Add Operational Policy query failed");
- return {};
+ return response.text();
}
})
- .catch(function (error) {
- console.error("Add Operational Policy error received", error);
- return {};
- });
+ .then(function (object) {
+ console.error("Add Operational Policy query failed");
+ throw new Error(object);
+ })
}
static removeOperationalPolicyType(loopName, policyType, policyVersion) {
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 (
+ <div>
+ <Alert variant="danger" show={this.state.showFailAlert} onClose={this.disableAlert} dismissible>
+ {this.state.showMessage}
+ </Alert>
+ </div>
+ );
+ }
+
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'
- })
+ })
}}
/>
<div>
<TextModal value={this.state.content} onChange={this.handleYamlContent}/>
</div>
</Modal.Body>
+ {this.renderAlert()}
</Tab>
<Tab eventKey="remove" title="Remove Operational Policies">
<Modal.Body>