sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 1 | /*- |
| 2 | * ============LICENSE_START======================================================= |
| 3 | * ONAP POLICY-CLAMP |
| 4 | * ================================================================================ |
| 5 | * Copyright (C) 2021 AT&T Intellectual Property. All rights |
| 6 | * reserved. |
| 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 |
| 11 | * |
| 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | * |
| 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 | * =================================================================== |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | import React, { forwardRef } from 'react' |
| 25 | import Button from 'react-bootstrap/Button'; |
| 26 | import Modal from 'react-bootstrap/Modal'; |
| 27 | import styled from 'styled-components'; |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 28 | import AddBox from '@material-ui/icons/AddBox'; |
| 29 | import ArrowDownward from '@material-ui/icons/ArrowDownward'; |
| 30 | import Check from '@material-ui/icons/Check'; |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 31 | import ChevronLeft from '@material-ui/icons/ChevronLeft'; |
| 32 | import ChevronRight from '@material-ui/icons/ChevronRight'; |
| 33 | import Clear from '@material-ui/icons/Clear'; |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 34 | import DeleteRoundedIcon from '@material-ui/icons/DeleteRounded'; |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 35 | import Edit from '@material-ui/icons/Edit'; |
| 36 | import FilterList from '@material-ui/icons/FilterList'; |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 37 | import FirstPage from '@material-ui/icons/FirstPage'; |
| 38 | import LastPage from '@material-ui/icons/LastPage'; |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 39 | import Remove from '@material-ui/icons/Remove'; |
| 40 | import SaveAlt from '@material-ui/icons/SaveAlt'; |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 41 | import Search from '@material-ui/icons/Search'; |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 42 | import ViewColumn from '@material-ui/icons/ViewColumn'; |
sebdet | b8831e5 | 2021-03-12 19:30:22 +0100 | [diff] [blame^] | 43 | import DehazeIcon from '@material-ui/icons/Dehaze'; |
| 44 | import ArrowForwardIosIcon from '@material-ui/icons/ArrowForwardIos'; |
| 45 | import AddIcon from '@material-ui/icons/Add'; |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 46 | import FormControlLabel from '@material-ui/core/FormControlLabel'; |
| 47 | import Switch from '@material-ui/core/Switch'; |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 48 | import MaterialTable from "material-table"; |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 49 | import PolicyService from '../../../api/PolicyService'; |
sebdet | 3718a16 | 2021-02-12 17:18:47 +0100 | [diff] [blame] | 50 | import PolicyToscaService from '../../../api/PolicyToscaService'; |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 51 | import Select from 'react-select'; |
sebdet | c427e64 | 2021-02-17 17:53:17 +0100 | [diff] [blame] | 52 | import Alert from 'react-bootstrap/Alert'; |
sebdet | ea2969f | 2021-02-25 13:58:36 +0100 | [diff] [blame] | 53 | import Tabs from 'react-bootstrap/Tabs'; |
| 54 | import Tab from 'react-bootstrap/Tab'; |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 55 | import PolicyEditor from './PolicyEditor'; |
| 56 | import ToscaViewer from './ToscaViewer'; |
sebdet | c427e64 | 2021-02-17 17:53:17 +0100 | [diff] [blame] | 57 | |
| 58 | const DivWhiteSpaceStyled = styled.div` |
sebdet | ea2969f | 2021-02-25 13:58:36 +0100 | [diff] [blame] | 59 | white-space: pre; |
sebdet | c427e64 | 2021-02-17 17:53:17 +0100 | [diff] [blame] | 60 | ` |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 61 | |
| 62 | const ModalStyled = styled(Modal)` |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 63 | @media (min-width: 1000px) { |
sebdet | 3718a16 | 2021-02-12 17:18:47 +0100 | [diff] [blame] | 64 | .modal-xl { |
| 65 | max-width: 96%; |
| 66 | } |
| 67 | } |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 68 | background-color: transparent; |
| 69 | ` |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 70 | const DetailedRow = styled.div` |
| 71 | margin: 0 auto; |
| 72 | background-color: ${props => props.theme.policyEditorBackgroundColor}; |
| 73 | font-size: ${props => props.theme.policyEditorFontSize}; |
| 74 | width: 97%; |
| 75 | margin-left: auto; |
| 76 | margin-right: 0; |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 77 | ` |
| 78 | |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 79 | |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 80 | const standardCellStyle = { backgroundColor: '#039be5', color: '#FFF', border: '1px solid black' }; |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 81 | const cellPdpGroupStyle = { backgroundColor: '#039be5', color: '#FFF', border: '1px solid black'}; |
| 82 | const headerStyle = { backgroundColor: '#ddd', border: '2px solid black' }; |
| 83 | const rowHeaderStyle = {backgroundColor:'#ddd', fontSize: '15pt', text: 'bold', border: '1px solid black'}; |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 84 | |
| 85 | export default class ViewAllPolicies extends React.Component { |
| 86 | state = { |
| 87 | show: true, |
| 88 | content: 'Please select a policy to display it', |
sebdet | c427e64 | 2021-02-17 17:53:17 +0100 | [diff] [blame] | 89 | selectedRowId: -1, |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 90 | policiesListData: [], |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 91 | toscaModelsListData: [], |
| 92 | jsonEditorForPolicy: new Map(), |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 93 | prefixGrouping: false, |
sebdet | c427e64 | 2021-02-17 17:53:17 +0100 | [diff] [blame] | 94 | showSuccessAlert: false, |
| 95 | showFailAlert: false, |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 96 | policyColumnsDefinition: [ |
| 97 | { |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 98 | title: "Policy Name", field: "name", |
| 99 | cellStyle: standardCellStyle, |
| 100 | headerStyle: headerStyle |
| 101 | }, |
| 102 | { |
| 103 | title: "Policy Version", field: "version", |
| 104 | cellStyle: standardCellStyle, |
| 105 | headerStyle: headerStyle |
| 106 | }, |
| 107 | { |
| 108 | title: "Policy Type", field: "type", |
| 109 | cellStyle: standardCellStyle, |
| 110 | headerStyle: headerStyle |
| 111 | }, |
| 112 | { |
| 113 | title: "Policy Type Version", field: "type_version", |
| 114 | cellStyle: standardCellStyle, |
| 115 | headerStyle: headerStyle |
| 116 | }, |
| 117 | { |
| 118 | title: "Deployed in PDP", field: "pdpGroupInfo.pdpGroup", |
| 119 | cellStyle: cellPdpGroupStyle, |
| 120 | headerStyle: headerStyle, |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 121 | render: rowData => this.renderPdpGroupDropBox(rowData), |
| 122 | grouping: false |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 123 | }, |
| 124 | { |
| 125 | title: "PDP Group", field: "pdpGroupInfo.pdpGroup", |
| 126 | cellStyle: cellPdpGroupStyle, |
| 127 | headerStyle: headerStyle |
| 128 | }, |
| 129 | { |
| 130 | title: "PDP SubGroup", field: "pdpGroupInfo.pdpSubGroup", |
| 131 | cellStyle: cellPdpGroupStyle, |
| 132 | headerStyle: headerStyle |
| 133 | } |
| 134 | ], |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 135 | toscaColumnsDefinition: [ |
| 136 | { |
| 137 | title: "Policy Model Type", field: "policyModelType", |
| 138 | cellStyle: standardCellStyle, |
| 139 | headerStyle: headerStyle |
| 140 | }, |
| 141 | { |
| 142 | title: "Policy Acronym", field: "policyAcronym", |
| 143 | cellStyle: standardCellStyle, |
| 144 | headerStyle: headerStyle |
| 145 | }, |
| 146 | { |
| 147 | title: "Version", field: "version", |
| 148 | cellStyle: standardCellStyle, |
| 149 | headerStyle: headerStyle |
| 150 | }, |
| 151 | { |
| 152 | title: "Uploaded By", field: "updatedBy", |
| 153 | cellStyle: standardCellStyle, |
| 154 | headerStyle: headerStyle |
| 155 | }, |
| 156 | { |
| 157 | title: "Uploaded Date", field: "updatedDate", editable: 'never', |
| 158 | cellStyle: standardCellStyle, |
| 159 | headerStyle: headerStyle |
| 160 | } |
| 161 | ], |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 162 | tableIcons: { |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 163 | Add: forwardRef((props, ref) => <AddBox {...props} ref={ref} />), |
| 164 | Check: forwardRef((props, ref) => <Check {...props} ref={ref} />), |
| 165 | Clear: forwardRef((props, ref) => <Clear {...props} ref={ref} />), |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 166 | Delete: forwardRef((props, ref) => <DeleteRoundedIcon {...props} ref={ref} />), |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 167 | DetailPanel: forwardRef((props, ref) => <ChevronRight {...props} ref={ref} />), |
| 168 | Edit: forwardRef((props, ref) => <Edit {...props} ref={ref} />), |
| 169 | Export: forwardRef((props, ref) => <SaveAlt {...props} ref={ref} />), |
| 170 | Filter: forwardRef((props, ref) => <FilterList {...props} ref={ref} />), |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 171 | FirstPage: forwardRef((props, ref) => <FirstPage {...props} ref={ref} />), |
| 172 | LastPage: forwardRef((props, ref) => <LastPage {...props} ref={ref} />), |
| 173 | NextPage: forwardRef((props, ref) => <ChevronRight {...props} ref={ref} />), |
| 174 | PreviousPage: forwardRef((props, ref) => <ChevronLeft {...props} ref={ref} />), |
| 175 | ResetSearch: forwardRef((props, ref) => <Clear {...props} ref={ref} />), |
| 176 | Search: forwardRef((props, ref) => <Search {...props} ref={ref} />), |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 177 | SortArrow: forwardRef((props, ref) => <ArrowDownward {...props} ref={ref} />), |
| 178 | ThirdStateCheck: forwardRef((props, ref) => <Remove {...props} ref={ref} />), |
| 179 | ViewColumn: forwardRef((props, ref) => <ViewColumn {...props} ref={ref} />) |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 180 | } |
| 181 | }; |
| 182 | |
| 183 | constructor(props, context) { |
| 184 | super(props, context); |
| 185 | this.handleClose = this.handleClose.bind(this); |
| 186 | this.renderPdpGroupDropBox = this.renderPdpGroupDropBox.bind(this); |
| 187 | this.handlePdpGroupChange = this.handlePdpGroupChange.bind(this); |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 188 | this.handlePrefixGrouping = this.handlePrefixGrouping.bind(this); |
sebdet | a0a3a03 | 2021-02-16 14:53:43 +0100 | [diff] [blame] | 189 | this.handleDeletePolicy = this.handleDeletePolicy.bind(this); |
sebdet | c427e64 | 2021-02-17 17:53:17 +0100 | [diff] [blame] | 190 | this.disableAlert = this.disableAlert.bind(this); |
sebdet | b8831e5 | 2021-03-12 19:30:22 +0100 | [diff] [blame^] | 191 | this.getAllPolicies = this.getAllPolicies.bind(this); |
| 192 | this.getAllToscaModels = this.getAllToscaModels.bind(this); |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 193 | this.getAllPolicies(); |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 194 | this.getAllToscaModels(); |
| 195 | } |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 196 | |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 197 | getAllToscaModels() { |
| 198 | PolicyToscaService.getToscaPolicyModels().then(toscaModelsList => { |
| 199 | this.setState({ toscaModelsListData: toscaModelsList }); |
| 200 | }); |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | handlePdpGroupChange(e) { |
| 204 | let pdpSplit = e.value.split("/"); |
| 205 | let selectedPdpGroup = pdpSplit[0]; |
| 206 | let selectedSubPdpGroup = pdpSplit[1]; |
| 207 | if (typeof selectedSubPdpGroup !== "undefined") { |
sebdet | 3718a16 | 2021-02-12 17:18:47 +0100 | [diff] [blame] | 208 | let temp = this.state.policiesListData; |
sebdet | c427e64 | 2021-02-17 17:53:17 +0100 | [diff] [blame] | 209 | temp[this.state.selectedRowId]["pdpGroupInfo"] = {"pdpGroup":selectedPdpGroup,"pdpSubGroup":selectedSubPdpGroup}; |
sebdet | 3718a16 | 2021-02-12 17:18:47 +0100 | [diff] [blame] | 210 | this.setState({policiesListData: temp}); |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 211 | } else { |
sebdet | c427e64 | 2021-02-17 17:53:17 +0100 | [diff] [blame] | 212 | delete this.state.policiesListData[this.state.selectedRowId]["pdpGroupInfo"]; |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 213 | } |
| 214 | } |
| 215 | |
| 216 | renderPdpGroupDropBox(dataRow) { |
| 217 | let optionItems = [{label: "NOT DEPLOYED", value: "NOT DEPLOYED"}]; |
| 218 | let selectedItem = {label: "NOT DEPLOYED", value: "NOT DEPLOYED"}; |
| 219 | if (typeof dataRow.supportedPdpGroups !== "undefined") { |
| 220 | for (const pdpGroup of dataRow["supportedPdpGroups"]) { |
| 221 | for (const pdpSubGroup of Object.values(pdpGroup)[0]) { |
| 222 | optionItems.push({ label: Object.keys(pdpGroup)[0]+"/"+pdpSubGroup, |
| 223 | value: Object.keys(pdpGroup)[0]+"/"+pdpSubGroup }); |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | if (typeof dataRow.pdpGroupInfo !== "undefined") { |
| 228 | selectedItem = {label: dataRow["pdpGroupInfo"]["pdpGroup"]+"/"+dataRow["pdpGroupInfo"]["pdpSubGroup"], |
| 229 | value: dataRow["pdpGroupInfo"]["pdpGroup"]+"/"+dataRow["pdpGroupInfo"]["pdpSubGroup"]}; |
| 230 | } |
| 231 | return (<div style={{width: '250px'}}><Select value={selectedItem} options={optionItems} onChange={this.handlePdpGroupChange}/></div>); |
| 232 | } |
| 233 | |
| 234 | getAllPolicies() { |
| 235 | PolicyService.getPoliciesList().then(allPolicies => { |
| 236 | this.setState({ policiesListData: allPolicies["policies"] }) |
| 237 | }); |
| 238 | } |
| 239 | |
| 240 | handleClose() { |
| 241 | this.setState({ show: false }); |
| 242 | this.props.history.push('/') |
| 243 | } |
| 244 | |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 245 | handlePrefixGrouping(event) { |
| 246 | this.setState({prefixGrouping: event.target.checked}); |
sebdet | a0a3a03 | 2021-02-16 14:53:43 +0100 | [diff] [blame] | 247 | } |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 248 | |
sebdet | a0a3a03 | 2021-02-16 14:53:43 +0100 | [diff] [blame] | 249 | handleDeletePolicy(event, rowData) { |
sebdet | ea2969f | 2021-02-25 13:58:36 +0100 | [diff] [blame] | 250 | PolicyService.deletePolicy(rowData["type"], rowData["type_version"], rowData["name"],rowData["version"]).then( |
| 251 | respPolicyDeletion => { |
sebdet | b8831e5 | 2021-03-12 19:30:22 +0100 | [diff] [blame^] | 252 | if (typeof(respPolicyDeletion) === "undefined") { |
sebdet | ea2969f | 2021-02-25 13:58:36 +0100 | [diff] [blame] | 253 | //it indicates a failure |
| 254 | this.setState({ |
| 255 | showFailAlert: true, |
| 256 | showMessage: 'Policy Deletion Failure' |
| 257 | }); |
| 258 | } else { |
| 259 | this.setState({ |
| 260 | showSuccessAlert: true, |
| 261 | showMessage: 'Policy successfully Deleted' |
| 262 | }); |
| 263 | } |
sebdet | b8831e5 | 2021-03-12 19:30:22 +0100 | [diff] [blame^] | 264 | this.getAllPolicies(); |
sebdet | ea2969f | 2021-02-25 13:58:36 +0100 | [diff] [blame] | 265 | } |
| 266 | ) |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 267 | } |
| 268 | |
sebdet | c427e64 | 2021-02-17 17:53:17 +0100 | [diff] [blame] | 269 | disableAlert() { |
| 270 | this.setState ({ showSuccessAlert: false, showFailAlert: false }); |
| 271 | } |
| 272 | |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 273 | renderPoliciesTab() { |
| 274 | return ( |
| 275 | <Tab eventKey="policies" title="Policies in Policy Framework"> |
| 276 | <Modal.Body> |
| 277 | <FormControlLabel |
| 278 | control={<Switch checked={this.state.prefixGrouping} onChange={this.handlePrefixGrouping} />} |
| 279 | label="Group by prefix" |
| 280 | /> |
| 281 | <MaterialTable |
| 282 | title={"Policies"} |
| 283 | data={this.state.policiesListData} |
| 284 | columns={this.state.policyColumnsDefinition} |
| 285 | icons={this.state.tableIcons} |
| 286 | onRowClick={(event, rowData, togglePanel) => togglePanel()} |
| 287 | options={{ |
| 288 | grouping: true, |
| 289 | exportButton: true, |
| 290 | headerStyle:rowHeaderStyle, |
| 291 | rowStyle: rowData => ({ |
| 292 | backgroundColor: (this.state.selectedRowId !== -1 && this.state.selectedRowId === rowData.tableData.id) ? '#EEE' : '#FFF' |
| 293 | }), |
| 294 | actionsColumnIndex: -1 |
| 295 | }} |
| 296 | detailPanel={[ |
| 297 | { |
sebdet | b8831e5 | 2021-03-12 19:30:22 +0100 | [diff] [blame^] | 298 | icon: ArrowForwardIosIcon, |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 299 | tooltip: 'Show Configuration', |
| 300 | render: rowData => { |
| 301 | return ( |
| 302 | <DetailedRow> |
sebdet | b8831e5 | 2021-03-12 19:30:22 +0100 | [diff] [blame^] | 303 | <PolicyEditor policyModelType={rowData["type"]} policyModelTypeVersion={rowData["type_version"]} policyName={rowData["name"]} policyVersion={rowData["version"]} policyProperties={rowData["properties"]} policyUpdateFunction={this.getAllPolicies} /> |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 304 | </DetailedRow> |
| 305 | ) |
| 306 | }, |
| 307 | }, |
| 308 | { |
sebdet | b8831e5 | 2021-03-12 19:30:22 +0100 | [diff] [blame^] | 309 | icon: DehazeIcon, |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 310 | tooltip: 'Show Raw Data', |
| 311 | render: rowData => { |
| 312 | return ( |
| 313 | <DetailedRow> |
| 314 | <pre>{JSON.stringify(rowData, null, 2)}</pre> |
| 315 | </DetailedRow> |
| 316 | ) |
| 317 | }, |
| 318 | }, |
| 319 | ]} |
| 320 | actions={[ |
| 321 | { |
| 322 | icon: forwardRef((props, ref) => <DeleteRoundedIcon {...props} ref={ref} />), |
| 323 | tooltip: 'Delete Policy', |
| 324 | onClick: (event, rowData) => this.handleDeletePolicy(event, rowData) |
| 325 | } |
| 326 | ]} |
| 327 | /> |
| 328 | </Modal.Body> |
| 329 | </Tab> |
| 330 | ); |
| 331 | } |
| 332 | |
| 333 | renderToscaTab() { |
| 334 | return ( |
| 335 | <Tab eventKey="tosca models" title="Tosca Models in Policy Framework"> |
| 336 | <Modal.Body> |
| 337 | <FormControlLabel |
| 338 | control={<Switch checked={this.state.prefixGrouping} onChange={this.handlePrefixGrouping} />} |
| 339 | label="Group by prefix" |
| 340 | /> |
| 341 | <MaterialTable |
| 342 | title={"Tosca Models"} |
| 343 | data={this.state.toscaModelsListData} |
| 344 | columns={this.state.toscaColumnsDefinition} |
| 345 | icons={this.state.tableIcons} |
| 346 | onRowClick={(event, rowData, togglePanel) => togglePanel()} |
| 347 | options={{ |
| 348 | grouping: true, |
| 349 | exportButton: true, |
| 350 | headerStyle:rowHeaderStyle, |
| 351 | rowStyle: rowData => ({ |
| 352 | backgroundColor: (this.state.selectedRowId !== -1 && this.state.selectedRowId === rowData.tableData.id) ? '#EEE' : '#FFF' |
| 353 | }), |
| 354 | actionsColumnIndex: -1 |
| 355 | }} |
| 356 | detailPanel={[ |
| 357 | { |
sebdet | b8831e5 | 2021-03-12 19:30:22 +0100 | [diff] [blame^] | 358 | icon: ArrowForwardIosIcon, |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 359 | tooltip: 'Show Tosca', |
| 360 | render: rowData => { |
| 361 | return ( |
| 362 | <DetailedRow> |
| 363 | <ToscaViewer toscaData={rowData} /> |
| 364 | </DetailedRow> |
| 365 | ) |
| 366 | }, |
| 367 | }, |
| 368 | { |
sebdet | b8831e5 | 2021-03-12 19:30:22 +0100 | [diff] [blame^] | 369 | icon: DehazeIcon, |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 370 | tooltip: 'Show Raw Data', |
| 371 | render: rowData => { |
| 372 | return ( |
| 373 | <DetailedRow> |
| 374 | <pre>{JSON.stringify(rowData, null, 2)}</pre> |
| 375 | </DetailedRow> |
| 376 | ) |
| 377 | }, |
| 378 | }, |
| 379 | { |
sebdet | b8831e5 | 2021-03-12 19:30:22 +0100 | [diff] [blame^] | 380 | icon: AddIcon, |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 381 | tooltip: 'Create a policy from this model', |
| 382 | render: rowData => { |
| 383 | return ( |
| 384 | <DetailedRow> |
sebdet | b8831e5 | 2021-03-12 19:30:22 +0100 | [diff] [blame^] | 385 | <PolicyEditor policyModelType={rowData["policyModelType"]} policyModelTypeVersion={rowData["version"]} policyProperties={{}} policyUpdateFunction={this.getAllPolicies} /> |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 386 | </DetailedRow> |
| 387 | ) |
| 388 | }, |
| 389 | }, |
| 390 | ]} |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 391 | /> |
| 392 | </Modal.Body> |
| 393 | </Tab> |
| 394 | ); |
| 395 | } |
| 396 | |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 397 | render() { |
| 398 | return ( |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 399 | <ModalStyled size="xl" show={this.state.show} onHide={this.handleClose} backdrop="static" keyboard={false}> |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 400 | <Modal.Header closeButton> |
| 401 | </Modal.Header> |
sebdet | ea2969f | 2021-02-25 13:58:36 +0100 | [diff] [blame] | 402 | <Tabs id="controlled-tab-example" activeKey={this.state.key} onSelect={key => this.setState({ key, selectedRowData: {} })}> |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 403 | {this.renderPoliciesTab()} |
| 404 | {this.renderToscaTab()} |
sebdet | ea2969f | 2021-02-25 13:58:36 +0100 | [diff] [blame] | 405 | </Tabs> |
sebdet | c427e64 | 2021-02-17 17:53:17 +0100 | [diff] [blame] | 406 | <Alert variant="success" show={this.state.showSuccessAlert} onClose={this.disableAlert} dismissible> |
sebdet | ea2969f | 2021-02-25 13:58:36 +0100 | [diff] [blame] | 407 | <DivWhiteSpaceStyled> |
| 408 | {this.state.showMessage} |
| 409 | </DivWhiteSpaceStyled> |
| 410 | </Alert> |
| 411 | <Alert variant="danger" show={this.state.showFailAlert} onClose={this.disableAlert} dismissible> |
| 412 | <DivWhiteSpaceStyled> |
| 413 | {this.state.showMessage} |
| 414 | </DivWhiteSpaceStyled> |
| 415 | </Alert> |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 416 | <Modal.Footer> |
| 417 | <Button variant="secondary" onClick={this.handleClose}>Close</Button> |
| 418 | </Modal.Footer> |
| 419 | </ModalStyled> |
| 420 | ); |
| 421 | } |
| 422 | } |