Adding Prettier and fixing up eslint version
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / softwareProduct / components / network / SoftwareProductComponentsNetworkList.js
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 { 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                 modalClassName: 'network-nic-modal-create',
75                 version
76             }),
77         onDeleteNic: nic =>
78             dispatch({
79                 type: GlobalModalActions.GLOBAL_MODAL_WARNING,
80                 data: {
81                     msg: i18n('Are you sure you want to delete "{name}"?', {
82                         name: nic.name
83                     }),
84                     onConfirmed: () =>
85                         SoftwareProductComponentsNetworkActionHelper.deleteNIC(
86                             dispatch,
87                             {
88                                 softwareProductId,
89                                 componentId,
90                                 nicId: nic.id,
91                                 version
92                             }
93                         )
94                 }
95             }),
96         onEditNicClick: (nic, isReadOnlyMode) => {
97             Promise.all([
98                 SoftwareProductComponentsNetworkActionHelper.loadNICData({
99                     softwareProductId,
100                     version,
101                     componentId,
102                     nicId: nic.id
103                 }),
104                 SoftwareProductComponentsNetworkActionHelper.loadNICQuestionnaire(
105                     dispatch,
106                     {
107                         softwareProductId,
108                         version,
109                         componentId,
110                         nicId: nic.id
111                     }
112                 )
113             ]).then(([{ data }]) =>
114                 SoftwareProductComponentsNetworkActionHelper.openNICEditor(
115                     dispatch,
116                     {
117                         nic,
118                         data,
119                         isReadOnlyMode,
120                         softwareProductId,
121                         componentId,
122                         modalClassName: 'network-nic-modal-edit',
123                         version
124                     }
125                 )
126             );
127         },
128         onSubmit: ({ qdata }) => {
129             return SoftwareProductComponentsActionHelper.updateSoftwareProductComponentQuestionnaire(
130                 dispatch,
131                 {
132                     softwareProductId,
133                     version,
134                     vspComponentId: componentId,
135                     qdata
136                 }
137             );
138         }
139     };
140 };
141
142 export default connect(mapStateToProps, mapActionsToProps, null, {
143     withRef: true
144 })(SoftwareProductComponentsNetworkListView);