blob: 9535147a461a5d813a8fe1d59d813c11c84c1b9a [file] [log] [blame]
svishnev091edfd2018-03-19 12:15:19 +02001/*
2 * Copyright © 2016-2018 European Support Limited
AviZi280f8012017-06-09 02:39:56 +03003 *
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
svishnev091edfd2018-03-19 12:15:19 +02007 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
AviZi280f8012017-06-09 02:39:56 +030010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
svishnev091edfd2018-03-19 12:15:19 +020012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
AviZi280f8012017-06-09 02:39:56 +030015 */
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';
svishnev091edfd2018-03-19 12:15:19 +020024import {tabsMapping} from './onboardingCatalog/OnboardingCatalogConstants.js';
25import {itemsType} from './filter/FilterConstants.js';
AviZi280f8012017-06-09 02:39:56 +030026
27export const mapStateToProps = ({
talig8e9c0652017-12-20 14:30:43 +020028 onboard: {
29 onboardingCatalog,
30 activeTab,
svishnev091edfd2018-03-19 12:15:19 +020031 searchValue,
32 filter
talig8e9c0652017-12-20 14:30:43 +020033 },
34 licenseModelList,
35 users,
svishnev091edfd2018-03-19 12:15:19 +020036 archivedLicenseModelList,
37 archivedSoftwareProductList,
talig8e9c0652017-12-20 14:30:43 +020038 finalizedLicenseModelList,
39 softwareProductList,
40 finalizedSoftwareProductList
AviZi280f8012017-06-09 02:39:56 +030041}) => {
42
talig8e9c0652017-12-20 14:30:43 +020043 const fullSoftwareProducts = softwareProductList.filter(vsp =>
44 !finalizedSoftwareProductList
45 .find(fvsp => fvsp.id === vsp.id)
46 ).concat(finalizedSoftwareProductList);
47
48 const reduceLicenseModelList = (accum, vlm) => {
AviZi280f8012017-06-09 02:39:56 +030049 let currentSoftwareProductList = sortByStringProperty(
talig8e9c0652017-12-20 14:30:43 +020050 fullSoftwareProducts
AviZi280f8012017-06-09 02:39:56 +030051 .filter(vsp => vsp.vendorId === vlm.id),
52 'name'
53 );
54 accum.push({...vlm, softwareProductList: currentSoftwareProductList});
55 return accum;
56 };
57
talig8e9c0652017-12-20 14:30:43 +020058 licenseModelList = sortByStringProperty(
AviZi280f8012017-06-09 02:39:56 +030059 licenseModelList
AviZi280f8012017-06-09 02:39:56 +030060 .reduce(reduceLicenseModelList, []),
AviZi280f8012017-06-09 02:39:56 +030061 'name'
62 );
63
talig8e9c0652017-12-20 14:30:43 +020064 finalizedLicenseModelList = sortByStringProperty(
65 finalizedLicenseModelList
66 .reduce(reduceLicenseModelList, []),
67 'name'
68 );
69
70 const fullLicenseModelList = licenseModelList.filter(vlm =>
71 !finalizedLicenseModelList
72 .find(fvlm => fvlm.id === vlm.id)
73 ).concat(finalizedLicenseModelList);
AviZi280f8012017-06-09 02:39:56 +030074
75 let {activeTab: catalogActiveTab, vendorCatalog: {vspOverlay, selectedVendor}} = onboardingCatalog;
svishnev091edfd2018-03-19 12:15:19 +020076 if (filter.byVendorView) {
77 catalogActiveTab = tabsMapping.BY_VENDOR;
78 }
79 else if (filter.itemsType && filter.itemsType === itemsType.ARCHIVED) {
80 catalogActiveTab = tabsMapping.ARCHIVE;
81 }
AviZi280f8012017-06-09 02:39:56 +030082
83 return {
84 finalizedLicenseModelList,
85 finalizedSoftwareProductList,
86 licenseModelList,
87 softwareProductList,
svishnev091edfd2018-03-19 12:15:19 +020088 archivedLicenseModelList,
89 archivedSoftwareProductList,
talig8e9c0652017-12-20 14:30:43 +020090 fullLicenseModelList,
AviZi280f8012017-06-09 02:39:56 +030091 activeTab,
92 catalogActiveTab,
93 searchValue,
94 vspOverlay,
talig8e9c0652017-12-20 14:30:43 +020095 selectedVendor,
96 users: users.usersList
AviZi280f8012017-06-09 02:39:56 +030097 };
talig8e9c0652017-12-20 14:30:43 +020098
AviZi280f8012017-06-09 02:39:56 +030099};
100
101const mapActionsToProps = (dispatch) => {
talig8e9c0652017-12-20 14:30:43 +0200102
AviZi280f8012017-06-09 02:39:56 +0300103 return {
miriamed411d152018-01-02 15:35:55 +0200104 onSelectLicenseModel({id: licenseModelId, name}, users, tab) {
105 OnboardActionHelper.loadVLMScreen(dispatch, {id: licenseModelId, name}, users, tab);
AviZi280f8012017-06-09 02:39:56 +0300106 },
miriamed411d152018-01-02 15:35:55 +0200107 onSelectSoftwareProduct(softwareProduct, users, tab) {
108 OnboardActionHelper.loadVSPScreen(dispatch, softwareProduct, users, tab);
AviZi280f8012017-06-09 02:39:56 +0300109 },
110 onAddSoftwareProductClick: (vendorId) => SoftwareProductCreationActionHelper.open(dispatch, vendorId),
111 onAddLicenseModelClick: () => LicenseModelCreationActionHelper.open(dispatch),
112 onVspOverlayChange: (vendor) => OnboardingCatalogActionHelper.changeVspOverlay(dispatch, vendor),
113 closeVspOverlay: () => OnboardingCatalogActionHelper.closeVspOverlay(dispatch),
114 onCatalogTabClick: (tab) => OnboardingCatalogActionHelper.changeActiveTab(dispatch, tab),
115 onTabClick: (tab) => OnboardActionHelper.changeActiveTab(dispatch, tab),
116 onSearch: (searchValue) => OnboardActionHelper.changeSearchValue(dispatch, searchValue),
117 onVendorSelect: (vendor) => OnboardingCatalogActionHelper.onVendorSelect(dispatch, {vendor}),
118 onMigrate: ({softwareProduct}) => OnboardingCatalogActionHelper.onMigrate(dispatch, softwareProduct)
119 };
AviZi280f8012017-06-09 02:39:56 +0300120};
121
122export default connect(mapStateToProps, mapActionsToProps)(OnboardView);