react 16 upgrade
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / softwareProduct / components / network / nicEditorComponents / PacketsBytes.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 GridSection from 'nfvo-components/grid/GridSection.jsx';
21 import GridItem from 'nfvo-components/grid/GridItem.jsx';
22
23 const PointerInput = ({
24     label,
25     value,
26     onQDataChanged,
27     qgenericFieldInfo,
28     dataMap,
29     lastColInRow
30 }) => {
31     return (
32         <GridItem lastColInRow={lastColInRow}>
33             <Input
34                 label={i18n(label)}
35                 type="number"
36                 data-test-id={`${value}`}
37                 isValid={qgenericFieldInfo[value].isValid}
38                 errorText={qgenericFieldInfo[value].errorText}
39                 value={dataMap[value]}
40                 onChange={val => onQDataChanged({ [value]: val })}
41             />
42         </GridItem>
43     );
44 };
45
46 PointerInput.propTypes = {
47     label: PropTypes.string,
48     value: PropTypes.string
49 };
50
51 const PacketsBytes = ({
52     title,
53     pointers = [],
54     qgenericFieldInfo,
55     dataMap,
56     onQDataChanged
57 }) => {
58     return (
59         <GridSection title={title} hasLastColSet>
60             <GridItem colSpan={2}>
61                 <div className="part-title-small packets">
62                     {i18n('Packets')}
63                 </div>
64             </GridItem>
65             <GridItem colSpan={2} lastColInRow>
66                 <div className="part-title-small bytes">{i18n('Bytes')}</div>
67             </GridItem>
68             {pointers.map((pointer, i) => {
69                 return (
70                     <PointerInput
71                         key={i}
72                         label={pointer.label}
73                         value={pointer.value}
74                         qgenericFieldInfo={qgenericFieldInfo}
75                         onQDataChanged={onQDataChanged}
76                         dataMap={dataMap}
77                         lastColInRow={i === 3}
78                     />
79                 );
80             })}
81         </GridSection>
82     );
83 };
84
85 PacketsBytes.PropTypes = {
86     title: PropTypes.string,
87     pointers: PropTypes.array,
88     onQDataChanged: PropTypes.function,
89     dataMap: PropTypes.object,
90     qgenericFieldInfo: PropTypes.object
91 };
92
93 export default PacketsBytes;