Added jest/enzyme tests for new components
[policy/gui.git] / gui-clamp / ui-react / src / components / dialogs / ReadAndConvertYaml.js
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20 import React, { useState } from "react";
21 import GetToscaTemplate from "../../api/GetToscaTemplate";
22 import Modal from "react-bootstrap/Modal";
23 import Button from "react-bootstrap/Button";
24
25 import styled from 'styled-components';
26
27 const ModalStyled = styled(Modal)`
28   background-color: transparent;
29 `
30
31 const ErrMsgStyled = styled.div`
32   color: red;
33 `
34
35 const PreStyled = styled.pre`
36   color: #7F0055;
37   overflow: auto;
38   max-height: 70vh;
39 `
40
41 const ReadAndConvertYaml = (props) => {
42   const [show, setShow] = useState(true);
43   const [toscaTemplateData, setToscaTemplateData] = useState();
44   const name = 'ToscaServiceTemplateSimple';
45   const version = '1.0.0';
46
47   const handleClose = () => {
48     console.log('handleClose called');
49     setShow(false);
50     props.history.push('/');
51   }
52
53   const getToscaServiceTemplateHandler = async (toscaServiceTemplate) => {
54     console.log('getToscaServiceTemplateHandler called');
55     const toscaData = {
56       ...toscaServiceTemplate,
57       id: Math.random().toString()
58     };
59     // console.log(toscaData);
60     setToscaTemplateData(toscaData);
61   }
62
63   return (
64     <ModalStyled size="xl"
65                  show={ show }
66                  onHide={ handleClose }
67                  backdrop="static"
68                  keyboard={ false }>
69       <Modal.Header closeButton>
70         <Modal.Title>View Tosca Template</Modal.Title>
71       </Modal.Header>
72       <Modal.Body>
73         <GetToscaTemplate templateName={ name }
74                           templateVersion={ version }
75                           onGetToscaServiceTemplate={ getToscaServiceTemplateHandler }/>
76         <PreStyled>{ JSON.stringify(toscaTemplateData, null, 2) }</PreStyled>
77       </Modal.Body>
78       <Modal.Footer>
79         <Button variant="secondary"
80                 type="null"
81                 onClick={ handleClose }>Cancel</Button>
82       </Modal.Footer>
83     </ModalStyled>
84   );
85 }
86
87 export default ReadAndConvertYaml;