88525c051d52aad6ce2f13a2e04291a32db69b26
[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 i18n from 'nfvo-utils/i18n/i18n.js';
19 import Input from 'nfvo-components/input/validation/Input.jsx';
20 import Form from 'nfvo-components/input/validation/Form.jsx';
21 import GridSection from 'nfvo-components/grid/GridSection.jsx';
22 import GridItem from 'nfvo-components/grid/GridItem.jsx';
23
24 const NICPropType = PropTypes.shape({
25     id: PropTypes.string,
26     name: PropTypes.string,
27     description: PropTypes.string,
28     networkId: PropTypes.string
29 });
30
31 class NICCreationView extends React.Component {
32     static propTypes = {
33         data: NICPropType,
34         onDataChanged: PropTypes.func.isRequired,
35         onSubmit: PropTypes.func.isRequired,
36         onCancel: PropTypes.func.isRequired
37     };
38
39     render() {
40         let {
41             data = {},
42             onDataChanged,
43             genericFieldInfo,
44             isFormValid,
45             onValidateForm,
46             formReady
47         } = this.props;
48         let { name, description, networkDescription } = data;
49         return (
50             <div>
51                 {genericFieldInfo && (
52                     <Form
53                         ref={form => (this.form = form)}
54                         hasButtons={true}
55                         onSubmit={() => this.submit()}
56                         submitButtonText={
57                             data.id ? i18n('Save') : i18n('Create')
58                         }
59                         onReset={() => this.props.onCancel()}
60                         labledButtons={true}
61                         isValid={isFormValid}
62                         onValidateForm={() => onValidateForm()}
63                         formReady={formReady}>
64                         <GridSection hasLastColSet>
65                             <GridItem colSpan={4} lastColInRow>
66                                 <Input
67                                     value={name}
68                                     label={i18n('Name')}
69                                     data-test-id="nic-name"
70                                     onChange={name => onDataChanged({ name })}
71                                     isRequired={true}
72                                     type="text"
73                                     isValid={genericFieldInfo['name'].isValid}
74                                     errorText={
75                                         genericFieldInfo['name'].errorText
76                                     }
77                                     className="field-section"
78                                 />
79                                 <Input
80                                     value={description}
81                                     label={i18n('Description')}
82                                     data-test-id="nic-description"
83                                     onChange={description =>
84                                         onDataChanged({ description })
85                                     }
86                                     isValid={
87                                         genericFieldInfo['description'].isValid
88                                     }
89                                     errorText={
90                                         genericFieldInfo['description']
91                                             .errorText
92                                     }
93                                     type="textarea"
94                                     className="field-section"
95                                 />
96                             </GridItem>
97                         </GridSection>
98                         <GridSection title={i18n('Network')} hasLastColSet>
99                             <GridItem colSpan={2}>
100                                 <div className="form-group">
101                                     <label className="control-label">
102                                         {i18n('Network Type')}
103                                     </label>
104                                     <div className="network-type-radio">
105                                         <Input
106                                             label={i18n('Internal')}
107                                             disabled
108                                             checked={false}
109                                             data-test-id="nic-internal"
110                                             className="network-radio disabled"
111                                             type="radio"
112                                         />
113                                         <Input
114                                             label={i18n('External')}
115                                             disabled
116                                             checked={true}
117                                             data-test-id="nic-external"
118                                             className="network-radio disabled"
119                                             type="radio"
120                                         />
121                                     </div>
122                                 </div>
123                             </GridItem>
124                             <GridItem colSpan={2} lastColInRow>
125                                 <Input
126                                     value={networkDescription}
127                                     label={i18n('Network Description')}
128                                     data-test-id="nic-network-description"
129                                     onChange={networkDescription =>
130                                         onDataChanged({ networkDescription })
131                                     }
132                                     isValid={
133                                         genericFieldInfo['networkDescription']
134                                             .isValid
135                                     }
136                                     errorText={
137                                         genericFieldInfo['networkDescription']
138                                             .errorText
139                                     }
140                                     type="text"
141                                     className="field-section"
142                                 />
143                             </GridItem>
144                         </GridSection>
145                     </Form>
146                 )}
147             </div>
148         );
149     }
150
151     submit() {
152         const { data: nic, componentId } = this.props;
153         this.props.onSubmit({ nic, componentId });
154     }
155 }
156
157 export default NICCreationView;