Add collaboration feature
[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 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';
23
24 class SoftwareProductComponentComputeView extends React.Component {
25
26         static propTypes = {
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
34         };
35
36         render() {
37                 let {softwareProductId, componentId, version, qdata, dataMap, qgenericFieldInfo, isReadOnlyMode, onQDataChanged, qValidateData,
38                         onSubmit, computeFlavorsList, isManual} = this.props;
39
40                 return (
41                         <div className='vsp-component-questionnaire-view'>
42                                 { qgenericFieldInfo && <Form
43                                         ref={ (form) => { this.form = form; }}
44                                         formReady={null}
45                                         isValid={true}
46                                         hasButtons={false}
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}/>
56                                 </Form> }
57                         </div>
58                 );
59         }
60
61         save(){
62                 return this.form.handleFormSubmit(new Event('dummy'));
63         }
64
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: '' };
71                 } else {
72                         return Validator.validateItem(value, maxVal,'maximum');
73                 }
74         }
75
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
80                         // against it.
81                         return { isValid: true, errorText: '' };
82                 } else {
83                         return Validator.validateItem(value,minVal,'minimum');
84                 }
85         }
86 }
87
88 export default SoftwareProductComponentComputeView;