diff options
author | 2021-07-20 13:44:23 +0000 | |
---|---|---|
committer | 2021-07-20 13:44:23 +0000 | |
commit | 29871bc266df6b4418f30311ce9d0ef9ddd9965c (patch) | |
tree | a58d71644fb500c6b60089c9af78e7185262e85b /gui-clamp/ui-react/src/components/dialogs/ControlLoop/ReadAndConvertYaml.js | |
parent | efaa2f3f7d22a5096625b51643f707b471569d78 (diff) | |
parent | 3f99e6d9f007477fe6074f470048440d2b29c1ff (diff) |
Merge "Added Commissioning Template Editor"
Diffstat (limited to 'gui-clamp/ui-react/src/components/dialogs/ControlLoop/ReadAndConvertYaml.js')
-rw-r--r-- | gui-clamp/ui-react/src/components/dialogs/ControlLoop/ReadAndConvertYaml.js | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/ReadAndConvertYaml.js b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/ReadAndConvertYaml.js index 53b541c..0ff8833 100644 --- a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/ReadAndConvertYaml.js +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/ReadAndConvertYaml.js @@ -24,6 +24,7 @@ import Button from "react-bootstrap/Button"; import { Alert } from "react-bootstrap"; import styled from 'styled-components'; +import DeleteToscaTemplate from "./DeleteToscaTemplate"; const ModalStyled = styled(Modal)` background-color: transparent; @@ -43,7 +44,9 @@ const PreStyled = styled.pre` const ReadAndConvertYaml = (props) => { const [show, setShow] = useState(true); const [toscaTemplateData, setToscaTemplateData] = useState(); - const [responeOk, setResponseOk] = useState(true); + const [deleteToscaTemplateData, setDeleteToscaTemplateData] = useState(); + const [responseOk, setResponseOk] = useState(true); + const [deleteResponseOk, setDeleteResponseOk] = useState(true); const name = 'ToscaServiceTemplateSimple'; const version = '1.0.0'; @@ -57,8 +60,9 @@ const ReadAndConvertYaml = (props) => { // console.log('getToscaServiceTemplateHandler called: ' + toscaServiceTemplate); if (!toscaServiceTemplateResponse.ok) { + console.log('Response is not ok'); setResponseOk(false); - const toscaData = await toscaServiceTemplateResponse; + const toscaData = await toscaServiceTemplateResponse.json(); setToscaTemplateData(toscaData); } else { setResponseOk(true); @@ -67,6 +71,20 @@ const ReadAndConvertYaml = (props) => { } } + const deleteToscaServiceTemplateHandler = async (deleteToscaServiceTemplateResponse) => { + + if (!deleteToscaServiceTemplateResponse.ok) { + console.log('Delete response not ok'); + setDeleteResponseOk(false); + const deleteToscaData = await deleteToscaServiceTemplateResponse; + setDeleteToscaTemplateData(deleteToscaData); + } else { + setDeleteResponseOk(true); + const deleteToscaData = await deleteToscaServiceTemplateResponse.json(); + setDeleteToscaTemplateData(deleteToscaData); + } + } + return ( <ModalStyled size="xl" show={ show } @@ -80,17 +98,28 @@ const ReadAndConvertYaml = (props) => { <GetToscaTemplate templateName={ name } templateVersion={ version } onGetToscaServiceTemplate={ getToscaServiceTemplateHandler }/> - { responeOk && <PreStyled> { JSON.stringify(toscaTemplateData, null, 2) } </PreStyled> } - <AlertStyled show={ !responeOk } - variant="danger">{ toscaTemplateData }</AlertStyled> + { responseOk && <PreStyled> { JSON.stringify(toscaTemplateData, null, 2) } </PreStyled> } + <AlertStyled show={ !responseOk } + variant="danger">{ JSON.stringify(toscaTemplateData, null, 2) }</AlertStyled> + { deleteResponseOk && responseOk && toscaTemplateData != null && + <DeleteToscaTemplate templateName={ name } + templateVersion={ version } + onDeleteToscaServiceTemplate={ deleteToscaServiceTemplateHandler } + /> + } + <AlertStyled show={ !deleteResponseOk } + variant="danger">{ deleteToscaTemplateData }</AlertStyled> + <AlertStyled show={ deleteResponseOk && deleteToscaTemplateData != null } + variant="success"><h2>Delete Successful</h2><PreStyled>{ JSON.stringify(deleteToscaTemplateData, null, 2) }</PreStyled></AlertStyled> </Modal.Body> <Modal.Footer> <Button variant="secondary" type="null" - onClick={ handleClose }>Cancel</Button> + onClick={ handleClose }>Close</Button> </Modal.Footer> </ModalStyled> ); -}; +} +; export default ReadAndConvertYaml; |