react 16 upgrade
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / softwareProduct / components / network / nicEditorComponents / Protocols.jsx
1 /*
2  * Copyright © 2016-2018 European Support Limited
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 or implied.
13  * See the License for the specific language governing permissions and
14  * 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 InputOptions from 'nfvo-components/input/validation/InputOptions.jsx';
21 import GridSection from 'nfvo-components/grid/GridSection.jsx';
22 import GridItem from 'nfvo-components/grid/GridItem.jsx';
23
24 const Protocols = ({
25     protocols,
26     qgenericFieldInfo,
27     dataMap,
28     onQDataChanged
29 }) => {
30     return (
31         <GridSection title={i18n('Protocols')} hasLastColSet>
32             <GridItem colSpan={2}>
33                 <InputOptions
34                     data-test-id="nic-protocols"
35                     label={i18n('Protocols')}
36                     type="select"
37                     isMultiSelect={true}
38                     isValid={qgenericFieldInfo['protocols/protocols'].isValid}
39                     errorText={
40                         qgenericFieldInfo['protocols/protocols'].errorText
41                     }
42                     onInputChange={() => {}}
43                     onEnumChange={protocols => {
44                         onQDataChanged({ 'protocols/protocols': protocols });
45                     }}
46                     multiSelectedEnum={dataMap['protocols/protocols']}
47                     clearable={false}
48                     values={qgenericFieldInfo['protocols/protocols'].enum}
49                 />
50             </GridItem>
51             <GridItem colSpan={2} lastColInRow>
52                 <Input
53                     data-test-id="nic-protocolWithHighestTrafficProfile"
54                     label={i18n('Protocol with Highest Traffic Profile')}
55                     type="select"
56                     groupClassName="bootstrap-input-options"
57                     className="input-options-select"
58                     isValid={
59                         qgenericFieldInfo[
60                             'protocols/protocolWithHighestTrafficProfile'
61                         ].isValid
62                     }
63                     errorText={
64                         qgenericFieldInfo[
65                             'protocols/protocolWithHighestTrafficProfile'
66                         ].errorText
67                     }
68                     value={
69                         dataMap['protocols/protocolWithHighestTrafficProfile']
70                     }
71                     onChange={e => {
72                         const selectedIndex = e.target.selectedIndex;
73                         const val = e.target.options[selectedIndex].value;
74                         onQDataChanged({
75                             'protocols/protocolWithHighestTrafficProfile': val
76                         });
77                     }}>
78                     {protocols.length === 0 && (
79                         <option
80                             key={'You must select protocols first...'}
81                             value="">
82                             {i18n('You must select protocols first...')}
83                         </option>
84                     )}
85                     {protocols.map(protocol => (
86                         <option key={protocol} value={protocol}>
87                             {protocol}
88                         </option>
89                     ))}
90                 </Input>
91             </GridItem>
92         </GridSection>
93     );
94 };
95
96 Protocols.propTypes = {
97     protocols: PropTypes.array,
98     onQDataChanged: PropTypes.func,
99     dataMap: PropTypes.object,
100     qgenericFieldInfo: PropTypes.object
101 };
102
103 export default Protocols;