Create new VSP, onboard from TOSCA file - UI
[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 OnboardingActionHelper from 'sdc-app/onboarding/OnboardingActionHelper.js';
24 import HeatSetup from './setup/HeatSetup.js';
25 import {doesHeatDataExist} from './SoftwareProductAttachmentsUtils.js';
26 import SoftwareProductAttachmentsActionHelper from './SoftwareProductAttachmentsActionHelper.js';
27
28 import VersionControllerUtils from 'nfvo-components/panel/versionController/VersionControllerUtils.js';
29
30 export const mapStateToProps = (state) => {
31         let {
32                 softwareProduct: {
33                         softwareProductEditor:{data: currentSoftwareProduct = {}},
34                         softwareProductAttachments: {attachmentsDetails: {activeTab}, heatSetup, heatSetupCache, heatValidation : {errorList}}
35                 }
36         } = state;
37
38         let {unassigned = [], modules = []} = heatSetup;
39         let goToOverview = true;
40         if (errorList) {
41                 for (let i = 0 ; i < errorList.length ; i++) {
42                         if (errorList[i].level === errorLevels.ERROR) {
43                                 goToOverview = false;
44                         }
45                 }
46         }
47         let heatDataExist = doesHeatDataExist(heatSetup);
48
49         let isReadOnlyMode = currentSoftwareProduct && currentSoftwareProduct.version ?
50                         VersionControllerUtils.isReadOnly(currentSoftwareProduct) : false;
51         let {version, onboardingOrigin} = currentSoftwareProduct;
52         return {
53                 isValidationAvailable: unassigned.length === 0 && modules.length > 0,
54                 heatSetup,
55                 heatSetupCache,
56                 heatDataExist,
57                 goToOverview,
58                 HeatSetupComponent: HeatSetup,
59                 isReadOnlyMode,
60                 version,
61                 onboardingOrigin,
62                 activeTab
63         };
64 };
65
66 export const mapActionsToProps = (dispatch, {softwareProductId}) => {
67         return {
68                 onDownload: ({heatCandidate, isReadOnlyMode, version}) => SoftwareProductActionHelper.downloadHeatFile(dispatch, {softwareProductId, heatCandidate, isReadOnlyMode, version}),
69                 onUpload: (formData, version) => dispatch({
70                         type: modalActionTypes.GLOBAL_MODAL_WARNING,
71                         data:{
72                                 msg: i18n('Upload will erase existing data. Do you want to continue?'),
73                                 confirmationButtonText: i18n('Continue'),
74                                 onConfirmed: ()=>SoftwareProductActionHelper.uploadFile(dispatch, {
75                                         softwareProductId,
76                                         formData,
77                                         failedNotificationTitle: i18n('Upload validation failed'),
78                                         version
79                                 })
80                         }
81                 }),
82                 onSave: (heatCandidate, version) => SoftwareProductActionHelper.updateSoftwareProductHeatCandidate(dispatch, {softwareProductId, heatCandidate, version}),
83                 onGoToOverview: ({version}) => {
84                         OnboardingActionHelper.navigateToSoftwareProductLandingPage(dispatch, {softwareProductId, version});
85                 },
86                 onProcessAndValidate: ({heatData, heatDataCache, isReadOnlyMode, version}) => {
87                         return HeatSetupActionHelper.processAndValidateHeat(dispatch,
88                                 {softwareProductId, heatData, heatDataCache, isReadOnlyMode, version});
89                 },
90                 setActiveTab: ({activeTab}) => SoftwareProductAttachmentsActionHelper.setActiveTab(dispatch, {activeTab})
91         };
92 };
93
94 export default connect(mapStateToProps, mapActionsToProps, null, {withRef: true})(SoftwareProductAttachmentsView);