2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
16 import React from 'react';
17 import PropTypes from 'prop-types';
18 import Form from 'nfvo-components/input/validation/Form.jsx';
19 import NumberOfVms from './computeComponents/NumberOfVms.jsx';
20 import GuestOs from './computeComponents/GuestOs.jsx';
21 import ComputeFlavors from './computeComponents/ComputeFlavors.js';
22 import Validator from 'nfvo-utils/Validator.js';
24 class SoftwareProductComponentComputeView extends React.Component {
27 dataMap: PropTypes.object,
28 qgenericFieldInfo: PropTypes.object,
29 isReadOnlyMode: PropTypes.bool,
30 isManual: PropTypes.bool,
31 onQDataChanged: PropTypes.func.isRequired,
32 qValidateData: PropTypes.func.isRequired,
33 onSubmit: PropTypes.func.isRequired
37 let {softwareProductId, componentId, version, qdata, dataMap, qgenericFieldInfo, isReadOnlyMode, onQDataChanged, qValidateData,
38 onSubmit, computeFlavorsList, isManual} = this.props;
41 <div className='vsp-component-questionnaire-view'>
42 { qgenericFieldInfo && <Form
43 ref={ (form) => { this.form = form; }}
47 onSubmit={() => onSubmit({qdata})}
48 className='component-questionnaire-validation-form'
49 isReadOnlyMode={isReadOnlyMode} >
50 <NumberOfVms onQDataChanged={onQDataChanged} dataMap={dataMap}
51 qgenericFieldInfo={qgenericFieldInfo} qValidateData={qValidateData}
52 customValidations={{'compute/numOfVMs/maximum' : this.validateMax, 'compute/numOfVMs/minimum': this.validateMin}} />
53 <GuestOs onQDataChanged={onQDataChanged} dataMap={dataMap} qgenericFieldInfo={qgenericFieldInfo} />
54 <ComputeFlavors computeFlavorsList={computeFlavorsList} softwareProductId={softwareProductId} componentId={componentId}
55 version={version} isReadOnlyMode={isReadOnlyMode} isManual={isManual}/>
62 return this.form.handleFormSubmit(new Event('dummy'));
65 validateMin(value, state) {
66 let maxVal = state.dataMap['compute/numOfVMs/maximum'];
67 // we are allowed to have an empty maxval, that will allow all minvals.
68 // if we do not have a minval than there is no point to check it either.
69 if (value === undefined || maxVal === undefined) {
70 return { isValid: true, errorText: '' };
72 return Validator.validateItem(value, maxVal,'maximum');
76 validateMax(value, state) {
77 let minVal = state.dataMap['compute/numOfVMs/minimum'];
78 if (minVal === undefined ) {
79 // having no minimum is the same as 0, maximum value doesn't need to be checked
81 return { isValid: true, errorText: '' };
83 return Validator.validateItem(value,minVal,'minimum');
88 export default SoftwareProductComponentComputeView;