diff options
author | saul.gill <saul.gill@est.tech> | 2021-08-09 14:19:33 +0100 |
---|---|---|
committer | saul.gill <saul.gill@est.tech> | 2021-08-11 14:18:58 +0100 |
commit | 706b284cb8091ef00bc352bc5ee32f4fdca1162a (patch) | |
tree | b7eb30cc36c9f0dc75c24784d71faeb992ace429 /gui-clamp/ui-react/src/components/dialogs/ControlLoop/ReadAndConvertYaml.js | |
parent | bdc4cc9d4a75bfdd2f5656f102d2f6ac7817e4ef (diff) |
Add error handling and refactoring
Added error for when common or instance props can't be retrieved
Added error for monitoring when control loops can't be retrieved
Made node templates collapsed by default when editing properties
Added single service function to get common or instance properties
Issue-ID: POLICY-3439
Change-Id: I74560a06aae1a820862f977d5e7ac86597a093c0
Signed-off-by: saul.gill <saul.gill@est.tech>
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 | 18 |
1 files changed, 12 insertions, 6 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 0ff8833..0eff5fe 100644 --- a/gui-clamp/ui-react/src/components/dialogs/ControlLoop/ReadAndConvertYaml.js +++ b/gui-clamp/ui-react/src/components/dialogs/ControlLoop/ReadAndConvertYaml.js @@ -44,9 +44,10 @@ const PreStyled = styled.pre` const ReadAndConvertYaml = (props) => { const [show, setShow] = useState(true); const [toscaTemplateData, setToscaTemplateData] = useState(); - const [deleteToscaTemplateData, setDeleteToscaTemplateData] = useState(); + const [deleteToscaTemplateData, setDeleteToscaTemplateData] = useState(null); const [responseOk, setResponseOk] = useState(true); const [deleteResponseOk, setDeleteResponseOk] = useState(true); + const [showDeleteButton, setShowDeleteButton] = useState(false); const name = 'ToscaServiceTemplateSimple'; const version = '1.0.0'; @@ -57,7 +58,6 @@ const ReadAndConvertYaml = (props) => { } const getToscaServiceTemplateHandler = async (toscaServiceTemplateResponse) => { - // console.log('getToscaServiceTemplateHandler called: ' + toscaServiceTemplate); if (!toscaServiceTemplateResponse.ok) { console.log('Response is not ok'); @@ -68,20 +68,26 @@ const ReadAndConvertYaml = (props) => { setResponseOk(true); const toscaData = await toscaServiceTemplateResponse.json(); setToscaTemplateData(toscaData); + setShowDeleteButton(true) } } const deleteToscaServiceTemplateHandler = async (deleteToscaServiceTemplateResponse) => { if (!deleteToscaServiceTemplateResponse.ok) { + setShowDeleteButton(false) console.log('Delete response not ok'); setDeleteResponseOk(false); - const deleteToscaData = await deleteToscaServiceTemplateResponse; + const deleteToscaData = await deleteToscaServiceTemplateResponse.json(); + console.log(deleteToscaData) setDeleteToscaTemplateData(deleteToscaData); } else { + setShowDeleteButton(false) setDeleteResponseOk(true); const deleteToscaData = await deleteToscaServiceTemplateResponse.json(); + setDeleteToscaTemplateData(null) setDeleteToscaTemplateData(deleteToscaData); + setShowDeleteButton(false); } } @@ -101,15 +107,15 @@ const ReadAndConvertYaml = (props) => { { responseOk && <PreStyled> { JSON.stringify(toscaTemplateData, null, 2) } </PreStyled> } <AlertStyled show={ !responseOk } variant="danger">{ JSON.stringify(toscaTemplateData, null, 2) }</AlertStyled> - { deleteResponseOk && responseOk && toscaTemplateData != null && + { showDeleteButton && <DeleteToscaTemplate templateName={ name } templateVersion={ version } onDeleteToscaServiceTemplate={ deleteToscaServiceTemplateHandler } /> } <AlertStyled show={ !deleteResponseOk } - variant="danger">{ deleteToscaTemplateData }</AlertStyled> - <AlertStyled show={ deleteResponseOk && deleteToscaTemplateData != null } + variant="danger">{ JSON.stringify(deleteToscaTemplateData, null, 2) }</AlertStyled> + <AlertStyled show={ deleteResponseOk && deleteToscaTemplateData != null && toscaTemplateData != null} variant="success"><h2>Delete Successful</h2><PreStyled>{ JSON.stringify(deleteToscaTemplateData, null, 2) }</PreStyled></AlertStyled> </Modal.Body> <Modal.Footer> |