aboutsummaryrefslogtreecommitdiffstats
path: root/gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationManagementModal.js
diff options
context:
space:
mode:
authorbrunomilitzer <bruno.militzer@est.tech>2021-12-17 17:41:57 +0000
committerBruno Militzer <bruno.militzer@est.tech>2022-01-04 15:51:54 +0000
commit4be96f85c65df9384b11d68e87ca9e03e27a083c (patch)
treeaf178c54ace2b5d7457e3547b81cae6f4b6d5ebc /gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationManagementModal.js
parentacd025f30f0005731c9b2894cb954bd31401ab76 (diff)
Added Jest Unit Tests
Jest Tests for creation of instance properties Jest Tests for deletion of instance properties Included Issue-Id: 3566 Issue-ID: POLICY-3563 Signed-off-by: brunomilitzer <bruno.militzer@est.tech> Change-Id: I227ae8f306df10ee3cc341791471dda9ca79d9d1
Diffstat (limited to 'gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationManagementModal.js')
-rw-r--r--gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationManagementModal.js45
1 files changed, 16 insertions, 29 deletions
diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationManagementModal.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationManagementModal.js
index 6a435e4..93b504a 100644
--- a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationManagementModal.js
+++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/InstantiationManagementModal.js
@@ -27,6 +27,7 @@ import styled from "styled-components";
import { Link } from "react-router-dom";
import ControlLoopService from "../../../api/ControlLoopService";
import Row from "react-bootstrap/Row";
+import InstantiationUtils from "./utils/InstantiationUtils";
const ModalStyled = styled(Modal)`
background-color: transparent;
@@ -47,6 +48,7 @@ const DivWhiteSpaceStyled = styled.div`
const InstantiationManagementModal = (props) => {
const [show, setShow] = useState(true);
const [instantiationList, setInstantiationList] = useState([]);
+ const [deleteInstantiation, setDeleteInstantiation] = useState(false);
const [alertMessage, setAlertMessage] = useState(null);
useEffect(async () => {
@@ -55,16 +57,7 @@ const InstantiationManagementModal = (props) => {
const instantiationListJson = await response.json();
- const parsedInstantiationList = instantiationListJson['controlLoopList'].map((instance, index) => {
- return {
- index: index,
- name: instance['name'],
- version: instance['version'],
- orderedState: instance['orderedState'],
- currentState: instance['state'],
- disableDelete: instance['state'] !== 'UNINITIALISED'
- }
- });
+ const parsedInstantiationList = InstantiationUtils.parseInstantiationList(instantiationListJson['controlLoopList']);
setInstantiationList(parsedInstantiationList);
}, []);
@@ -77,18 +70,26 @@ const InstantiationManagementModal = (props) => {
return 'White';
}
- const deleteInstantiationHandler = async (instantiation, index) => {
+ const deleteInstantiationHandler = async (index, instantiation) => {
console.log("deleteInstantiationHandler called");
+ setDeleteInstantiation(true);
+
+ if (instantiation.disableDelete) {
+ return;
+ }
const name = instantiation.name;
const version = instantiation.version;
const response = await ControlLoopService.deleteInstantiation(name, version);
+ console.log(response);
+
updateList(index);
if (response.ok) {
successAlert();
+ setDeleteInstantiation(false);
} else {
await errorAlert(response);
}
@@ -96,7 +97,6 @@ const InstantiationManagementModal = (props) => {
const updateList = (index) => {
console.log("updateList called")
- console.log(instantiationList)
const updatedList = [...instantiationList];
updatedList.splice(index, 1);
@@ -104,22 +104,6 @@ const InstantiationManagementModal = (props) => {
setInstantiationList(updatedList);
}
- const renderDeleteButton = (instantiation, index) => {
- if (instantiation.disableDelete) {
- return (
- <Button variant="outline-danger" type="null"
- disabled={ true }
- style={ { cursor: "not-allowed" } }>Delete</Button>
- );
-
- } else {
- return (
- <Button variant="danger" type="null"
- onClick={ async () => deleteInstantiationHandler(instantiation, index) }>Delete</Button>
- );
- }
- }
-
const handleClose = () => {
console.log("handleClose called");
setShow(false);
@@ -200,7 +184,10 @@ const InstantiationManagementModal = (props) => {
</Link>
</td>
<td style={ { textAlign: "center" } }>
- { renderDeleteButton(instantiation, index) }
+ <Button variant={ instantiation.disabled ? "outline-danger" : "danger" } type="null"
+ disabled={ instantiation.disableDelete }
+ style={ instantiation.disableDelete ? { cursor: "not-allowed" } : {} }
+ onClick={(e) => deleteInstantiationHandler(index, instantiation)}>Delete</Button>
</td>
<td style={ { textAlign: "center" } }>
<Link to={ {