Add collaboration feature
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / softwareProduct / attachments / SoftwareProductAttachments.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 import {actionTypes as modalActionTypes} from 'nfvo-components/modal/GlobalModalConstants.js';
19 import SoftwareProductActionHelper from 'sdc-app/onboarding/softwareProduct/SoftwareProductActionHelper.js';
20 import HeatSetupActionHelper from './setup/HeatSetupActionHelper.js';
21 import SoftwareProductAttachmentsView from './SoftwareProductAttachmentsView.jsx';
22 import {errorLevels} from 'sdc-app/onboarding/softwareProduct/attachments/validation/HeatValidationConstants.js';
23 import HeatSetup from './setup/HeatSetup.js';
24 import {doesHeatDataExist} from './SoftwareProductAttachmentsUtils.js';
25 import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js';
26 import {enums, screenTypes} from 'sdc-app/onboarding/OnboardingConstants.js';
27 import SoftwareProductAttachmentsActionHelper from './SoftwareProductAttachmentsActionHelper.js';
28
29 export const mapStateToProps = (state) => {
30         let {
31                 softwareProduct: {
32                         softwareProductEditor:{data: currentSoftwareProduct = {}},
33                         softwareProductAttachments: {attachmentsDetails: {activeTab}, heatSetup, heatSetupCache, heatValidation : {errorList}}
34                 }
35         } = state;
36
37         let {unassigned = [], modules = []} = heatSetup;
38         let goToOverview = true;
39         if (errorList) {
40                 for (let i = 0 ; i < errorList.length ; i++) {
41                         if (errorList[i].level === errorLevels.ERROR) {
42                                 goToOverview = false;
43                         }
44                 }
45         }
46         let heatDataExist = doesHeatDataExist(heatSetup);
47
48         let {version, onboardingOrigin} = currentSoftwareProduct;
49         return {
50                 isValidationAvailable: unassigned.length === 0 && modules.length > 0,
51                 heatSetup,
52                 heatSetupCache,
53                 heatDataExist,
54                 goToOverview,
55                 HeatSetupComponent: HeatSetup,
56                 version,
57                 onboardingOrigin,
58                 activeTab
59         };
60 };
61
62 export const mapActionsToProps = (dispatch, {softwareProductId, version}) => {
63         return {
64                 onDownload: ({heatCandidate, isReadOnlyMode}) => SoftwareProductActionHelper.downloadHeatFile(dispatch, {softwareProductId, heatCandidate, isReadOnlyMode, version}),
65                 onUpload: (formData) => dispatch({
66                         type: modalActionTypes.GLOBAL_MODAL_WARNING,
67                         data:{
68                                 msg: i18n('Upload will erase existing data. Do you want to continue?'),
69                                 confirmationButtonText: i18n('Continue'),
70                                 onConfirmed: ()=>SoftwareProductActionHelper.uploadFile(dispatch, {
71                                         softwareProductId,
72                                         formData,
73                                         failedNotificationTitle: i18n('Upload validation failed'),
74                                         version
75                                 })
76                         }
77                 }),
78                 onInvalidFileUpload: () => dispatch({
79                         type: modalActionTypes.GLOBAL_MODAL_ERROR,
80                         data: {
81                                 title: i18n('Upload Failed'),
82                                 confirmationButtonText: i18n('Continue'),
83                                 msg: i18n('no zip or csar file was uploaded or expected file doesn\'t exist')
84                         }
85                 }),
86                 onSave: (heatCandidate) => SoftwareProductActionHelper.updateSoftwareProductHeatCandidate(dispatch, {softwareProductId, heatCandidate, version}),
87                 onGoToOverview: () => ScreensHelper.loadScreen(dispatch, {
88                         screen: enums.SCREEN.SOFTWARE_PRODUCT_LANDING_PAGE, screenType: screenTypes.SOFTWARE_PRODUCT,
89                         props: {softwareProductId, version}
90                 }),
91                 onProcessAndValidate: ({heatData, heatDataCache, isReadOnlyMode}) => {
92                         return HeatSetupActionHelper.processAndValidateHeat(dispatch,
93                                 {softwareProductId, heatData, heatDataCache, isReadOnlyMode, version});
94                 },
95                 setActiveTab: ({activeTab}) => SoftwareProductAttachmentsActionHelper.setActiveTab(dispatch, {activeTab})
96
97         };
98 };
99
100 export default connect(mapStateToProps, mapActionsToProps, null, {withRef: true})(SoftwareProductAttachmentsView);