2 * Copyright (c) 2019 Vodafone Group
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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 or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 import React, { Component } from 'react';
17 import PropTypes from 'prop-types';
18 import UUID from 'uuid-js';
19 import i18n from 'nfvo-utils/i18n/i18n.js';
20 import { Button } from 'onap-ui-react';
21 import GridSection from 'nfvo-components/grid/GridSection.jsx';
22 import GridItem from 'nfvo-components/grid/GridItem.jsx';
23 import Input from 'nfvo-components/input/validation/Input.jsx';
24 import Form from 'nfvo-components/input/validation/Form.jsx';
26 class VspInputs extends React.Component {
32 shouldComponentUpdate() {
36 changeInputs(e, check, parameterName) {
37 let { testsRequest, generalInfo, setTestsRequest } = this.props;
38 if (e instanceof File) {
39 var timestamp = new Date().getTime();
41 e.name.match(/[^\\\/]\.([^.\\\/]+)$/) || [null]
43 var fileName = fileExtension
44 ? timestamp + '.' + fileExtension
46 testsRequest[check].parameters[parameterName] =
49 testsRequest[check].files = testsRequest[check].files
50 ? testsRequest[check].files
52 testsRequest[check].files.push({ file: e, name: fileName });
54 testsRequest[check].parameters[parameterName] = e;
57 generalInfo[check][parameterName] = { isValid: true, errorText: '' };
58 setTestsRequest(testsRequest, generalInfo);
61 renderInputs(check, indexKey) {
62 let { vspTestsMap, testsRequest, generalInfo } = this.props;
64 <div key={indexKey} className="div-clear-both">
66 title={i18n('{title} Inputs :', {
67 title: vspTestsMap[check].title.split(/\r?\n/)[0]
69 {vspTestsMap[check].parameters.map((parameter, index) => {
70 parameter.metadata = parameter.metadata
74 !this.props.filterField(parameter) ||
75 parameter.metadata.hidden
80 parameter.type === 'text' ||
81 parameter.type === 'string' ||
82 parameter.type === 'json'
85 <GridItem key={index}>
93 isRequired={!parameter.isOptional}
94 label={parameter.description}
96 generalInfo[check][parameter.name]
100 generalInfo[check][parameter.name]
104 parameter.metadata.choices
109 testsRequest[check].parameters[
115 e.target ? e.target.value : e,
121 parameter.metadata.disabled || false
123 {parameter.metadata.choices && (
124 <option key="placeholder" value="">
128 {parameter.metadata.choices &&
129 parameter.metadata.choices.map(
132 key={selectOption.key}
143 } else if (parameter.type === 'binary') {
145 <GridItem key={index}>
147 label={parameter.description}
149 isRequired={!parameter.isOptional}
151 generalInfo[check][parameter.name]
155 generalInfo[check][parameter.name]
160 e.target ? e.target.value : e,
183 {complianceChecked.map((complianceCheck, index) => {
184 if (vspTestsMap[complianceCheck].parameters.length === 0) {
187 return this.renderInputs(complianceCheck, index);
190 {certificationChecked.map((certificateCheck, index) => {
191 if (vspTestsMap[certificateCheck].parameters.length === 0) {
194 return this.renderInputs(certificateCheck, index);
202 class VspValidationInputs extends Component {
204 softwareProductValidation: PropTypes.object
212 shouldComponentUpdate() {
215 filterField(parameter) {
217 parameter.name === 'host-username' ||
218 parameter.name === 'vsp' ||
219 parameter.name === 'vsp-zip' ||
220 parameter.name === 'host-password' ||
221 parameter.name === 'host-url'
229 let areInputsValid = true;
230 let { softwareProductValidation, setGeneralInfo } = this.props;
231 let generalInfo = softwareProductValidation.generalInfo;
232 Object.keys(softwareProductValidation.testsRequest).forEach(
234 let requestParameters =
235 softwareProductValidation.testsRequest[testCaseName]
237 let validationParameters =
238 softwareProductValidation.vspTestsMap[testCaseName]
240 Object.keys(requestParameters).forEach(parameterName => {
241 let parameter = validationParameters.find(
242 o => o.name === parameterName
244 let isParameterValid = true;
246 if (!this.filterField(parameter)) {
247 // Not required any action
250 (parameter.type === 'text' ||
251 parameter.type === 'string') &&
252 parameter.metadata.choices
255 !parameter.isOptional &&
256 !requestParameters[parameterName]
258 isParameterValid = false;
259 errorText = i18n('Field is required');
262 parameter.type === 'text' ||
263 parameter.type === 'string' ||
264 parameter.type === 'json' ||
265 parameter.type === 'binary'
268 !parameter.isOptional &&
269 !requestParameters[parameterName]
271 isParameterValid = false;
272 errorText = i18n('Field is required');
274 (!parameter.isOptional &&
275 !requestParameters[parameterName]) ||
276 (parameter.metadata.maxLength &&
277 requestParameters[parameterName].length >
279 parameter.metadata.maxLength
281 (parameter.metadata.minLength &&
282 requestParameters[parameterName].length <
284 parameter.metadata.minLength
286 requestParameters[parameterName].length > 0)
288 isParameterValid = false;
290 'Value Should Be Minimum of {minLength} characters and a Maximum of {maxLength} characters',
292 minLength: parameter.metadata.minLength,
293 maxLength: parameter.metadata.maxLength
299 generalInfo[testCaseName][
301 ].isValid = isParameterValid;
302 generalInfo[testCaseName][
304 ].errorText = errorText;
305 areInputsValid = areInputsValid && isParameterValid;
309 if (!areInputsValid) {
310 setGeneralInfo(generalInfo);
312 return areInputsValid;
322 softwareProductValidation
325 Object.keys(softwareProductValidation.testsRequest).forEach(key => {
326 var testReq = softwareProductValidation.testsRequest[key];
327 this.removeParameterFromTest(testReq);
330 if (this.validateInputs()) {
331 var requestId = UUID.create()
334 onTestSubmit(softwareProductId, version, status, tests, requestId);
337 removeParameterFromTest(testReq) {
338 delete testReq.parameters['host-username'];
339 delete testReq.parameters['host-password'];
340 delete testReq.parameters['host-url'];
342 prepareDataForVspInputs() {
343 let { setTestsRequest } = this.props;
346 certificationChecked,
350 } = this.props.softwareProductValidation;
354 certificationChecked,
363 <div className="vsp-validation-view">
368 onSubmit={() => this.performVSPTests()}
369 isReadOnlyMode={false}>
371 {...this.prepareDataForVspInputs()}
372 filterField={this.filterField}
376 data-test-id="proceed-to-validation-results-btn"
379 className="proceed-to-validation-monitor-btn">
388 export default VspValidationInputs;