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