Add collaboration feature
[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
29 export const mapStateToProps = ({softwareProduct}) => {
30
31         let {softwareProductEditor: {data: currentSoftwareProduct = {}, isValidityData = true}, softwareProductComponents} = softwareProduct;
32         let {network: {nicList = []}, componentEditor: {data: componentData, qdata, dataMap, qgenericFieldInfo}} = softwareProductComponents;
33         let {version, onboardingMethod} = currentSoftwareProduct;
34         let isManual = onboardingMethod === onboardingMethodTypes.MANUAL;
35
36         return {
37                 version,
38                 componentData,
39                 qdata,
40                 dataMap,
41                 qgenericFieldInfo,
42                 isValidityData,
43                 nicList,
44                 isManual
45         };
46
47 };
48
49 const mapActionsToProps = (dispatch, {softwareProductId, componentId, version}) => {
50         return {
51                 onQDataChanged: (deltaData) => ValidationHelper.qDataChanged(dispatch, {deltaData,
52                         qName: COMPONENTS_QUESTIONNAIRE}),
53                 onAddNic: () => NICCreationActionHelper.open(dispatch, {softwareProductId, componentId, modalClassName: 'network-nic-modal-create', version}),
54                 onDeleteNic: (nic) => dispatch({
55                         type: GlobalModalActions.GLOBAL_MODAL_WARNING,
56                         data:{
57                                 msg: i18n('Are you sure you want to delete "{name}"?', {name: nic.name}),
58                                 onConfirmed: () => SoftwareProductComponentsNetworkActionHelper.deleteNIC(dispatch, {softwareProductId,
59                                         componentId, nicId: nic.id, version})
60                         }
61                 }),
62                 onEditNicClick: (nic, isReadOnlyMode) => {
63                         Promise.all([
64                                 SoftwareProductComponentsNetworkActionHelper.loadNICData({
65                                         softwareProductId,
66                                         version,
67                                         componentId,
68                                         nicId: nic.id
69                                 }),
70                                 SoftwareProductComponentsNetworkActionHelper.loadNICQuestionnaire(dispatch, {
71                                         softwareProductId,
72                                         version,
73                                         componentId,
74                                         nicId: nic.id
75                                 })
76                         ]).then(
77                                 ([{data}]) => SoftwareProductComponentsNetworkActionHelper.openNICEditor(dispatch, {nic, data,
78                                         isReadOnlyMode, softwareProductId, componentId, modalClassName: 'network-nic-modal-edit', version})
79                         );
80                 },
81                 onSubmit: ({qdata}) => { return SoftwareProductComponentsActionHelper.updateSoftwareProductComponentQuestionnaire(dispatch,
82                         {softwareProductId, version,
83                         vspComponentId: componentId,
84                         qdata});
85                 }
86
87
88         };
89 };
90
91 export default connect(mapStateToProps, mapActionsToProps, null, {withRef: true})(SoftwareProductComponentsNetworkListView);