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 | ee23356 | 2021-03-22 18:55:46 +0100 | [diff] [blame] | 46 | import PublishIcon from '@material-ui/icons/Publish'; |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 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 | ee23356 | 2021-03-22 18:55:46 +0100 | [diff] [blame] | 51 | import Select from '@material-ui/core/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 | ee23356 | 2021-03-22 18:55:46 +0100 | [diff] [blame] | 57 | import PolicyDeploymentEditor from './PolicyDeploymentEditor'; |
sebdet | b496fda | 2021-03-30 00:30:49 +0200 | [diff] [blame] | 58 | import PoliciesTreeViewer from './PoliciesTreeViewer'; |
sebdet | d1ed0a9 | 2021-04-21 16:28:33 +0200 | [diff] [blame] | 59 | import PolicyToscaFileSelector from './PolicyToscaFileSelector'; |
sebdet | c427e64 | 2021-02-17 17:53:17 +0100 | [diff] [blame] | 60 | |
| 61 | const DivWhiteSpaceStyled = styled.div` |
sebdet | ea2969f | 2021-02-25 13:58:36 +0100 | [diff] [blame] | 62 | white-space: pre; |
sebdet | c427e64 | 2021-02-17 17:53:17 +0100 | [diff] [blame] | 63 | ` |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 64 | |
| 65 | const ModalStyled = styled(Modal)` |
sebdet | ee23356 | 2021-03-22 18:55:46 +0100 | [diff] [blame] | 66 | @media (min-width: 800px) { |
sebdet | 3718a16 | 2021-02-12 17:18:47 +0100 | [diff] [blame] | 67 | .modal-xl { |
| 68 | max-width: 96%; |
| 69 | } |
| 70 | } |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 71 | background-color: transparent; |
| 72 | ` |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 73 | const DetailedRow = styled.div` |
| 74 | margin: 0 auto; |
| 75 | background-color: ${props => props.theme.policyEditorBackgroundColor}; |
| 76 | font-size: ${props => props.theme.policyEditorFontSize}; |
| 77 | width: 97%; |
| 78 | margin-left: auto; |
sebdet | 42fa9f4 | 2021-03-26 18:31:08 +0100 | [diff] [blame] | 79 | margin-right: auto; |
| 80 | margin-top: 20px; |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 81 | ` |
| 82 | |
sebdet | b496fda | 2021-03-30 00:30:49 +0200 | [diff] [blame] | 83 | const PoliciesTreeViewerDiv = styled.div` |
| 84 | width: 20%; |
| 85 | float: left; |
| 86 | left: 0; |
| 87 | overflow: auto; |
| 88 | ` |
| 89 | |
| 90 | const MaterialTableDiv = styled.div` |
| 91 | float: right; |
| 92 | width: 80%; |
| 93 | left: 20%; |
| 94 | ` |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 95 | |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 96 | const standardCellStyle = { backgroundColor: '#039be5', color: '#FFF', border: '1px solid black' }; |
sebdet | ee23356 | 2021-03-22 18:55:46 +0100 | [diff] [blame] | 97 | const headerStyle = { backgroundColor: '#ddd', border: '2px solid black' }; |
| 98 | const rowHeaderStyle = {backgroundColor:'#ddd', fontSize: '15pt', text: 'bold', border: '1px solid black'}; |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 99 | |
| 100 | export default class ViewAllPolicies extends React.Component { |
| 101 | state = { |
| 102 | show: true, |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 103 | policiesListData: [], |
sebdet | b496fda | 2021-03-30 00:30:49 +0200 | [diff] [blame] | 104 | policiesListDataFiltered: [], |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 105 | toscaModelsListData: [], |
sebdet | b496fda | 2021-03-30 00:30:49 +0200 | [diff] [blame] | 106 | toscaModelsListDataFiltered: [], |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 107 | jsonEditorForPolicy: new Map(), |
sebdet | c427e64 | 2021-02-17 17:53:17 +0100 | [diff] [blame] | 108 | showSuccessAlert: false, |
| 109 | showFailAlert: false, |
sebdet | d1ed0a9 | 2021-04-21 16:28:33 +0200 | [diff] [blame] | 110 | showFileSelector: false, |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 111 | policyColumnsDefinition: [ |
| 112 | { |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 113 | title: "Policy Name", field: "name", |
| 114 | cellStyle: standardCellStyle, |
| 115 | headerStyle: headerStyle |
| 116 | }, |
| 117 | { |
| 118 | title: "Policy Version", field: "version", |
| 119 | cellStyle: standardCellStyle, |
sebdet | ee23356 | 2021-03-22 18:55:46 +0100 | [diff] [blame] | 120 | headerStyle: headerStyle, |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 121 | }, |
| 122 | { |
| 123 | title: "Policy Type", field: "type", |
| 124 | cellStyle: standardCellStyle, |
| 125 | headerStyle: headerStyle |
| 126 | }, |
| 127 | { |
| 128 | title: "Policy Type Version", field: "type_version", |
| 129 | cellStyle: standardCellStyle, |
| 130 | headerStyle: headerStyle |
| 131 | }, |
| 132 | { |
sebdet | ee23356 | 2021-03-22 18:55:46 +0100 | [diff] [blame] | 133 | title: "Deployable in PDP Group", field: "supportedPdpGroupsString", |
| 134 | cellStyle: standardCellStyle, |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 135 | headerStyle: headerStyle |
| 136 | }, |
| 137 | { |
sebdet | ee23356 | 2021-03-22 18:55:46 +0100 | [diff] [blame] | 138 | title: "Deployed in PDP Group", field: "pdpGroupInfoString", |
| 139 | cellStyle: standardCellStyle, |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 140 | headerStyle: headerStyle |
| 141 | } |
| 142 | ], |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 143 | toscaColumnsDefinition: [ |
| 144 | { |
| 145 | title: "Policy Model Type", field: "policyModelType", |
| 146 | cellStyle: standardCellStyle, |
| 147 | headerStyle: headerStyle |
| 148 | }, |
| 149 | { |
| 150 | title: "Policy Acronym", field: "policyAcronym", |
| 151 | cellStyle: standardCellStyle, |
| 152 | headerStyle: headerStyle |
| 153 | }, |
| 154 | { |
| 155 | title: "Version", field: "version", |
| 156 | cellStyle: standardCellStyle, |
| 157 | headerStyle: headerStyle |
| 158 | }, |
| 159 | { |
| 160 | title: "Uploaded By", field: "updatedBy", |
| 161 | cellStyle: standardCellStyle, |
| 162 | headerStyle: headerStyle |
| 163 | }, |
| 164 | { |
| 165 | title: "Uploaded Date", field: "updatedDate", editable: 'never', |
| 166 | cellStyle: standardCellStyle, |
| 167 | headerStyle: headerStyle |
| 168 | } |
| 169 | ], |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 170 | tableIcons: { |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 171 | Add: forwardRef((props, ref) => <AddBox {...props} ref={ref} />), |
| 172 | Check: forwardRef((props, ref) => <Check {...props} ref={ref} />), |
| 173 | Clear: forwardRef((props, ref) => <Clear {...props} ref={ref} />), |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 174 | Delete: forwardRef((props, ref) => <DeleteRoundedIcon {...props} ref={ref} />), |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 175 | DetailPanel: forwardRef((props, ref) => <ChevronRight {...props} ref={ref} />), |
| 176 | Edit: forwardRef((props, ref) => <Edit {...props} ref={ref} />), |
| 177 | Export: forwardRef((props, ref) => <SaveAlt {...props} ref={ref} />), |
| 178 | Filter: forwardRef((props, ref) => <FilterList {...props} ref={ref} />), |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 179 | FirstPage: forwardRef((props, ref) => <FirstPage {...props} ref={ref} />), |
| 180 | LastPage: forwardRef((props, ref) => <LastPage {...props} ref={ref} />), |
| 181 | NextPage: forwardRef((props, ref) => <ChevronRight {...props} ref={ref} />), |
| 182 | PreviousPage: forwardRef((props, ref) => <ChevronLeft {...props} ref={ref} />), |
| 183 | ResetSearch: forwardRef((props, ref) => <Clear {...props} ref={ref} />), |
| 184 | Search: forwardRef((props, ref) => <Search {...props} ref={ref} />), |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 185 | SortArrow: forwardRef((props, ref) => <ArrowDownward {...props} ref={ref} />), |
| 186 | ThirdStateCheck: forwardRef((props, ref) => <Remove {...props} ref={ref} />), |
| 187 | ViewColumn: forwardRef((props, ref) => <ViewColumn {...props} ref={ref} />) |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 188 | } |
| 189 | }; |
| 190 | |
| 191 | constructor(props, context) { |
| 192 | super(props, context); |
| 193 | this.handleClose = this.handleClose.bind(this); |
sebdet | a0a3a03 | 2021-02-16 14:53:43 +0100 | [diff] [blame] | 194 | this.handleDeletePolicy = this.handleDeletePolicy.bind(this); |
sebdet | c427e64 | 2021-02-17 17:53:17 +0100 | [diff] [blame] | 195 | this.disableAlert = this.disableAlert.bind(this); |
sebdet | b8831e5 | 2021-03-12 19:30:22 +0100 | [diff] [blame] | 196 | this.getAllPolicies = this.getAllPolicies.bind(this); |
| 197 | this.getAllToscaModels = this.getAllToscaModels.bind(this); |
sebdet | ee23356 | 2021-03-22 18:55:46 +0100 | [diff] [blame] | 198 | this.generateAdditionalPolicyColumns = this.generateAdditionalPolicyColumns.bind(this); |
sebdet | b496fda | 2021-03-30 00:30:49 +0200 | [diff] [blame] | 199 | this.filterPolicies = this.filterPolicies.bind(this); |
| 200 | this.filterTosca = this.filterTosca.bind(this); |
sebdet | d1ed0a9 | 2021-04-21 16:28:33 +0200 | [diff] [blame] | 201 | this.showFileSelector = this.showFileSelector.bind(this); |
| 202 | this.disableFileSelector = this.disableFileSelector.bind(this); |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 203 | this.getAllPolicies(); |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 204 | this.getAllToscaModels(); |
| 205 | } |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 206 | |
sebdet | ee23356 | 2021-03-22 18:55:46 +0100 | [diff] [blame] | 207 | generateAdditionalPolicyColumns(policiesData) { |
| 208 | policiesData.forEach(policy => { |
| 209 | let supportedPdpGroupsString = ""; |
| 210 | if (typeof policy.supportedPdpGroups !== "undefined") { |
| 211 | for (const pdpGroup of policy["supportedPdpGroups"]) { |
| 212 | for (const pdpSubGroup of Object.values(pdpGroup)[0]) { |
| 213 | supportedPdpGroupsString += (Object.keys(pdpGroup)[0] + "/" + pdpSubGroup + "\r\n"); |
| 214 | } |
| 215 | } |
| 216 | policy["supportedPdpGroupsString"] = supportedPdpGroupsString; |
| 217 | } |
| 218 | |
| 219 | let infoPdpGroup = ""; |
| 220 | if (typeof policy.pdpGroupInfo !== "undefined") { |
| 221 | policy["pdpGroupInfo"].forEach(pdpGroupElem => { |
| 222 | let groupName = Object.keys(pdpGroupElem)[0]; |
| 223 | pdpGroupElem[groupName]["pdpSubgroups"].forEach(pdpSubGroupElem => { |
| 224 | infoPdpGroup += (groupName + "/" + pdpSubGroupElem["pdpType"] + " (" |
| 225 | + pdpGroupElem[groupName]["pdpGroupState"] + ")" + "\r\n"); |
| 226 | }); |
| 227 | policy["pdpGroupInfoString"] = infoPdpGroup; |
| 228 | }); |
| 229 | } |
| 230 | }); |
| 231 | } |
| 232 | |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 233 | getAllToscaModels() { |
| 234 | PolicyToscaService.getToscaPolicyModels().then(toscaModelsList => { |
sebdet | b496fda | 2021-03-30 00:30:49 +0200 | [diff] [blame] | 235 | this.setState({ toscaModelsListData: toscaModelsList, |
| 236 | toscaModelsListDataFiltered: toscaModelsList |
| 237 | }); |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 238 | }); |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 239 | } |
| 240 | |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 241 | getAllPolicies() { |
| 242 | PolicyService.getPoliciesList().then(allPolicies => { |
sebdet | ee23356 | 2021-03-22 18:55:46 +0100 | [diff] [blame] | 243 | this.generateAdditionalPolicyColumns(allPolicies["policies"]) |
sebdet | b496fda | 2021-03-30 00:30:49 +0200 | [diff] [blame] | 244 | this.setState({ policiesListData: allPolicies["policies"], |
| 245 | policiesListDataFiltered: allPolicies["policies"], |
| 246 | }) |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 247 | }); |
sebdet | ee23356 | 2021-03-22 18:55:46 +0100 | [diff] [blame] | 248 | |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | handleClose() { |
| 252 | this.setState({ show: false }); |
| 253 | this.props.history.push('/') |
| 254 | } |
| 255 | |
sebdet | a0a3a03 | 2021-02-16 14:53:43 +0100 | [diff] [blame] | 256 | handleDeletePolicy(event, rowData) { |
sebdet | ea2969f | 2021-02-25 13:58:36 +0100 | [diff] [blame] | 257 | PolicyService.deletePolicy(rowData["type"], rowData["type_version"], rowData["name"],rowData["version"]).then( |
| 258 | respPolicyDeletion => { |
sebdet | b8831e5 | 2021-03-12 19:30:22 +0100 | [diff] [blame] | 259 | if (typeof(respPolicyDeletion) === "undefined") { |
sebdet | ea2969f | 2021-02-25 13:58:36 +0100 | [diff] [blame] | 260 | //it indicates a failure |
| 261 | this.setState({ |
| 262 | showFailAlert: true, |
| 263 | showMessage: 'Policy Deletion Failure' |
| 264 | }); |
| 265 | } else { |
| 266 | this.setState({ |
| 267 | showSuccessAlert: true, |
| 268 | showMessage: 'Policy successfully Deleted' |
| 269 | }); |
sebdet | d1ed0a9 | 2021-04-21 16:28:33 +0200 | [diff] [blame] | 270 | this.getAllPolicies(); |
sebdet | ea2969f | 2021-02-25 13:58:36 +0100 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | ) |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 274 | } |
| 275 | |
sebdet | c427e64 | 2021-02-17 17:53:17 +0100 | [diff] [blame] | 276 | disableAlert() { |
| 277 | this.setState ({ showSuccessAlert: false, showFailAlert: false }); |
| 278 | } |
| 279 | |
sebdet | b496fda | 2021-03-30 00:30:49 +0200 | [diff] [blame] | 280 | filterPolicies(prefixForFiltering) { |
| 281 | this.setState({policiesListDataFiltered: this.state.policiesListData.filter(element => element.name.startsWith(prefixForFiltering))}); |
| 282 | } |
| 283 | |
| 284 | filterTosca(prefixForFiltering) { |
| 285 | this.setState({toscaModelsListDataFiltered: this.state.toscaModelsListData.filter(element => element.policyModelType.startsWith(prefixForFiltering))}); |
| 286 | } |
| 287 | |
sebdet | d1ed0a9 | 2021-04-21 16:28:33 +0200 | [diff] [blame] | 288 | showFileSelector() { |
| 289 | this.setState({showFileSelector:true}); |
| 290 | } |
| 291 | |
| 292 | disableFileSelector() { |
| 293 | this.setState({showFileSelector:false}); |
| 294 | } |
| 295 | |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 296 | renderPoliciesTab() { |
| 297 | return ( |
| 298 | <Tab eventKey="policies" title="Policies in Policy Framework"> |
| 299 | <Modal.Body> |
sebdet | b496fda | 2021-03-30 00:30:49 +0200 | [diff] [blame] | 300 | <div> |
| 301 | <PoliciesTreeViewerDiv> |
| 302 | <PoliciesTreeViewer policiesData={this.state.policiesListData} valueForTreeCreation="name" policiesFilterFunction={this.filterPolicies} /> |
| 303 | </PoliciesTreeViewerDiv> |
| 304 | <MaterialTableDiv> |
| 305 | <MaterialTable |
| 306 | title={"Policies"} |
| 307 | data={this.state.policiesListDataFiltered} |
| 308 | columns={this.state.policyColumnsDefinition} |
| 309 | icons={this.state.tableIcons} |
| 310 | onRowClick={(event, rowData, togglePanel) => togglePanel()} |
| 311 | options={{ |
| 312 | grouping: true, |
| 313 | exportButton: true, |
| 314 | headerStyle:rowHeaderStyle, |
| 315 | actionsColumnIndex: -1 |
| 316 | }} |
| 317 | detailPanel={[ |
| 318 | { |
| 319 | icon: ArrowForwardIosIcon, |
| 320 | tooltip: 'Show Configuration', |
| 321 | render: rowData => { |
| 322 | return ( |
| 323 | <DetailedRow> |
| 324 | <PolicyEditor policyModelType={rowData["type"]} policyModelTypeVersion={rowData["type_version"]} |
| 325 | policyName={rowData["name"]} policyVersion={rowData["version"]} policyProperties={rowData["properties"]} |
| 326 | policiesTableUpdateFunction={this.getAllPolicies} /> |
| 327 | </DetailedRow> |
| 328 | ) |
| 329 | }, |
| 330 | }, |
| 331 | { |
| 332 | icon: DehazeIcon, |
| 333 | openIcon: DehazeIcon, |
| 334 | tooltip: 'Show Raw Data', |
| 335 | render: rowData => { |
| 336 | return ( |
| 337 | <DetailedRow> |
| 338 | <pre>{JSON.stringify(rowData, null, 2)}</pre> |
| 339 | </DetailedRow> |
| 340 | ) |
| 341 | }, |
| 342 | }, |
| 343 | { |
| 344 | icon: PublishIcon, |
| 345 | openIcon: PublishIcon, |
| 346 | tooltip: 'PDP Group Deployment', |
| 347 | render: rowData => { |
| 348 | return ( |
| 349 | <DetailedRow> |
| 350 | <PolicyDeploymentEditor policyData={rowData} policiesTableUpdateFunction={this.getAllPolicies} /> |
| 351 | </DetailedRow> |
| 352 | ) |
| 353 | }, |
| 354 | } |
| 355 | ]} |
| 356 | actions={[ |
| 357 | { |
sebdet | d1ed0a9 | 2021-04-21 16:28:33 +0200 | [diff] [blame] | 358 | icon: DeleteRoundedIcon, |
sebdet | b496fda | 2021-03-30 00:30:49 +0200 | [diff] [blame] | 359 | tooltip: 'Delete Policy', |
| 360 | onClick: (event, rowData) => this.handleDeletePolicy(event, rowData) |
| 361 | } |
| 362 | ]} |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 363 | /> |
sebdet | b496fda | 2021-03-30 00:30:49 +0200 | [diff] [blame] | 364 | </MaterialTableDiv> |
| 365 | </div> |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 366 | </Modal.Body> |
| 367 | </Tab> |
| 368 | ); |
| 369 | } |
| 370 | |
| 371 | renderToscaTab() { |
| 372 | return ( |
| 373 | <Tab eventKey="tosca models" title="Tosca Models in Policy Framework"> |
| 374 | <Modal.Body> |
sebdet | b496fda | 2021-03-30 00:30:49 +0200 | [diff] [blame] | 375 | <div> |
| 376 | <PoliciesTreeViewerDiv> |
| 377 | <PoliciesTreeViewer policiesData={this.state.toscaModelsListData} valueForTreeCreation="policyModelType" policiesFilterFunction={this.filterTosca} /> |
| 378 | </PoliciesTreeViewerDiv> |
| 379 | <MaterialTableDiv> |
| 380 | <MaterialTable |
| 381 | title={"Tosca Models"} |
| 382 | data={this.state.toscaModelsListDataFiltered} |
| 383 | columns={this.state.toscaColumnsDefinition} |
| 384 | icons={this.state.tableIcons} |
| 385 | onRowClick={(event, rowData, togglePanel) => togglePanel()} |
| 386 | options={{ |
| 387 | grouping: true, |
| 388 | exportButton: true, |
| 389 | headerStyle:rowHeaderStyle, |
| 390 | actionsColumnIndex: -1 |
| 391 | }} |
sebdet | d1ed0a9 | 2021-04-21 16:28:33 +0200 | [diff] [blame] | 392 | actions={[ |
| 393 | { |
| 394 | icon: AddIcon, |
| 395 | tooltip: 'Add New Tosca Model', |
| 396 | isFreeAction: true, |
| 397 | onClick: () => this.showFileSelector() |
| 398 | } |
| 399 | ]} |
sebdet | b496fda | 2021-03-30 00:30:49 +0200 | [diff] [blame] | 400 | detailPanel={[ |
| 401 | { |
| 402 | icon: ArrowForwardIosIcon, |
| 403 | tooltip: 'Show Tosca', |
| 404 | render: rowData => { |
| 405 | return ( |
| 406 | <DetailedRow> |
| 407 | <ToscaViewer toscaData={rowData} /> |
| 408 | </DetailedRow> |
| 409 | ) |
| 410 | }, |
| 411 | }, |
| 412 | { |
| 413 | icon: DehazeIcon, |
| 414 | openIcon: DehazeIcon, |
| 415 | tooltip: 'Show Raw Data', |
| 416 | render: rowData => { |
| 417 | return ( |
| 418 | <DetailedRow> |
| 419 | <pre>{JSON.stringify(rowData, null, 2)}</pre> |
| 420 | </DetailedRow> |
| 421 | ) |
| 422 | }, |
| 423 | }, |
| 424 | { |
| 425 | icon: AddIcon, |
| 426 | openIcon: AddIcon, |
| 427 | tooltip: 'Create a policy from this model', |
| 428 | render: rowData => { |
| 429 | return ( |
| 430 | <DetailedRow> |
| 431 | <PolicyEditor policyModelType={rowData["policyModelType"]} policyModelTypeVersion={rowData["version"]} policyProperties={{}} policiesTableUpdateFunction={this.getAllPolicies} /> |
| 432 | </DetailedRow> |
| 433 | ) |
| 434 | }, |
| 435 | }, |
| 436 | ]} |
| 437 | /> |
| 438 | </MaterialTableDiv> |
| 439 | </div> |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 440 | </Modal.Body> |
| 441 | </Tab> |
| 442 | ); |
| 443 | } |
| 444 | |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 445 | render() { |
sebdet | d1ed0a9 | 2021-04-21 16:28:33 +0200 | [diff] [blame] | 446 | return ( |
| 447 | <React.Fragment> |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 448 | <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] | 449 | <Modal.Header closeButton> |
| 450 | </Modal.Header> |
sebdet | ea2969f | 2021-02-25 13:58:36 +0100 | [diff] [blame] | 451 | <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] | 452 | {this.renderPoliciesTab()} |
| 453 | {this.renderToscaTab()} |
sebdet | ea2969f | 2021-02-25 13:58:36 +0100 | [diff] [blame] | 454 | </Tabs> |
sebdet | c427e64 | 2021-02-17 17:53:17 +0100 | [diff] [blame] | 455 | <Alert variant="success" show={this.state.showSuccessAlert} onClose={this.disableAlert} dismissible> |
sebdet | ea2969f | 2021-02-25 13:58:36 +0100 | [diff] [blame] | 456 | <DivWhiteSpaceStyled> |
| 457 | {this.state.showMessage} |
| 458 | </DivWhiteSpaceStyled> |
| 459 | </Alert> |
| 460 | <Alert variant="danger" show={this.state.showFailAlert} onClose={this.disableAlert} dismissible> |
| 461 | <DivWhiteSpaceStyled> |
| 462 | {this.state.showMessage} |
| 463 | </DivWhiteSpaceStyled> |
| 464 | </Alert> |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 465 | <Modal.Footer> |
| 466 | <Button variant="secondary" onClick={this.handleClose}>Close</Button> |
| 467 | </Modal.Footer> |
sebdet | ee23356 | 2021-03-22 18:55:46 +0100 | [diff] [blame] | 468 | </ModalStyled> |
sebdet | d1ed0a9 | 2021-04-21 16:28:33 +0200 | [diff] [blame] | 469 | <PolicyToscaFileSelector show={this.state.showFileSelector} disableFunction={this.disableFileSelector} toscaTableUpdateFunction={this.getAllToscaModels}/> |
| 470 | </React.Fragment> |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 471 | ); |
| 472 | } |
| 473 | } |