blob: 793a42074af9c067a357e3f1da42147429f0c9e4 [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
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 Keidar7fdf7332018-03-20 14:45:40 +020016import React, { Component } from 'react';
Michael Landoefa037d2017-02-19 12:57:33 +020017import ListGroupItem from 'react-bootstrap/lib/ListGroupItem.js';
Michael Landoefa037d2017-02-19 12:57:33 +020018import i18n from 'nfvo-utils/i18n/i18n.js';
Arielka51eac02019-07-07 12:56:11 +030019import { SVGIcon } from 'onap-ui-react';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020020import { Collapse } from 'react-bootstrap';
Michael Landoefa037d2017-02-19 12:57:33 +020021/**
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 */
44class SubmitErrorResponse extends Component {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020045 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 Landoefa037d2017-02-19 12:57:33 +020066
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020067 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 Landoefa037d2017-02-19 12:57:33 +020081
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020082 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 Landoefa037d2017-02-19 12:57:33 +020094
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020095 renderUploadDataErrors(uploadDataErrors) {
96 return (
97 <ErrorBlock errorType={i18n('Upload Data Errors')}>
98 <div>
99 <UploadErrorList items={uploadDataErrors} />
100 </div>
101 </ErrorBlock>
102 );
103 }
Michael Landoefa037d2017-02-19 12:57:33 +0200104}
105
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200106const 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 );
AviZi280f8012017-06-09 02:39:56 +0300115};
116
117function* entries(obj) {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200118 for (let key of Object.keys(obj)) {
119 yield { header: key, list: obj[key] };
120 }
AviZi280f8012017-06-09 02:39:56 +0300121}
122
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200123const UploadErrorList = ({ items }) => {
124 let generator = entries(items);
AviZi280f8012017-06-09 02:39:56 +0300125
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200126 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 }
avigaffa00e935f2017-09-10 08:58:51 +0300141
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200142 return <div>{errors}</div>;
AviZi280f8012017-06-09 02:39:56 +0300143};
144
145class ErrorBlock extends React.Component {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200146 state = {
147 collapsed: false
148 };
AviZi280f8012017-06-09 02:39:56 +0300149
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200150 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 }
AviZi280f8012017-06-09 02:39:56 +0300165}
166
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200167const 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 );
AviZi280f8012017-06-09 02:39:56 +0300178};
179
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200180const 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 );
AviZi280f8012017-06-09 02:39:56 +0300190};
191
Michael Landoefa037d2017-02-19 12:57:33 +0200192export default SubmitErrorResponse;