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 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';
26 export const mapStateToProps = ({
28 licenseModel: {licenseAgreement},
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;
41 let categoryName = '', subCategoryName = '', fullCategoryDisplayName = '';
42 const category = softwareProductCategories.find(ca => ca.uniqueId === currentSoftwareProduct.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 : '';
49 fullCategoryDisplayName = `${subCategoryName} (${categoryName})`;
53 currentSoftwareProduct: {
54 ...currentSoftwareProduct,
56 fullCategoryDisplayName
59 isManual: currentSoftwareProduct.onboardingMethod === onboardingMethod.MANUAL
63 const mapActionsToProps = (dispatch, {version}) => {
65 onDetailsSelect: ({id: softwareProductId}) =>
66 ScreensHelper.loadScreen(dispatch, {
67 screen: enums.SCREEN.SOFTWARE_PRODUCT_DETAILS, screenType: screenTypes.SOFTWARE_PRODUCT,
68 props: {softwareProductId, version}
71 onUpload: (softwareProductId, formData) =>
72 SoftwareProductActionHelper.uploadFile(dispatch, {
75 failedNotificationTitle: i18n('Upload validation failed'),
79 onUploadConfirmation: (softwareProductId, formData) =>
81 type: modalActionTypes.GLOBAL_MODAL_WARNING,
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, {
89 failedNotificationTitle: i18n('Upload validation failed'),
92 onDeclined: () => dispatch({
93 type: modalActionTypes.GLOBAL_MODAL_CLOSE
98 onInvalidFileSizeUpload: () => dispatch({
99 type: modalActionTypes.GLOBAL_MODAL_ERROR,
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')
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}
110 /** for the next version */
111 onAddComponent: () => SoftwareProductActionHelper.addComponent(dispatch)
115 export default connect(mapStateToProps, mapActionsToProps, null, {withRef: true})(LandingPageView);