blob: a308e1ec5ef0e1ede62e724dada2a69d9932636a [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 +020024
AviZi280f8012017-06-09 02:39:56 +030025
26export const mapStateToProps = ({
talig8e9c0652017-12-20 14:30:43 +020027 onboard: {
28 onboardingCatalog,
29 activeTab,
30 searchValue
31 },
32 licenseModelList,
33 users,
34 finalizedLicenseModelList,
35 softwareProductList,
36 finalizedSoftwareProductList
AviZi280f8012017-06-09 02:39:56 +030037}) => {
38
talig8e9c0652017-12-20 14:30:43 +020039 const fullSoftwareProducts = softwareProductList.filter(vsp =>
40 !finalizedSoftwareProductList
41 .find(fvsp => fvsp.id === vsp.id)
42 ).concat(finalizedSoftwareProductList);
43
44 const reduceLicenseModelList = (accum, vlm) => {
AviZi280f8012017-06-09 02:39:56 +030045 let currentSoftwareProductList = sortByStringProperty(
talig8e9c0652017-12-20 14:30:43 +020046 fullSoftwareProducts
AviZi280f8012017-06-09 02:39:56 +030047 .filter(vsp => vsp.vendorId === vlm.id),
48 'name'
49 );
50 accum.push({...vlm, softwareProductList: currentSoftwareProductList});
51 return accum;
52 };
53
talig8e9c0652017-12-20 14:30:43 +020054 licenseModelList = sortByStringProperty(
AviZi280f8012017-06-09 02:39:56 +030055 licenseModelList
AviZi280f8012017-06-09 02:39:56 +030056 .reduce(reduceLicenseModelList, []),
AviZi280f8012017-06-09 02:39:56 +030057 'name'
58 );
59
talig8e9c0652017-12-20 14:30:43 +020060 finalizedLicenseModelList = sortByStringProperty(
61 finalizedLicenseModelList
62 .reduce(reduceLicenseModelList, []),
63 'name'
64 );
65
66 const fullLicenseModelList = licenseModelList.filter(vlm =>
67 !finalizedLicenseModelList
68 .find(fvlm => fvlm.id === vlm.id)
69 ).concat(finalizedLicenseModelList);
AviZi280f8012017-06-09 02:39:56 +030070
71 let {activeTab: catalogActiveTab, vendorCatalog: {vspOverlay, selectedVendor}} = onboardingCatalog;
72
73 return {
74 finalizedLicenseModelList,
75 finalizedSoftwareProductList,
76 licenseModelList,
77 softwareProductList,
talig8e9c0652017-12-20 14:30:43 +020078 fullLicenseModelList,
AviZi280f8012017-06-09 02:39:56 +030079 activeTab,
80 catalogActiveTab,
81 searchValue,
82 vspOverlay,
talig8e9c0652017-12-20 14:30:43 +020083 selectedVendor,
84 users: users.usersList
AviZi280f8012017-06-09 02:39:56 +030085 };
talig8e9c0652017-12-20 14:30:43 +020086
AviZi280f8012017-06-09 02:39:56 +030087};
88
89const mapActionsToProps = (dispatch) => {
talig8e9c0652017-12-20 14:30:43 +020090
AviZi280f8012017-06-09 02:39:56 +030091 return {
miriamed411d152018-01-02 15:35:55 +020092 onSelectLicenseModel({id: licenseModelId, name}, users, tab) {
93 OnboardActionHelper.loadVLMScreen(dispatch, {id: licenseModelId, name}, users, tab);
AviZi280f8012017-06-09 02:39:56 +030094 },
miriamed411d152018-01-02 15:35:55 +020095 onSelectSoftwareProduct(softwareProduct, users, tab) {
96 OnboardActionHelper.loadVSPScreen(dispatch, softwareProduct, users, tab);
AviZi280f8012017-06-09 02:39:56 +030097 },
98 onAddSoftwareProductClick: (vendorId) => SoftwareProductCreationActionHelper.open(dispatch, vendorId),
99 onAddLicenseModelClick: () => LicenseModelCreationActionHelper.open(dispatch),
100 onVspOverlayChange: (vendor) => OnboardingCatalogActionHelper.changeVspOverlay(dispatch, vendor),
101 closeVspOverlay: () => OnboardingCatalogActionHelper.closeVspOverlay(dispatch),
102 onCatalogTabClick: (tab) => OnboardingCatalogActionHelper.changeActiveTab(dispatch, tab),
103 onTabClick: (tab) => OnboardActionHelper.changeActiveTab(dispatch, tab),
104 onSearch: (searchValue) => OnboardActionHelper.changeSearchValue(dispatch, searchValue),
105 onVendorSelect: (vendor) => OnboardingCatalogActionHelper.onVendorSelect(dispatch, {vendor}),
106 onMigrate: ({softwareProduct}) => OnboardingCatalogActionHelper.onMigrate(dispatch, softwareProduct)
107 };
talig8e9c0652017-12-20 14:30:43 +0200108
AviZi280f8012017-06-09 02:39:56 +0300109};
110
111export default connect(mapStateToProps, mapActionsToProps)(OnboardView);