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