2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
24 import React, { forwardRef } from 'react'
25 import MaterialTable from "material-table";
26 import Button from 'react-bootstrap/Button';
27 import Modal from 'react-bootstrap/Modal';
28 import styled from 'styled-components';
29 import PolicyToscaService from '../../../api/PolicyToscaService';
30 import ArrowUpward from '@material-ui/icons/ArrowUpward';
31 import ChevronLeft from '@material-ui/icons/ChevronLeft';
32 import ChevronRight from '@material-ui/icons/ChevronRight';
33 import Clear from '@material-ui/icons/Clear';
34 import FirstPage from '@material-ui/icons/FirstPage';
35 import LastPage from '@material-ui/icons/LastPage';
36 import Search from '@material-ui/icons/Search';
39 const ModalStyled = styled(Modal)`
40 background-color: transparent;
42 const TextModal = styled.textarea`
45 background-color: ${props => props.theme.toscaTextareaBackgroundColor};
47 font-size: ${props => props.theme.toscaTextareaFontSize};
51 const cellStyle = { border: '1px solid black' };
52 const headerStyle = { backgroundColor: '#ddd', border: '2px solid black' };
53 const rowHeaderStyle = {backgroundColor:'#ddd', fontSize: '15pt', text: 'bold', border: '1px solid black'};
55 export default class ViewToscalPolicyModal extends React.Component {
59 content: 'Please select Tosca model to view the details',
61 toscaPolicyModelNames: [],
63 { title: "#", field: "index", render: rowData => rowData.tableData.id + 1,
65 headerStyle: headerStyle
67 { title: "Policy Model Type", field: "policyModelType",
69 headerStyle: headerStyle
71 { title: "Policy Acronym", field: "policyAcronym",
73 headerStyle: headerStyle
75 { title: "Version", field: "version",
77 headerStyle: headerStyle
79 { title: "Uploaded By", field: "updatedBy",
81 headerStyle: headerStyle
83 { title: "Uploaded Date", field: "updatedDate", editable: 'never',
85 headerStyle: headerStyle
89 FirstPage: forwardRef((props, ref) => <FirstPage {...props} ref={ref} />),
90 LastPage: forwardRef((props, ref) => <LastPage {...props} ref={ref} />),
91 NextPage: forwardRef((props, ref) => <ChevronRight {...props} ref={ref} />),
92 PreviousPage: forwardRef((props, ref) => <ChevronLeft {...props} ref={ref} />),
93 ResetSearch: forwardRef((props, ref) => <Clear {...props} ref={ref} />),
94 Search: forwardRef((props, ref) => <Search {...props} ref={ref} />),
95 SortArrow: forwardRef((props, ref) => <ArrowUpward {...props} ref={ref} />)
99 constructor(props, context) {
100 super(props, context);
101 this.handleClose = this.handleClose.bind(this);
102 this.getPolicyToscaModels = this.getToscaPolicyModels.bind(this);
103 this.handleYamlContent = this.handleYamlContent.bind(this);
104 this.getToscaPolicyModelYaml = this.getToscaPolicyModelYaml.bind(this);
107 componentWillMount() {
108 this.getToscaPolicyModels();
111 getToscaPolicyModels() {
112 PolicyToscaService.getToscaPolicyModels().then(toscaPolicyModelNames => {
113 this.setState({ toscaPolicyModelNames: toscaPolicyModelNames });
117 getToscaPolicyModelYaml(policyModelType, policyModelVersion) {
118 if (typeof policyModelType !== "undefined") {
119 PolicyToscaService.getToscaPolicyModelYaml(policyModelType, policyModelVersion).then(toscaYaml => {
120 if (toscaYaml.length !== 0) {
121 this.setState({content: toscaYaml})
123 this.setState({ content: 'Please select Tosca model to view the details' })
127 this.setState({ content: 'Please select Tosca model to view the details' })
131 handleYamlContent(event) {
132 this.setState({ content: event.target.value });
136 this.setState({ show: false });
137 this.props.history.push('/');
142 <ModalStyled size="xl" show={this.state.show} onHide={this.handleClose} backdrop="static" keyboard={false}>
143 <Modal.Header closeButton>
147 title={"View Tosca Policy Models"}
148 data={this.state.toscaPolicyModelNames}
149 columns={this.state.toscaColumns}
150 icons={this.state.tableIcons}
151 onRowClick={(event, rowData) => {this.getToscaPolicyModelYaml(rowData.policyModelType,rowData.version);this.setState({selectedRow: rowData.tableData.id})}}
153 headerStyle: rowHeaderStyle,
154 rowStyle: rowData => ({
155 backgroundColor: (this.state.selectedRow !== -1 && this.state.selectedRow === rowData.tableData.id) ? '#EEE' : '#FFF'
160 <TextModal value={this.state.content} onChange={this.handleYamlContent}/>
164 <Button variant="secondary" onClick={this.handleClose}>Close</Button>