blob: 8d45d86a9deb9abeab8b55e83a41f4f2549f718b [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 */
Michael Landoefa037d2017-02-19 12:57:33 +020016import React, {Component} from 'react';
17import ListGroupItem from 'react-bootstrap/lib/ListGroupItem.js';
Michael Landoefa037d2017-02-19 12:57:33 +020018import i18n from 'nfvo-utils/i18n/i18n.js';
Avi Zivb8e2faf2017-07-18 19:45:38 +030019import SVGIcon from 'sdc-ui/lib/react/SVGIcon.js';
AviZi280f8012017-06-09 02:39:56 +030020import {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 {
45
46
47 render() {
AviZi280f8012017-06-09 02:39:56 +030048 let {validationResponse : {vspErrors, licensingDataErrors, questionnaireValidationResult, uploadDataErrors}} = this.props;
Michael Landoefa037d2017-02-19 12:57:33 +020049 return (
50 <div className='submit-error-response-view'>
AviZi280f8012017-06-09 02:39:56 +030051 {vspErrors && this.renderVspErrors(vspErrors)}
52 {licensingDataErrors && this.renderVspErrors(licensingDataErrors)}
53 {questionnaireValidationResult && this.renderComponentsErrors(questionnaireValidationResult)}
54 {uploadDataErrors && this.renderUploadDataErrors(uploadDataErrors)}
Michael Landoefa037d2017-02-19 12:57:33 +020055 </div>
56 );
57 }
58
AviZi280f8012017-06-09 02:39:56 +030059 renderVspErrors(errors) {
Michael Landoefa037d2017-02-19 12:57:33 +020060 return (
AviZi280f8012017-06-09 02:39:56 +030061 <ErrorBlock errorType={i18n('VSP Errors')}>
62 <div>
63 {errors.length && errors.map(error=>{return (<ErrorMessage error={error.message}/>);})}
64 </div>
65 </ErrorBlock>
Michael Landoefa037d2017-02-19 12:57:33 +020066 );
67 }
68
AviZi280f8012017-06-09 02:39:56 +030069
70 renderComponentsErrors(errors) {
Michael Landoefa037d2017-02-19 12:57:33 +020071 return (
AviZi280f8012017-06-09 02:39:56 +030072 <ErrorBlock errorType={i18n('Components Errors')}>
73 <div>
74 {errors.validationData.length && errors.validationData.map(item =>{ return (<ComponentError item={item}/>);})}
75 </div>
76 </ErrorBlock>
Michael Landoefa037d2017-02-19 12:57:33 +020077 );
78 }
79
80 renderUploadDataErrors(uploadDataErrors) {
81 return (
AviZi280f8012017-06-09 02:39:56 +030082 <ErrorBlock errorType={i18n('Upload Data Errors')}>
83 <div>
84 <UploadErrorList items={uploadDataErrors}/>
85 </div>
86 </ErrorBlock>
Michael Landoefa037d2017-02-19 12:57:33 +020087 );
88 }
Michael Landoefa037d2017-02-19 12:57:33 +020089}
90
AviZi280f8012017-06-09 02:39:56 +030091
92const ComponentError = ({item}) => {
93 let i = 0;
94 return (
95 <div>
96 <div className='component-name-header'>{item.entityName}</div>
97 {item.errors.map(error => {return(<ErrorMessage key={i++} error={error}/>);})}
98 </div>
99 );
100};
101
102function* entries(obj) {
103 for (let key of Object.keys(obj)) {
104 yield {header: key, list: obj[key]};
105 }
106}
107
108const UploadErrorList = ({items}) => {
109 let generator = entries(items);
110
111 let errors = [];
AviZi280f8012017-06-09 02:39:56 +0300112 for (let item of generator) {errors.push(
113 <div>
114 <div className='component-name-header'>{item.header}</div>
SVISHNEV3779f902017-08-30 16:09:04 +0300115 {item.list.map((error, i) => <ErrorMessage key={i} warning={error.level === 'WARNING'} error={error.message}/> )}
AviZi280f8012017-06-09 02:39:56 +0300116 </div>
117 );}
SVISHNEV3779f902017-08-30 16:09:04 +0300118
AviZi280f8012017-06-09 02:39:56 +0300119 return (
120 <div>
121 {errors}
122 </div>
123 );
124};
125
126class ErrorBlock extends React.Component {
127 state = {
128 collapsed: false
129 };
130
131 render() {
132 let {errorType, children} = this.props;
133 return (
134 <div className='error-block'>
135 <ErrorHeader collapsed={this.state.collapsed} onClick={()=>{this.setState({collapsed: !this.state.collapsed});}} errorType={errorType}/>
136 <Collapse in={this.state.collapsed}>
137 {children}
138 </Collapse>
139 </div>
140 );
141 }
142}
143
144const ErrorHeader = ({errorType, collapsed, onClick}) => {
145 return(
146 <div onClick={onClick} className='error-block-header'>
az2497644017c2017-08-10 17:49:40 +0300147 <SVGIcon iconClassName={collapsed ? '' : 'collapse-right' } name='chevronDown' label={errorType} labelPosition='right'/>
AviZi280f8012017-06-09 02:39:56 +0300148 </div>
149 );
150};
151
152const ErrorMessage = ({error, warning}) => {
153 return (
154 <ListGroupItem className='error-code-list-item'>
SVISHNEV3779f902017-08-30 16:09:04 +0300155 <SVGIcon
156 name={warning ? 'exclamationTriangleLine' : 'error'}
157 color={warning ? 'warning' : 'negative'} />
158 <span className='icon-label'>{error}</span>
AviZi280f8012017-06-09 02:39:56 +0300159 </ListGroupItem>
160 );
161};
162
Michael Landoefa037d2017-02-19 12:57:33 +0200163export default SubmitErrorResponse;