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';
25 import VspUploadStatus from 'sdc-app/onboarding/softwareProduct/landingPage/VspUploadStatus';
27 export const mapStateToProps = ({
30 licenseModel: { licenseAgreement },
31 currentScreen: { itemPermission: { isCertified } }
34 softwareProductEditor: { data: currentSoftwareProduct = {} },
35 softwareProductComponents,
36 softwareProductCategories = []
38 let { licensingData = {} } = currentSoftwareProduct;
39 let { licenseAgreementList } = licenseAgreement;
40 let { componentsList } = softwareProductComponents;
41 let licenseAgreementName = licenseAgreementList.find(
42 la => la.id === licensingData.licenseAgreement
44 if (licenseAgreementName) {
45 licenseAgreementName = licenseAgreementName.name;
46 } else if (licenseAgreementList.length === 0) {
47 // otherwise the state of traingle svgicon will be updated post unmounting
48 licenseAgreementName = null;
51 let categoryName = '',
53 fullCategoryDisplayName = '';
54 const category = softwareProductCategories.find(
55 ca => ca.uniqueId === currentSoftwareProduct.category
58 categoryName = category.name;
59 const subcategories = category.subcategories || [];
60 const subcat = subcategories.find(
61 sc => sc.uniqueId === currentSoftwareProduct.subCategory
63 subCategoryName = subcat && subcat.name ? subcat.name : '';
65 fullCategoryDisplayName = `${subCategoryName} (${categoryName})`;
69 currentSoftwareProduct: {
70 ...currentSoftwareProduct,
72 fullCategoryDisplayName
77 currentSoftwareProduct.onboardingMethod === onboardingMethod.MANUAL
81 function handleScreenChange(softwareProduct, dispatch, version) {
82 const softwareProductId = softwareProduct.id;
83 if (softwareProduct.licenseType === 'INTERNAL') {
84 ScreensHelper.loadScreen(dispatch, {
85 screen: enums.SCREEN.SOFTWARE_PRODUCT_DETAILS,
86 screenType: screenTypes.SOFTWARE_PRODUCT,
87 props: { softwareProductId, version }
90 ScreensHelper.loadScreen(dispatch, {
91 screen: enums.SCREEN.SOFTWARE_PRODUCT_LANDING_PAGE,
92 screenType: screenTypes.SOFTWARE_PRODUCT,
93 props: { softwareProductId, version }
98 const mapActionsToProps = (dispatch, { version }) => {
100 onLicenseChange: softwareProduct => {
101 SoftwareProductActionHelper.updateSoftwareProductData(dispatch, {
105 handleScreenChange(softwareProduct, dispatch, version);
107 onCandidateInProcess: softwareProductId =>
108 ScreensHelper.loadScreen(dispatch, {
109 screen: enums.SCREEN.SOFTWARE_PRODUCT_ATTACHMENTS_SETUP,
110 screenType: screenTypes.SOFTWARE_PRODUCT,
111 props: { softwareProductId, version }
116 onUploadStart = () => {
117 // do nothing by default
119 onUploadProgress = undefined,
120 onUploadFinished = () => {
121 // do nothing by default
124 SoftwareProductActionHelper.createUploadStatus(
129 const vspUploadStatus = new VspUploadStatus(response);
130 onUploadStart(vspUploadStatus);
131 SoftwareProductActionHelper.uploadFile(dispatch, {
134 failedNotificationTitle: i18n(
135 'Upload validation failed'
145 type: modalActionTypes.GLOBAL_MODAL_ERROR,
147 title: i18n('upload.failed'),
154 onUploadConfirmation: (
157 onUploadStart = () => {
158 // do nothing by default
160 onUploadProgress = undefined,
161 onUploadFinished = () => {
162 // do nothing by default
166 type: modalActionTypes.GLOBAL_MODAL_WARNING,
169 'Upload will erase existing data. Do you want to continue?'
171 confirmationButtonText: i18n('Continue'),
172 title: i18n('Warning'),
174 SoftwareProductActionHelper.createUploadStatus(
179 const vspUploadStatus = new VspUploadStatus(
182 onUploadStart(vspUploadStatus);
183 SoftwareProductActionHelper.uploadFile(
188 failedNotificationTitle: i18n(
189 'Upload validation failed'
200 type: modalActionTypes.GLOBAL_MODAL_ERROR,
202 title: i18n('upload.failed'),
210 type: modalActionTypes.GLOBAL_MODAL_CLOSE
215 onInvalidFileSizeUpload: () =>
217 type: modalActionTypes.GLOBAL_MODAL_ERROR,
219 title: i18n('Upload Failed'),
220 confirmationButtonText: i18n('Continue'),
222 "no zip or csar file was uploaded or expected file doesn't exist"
227 fetchUploadStatus: softwareProductId => {
228 return SoftwareProductActionHelper.fetchUploadStatus(
234 onComponentSelect: ({ id: softwareProductId, componentId }) =>
235 ScreensHelper.loadScreen(dispatch, {
236 screen: screenTypes.SOFTWARE_PRODUCT_COMPONENT_DEFAULT_GENERAL,
237 screenType: screenTypes.SOFTWARE_PRODUCT,
238 props: { softwareProductId, version, componentId }
240 /** for the next version */
241 onAddComponent: () =>
242 SoftwareProductActionHelper.addComponent(dispatch),
244 onBrowseVNF: currentSoftwareProduct => {
245 VNFImportActionHelper.open(dispatch, currentSoftwareProduct);
250 export default connect(mapStateToProps, mapActionsToProps, null, {