2 * Copyright © 2016-2018 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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 or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
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 import isEqual from 'lodash/isEqual.js';
25 const NICPropType = PropTypes.shape({
27 name: PropTypes.string,
28 description: PropTypes.string,
29 networkId: PropTypes.string
32 class NICCreationView extends React.Component {
35 onDataChanged: PropTypes.func.isRequired,
36 onSubmit: PropTypes.func.isRequired,
37 onCancel: PropTypes.func.isRequired
39 shouldComponentUpdate(nextProps) {
41 const { data, isFormValid, formReady, genericFieldInfo } = this.props;
43 isEqual(data, nextProps.data) &&
44 isEqual(isFormValid, nextProps.isFormValid) &&
45 formReady === nextProps.formReady &&
46 isEqual(genericFieldInfo, nextProps.genericFieldInfo)
60 let { name, description, networkDescription } = data;
62 <div className="network-nic-modal-create">
63 {genericFieldInfo && (
66 onSubmit={this.submit}
68 data.id ? i18n('Save') : i18n('Create')
73 onValidateForm={this.validate}
75 btnClassName="sdc-modal__footer">
76 <GridSection hasLastColSet>
77 <GridItem colSpan={4} lastColInRow>
81 data-test-id="nic-name"
82 onChange={name => onDataChanged({ name })}
85 isValid={genericFieldInfo['name'].isValid}
87 genericFieldInfo['name'].errorText
89 className="field-section"
93 label={i18n('Description')}
94 data-test-id="nic-description"
95 onChange={description =>
96 onDataChanged({ description })
99 genericFieldInfo['description'].isValid
102 genericFieldInfo['description']
106 className="field-section"
110 <GridSection title={i18n('Network')} hasLastColSet>
111 <GridItem colSpan={2}>
112 <div className="form-group">
113 <label className="control-label">
114 {i18n('Network Type')}
116 <div className="network-type-radio">
118 label={i18n('Internal')}
121 data-test-id="nic-internal"
122 className="network-radio disabled"
126 label={i18n('External')}
129 data-test-id="nic-external"
130 className="network-radio disabled"
136 <GridItem colSpan={2} lastColInRow>
138 value={networkDescription}
139 label={i18n('Network Description')}
140 data-test-id="nic-network-description"
141 onChange={networkDescription =>
142 onDataChanged({ networkDescription })
145 genericFieldInfo['networkDescription']
149 genericFieldInfo['networkDescription']
153 className="field-section"
164 const { data: nic, componentId } = this.props;
165 this.props.onSubmit({ nic, componentId });
169 this.props.onValidateForm();
173 this.props.onCancel();
177 export default NICCreationView;