2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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';
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;
36 let categoryName = '', subCategoryName = '', fullCategoryDisplayName = '';
37 const category = softwareProductCategories.find(ca => ca.uniqueId === currentSoftwareProduct.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 : '';
44 fullCategoryDisplayName = `${subCategoryName} (${categoryName})`;
46 const isReadOnlyMode = VersionControllerUtils.isReadOnly(currentSoftwareProduct);
49 currentSoftwareProduct: {
50 ...currentSoftwareProduct,
52 fullCategoryDisplayName
59 const mapActionsToProps = (dispatch, {version}) => {
61 onDetailsSelect: ({id: softwareProductId, vendorId: licenseModelId, version}) => OnboardingActionHelper.navigateToSoftwareProductDetails(dispatch, {
66 onAttachmentsSelect: ({id: softwareProductId}) => OnboardingActionHelper.navigateToSoftwareProductAttachments(dispatch, {softwareProductId, version}),
67 onUpload: (softwareProductId, formData) =>
68 SoftwareProductActionHelper.uploadFile(dispatch, {
71 failedNotificationTitle: i18n('Upload validation failed'),
75 onUploadConfirmation: (softwareProductId, formData) =>
77 type: modalActionTypes.GLOBAL_MODAL_WARNING,
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, {
85 failedNotificationTitle: i18n('Upload validation failed'),
88 onDeclined: () => dispatch({
89 type: modalActionTypes.GLOBAL_MODAL_CLOSE
94 onInvalidFileSizeUpload: () => dispatch({
95 type: modalActionTypes.GLOBAL_MODAL_ERROR,
97 title: i18n('Upload Failed'),
98 confirmationButtonText: i18n('Continue'),
99 msg: i18n('no zip file was uploaded or zip file doesn\'t exist')
102 onComponentSelect: ({id: softwareProductId, componentId}) => {
103 OnboardingActionHelper.navigateToSoftwareProductComponentGeneralAndUpdateLeftPanel(dispatch, {softwareProductId, componentId, version });
105 /** for the next version */
106 onAddComponent: () => SoftwareProductActionHelper.addComponent(dispatch)
110 export default connect(mapStateToProps, mapActionsToProps, null, {withRef: true})(LandingPageView);