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 Form from 'nfvo-components/input/validation/Form.jsx';
18 import NumberOfVms from './computeComponents/NumberOfVms.jsx';
19 import GuestOs from './computeComponents/GuestOs.jsx';
20 import ComputeFlavors from './computeComponents/ComputeFlavors.js';
21 import Validator from 'nfvo-utils/Validator.js';
23 class SoftwareProductComponentComputeView extends React.Component {
26 dataMap: React.PropTypes.object,
27 qgenericFieldInfo: React.PropTypes.object,
28 isReadOnlyMode: React.PropTypes.bool,
29 isManual: React.PropTypes.bool,
30 onQDataChanged: React.PropTypes.func.isRequired,
31 qValidateData: React.PropTypes.func.isRequired,
32 onSubmit: React.PropTypes.func.isRequired
36 let {softwareProductId, componentId, version, qdata, dataMap, qgenericFieldInfo, isReadOnlyMode, onQDataChanged, qValidateData,
37 onSubmit, computeFlavorsList, isManual} = this.props;
40 <div className='vsp-component-questionnaire-view'>
41 { qgenericFieldInfo && <Form
42 ref={ (form) => { this.form = form; }}
46 onSubmit={() => onSubmit({qdata})}
47 className='component-questionnaire-validation-form'
48 isReadOnlyMode={isReadOnlyMode} >
49 <NumberOfVms onQDataChanged={onQDataChanged} dataMap={dataMap}
50 qgenericFieldInfo={qgenericFieldInfo} qValidateData={qValidateData}
51 customValidations={{'compute/numOfVMs/maximum' : this.validateMax, 'compute/numOfVMs/minimum': this.validateMin}} />
52 <GuestOs onQDataChanged={onQDataChanged} dataMap={dataMap} qgenericFieldInfo={qgenericFieldInfo} />
53 <ComputeFlavors computeFlavorsList={computeFlavorsList} softwareProductId={softwareProductId} componentId={componentId}
54 version={version} isReadOnlyMode={isReadOnlyMode} isManual={isManual}/>
61 return this.form.handleFormSubmit(new Event('dummy'));
64 validateMin(value, state) {
65 let maxVal = state.dataMap['compute/numOfVMs/maximum'];
66 // we are allowed to have an empty maxval, that will allow all minvals.
67 // if we do not have a minval than there is no point to check it either.
68 if (value === undefined || maxVal === undefined) {
69 return { isValid: true, errorText: '' };
71 return Validator.validateItem(value, maxVal,'maximum');
75 validateMax(value, state) {
76 let minVal = state.dataMap['compute/numOfVMs/minimum'];
77 if (minVal === undefined ) {
78 // having no minimum is the same as 0, maximum value doesn't need to be checked
80 return { isValid: true, errorText: '' };
82 return Validator.validateItem(value,minVal,'minimum');
87 export default SoftwareProductComponentComputeView;