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 FormControlLabel from '@material-ui/core/FormControlLabel'; |
| 48 | import Switch from '@material-ui/core/Switch'; |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 49 | import MaterialTable from "material-table"; |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 50 | import PolicyService from '../../../api/PolicyService'; |
sebdet | 3718a16 | 2021-02-12 17:18:47 +0100 | [diff] [blame] | 51 | import PolicyToscaService from '../../../api/PolicyToscaService'; |
sebdet | ee23356 | 2021-03-22 18:55:46 +0100 | [diff] [blame] | 52 | import Select from '@material-ui/core/Select'; |
sebdet | c427e64 | 2021-02-17 17:53:17 +0100 | [diff] [blame] | 53 | import Alert from 'react-bootstrap/Alert'; |
sebdet | ea2969f | 2021-02-25 13:58:36 +0100 | [diff] [blame] | 54 | import Tabs from 'react-bootstrap/Tabs'; |
| 55 | import Tab from 'react-bootstrap/Tab'; |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 56 | import PolicyEditor from './PolicyEditor'; |
| 57 | import ToscaViewer from './ToscaViewer'; |
sebdet | ee23356 | 2021-03-22 18:55:46 +0100 | [diff] [blame] | 58 | import PolicyDeploymentEditor from './PolicyDeploymentEditor'; |
sebdet | c427e64 | 2021-02-17 17:53:17 +0100 | [diff] [blame] | 59 | |
| 60 | const DivWhiteSpaceStyled = styled.div` |
sebdet | ea2969f | 2021-02-25 13:58:36 +0100 | [diff] [blame] | 61 | white-space: pre; |
sebdet | c427e64 | 2021-02-17 17:53:17 +0100 | [diff] [blame] | 62 | ` |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 63 | |
| 64 | const ModalStyled = styled(Modal)` |
sebdet | ee23356 | 2021-03-22 18:55:46 +0100 | [diff] [blame] | 65 | @media (min-width: 800px) { |
sebdet | 3718a16 | 2021-02-12 17:18:47 +0100 | [diff] [blame] | 66 | .modal-xl { |
| 67 | max-width: 96%; |
| 68 | } |
| 69 | } |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 70 | background-color: transparent; |
| 71 | ` |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 72 | const DetailedRow = styled.div` |
| 73 | margin: 0 auto; |
| 74 | background-color: ${props => props.theme.policyEditorBackgroundColor}; |
| 75 | font-size: ${props => props.theme.policyEditorFontSize}; |
| 76 | width: 97%; |
| 77 | margin-left: auto; |
| 78 | margin-right: 0; |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 79 | ` |
| 80 | |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 81 | |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 82 | const standardCellStyle = { backgroundColor: '#039be5', color: '#FFF', border: '1px solid black' }; |
sebdet | ee23356 | 2021-03-22 18:55:46 +0100 | [diff] [blame] | 83 | const headerStyle = { backgroundColor: '#ddd', border: '2px solid black' }; |
| 84 | const rowHeaderStyle = {backgroundColor:'#ddd', fontSize: '15pt', text: 'bold', border: '1px solid black'}; |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 85 | |
| 86 | export default class ViewAllPolicies extends React.Component { |
| 87 | state = { |
| 88 | show: true, |
sebdet | ee23356 | 2021-03-22 18:55:46 +0100 | [diff] [blame] | 89 | showPolicyDeploymentDialog: false, |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 90 | content: 'Please select a policy to display it', |
sebdet | c427e64 | 2021-02-17 17:53:17 +0100 | [diff] [blame] | 91 | selectedRowId: -1, |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 92 | policiesListData: [], |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 93 | toscaModelsListData: [], |
| 94 | jsonEditorForPolicy: new Map(), |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 95 | prefixGrouping: false, |
sebdet | c427e64 | 2021-02-17 17:53:17 +0100 | [diff] [blame] | 96 | showSuccessAlert: false, |
| 97 | showFailAlert: false, |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 98 | policyColumnsDefinition: [ |
| 99 | { |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 100 | title: "Policy Name", field: "name", |
| 101 | cellStyle: standardCellStyle, |
| 102 | headerStyle: headerStyle |
| 103 | }, |
| 104 | { |
| 105 | title: "Policy Version", field: "version", |
| 106 | cellStyle: standardCellStyle, |
sebdet | ee23356 | 2021-03-22 18:55:46 +0100 | [diff] [blame] | 107 | headerStyle: headerStyle, |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 108 | }, |
| 109 | { |
| 110 | title: "Policy Type", field: "type", |
| 111 | cellStyle: standardCellStyle, |
| 112 | headerStyle: headerStyle |
| 113 | }, |
| 114 | { |
| 115 | title: "Policy Type Version", field: "type_version", |
| 116 | cellStyle: standardCellStyle, |
| 117 | headerStyle: headerStyle |
| 118 | }, |
| 119 | { |
sebdet | ee23356 | 2021-03-22 18:55:46 +0100 | [diff] [blame] | 120 | title: "Deployable in PDP Group", field: "supportedPdpGroupsString", |
| 121 | cellStyle: standardCellStyle, |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 122 | headerStyle: headerStyle |
| 123 | }, |
| 124 | { |
sebdet | ee23356 | 2021-03-22 18:55:46 +0100 | [diff] [blame] | 125 | title: "Deployed in PDP Group", field: "pdpGroupInfoString", |
| 126 | cellStyle: standardCellStyle, |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 127 | headerStyle: headerStyle |
| 128 | } |
| 129 | ], |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 130 | toscaColumnsDefinition: [ |
| 131 | { |
| 132 | title: "Policy Model Type", field: "policyModelType", |
| 133 | cellStyle: standardCellStyle, |
| 134 | headerStyle: headerStyle |
| 135 | }, |
| 136 | { |
| 137 | title: "Policy Acronym", field: "policyAcronym", |
| 138 | cellStyle: standardCellStyle, |
| 139 | headerStyle: headerStyle |
| 140 | }, |
| 141 | { |
| 142 | title: "Version", field: "version", |
| 143 | cellStyle: standardCellStyle, |
| 144 | headerStyle: headerStyle |
| 145 | }, |
| 146 | { |
| 147 | title: "Uploaded By", field: "updatedBy", |
| 148 | cellStyle: standardCellStyle, |
| 149 | headerStyle: headerStyle |
| 150 | }, |
| 151 | { |
| 152 | title: "Uploaded Date", field: "updatedDate", editable: 'never', |
| 153 | cellStyle: standardCellStyle, |
| 154 | headerStyle: headerStyle |
| 155 | } |
| 156 | ], |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 157 | tableIcons: { |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 158 | Add: forwardRef((props, ref) => <AddBox {...props} ref={ref} />), |
| 159 | Check: forwardRef((props, ref) => <Check {...props} ref={ref} />), |
| 160 | Clear: forwardRef((props, ref) => <Clear {...props} ref={ref} />), |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 161 | Delete: forwardRef((props, ref) => <DeleteRoundedIcon {...props} ref={ref} />), |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 162 | DetailPanel: forwardRef((props, ref) => <ChevronRight {...props} ref={ref} />), |
| 163 | Edit: forwardRef((props, ref) => <Edit {...props} ref={ref} />), |
| 164 | Export: forwardRef((props, ref) => <SaveAlt {...props} ref={ref} />), |
| 165 | Filter: forwardRef((props, ref) => <FilterList {...props} ref={ref} />), |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 166 | FirstPage: forwardRef((props, ref) => <FirstPage {...props} ref={ref} />), |
| 167 | LastPage: forwardRef((props, ref) => <LastPage {...props} ref={ref} />), |
| 168 | NextPage: forwardRef((props, ref) => <ChevronRight {...props} ref={ref} />), |
| 169 | PreviousPage: forwardRef((props, ref) => <ChevronLeft {...props} ref={ref} />), |
| 170 | ResetSearch: forwardRef((props, ref) => <Clear {...props} ref={ref} />), |
| 171 | Search: forwardRef((props, ref) => <Search {...props} ref={ref} />), |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 172 | SortArrow: forwardRef((props, ref) => <ArrowDownward {...props} ref={ref} />), |
| 173 | ThirdStateCheck: forwardRef((props, ref) => <Remove {...props} ref={ref} />), |
| 174 | ViewColumn: forwardRef((props, ref) => <ViewColumn {...props} ref={ref} />) |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 175 | } |
| 176 | }; |
| 177 | |
| 178 | constructor(props, context) { |
| 179 | super(props, context); |
| 180 | this.handleClose = this.handleClose.bind(this); |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 181 | this.handlePrefixGrouping = this.handlePrefixGrouping.bind(this); |
sebdet | a0a3a03 | 2021-02-16 14:53:43 +0100 | [diff] [blame] | 182 | this.handleDeletePolicy = this.handleDeletePolicy.bind(this); |
sebdet | c427e64 | 2021-02-17 17:53:17 +0100 | [diff] [blame] | 183 | this.disableAlert = this.disableAlert.bind(this); |
sebdet | b8831e5 | 2021-03-12 19:30:22 +0100 | [diff] [blame] | 184 | this.getAllPolicies = this.getAllPolicies.bind(this); |
| 185 | this.getAllToscaModels = this.getAllToscaModels.bind(this); |
sebdet | ee23356 | 2021-03-22 18:55:46 +0100 | [diff] [blame] | 186 | this.generateAdditionalPolicyColumns = this.generateAdditionalPolicyColumns.bind(this); |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 187 | this.getAllPolicies(); |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 188 | this.getAllToscaModels(); |
| 189 | } |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 190 | |
sebdet | ee23356 | 2021-03-22 18:55:46 +0100 | [diff] [blame] | 191 | generateAdditionalPolicyColumns(policiesData) { |
| 192 | policiesData.forEach(policy => { |
| 193 | let supportedPdpGroupsString = ""; |
| 194 | if (typeof policy.supportedPdpGroups !== "undefined") { |
| 195 | for (const pdpGroup of policy["supportedPdpGroups"]) { |
| 196 | for (const pdpSubGroup of Object.values(pdpGroup)[0]) { |
| 197 | supportedPdpGroupsString += (Object.keys(pdpGroup)[0] + "/" + pdpSubGroup + "\r\n"); |
| 198 | } |
| 199 | } |
| 200 | policy["supportedPdpGroupsString"] = supportedPdpGroupsString; |
| 201 | } |
| 202 | |
| 203 | let infoPdpGroup = ""; |
| 204 | if (typeof policy.pdpGroupInfo !== "undefined") { |
| 205 | policy["pdpGroupInfo"].forEach(pdpGroupElem => { |
| 206 | let groupName = Object.keys(pdpGroupElem)[0]; |
| 207 | pdpGroupElem[groupName]["pdpSubgroups"].forEach(pdpSubGroupElem => { |
| 208 | infoPdpGroup += (groupName + "/" + pdpSubGroupElem["pdpType"] + " (" |
| 209 | + pdpGroupElem[groupName]["pdpGroupState"] + ")" + "\r\n"); |
| 210 | }); |
| 211 | policy["pdpGroupInfoString"] = infoPdpGroup; |
| 212 | }); |
| 213 | } |
| 214 | }); |
| 215 | } |
| 216 | |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 217 | getAllToscaModels() { |
| 218 | PolicyToscaService.getToscaPolicyModels().then(toscaModelsList => { |
| 219 | this.setState({ toscaModelsListData: toscaModelsList }); |
| 220 | }); |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 221 | } |
| 222 | |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 223 | getAllPolicies() { |
| 224 | PolicyService.getPoliciesList().then(allPolicies => { |
sebdet | ee23356 | 2021-03-22 18:55:46 +0100 | [diff] [blame] | 225 | this.generateAdditionalPolicyColumns(allPolicies["policies"]) |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 226 | this.setState({ policiesListData: allPolicies["policies"] }) |
| 227 | }); |
sebdet | ee23356 | 2021-03-22 18:55:46 +0100 | [diff] [blame] | 228 | |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | handleClose() { |
| 232 | this.setState({ show: false }); |
| 233 | this.props.history.push('/') |
| 234 | } |
| 235 | |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 236 | handlePrefixGrouping(event) { |
| 237 | this.setState({prefixGrouping: event.target.checked}); |
sebdet | a0a3a03 | 2021-02-16 14:53:43 +0100 | [diff] [blame] | 238 | } |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 239 | |
sebdet | a0a3a03 | 2021-02-16 14:53:43 +0100 | [diff] [blame] | 240 | handleDeletePolicy(event, rowData) { |
sebdet | ea2969f | 2021-02-25 13:58:36 +0100 | [diff] [blame] | 241 | PolicyService.deletePolicy(rowData["type"], rowData["type_version"], rowData["name"],rowData["version"]).then( |
| 242 | respPolicyDeletion => { |
sebdet | b8831e5 | 2021-03-12 19:30:22 +0100 | [diff] [blame] | 243 | if (typeof(respPolicyDeletion) === "undefined") { |
sebdet | ea2969f | 2021-02-25 13:58:36 +0100 | [diff] [blame] | 244 | //it indicates a failure |
| 245 | this.setState({ |
| 246 | showFailAlert: true, |
| 247 | showMessage: 'Policy Deletion Failure' |
| 248 | }); |
| 249 | } else { |
| 250 | this.setState({ |
| 251 | showSuccessAlert: true, |
| 252 | showMessage: 'Policy successfully Deleted' |
| 253 | }); |
| 254 | } |
sebdet | b8831e5 | 2021-03-12 19:30:22 +0100 | [diff] [blame] | 255 | this.getAllPolicies(); |
sebdet | ea2969f | 2021-02-25 13:58:36 +0100 | [diff] [blame] | 256 | } |
| 257 | ) |
sebdet | 3728547 | 2021-02-15 18:09:38 +0100 | [diff] [blame] | 258 | } |
| 259 | |
sebdet | c427e64 | 2021-02-17 17:53:17 +0100 | [diff] [blame] | 260 | disableAlert() { |
| 261 | this.setState ({ showSuccessAlert: false, showFailAlert: false }); |
| 262 | } |
| 263 | |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 264 | renderPoliciesTab() { |
| 265 | return ( |
| 266 | <Tab eventKey="policies" title="Policies in Policy Framework"> |
| 267 | <Modal.Body> |
| 268 | <FormControlLabel |
| 269 | control={<Switch checked={this.state.prefixGrouping} onChange={this.handlePrefixGrouping} />} |
| 270 | label="Group by prefix" |
| 271 | /> |
| 272 | <MaterialTable |
| 273 | title={"Policies"} |
| 274 | data={this.state.policiesListData} |
| 275 | columns={this.state.policyColumnsDefinition} |
| 276 | icons={this.state.tableIcons} |
| 277 | onRowClick={(event, rowData, togglePanel) => togglePanel()} |
| 278 | options={{ |
| 279 | grouping: true, |
| 280 | exportButton: true, |
| 281 | headerStyle:rowHeaderStyle, |
| 282 | rowStyle: rowData => ({ |
| 283 | backgroundColor: (this.state.selectedRowId !== -1 && this.state.selectedRowId === rowData.tableData.id) ? '#EEE' : '#FFF' |
| 284 | }), |
| 285 | actionsColumnIndex: -1 |
| 286 | }} |
| 287 | detailPanel={[ |
| 288 | { |
sebdet | b8831e5 | 2021-03-12 19:30:22 +0100 | [diff] [blame] | 289 | icon: ArrowForwardIosIcon, |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 290 | tooltip: 'Show Configuration', |
| 291 | render: rowData => { |
| 292 | return ( |
| 293 | <DetailedRow> |
sebdet | b8831e5 | 2021-03-12 19:30:22 +0100 | [diff] [blame] | 294 | <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] | 295 | </DetailedRow> |
| 296 | ) |
| 297 | }, |
| 298 | }, |
| 299 | { |
sebdet | b8831e5 | 2021-03-12 19:30:22 +0100 | [diff] [blame] | 300 | icon: DehazeIcon, |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 301 | tooltip: 'Show Raw Data', |
| 302 | render: rowData => { |
| 303 | return ( |
| 304 | <DetailedRow> |
| 305 | <pre>{JSON.stringify(rowData, null, 2)}</pre> |
| 306 | </DetailedRow> |
| 307 | ) |
| 308 | }, |
| 309 | }, |
sebdet | ee23356 | 2021-03-22 18:55:46 +0100 | [diff] [blame] | 310 | { |
| 311 | icon: PublishIcon, |
| 312 | tooltip: 'PDP Group Deployment', |
| 313 | render: rowData => { |
| 314 | return ( |
| 315 | <PolicyDeploymentEditor policyData={rowData}/> |
| 316 | ) |
| 317 | }, |
| 318 | } |
sebdet | 1e2760e | 2021-02-26 19:14:03 +0100 | [diff] [blame] | 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> |
sebdet | ee23356 | 2021-03-22 18:55:46 +0100 | [diff] [blame] | 419 | </ModalStyled> |
sebdet | eb8e3f1 | 2021-01-24 18:12:36 +0100 | [diff] [blame] | 420 | ); |
| 421 | } |
| 422 | } |