Add new code new version
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / softwareProduct / landingPage / SoftwareProductLandingPage.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 import {connect} from 'react-redux';
22
23 import i18n from 'nfvo-utils/i18n/i18n.js';
24 import VersionControllerUtils from 'nfvo-components/panel/versionController/VersionControllerUtils.js';
25 import NotificationConstants from 'nfvo-components/notifications/NotificationConstants.js';
26 import OnboardingActionHelper from 'sdc-app/onboarding/OnboardingActionHelper.js';
27 import SoftwareProductActionHelper from 'sdc-app/onboarding/softwareProduct/SoftwareProductActionHelper.js';
28 import LandingPageView from './SoftwareProductLandingPageView.jsx';
29
30 const mapStateToProps = ({softwareProduct, licenseModel: {licenseAgreement}}) => {
31         let {softwareProductEditor: {data:currentSoftwareProduct = {}}, softwareProductComponents, softwareProductCategories = []} = softwareProduct;
32         let {licensingData = {}} = currentSoftwareProduct;
33         let {licenseAgreementList} = licenseAgreement;
34         let {componentsList} = softwareProductComponents;
35         let licenseAgreementName = licenseAgreementList.find(la => la.id === licensingData.licenseAgreement);
36         if (licenseAgreementName) {
37                 licenseAgreementName = licenseAgreementName.name;
38         }
39
40         let categoryName = '', subCategoryName = '', fullCategoryDisplayName = '';
41         const category = softwareProductCategories.find(ca => ca.uniqueId === currentSoftwareProduct.category);
42         if (category) {
43                 categoryName = category.name;
44                 const subcategories = category.subcategories || [];
45                 const subcat = subcategories.find(sc => sc.uniqueId === currentSoftwareProduct.subCategory);
46                 subCategoryName = subcat && subcat.name ? subcat.name : '';
47         }
48         fullCategoryDisplayName = `${subCategoryName} (${categoryName})`;
49
50         const isReadOnlyMode = VersionControllerUtils.isReadOnly(currentSoftwareProduct);
51
52         return {
53                 currentSoftwareProduct: {
54                         ...currentSoftwareProduct,
55                         licenseAgreementName,
56                         fullCategoryDisplayName
57                 },
58                 isReadOnlyMode,
59                 componentsList
60         };
61 };
62
63 const mapActionsToProps = (dispatch, {version}) => {
64         return {
65                 onDetailsSelect: ({id: softwareProductId, vendorId: licenseModelId}) => OnboardingActionHelper.navigateToSoftwareProductDetails(dispatch, {
66                         softwareProductId,
67                         licenseModelId
68                 }),
69                 onAttachmentsSelect: ({id: softwareProductId}) => OnboardingActionHelper.navigateToSoftwareProductAttachments(dispatch, {softwareProductId}),
70                 onUpload: (softwareProductId, formData) =>
71                         SoftwareProductActionHelper.uploadFile(dispatch, {
72                                 softwareProductId,
73                                 formData,
74                                 failedNotificationTitle: i18n('Upload validation failed')
75                         }),
76                 onUploadConfirmation: (softwareProductId, formData) =>
77                         SoftwareProductActionHelper.uploadConfirmation(dispatch, {
78                                 softwareProductId,
79                                 formData,
80                                 failedNotificationTitle: i18n('Upload validation failed')}),
81
82                 onInvalidFileSizeUpload: () => dispatch({
83                         type: NotificationConstants.NOTIFY_ERROR,
84                         data: {
85                                 title: i18n('Upload Failed'),
86                                 msg: i18n('no zip file was uploaded or zip file doesn\'t exist')
87                         }
88                 }),
89                 onComponentSelect: ({id: softwareProductId, componentId}) => {
90                         OnboardingActionHelper.navigateToSoftwareProductComponentGeneralAndUpdateLeftPanel(dispatch, {softwareProductId, componentId, version });
91                 },
92                 /** for the next version */
93                 onAddComponent: () => SoftwareProductActionHelper.addComponent(dispatch)
94         };
95 };
96
97 export default connect(mapStateToProps, mapActionsToProps, null, {withRef: true})(LandingPageView);