2 * Copyright © 2016-2018 European Support Limited
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';
24 import VNFImportActionHelper from '../vnfMarketPlace/VNFImportActionHelper.js';
26 export const mapStateToProps = ({
29 licenseModel: { licenseAgreement },
30 currentScreen: { itemPermission: { isCertified } }
33 softwareProductEditor: { data: currentSoftwareProduct = {} },
34 softwareProductComponents,
35 softwareProductCategories = []
37 let { licensingData = {} } = currentSoftwareProduct;
38 let { licenseAgreementList } = licenseAgreement;
39 let { componentsList } = softwareProductComponents;
40 let licenseAgreementName = licenseAgreementList.find(
41 la => la.id === licensingData.licenseAgreement
43 if (licenseAgreementName) {
44 licenseAgreementName = licenseAgreementName.name;
45 } else if (licenseAgreementList.length === 0) {
46 // otherwise the state of traingle svgicon will be updated post unmounting
47 licenseAgreementName = null;
50 let categoryName = '',
52 fullCategoryDisplayName = '';
53 const category = softwareProductCategories.find(
54 ca => ca.uniqueId === currentSoftwareProduct.category
57 categoryName = category.name;
58 const subcategories = category.subcategories || [];
59 const subcat = subcategories.find(
60 sc => sc.uniqueId === currentSoftwareProduct.subCategory
62 subCategoryName = subcat && subcat.name ? subcat.name : '';
64 fullCategoryDisplayName = `${subCategoryName} (${categoryName})`;
68 currentSoftwareProduct: {
69 ...currentSoftwareProduct,
71 fullCategoryDisplayName
76 currentSoftwareProduct.onboardingMethod === onboardingMethod.MANUAL
80 function handleScreenChange(softwareProduct, dispatch, version) {
81 const softwareProductId = softwareProduct.id;
82 if (softwareProduct.licenseType === 'INTERNAL') {
83 ScreensHelper.loadScreen(dispatch, {
84 screen: enums.SCREEN.SOFTWARE_PRODUCT_DETAILS,
85 screenType: screenTypes.SOFTWARE_PRODUCT,
86 props: { softwareProductId, version }
89 ScreensHelper.loadScreen(dispatch, {
90 screen: enums.SCREEN.SOFTWARE_PRODUCT_LANDING_PAGE,
91 screenType: screenTypes.SOFTWARE_PRODUCT,
92 props: { softwareProductId, version }
97 const mapActionsToProps = (dispatch, { version }) => {
99 onLicenseChange: softwareProduct => {
100 SoftwareProductActionHelper.updateSoftwareProductData(dispatch, {
104 handleScreenChange(softwareProduct, dispatch, version);
106 onCandidateInProcess: softwareProductId =>
107 ScreensHelper.loadScreen(dispatch, {
108 screen: enums.SCREEN.SOFTWARE_PRODUCT_ATTACHMENTS_SETUP,
109 screenType: screenTypes.SOFTWARE_PRODUCT,
110 props: { softwareProductId, version }
115 onUploadStart = () => {
116 // do nothing by default
118 onUploadProgress = undefined,
119 onUploadFinished = () => {
120 // do nothing by default
123 SoftwareProductActionHelper.uploadFile(dispatch, {
126 failedNotificationTitle: i18n('Upload validation failed'),
135 onUploadConfirmation: (
138 onUploadStart = () => {
139 // do nothing by default
141 onUploadProgress = undefined,
142 onUploadFinished = () => {
143 // do nothing by default
147 type: modalActionTypes.GLOBAL_MODAL_WARNING,
150 'Upload will erase existing data. Do you want to continue?'
152 confirmationButtonText: i18n('Continue'),
153 title: i18n('Warning'),
155 SoftwareProductActionHelper.uploadFile(dispatch, {
158 failedNotificationTitle: i18n(
159 'Upload validation failed'
163 }).finally(value => {
164 console.log('upload finished', value);
171 type: modalActionTypes.GLOBAL_MODAL_CLOSE
176 onInvalidFileSizeUpload: () =>
178 type: modalActionTypes.GLOBAL_MODAL_ERROR,
180 title: i18n('Upload Failed'),
181 confirmationButtonText: i18n('Continue'),
183 "no zip or csar file was uploaded or expected file doesn't exist"
188 fetchUploadStatus: softwareProductId => {
189 return SoftwareProductActionHelper.fetchUploadStatus(
195 onComponentSelect: ({ id: softwareProductId, componentId }) =>
196 ScreensHelper.loadScreen(dispatch, {
197 screen: screenTypes.SOFTWARE_PRODUCT_COMPONENT_DEFAULT_GENERAL,
198 screenType: screenTypes.SOFTWARE_PRODUCT,
199 props: { softwareProductId, version, componentId }
201 /** for the next version */
202 onAddComponent: () =>
203 SoftwareProductActionHelper.addComponent(dispatch),
205 onBrowseVNF: currentSoftwareProduct => {
206 VNFImportActionHelper.open(dispatch, currentSoftwareProduct);
211 export default connect(mapStateToProps, mapActionsToProps, null, {