AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 1 | /*! |
| 2 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 13 | * or implied. See the License for the specific language governing |
| 14 | * permissions and limitations under the License. |
| 15 | */ |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 16 | import React, { Component } from 'react'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 17 | import ListGroupItem from 'react-bootstrap/lib/ListGroupItem.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 18 | import i18n from 'nfvo-utils/i18n/i18n.js'; |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 19 | import SVGIcon from 'sdc-ui/lib/react/SVGIcon.js'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 20 | import { Collapse } from 'react-bootstrap'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 21 | /** |
| 22 | * parsing and showing the following Java Response object |
| 23 | * |
| 24 | * public class ValidationResponse { |
| 25 | private boolean valid = true; |
| 26 | private Collection<ErrorCode> vspErrors; |
| 27 | private Collection<ErrorCode> licensingDataErrors; |
| 28 | private Map<String, List<ErrorMessage>> uploadDataErrors; |
| 29 | private Map<String, List<ErrorMessage>> compilationErrors; |
| 30 | private QuestionnaireValidationResult questionnaireValidationResult; |
| 31 | } |
| 32 | |
| 33 | * public class ErrorCode { |
| 34 | private String id; |
| 35 | private String message; |
| 36 | private ErrorCategory category; |
| 37 | } |
| 38 | |
| 39 | * public class ErrorMessage { |
| 40 | private final ErrorLevel level; |
| 41 | private final String message; |
| 42 | } |
| 43 | */ |
| 44 | class SubmitErrorResponse extends Component { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 45 | render() { |
| 46 | let { |
| 47 | validationResponse: { |
| 48 | vspErrors, |
| 49 | licensingDataErrors, |
| 50 | questionnaireValidationResult, |
| 51 | uploadDataErrors |
| 52 | } |
| 53 | } = this.props; |
| 54 | return ( |
| 55 | <div className="submit-error-response-view"> |
| 56 | {vspErrors && this.renderVspErrors(vspErrors)} |
| 57 | {licensingDataErrors && |
| 58 | this.renderVspErrors(licensingDataErrors)} |
| 59 | {questionnaireValidationResult && |
| 60 | this.renderComponentsErrors(questionnaireValidationResult)} |
| 61 | {uploadDataErrors && |
| 62 | this.renderUploadDataErrors(uploadDataErrors)} |
| 63 | </div> |
| 64 | ); |
| 65 | } |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 66 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 67 | renderVspErrors(errors) { |
| 68 | return ( |
| 69 | <ErrorBlock errorType={i18n('VSP Errors')}> |
| 70 | <div> |
| 71 | {errors.length && |
| 72 | errors.map((error, i) => { |
| 73 | return ( |
| 74 | <ErrorMessage key={i} error={error.message} /> |
| 75 | ); |
| 76 | })} |
| 77 | </div> |
| 78 | </ErrorBlock> |
| 79 | ); |
| 80 | } |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 81 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 82 | renderComponentsErrors(errors) { |
| 83 | return ( |
| 84 | <ErrorBlock errorType={i18n('Components Errors')}> |
| 85 | <div> |
| 86 | {errors.validationData.length && |
| 87 | errors.validationData.map((item, i) => { |
| 88 | return <ComponentError key={i} item={item} />; |
| 89 | })} |
| 90 | </div> |
| 91 | </ErrorBlock> |
| 92 | ); |
| 93 | } |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 94 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 95 | renderUploadDataErrors(uploadDataErrors) { |
| 96 | return ( |
| 97 | <ErrorBlock errorType={i18n('Upload Data Errors')}> |
| 98 | <div> |
| 99 | <UploadErrorList items={uploadDataErrors} /> |
| 100 | </div> |
| 101 | </ErrorBlock> |
| 102 | ); |
| 103 | } |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 104 | } |
| 105 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 106 | const ComponentError = ({ item }) => { |
| 107 | return ( |
| 108 | <div> |
| 109 | <div className="component-name-header">{item.entityName}</div> |
| 110 | {item.errors.map((error, i) => { |
| 111 | return <ErrorMessage key={i} error={error} />; |
| 112 | })} |
| 113 | </div> |
| 114 | ); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | function* entries(obj) { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 118 | for (let key of Object.keys(obj)) { |
| 119 | yield { header: key, list: obj[key] }; |
| 120 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 121 | } |
| 122 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 123 | const UploadErrorList = ({ items }) => { |
| 124 | let generator = entries(items); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 125 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 126 | let errors = []; |
| 127 | for (let item of generator) { |
| 128 | errors.push( |
| 129 | <div key={item.header}> |
| 130 | <div className="component-name-header">{item.header}</div> |
| 131 | {item.list.map((error, i) => ( |
| 132 | <ErrorMessage |
| 133 | key={i} |
| 134 | warning={error.level === 'WARNING'} |
| 135 | error={error.message} |
| 136 | /> |
| 137 | ))} |
| 138 | </div> |
| 139 | ); |
| 140 | } |
avigaffa | 00e935f | 2017-09-10 08:58:51 +0300 | [diff] [blame] | 141 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 142 | return <div>{errors}</div>; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | class ErrorBlock extends React.Component { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 146 | state = { |
| 147 | collapsed: false |
| 148 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 149 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 150 | render() { |
| 151 | let { errorType, children } = this.props; |
| 152 | return ( |
| 153 | <div className="error-block"> |
| 154 | <ErrorHeader |
| 155 | collapsed={this.state.collapsed} |
| 156 | onClick={() => { |
| 157 | this.setState({ collapsed: !this.state.collapsed }); |
| 158 | }} |
| 159 | errorType={errorType} |
| 160 | /> |
| 161 | <Collapse in={this.state.collapsed}>{children}</Collapse> |
| 162 | </div> |
| 163 | ); |
| 164 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 165 | } |
| 166 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 167 | const ErrorHeader = ({ errorType, collapsed, onClick }) => { |
| 168 | return ( |
| 169 | <div onClick={onClick} className="error-block-header"> |
| 170 | <SVGIcon |
| 171 | iconClassName={collapsed ? '' : 'collapse-right'} |
| 172 | name="chevronDown" |
| 173 | label={errorType} |
| 174 | labelPosition="right" |
| 175 | /> |
| 176 | </div> |
| 177 | ); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 178 | }; |
| 179 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 180 | const ErrorMessage = ({ error, warning }) => { |
| 181 | return ( |
| 182 | <ListGroupItem className="error-code-list-item"> |
| 183 | <SVGIcon |
| 184 | name={warning ? 'exclamationTriangleLine' : 'error'} |
| 185 | color={warning ? 'warning' : 'negative'} |
| 186 | /> |
| 187 | <span className="icon-label">{error}</span> |
| 188 | </ListGroupItem> |
| 189 | ); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 190 | }; |
| 191 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 192 | export default SubmitErrorResponse; |