[SDC] Onboarding 1710 rebase.
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / softwareProduct / components / compute / SoftwareProductComponentComputeView.jsx
1 /*!
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  */
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';
22
23 class SoftwareProductComponentComputeView extends React.Component {
24
25         static propTypes = {
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
33         };
34
35         render() {
36                 let {softwareProductId, componentId, version, qdata, dataMap, qgenericFieldInfo, isReadOnlyMode, onQDataChanged, qValidateData,
37                         onSubmit, computeFlavorsList, isManual} = this.props;
38
39                 return (
40                         <div className='vsp-component-questionnaire-view'>
41                                 { qgenericFieldInfo && <Form
42                                         ref={ (form) => { this.form = form; }}
43                                         formReady={null}
44                                         isValid={true}
45                                         hasButtons={false}
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}/>
55                                 </Form> }
56                         </div>
57                 );
58         }
59
60         save(){
61                 return this.form.handleFormSubmit(new Event('dummy'));
62         }
63
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: '' };
70                 } else {
71                         return Validator.validateItem(value, maxVal,'maximum');
72                 }
73         }
74
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
79                         // against it.
80                         return { isValid: true, errorText: '' };
81                 } else {
82                         return Validator.validateItem(value,minVal,'minimum');
83                 }
84         }
85 }
86
87 export default SoftwareProductComponentComputeView;