blob: 3422920b3a675b7cd5592929eed3793839006051 [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17import {connect} from 'react-redux';
18import OnboardView from './OnboardView.jsx';
AviZi280f8012017-06-09 02:39:56 +030019import OnboardingCatalogActionHelper from './onboardingCatalog/OnboardingCatalogActionHelper.js';
20import OnboardActionHelper from './OnboardActionHelper.js';
21import LicenseModelCreationActionHelper from '../licenseModel/creation/LicenseModelCreationActionHelper.js';
22import SoftwareProductCreationActionHelper from '../softwareProduct/creation/SoftwareProductCreationActionHelper.js';
23import sortByStringProperty from 'nfvo-utils/sortByStringProperty.js';
talig8e9c0652017-12-20 14:30:43 +020024import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js';
25import {enums, screenTypes} from 'sdc-app/onboarding/OnboardingConstants.js';
26
AviZi280f8012017-06-09 02:39:56 +030027
28export const mapStateToProps = ({
talig8e9c0652017-12-20 14:30:43 +020029 onboard: {
30 onboardingCatalog,
31 activeTab,
32 searchValue
33 },
34 licenseModelList,
35 users,
36 finalizedLicenseModelList,
37 softwareProductList,
38 finalizedSoftwareProductList
AviZi280f8012017-06-09 02:39:56 +030039}) => {
40
talig8e9c0652017-12-20 14:30:43 +020041 const fullSoftwareProducts = softwareProductList.filter(vsp =>
42 !finalizedSoftwareProductList
43 .find(fvsp => fvsp.id === vsp.id)
44 ).concat(finalizedSoftwareProductList);
45
46 const reduceLicenseModelList = (accum, vlm) => {
AviZi280f8012017-06-09 02:39:56 +030047 let currentSoftwareProductList = sortByStringProperty(
talig8e9c0652017-12-20 14:30:43 +020048 fullSoftwareProducts
AviZi280f8012017-06-09 02:39:56 +030049 .filter(vsp => vsp.vendorId === vlm.id),
50 'name'
51 );
52 accum.push({...vlm, softwareProductList: currentSoftwareProductList});
53 return accum;
54 };
55
talig8e9c0652017-12-20 14:30:43 +020056 licenseModelList = sortByStringProperty(
AviZi280f8012017-06-09 02:39:56 +030057 licenseModelList
AviZi280f8012017-06-09 02:39:56 +030058 .reduce(reduceLicenseModelList, []),
AviZi280f8012017-06-09 02:39:56 +030059 'name'
60 );
61
talig8e9c0652017-12-20 14:30:43 +020062 finalizedLicenseModelList = sortByStringProperty(
63 finalizedLicenseModelList
64 .reduce(reduceLicenseModelList, []),
65 'name'
66 );
67
68 const fullLicenseModelList = licenseModelList.filter(vlm =>
69 !finalizedLicenseModelList
70 .find(fvlm => fvlm.id === vlm.id)
71 ).concat(finalizedLicenseModelList);
AviZi280f8012017-06-09 02:39:56 +030072
73 let {activeTab: catalogActiveTab, vendorCatalog: {vspOverlay, selectedVendor}} = onboardingCatalog;
74
75 return {
76 finalizedLicenseModelList,
77 finalizedSoftwareProductList,
78 licenseModelList,
79 softwareProductList,
talig8e9c0652017-12-20 14:30:43 +020080 fullLicenseModelList,
AviZi280f8012017-06-09 02:39:56 +030081 activeTab,
82 catalogActiveTab,
83 searchValue,
84 vspOverlay,
talig8e9c0652017-12-20 14:30:43 +020085 selectedVendor,
86 users: users.usersList
AviZi280f8012017-06-09 02:39:56 +030087 };
talig8e9c0652017-12-20 14:30:43 +020088
AviZi280f8012017-06-09 02:39:56 +030089};
90
91const mapActionsToProps = (dispatch) => {
talig8e9c0652017-12-20 14:30:43 +020092
AviZi280f8012017-06-09 02:39:56 +030093 return {
talig8e9c0652017-12-20 14:30:43 +020094 onSelectLicenseModel({id: licenseModelId, name}, users) {
95 ScreensHelper.loadScreen(dispatch, {
96 screen: enums.SCREEN.VERSIONS_PAGE, screenType: screenTypes.LICENSE_MODEL,
97 props: {licenseModelId, licenseModel: {name}, usersList: users}
98 });
AviZi280f8012017-06-09 02:39:56 +030099 },
talig8e9c0652017-12-20 14:30:43 +0200100 onSelectSoftwareProduct(softwareProduct, users) {
101 let {id: softwareProductId, vendorId: licenseModelId, licensingVersion, name} = softwareProduct;
102 ScreensHelper.loadScreen(dispatch, {
103 screen: enums.SCREEN.SOFTWARE_PRODUCT_VERSIONS_PAGE, screenType: screenTypes.SOFTWARE_PRODUCT,
104 props: {softwareProductId, softwareProduct: {name, vendorId: licenseModelId, licensingVersion}, usersList: users}
105 });
AviZi280f8012017-06-09 02:39:56 +0300106 },
107 onAddSoftwareProductClick: (vendorId) => SoftwareProductCreationActionHelper.open(dispatch, vendorId),
108 onAddLicenseModelClick: () => LicenseModelCreationActionHelper.open(dispatch),
109 onVspOverlayChange: (vendor) => OnboardingCatalogActionHelper.changeVspOverlay(dispatch, vendor),
110 closeVspOverlay: () => OnboardingCatalogActionHelper.closeVspOverlay(dispatch),
111 onCatalogTabClick: (tab) => OnboardingCatalogActionHelper.changeActiveTab(dispatch, tab),
112 onTabClick: (tab) => OnboardActionHelper.changeActiveTab(dispatch, tab),
113 onSearch: (searchValue) => OnboardActionHelper.changeSearchValue(dispatch, searchValue),
114 onVendorSelect: (vendor) => OnboardingCatalogActionHelper.onVendorSelect(dispatch, {vendor}),
115 onMigrate: ({softwareProduct}) => OnboardingCatalogActionHelper.onMigrate(dispatch, softwareProduct)
116 };
talig8e9c0652017-12-20 14:30:43 +0200117
AviZi280f8012017-06-09 02:39:56 +0300118};
119
120export default connect(mapStateToProps, mapActionsToProps)(OnboardView);