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';
23 import {onboardingMethod} from '../SoftwareProductConstants.js';
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;
37 let categoryName = '', subCategoryName = '', fullCategoryDisplayName = '';
38 const category = softwareProductCategories.find(ca => ca.uniqueId === currentSoftwareProduct.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 : '';
45 fullCategoryDisplayName = `${subCategoryName} (${categoryName})`;
47 const isReadOnlyMode = VersionControllerUtils.isReadOnly(currentSoftwareProduct);
50 currentSoftwareProduct: {
51 ...currentSoftwareProduct,
53 fullCategoryDisplayName
57 isManual: currentSoftwareProduct.onboardingMethod === onboardingMethod.MANUAL
61 const mapActionsToProps = (dispatch, {version}) => {
63 onDetailsSelect: ({id: softwareProductId, vendorId: licenseModelId, version}) => OnboardingActionHelper.navigateToSoftwareProductDetails(dispatch, {
68 onUpload: (softwareProductId, formData) =>
69 SoftwareProductActionHelper.uploadFile(dispatch, {
72 failedNotificationTitle: i18n('Upload validation failed'),
76 onUploadConfirmation: (softwareProductId, formData) =>
78 type: modalActionTypes.GLOBAL_MODAL_WARNING,
80 msg: i18n('Upload will erase existing data. Do you want to continue?'),
81 confirmationButtonText: i18n('Continue'),
82 title: i18n('Warning'),
83 onConfirmed: ()=>SoftwareProductActionHelper.uploadFile(dispatch, {
86 failedNotificationTitle: i18n('Upload validation failed'),
89 onDeclined: () => dispatch({
90 type: modalActionTypes.GLOBAL_MODAL_CLOSE
95 onInvalidFileSizeUpload: () => dispatch({
96 type: modalActionTypes.GLOBAL_MODAL_ERROR,
98 title: i18n('Upload Failed'),
99 confirmationButtonText: i18n('Continue'),
100 msg: i18n('no zip or csar file was uploaded or expected file doesn\'t exist')
103 onComponentSelect: ({id: softwareProductId, componentId}) => {
104 OnboardingActionHelper.navigateToSoftwareProductComponentGeneralAndUpdateLeftPanel(dispatch, {softwareProductId, componentId, version });
106 /** for the next version */
107 onAddComponent: () => SoftwareProductActionHelper.addComponent(dispatch)
111 export default connect(mapStateToProps, mapActionsToProps, null, {withRef: true})(LandingPageView);