blob: c15cd1d0e8ead5f16f6076670aede5617e729cd1 [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>
talig8e9c0652017-12-20 14:30:43 +020063 {errors.length && errors.map((error, i) => {return (<ErrorMessage key={i} error={error.message}/>);})}
AviZi280f8012017-06-09 02:39:56 +030064 </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>
talig8e9c0652017-12-20 14:30:43 +020074 {errors.validationData.length && errors.validationData.map((item, i) =>{ return (<ComponentError key={i} item={item}/>);})}
AviZi280f8012017-06-09 02:39:56 +030075 </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}) => {
AviZi280f8012017-06-09 02:39:56 +030093 return (
94 <div>
95 <div className='component-name-header'>{item.entityName}</div>
talig8e9c0652017-12-20 14:30:43 +020096 {item.errors.map((error, i) => {return(<ErrorMessage key={i} error={error}/>);})}
AviZi280f8012017-06-09 02:39:56 +030097 </div>
98 );
99};
100
101function* entries(obj) {
102 for (let key of Object.keys(obj)) {
103 yield {header: key, list: obj[key]};
104 }
105}
106
107const UploadErrorList = ({items}) => {
108 let generator = entries(items);
109
110 let errors = [];
AviZi280f8012017-06-09 02:39:56 +0300111 for (let item of generator) {errors.push(
talig8e9c0652017-12-20 14:30:43 +0200112 <div key={item.header}>
AviZi280f8012017-06-09 02:39:56 +0300113 <div className='component-name-header'>{item.header}</div>
SVISHNEV3779f902017-08-30 16:09:04 +0300114 {item.list.map((error, i) => <ErrorMessage key={i} warning={error.level === 'WARNING'} error={error.message}/> )}
AviZi280f8012017-06-09 02:39:56 +0300115 </div>
116 );}
avigaffa00e935f2017-09-10 08:58:51 +0300117
AviZi280f8012017-06-09 02:39:56 +0300118 return (
119 <div>
120 {errors}
121 </div>
122 );
123};
124
125class ErrorBlock extends React.Component {
126 state = {
127 collapsed: false
128 };
129
130 render() {
131 let {errorType, children} = this.props;
132 return (
133 <div className='error-block'>
134 <ErrorHeader collapsed={this.state.collapsed} onClick={()=>{this.setState({collapsed: !this.state.collapsed});}} errorType={errorType}/>
135 <Collapse in={this.state.collapsed}>
136 {children}
137 </Collapse>
138 </div>
139 );
140 }
141}
142
143const ErrorHeader = ({errorType, collapsed, onClick}) => {
144 return(
145 <div onClick={onClick} className='error-block-header'>
az2497644017c2017-08-10 17:49:40 +0300146 <SVGIcon iconClassName={collapsed ? '' : 'collapse-right' } name='chevronDown' label={errorType} labelPosition='right'/>
AviZi280f8012017-06-09 02:39:56 +0300147 </div>
148 );
149};
150
151const ErrorMessage = ({error, warning}) => {
152 return (
153 <ListGroupItem className='error-code-list-item'>
avigaffa00e935f2017-09-10 08:58:51 +0300154 <SVGIcon
155 name={warning ? 'exclamationTriangleLine' : 'error'}
156 color={warning ? 'warning' : 'negative'} />
157 <span className='icon-label'>{error}</span>
AviZi280f8012017-06-09 02:39:56 +0300158 </ListGroupItem>
159 );
160};
161
Michael Landoefa037d2017-02-19 12:57:33 +0200162export default SubmitErrorResponse;