blob: a1e00181141a183280ffbe1941001dfe38b34e95 [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
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020017import { connect } from 'react-redux';
AviZi280f8012017-06-09 02:39:56 +030018import 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';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020024import { tabsMapping } from './onboardingCatalog/OnboardingCatalogConstants.js';
25import { itemsType } from './filter/FilterConstants.js';
AviZi280f8012017-06-09 02:39:56 +030026
27export const mapStateToProps = ({
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020028 onboard: { onboardingCatalog, activeTab, searchValue, filter },
29 licenseModelList,
30 users,
31 archivedLicenseModelList,
32 archivedSoftwareProductList,
33 finalizedLicenseModelList,
34 softwareProductList,
35 finalizedSoftwareProductList
AviZi280f8012017-06-09 02:39:56 +030036}) => {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020037 const fullSoftwareProducts = softwareProductList
38 .filter(
39 vsp =>
40 !finalizedSoftwareProductList.find(fvsp => fvsp.id === vsp.id)
41 )
42 .concat(finalizedSoftwareProductList);
AviZi280f8012017-06-09 02:39:56 +030043
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020044 const reduceLicenseModelList = (accum, vlm) => {
45 let currentSoftwareProductList = sortByStringProperty(
46 fullSoftwareProducts.filter(vsp => vsp.vendorId === vlm.id),
47 'name'
48 );
49 accum.push({ ...vlm, softwareProductList: currentSoftwareProductList });
50 return accum;
51 };
talig8e9c0652017-12-20 14:30:43 +020052
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020053 licenseModelList = sortByStringProperty(
54 licenseModelList.reduce(reduceLicenseModelList, []),
55 'name'
56 );
AviZi280f8012017-06-09 02:39:56 +030057
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020058 finalizedLicenseModelList = sortByStringProperty(
59 finalizedLicenseModelList.reduce(reduceLicenseModelList, []),
60 'name'
61 );
AviZi280f8012017-06-09 02:39:56 +030062
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020063 const fullLicenseModelList = licenseModelList
64 .filter(
65 vlm => !finalizedLicenseModelList.find(fvlm => fvlm.id === vlm.id)
66 )
67 .concat(finalizedLicenseModelList);
talig8e9c0652017-12-20 14:30:43 +020068
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020069 let {
70 activeTab: catalogActiveTab,
71 vendorCatalog: { vspOverlay, selectedVendor }
72 } = onboardingCatalog;
73 if (filter.byVendorView) {
74 catalogActiveTab = tabsMapping.BY_VENDOR;
75 } else if (filter.itemsType && filter.itemsType === itemsType.ARCHIVED) {
76 catalogActiveTab = tabsMapping.ARCHIVE;
77 }
AviZi280f8012017-06-09 02:39:56 +030078
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020079 return {
80 finalizedLicenseModelList,
81 finalizedSoftwareProductList,
82 licenseModelList,
83 softwareProductList,
84 archivedLicenseModelList,
85 archivedSoftwareProductList,
86 fullLicenseModelList,
87 activeTab,
88 catalogActiveTab,
89 searchValue,
90 vspOverlay,
91 selectedVendor,
92 users: users.usersList
93 };
AviZi280f8012017-06-09 02:39:56 +030094};
95
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020096const mapActionsToProps = dispatch => {
97 return {
98 onSelectLicenseModel({ id: licenseModelId, name }, users, tab) {
99 OnboardActionHelper.loadVLMScreen(
100 dispatch,
101 { id: licenseModelId, name },
102 users,
103 tab
104 );
105 },
106 onSelectSoftwareProduct(softwareProduct, users, tab) {
107 OnboardActionHelper.loadVSPScreen(
108 dispatch,
109 softwareProduct,
110 users,
111 tab
112 );
113 },
114 onAddSoftwareProductClick: vendorId =>
115 SoftwareProductCreationActionHelper.open(dispatch, vendorId),
116 onAddLicenseModelClick: () =>
117 LicenseModelCreationActionHelper.open(dispatch),
118 onVspOverlayChange: vendor =>
119 OnboardingCatalogActionHelper.changeVspOverlay(dispatch, vendor),
120 closeVspOverlay: () =>
121 OnboardingCatalogActionHelper.closeVspOverlay(dispatch),
122 onCatalogTabClick: tab =>
123 OnboardingCatalogActionHelper.changeActiveTab(dispatch, tab),
124 onTabClick: tab => OnboardActionHelper.changeActiveTab(dispatch, tab),
125 onSearch: searchValue =>
126 OnboardActionHelper.changeSearchValue(dispatch, searchValue),
127 onVendorSelect: vendor =>
128 OnboardingCatalogActionHelper.onVendorSelect(dispatch, { vendor }),
129 onMigrate: ({ softwareProduct }) =>
130 OnboardingCatalogActionHelper.onMigrate(dispatch, softwareProduct)
131 };
AviZi280f8012017-06-09 02:39:56 +0300132};
133
134export default connect(mapStateToProps, mapActionsToProps)(OnboardView);