react 16 upgrade
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / softwareProduct / components / network / SoftwareProductComponentsNetworkList.js
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 { connect } from 'react-redux';
17 import i18n from 'nfvo-utils/i18n/i18n.js';
18
19 import SoftwareProductComponentsActionHelper from 'sdc-app/onboarding/softwareProduct/components/SoftwareProductComponentsActionHelper.js';
20 import SoftwareProductComponentsNetworkListView from './SoftwareProductComponentsNetworkListView.jsx';
21 import SoftwareProductComponentsNetworkActionHelper from './SoftwareProductComponentsNetworkActionHelper.js';
22 import { COMPONENTS_QUESTIONNAIRE } from 'sdc-app/onboarding/softwareProduct/components/SoftwareProductComponentsConstants.js';
23 import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js';
24 import { actionTypes as GlobalModalActions } from 'nfvo-components/modal/GlobalModalConstants.js';
25 import NICCreationActionHelper from './NICCreation/NICCreationActionHelper.js';
26 import { onboardingMethod as onboardingMethodTypes } from '../../SoftwareProductConstants.js';
27
28 export const mapStateToProps = ({ softwareProduct }) => {
29     let {
30         softwareProductEditor: {
31             data: currentSoftwareProduct = {},
32             isValidityData = true
33         },
34         softwareProductComponents
35     } = softwareProduct;
36     let {
37         network: { nicList = [] },
38         componentEditor: {
39             data: componentData,
40             qdata,
41             dataMap,
42             qgenericFieldInfo
43         }
44     } = softwareProductComponents;
45     let { version, onboardingMethod } = currentSoftwareProduct;
46     let isManual = onboardingMethod === onboardingMethodTypes.MANUAL;
47
48     return {
49         version,
50         componentData,
51         qdata,
52         dataMap,
53         qgenericFieldInfo,
54         isValidityData,
55         nicList,
56         isManual
57     };
58 };
59
60 const mapActionsToProps = (
61     dispatch,
62     { softwareProductId, componentId, version }
63 ) => {
64     return {
65         onQDataChanged: deltaData =>
66             ValidationHelper.qDataChanged(dispatch, {
67                 deltaData,
68                 qName: COMPONENTS_QUESTIONNAIRE
69             }),
70         onAddNic: () =>
71             NICCreationActionHelper.open(dispatch, {
72                 softwareProductId,
73                 componentId,
74                 version
75             }),
76         onDeleteNic: nic =>
77             dispatch({
78                 type: GlobalModalActions.GLOBAL_MODAL_WARNING,
79                 data: {
80                     msg: i18n('Are you sure you want to delete "{name}"?', {
81                         name: nic.name
82                     }),
83                     onConfirmed: () =>
84                         SoftwareProductComponentsNetworkActionHelper.deleteNIC(
85                             dispatch,
86                             {
87                                 softwareProductId,
88                                 componentId,
89                                 nicId: nic.id,
90                                 version
91                             }
92                         )
93                 }
94             }),
95         onEditNicClick: (nic, isReadOnlyMode) => {
96             Promise.all([
97                 SoftwareProductComponentsNetworkActionHelper.loadNICData({
98                     softwareProductId,
99                     version,
100                     componentId,
101                     nicId: nic.id
102                 }),
103                 SoftwareProductComponentsNetworkActionHelper.loadNICQuestionnaire(
104                     dispatch,
105                     {
106                         softwareProductId,
107                         version,
108                         componentId,
109                         nicId: nic.id
110                     }
111                 )
112             ]).then(([{ data }]) =>
113                 SoftwareProductComponentsNetworkActionHelper.openNICEditor(
114                     dispatch,
115                     {
116                         nic,
117                         data,
118                         isReadOnlyMode,
119                         softwareProductId,
120                         componentId,
121                         version
122                     }
123                 )
124             );
125         },
126         onSubmit: ({ qdata }) => {
127             return SoftwareProductComponentsActionHelper.updateSoftwareProductComponentQuestionnaire(
128                 dispatch,
129                 {
130                     softwareProductId,
131                     version,
132                     vspComponentId: componentId,
133                     qdata
134                 }
135             );
136         }
137     };
138 };
139
140 export default connect(mapStateToProps, mapActionsToProps, null, {
141     withRef: true
142 })(SoftwareProductComponentsNetworkListView);