840f722bb2fec6316b735eaf6f6e8db8957bf93f
[sdc.git] /
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     static propTypes = {
27         data: PropTypes.object,
28         qdata: PropTypes.object,
29         qschema: PropTypes.object,
30         isReadOnlyMode: PropTypes.bool,
31         isManual: PropTypes.bool,
32         onDataChanged: PropTypes.func.isRequired,
33         onQDataChanged: PropTypes.func.isRequired,
34         onSubmit: PropTypes.func.isRequired,
35         onCancel: PropTypes.func.isRequired
36     };
37
38     render() {
39         let {
40             data = {},
41             qdata = {},
42             qgenericFieldInfo,
43             dataMap,
44             genericFieldInfo,
45             isReadOnlyMode,
46             isManual,
47             isFormValid,
48             formReady,
49             onDataChanged,
50             onQDataChanged,
51             onSubmit,
52             onCancel,
53             onValidateForm
54         } = this.props;
55         const { id, name, description } = data;
56         const edittingComputeMode = Boolean(id);
57
58         return (
59             <div className="vsp-component-computeFlavor-view">
60                 {genericFieldInfo && (
61                     <Form
62                         ref={form => {
63                             this.form = form;
64                         }}
65                         hasButtons={true}
66                         onSubmit={() => onSubmit({ data, qdata })}
67                         onReset={() => onCancel()}
68                         labledButtons={true}
69                         isReadOnlyMode={isReadOnlyMode}
70                         isValid={isFormValid}
71                         formReady={formReady}
72                         onValidateForm={() => onValidateForm()}
73                         className="component-questionnaire-validation-form"
74                         submitButtonText={
75                             edittingComputeMode ? i18n('Save') : i18n('Create')
76                         }>
77                         <GridSection hasLostColSet>
78                             <GridItem
79                                 colSpan={edittingComputeMode ? 2 : 4}
80                                 lastColInRow={!edittingComputeMode}>
81                                 <Input
82                                     disabled={!isManual}
83                                     data-test-id="name"
84                                     type="text"
85                                     label={i18n('Flavor Name')}
86                                     value={name}
87                                     onChange={name => onDataChanged({ name })}
88                                     isValid={genericFieldInfo['name'].isValid}
89                                     errorText={
90                                         genericFieldInfo['name'].errorText
91                                     }
92                                     isRequired
93                                 />
94                             </GridItem>
95                             <GridItem
96                                 colSpan={edittingComputeMode ? 2 : 4}
97                                 lastColInRow>
98                                 <Input
99                                     data-test-id="description"
100                                     type="textarea"
101                                     label={i18n('Description')}
102                                     value={description}
103                                     onChange={description =>
104                                         onDataChanged({ description })
105                                     }
106                                     isValid={
107                                         genericFieldInfo['description'].isValid
108                                     }
109                                     errorText={
110                                         genericFieldInfo['description']
111                                             .errorText
112                                     }
113                                 />
114                             </GridItem>
115                         </GridSection>
116                         {edittingComputeMode && (
117                             <VmSizing
118                                 qgenericFieldInfo={qgenericFieldInfo}
119                                 dataMap={dataMap}
120                                 onQDataChanged={onQDataChanged}
121                             />
122                         )}
123                     </Form>
124                 )}
125             </div>
126         );
127     }
128
129     save() {
130         return this.form.handleFormSubmit(new Event('dummy'));
131     }
132 }
133
134 export default ComputeEditorView;