Create new VSP, onboard from TOSCA file - UI
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / softwareProduct / landingPage / SoftwareProductLandingPage.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 VersionControllerUtils from 'nfvo-components/panel/versionController/VersionControllerUtils.js';
19 import OnboardingActionHelper from 'sdc-app/onboarding/OnboardingActionHelper.js';
20 import SoftwareProductActionHelper from 'sdc-app/onboarding/softwareProduct/SoftwareProductActionHelper.js';
21 import LandingPageView from './SoftwareProductLandingPageView.jsx';
22 import {actionTypes as modalActionTypes} from 'nfvo-components/modal/GlobalModalConstants.js';
23 import {onboardingMethod} from '../SoftwareProductConstants.js';
24
25 export const mapStateToProps = ({softwareProduct, licenseModel: {licenseAgreement}}) => {
26         let {softwareProductEditor: {data:currentSoftwareProduct = {}}, softwareProductComponents, softwareProductCategories = []} = softwareProduct;
27         let {licensingData = {}} = currentSoftwareProduct;
28         let {licenseAgreementList} = licenseAgreement;
29         let {componentsList} = softwareProductComponents;
30         let licenseAgreementName = licenseAgreementList.find(la => la.id === licensingData.licenseAgreement);
31         if (licenseAgreementName) {
32                 licenseAgreementName = licenseAgreementName.name;
33         } else if (licenseAgreementList.length === 0) { // otherwise the state of traingle svgicon will be updated post unmounting
34                 licenseAgreementName = null;
35         }
36
37         let categoryName = '', subCategoryName = '', fullCategoryDisplayName = '';
38         const category = softwareProductCategories.find(ca => ca.uniqueId === currentSoftwareProduct.category);
39         if (category) {
40                 categoryName = category.name;
41                 const subcategories = category.subcategories || [];
42                 const subcat = subcategories.find(sc => sc.uniqueId === currentSoftwareProduct.subCategory);
43                 subCategoryName = subcat && subcat.name ? subcat.name : '';
44         }
45         fullCategoryDisplayName = `${subCategoryName} (${categoryName})`;
46
47         const isReadOnlyMode = VersionControllerUtils.isReadOnly(currentSoftwareProduct);
48
49         return {
50                 currentSoftwareProduct: {
51                         ...currentSoftwareProduct,
52                         licenseAgreementName,
53                         fullCategoryDisplayName
54                 },
55                 isReadOnlyMode,
56                 componentsList,
57                 isManual: currentSoftwareProduct.onboardingMethod === onboardingMethod.MANUAL
58         };
59 };
60
61 const mapActionsToProps = (dispatch, {version}) => {
62         return {
63                 onDetailsSelect: ({id: softwareProductId, vendorId: licenseModelId, version}) => OnboardingActionHelper.navigateToSoftwareProductDetails(dispatch, {
64                         softwareProductId,
65                         licenseModelId,
66                         version
67                 }),
68                 onUpload: (softwareProductId, formData) =>
69                         SoftwareProductActionHelper.uploadFile(dispatch, {
70                                 softwareProductId,
71                                 formData,
72                                 failedNotificationTitle: i18n('Upload validation failed'),
73                                 version
74                         }),
75
76                 onUploadConfirmation: (softwareProductId, formData) =>
77                         dispatch({
78                                 type: modalActionTypes.GLOBAL_MODAL_WARNING,
79                                 data:{
80                                         msg: i18n('Upload will erase existing data. Do you want to continue?'),
81                                         confirmationButtonText: i18n('Continue'),
82                                         title: i18n('Warning'),
83                                         onConfirmed: ()=>SoftwareProductActionHelper.uploadFile(dispatch, {
84                                                 softwareProductId,
85                                                 formData,
86                                                 failedNotificationTitle: i18n('Upload validation failed'),
87                                                 version
88                                         }),
89                                         onDeclined: () => dispatch({
90                                                 type: modalActionTypes.GLOBAL_MODAL_CLOSE
91                                         })
92                                 }
93                         }),
94
95                 onInvalidFileSizeUpload: () => dispatch({
96                         type: modalActionTypes.GLOBAL_MODAL_ERROR,
97                         data: {
98                                 title: i18n('Upload Failed'),
99                                 confirmationButtonText: i18n('Continue'),
100                                 msg: i18n('no zip or csar file was uploaded or expected file doesn\'t exist')
101                         }
102                 }),
103                 onComponentSelect: ({id: softwareProductId, componentId}) => {
104                         OnboardingActionHelper.navigateToSoftwareProductComponentGeneralAndUpdateLeftPanel(dispatch, {softwareProductId, componentId, version });
105                 },
106                 /** for the next version */
107                 onAddComponent: () => SoftwareProductActionHelper.addComponent(dispatch)
108         };
109 };
110
111 export default connect(mapStateToProps, mapActionsToProps, null, {withRef: true})(LandingPageView);