Add collaboration feature
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / softwareProduct / components / compute / computeComponents / computeFlavor / ComputeFlavorEditorView.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 Input from 'nfvo-components/input/validation/Input.jsx';
20 import GridSection from 'nfvo-components/grid/GridSection.jsx';
21 import GridItem from 'nfvo-components/grid/GridItem.jsx';
22 import VmSizing from './VmSizing.jsx';
23 import i18n from 'nfvo-utils/i18n/i18n.js';
24
25 class ComputeEditorView extends React.Component {
26
27         static propTypes = {
28                 data: PropTypes.object,
29                 qdata: PropTypes.object,
30                 qschema: PropTypes.object,
31                 isReadOnlyMode: PropTypes.bool,
32                 isManual: PropTypes.bool,
33                 onDataChanged: PropTypes.func.isRequired,
34                 onQDataChanged: PropTypes.func.isRequired,
35                 onSubmit: PropTypes.func.isRequired,
36                 onCancel: PropTypes.func.isRequired
37         };
38
39         render() {
40                 let {data = {}, qdata = {}, qgenericFieldInfo, dataMap, genericFieldInfo, isReadOnlyMode, isManual, isFormValid, formReady,
41                         onDataChanged, onQDataChanged, onSubmit, onCancel, onValidateForm} = this.props;
42                 const {id, name, description} = data;
43                 const edittingComputeMode = Boolean(id);
44
45                 return (
46                         <div className='vsp-component-computeFlavor-view'>
47                                 {genericFieldInfo && <Form
48                                         ref={(form) => {
49                                                 this.form = form;
50                                         }}
51                                         hasButtons={true}
52                                         onSubmit={ () => onSubmit({data, qdata}) }
53                                         onReset={ () => onCancel() }
54                                         labledButtons={true}
55                                         isReadOnlyMode={isReadOnlyMode}
56                                         isValid={isFormValid}
57                                         formReady={formReady}
58                                         onValidateForm={() => onValidateForm() }
59                                         className='component-questionnaire-validation-form'
60                                         submitButtonText={edittingComputeMode ? i18n('Save') : i18n('Create')}>
61                                         <GridSection hasLostColSet>
62                                                 <GridItem colSpan={edittingComputeMode ? 2 : 4} lastColInRow={!edittingComputeMode}>
63                                                         <Input
64                                                                 disabled={!isManual}
65                                                                 data-test-id='name'
66                                                                 type='text'
67                                                                 label={i18n('Flavor Name')}
68                                                                 value={name}
69                                                                 onChange={name => onDataChanged({name})}
70                                                                 isValid={genericFieldInfo['name'].isValid}
71                                                                 errorText={genericFieldInfo['name'].errorText}
72                                                                 isRequired/>
73                                                         </GridItem>
74                                                         <GridItem colSpan={edittingComputeMode ? 2 : 4} lastColInRow>
75                                                         <Input
76                                                                 data-test-id='description'
77                                                                 type='textarea'
78                                                                 label={i18n('Description')}
79                                                                 value={description}
80                                                                 onChange={description => onDataChanged({description})}
81                                                                 isValid={genericFieldInfo['description'].isValid}
82                                                                 errorText={genericFieldInfo['description'].errorText}/>
83                                                 </GridItem>
84                                         </GridSection>
85                                         {edittingComputeMode && <VmSizing qgenericFieldInfo={qgenericFieldInfo} dataMap={dataMap} onQDataChanged={onQDataChanged}/>}
86                                 </Form>
87                                 }
88                         </div>
89                 );
90         }
91
92         save(){
93                 return this.form.handleFormSubmit(new Event('dummy'));
94         }
95 }
96
97 export default ComputeEditorView;