[SDC] Onboarding 1710 rebase.
[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                 onAttachmentsSelect: ({id: softwareProductId}) => OnboardingActionHelper.navigateToSoftwareProductAttachments(dispatch, {softwareProductId, version}),
69                 onUpload: (softwareProductId, formData) =>
70                         SoftwareProductActionHelper.uploadFile(dispatch, {
71                                 softwareProductId,
72                                 formData,
73                                 failedNotificationTitle: i18n('Upload validation failed'),
74                                 version
75                         }),
76
77                 onUploadConfirmation: (softwareProductId, formData) =>
78                         dispatch({
79                                 type: modalActionTypes.GLOBAL_MODAL_WARNING,
80                                 data:{
81                                         msg: i18n('Upload will erase existing data. Do you want to continue?'),
82                                         confirmationButtonText: i18n('Continue'),
83                                         title: i18n('Warning'),
84                                         onConfirmed: ()=>SoftwareProductActionHelper.uploadFile(dispatch, {
85                                                 softwareProductId,
86                                                 formData,
87                                                 failedNotificationTitle: i18n('Upload validation failed'),
88                                                 version
89                                         }),
90                                         onDeclined: () => dispatch({
91                                                 type: modalActionTypes.GLOBAL_MODAL_CLOSE
92                                         })
93                                 }
94                         }),
95
96                 onInvalidFileSizeUpload: () => dispatch({
97                         type: modalActionTypes.GLOBAL_MODAL_ERROR,
98                         data: {
99                                 title: i18n('Upload Failed'),
100                                 confirmationButtonText: i18n('Continue'),
101                                 msg: i18n('no zip file was uploaded or zip file doesn\'t exist')
102                         }
103                 }),
104                 onComponentSelect: ({id: softwareProductId, componentId}) => {
105                         OnboardingActionHelper.navigateToSoftwareProductComponentGeneralAndUpdateLeftPanel(dispatch, {softwareProductId, componentId, version });
106                 },
107                 /** for the next version */
108                 onAddComponent: () => SoftwareProductActionHelper.addComponent(dispatch)
109         };
110 };
111
112 export default connect(mapStateToProps, mapActionsToProps, null, {withRef: true})(LandingPageView);