blob: ea70f9c0b8123315c508d74982e8c70207c3d3cb [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';
svishnevea5e43c2018-04-15 09:06:57 +030025import { itemStatus } from 'sdc-app/common/helpers/ItemsHelperConstants.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,
svishnevea5e43c2018-04-15 09:06:57 +030035 finalizedSoftwareProductList,
36 filteredItems
AviZi280f8012017-06-09 02:39:56 +030037}) => {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020038 const fullSoftwareProducts = softwareProductList
39 .filter(
40 vsp =>
41 !finalizedSoftwareProductList.find(fvsp => fvsp.id === vsp.id)
42 )
43 .concat(finalizedSoftwareProductList);
AviZi280f8012017-06-09 02:39:56 +030044
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020045 const reduceLicenseModelList = (accum, vlm) => {
46 let currentSoftwareProductList = sortByStringProperty(
47 fullSoftwareProducts.filter(vsp => vsp.vendorId === vlm.id),
48 'name'
49 );
50 accum.push({ ...vlm, softwareProductList: currentSoftwareProductList });
51 return accum;
52 };
talig8e9c0652017-12-20 14:30:43 +020053
svishnevea5e43c2018-04-15 09:06:57 +030054 const reduceFilteredLicenseModelList = (accum, vlm) => {
55 let currentSoftwareProductList = sortByStringProperty(
56 filteredItems.vspList.filter(vsp => vsp.vendorId === vlm.id),
57 'name'
58 );
59 accum.push({ ...vlm, softwareProductList: currentSoftwareProductList });
60 return accum;
61 };
62
63 const updatedFilteredItems = {
64 vspList: [...filteredItems.vspList],
65 vlmList: sortByStringProperty(
66 filteredItems.vlmList.reduce(reduceFilteredLicenseModelList, []),
67 'name'
68 )
69 };
70
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020071 licenseModelList = sortByStringProperty(
72 licenseModelList.reduce(reduceLicenseModelList, []),
73 'name'
74 );
AviZi280f8012017-06-09 02:39:56 +030075
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020076 finalizedLicenseModelList = sortByStringProperty(
77 finalizedLicenseModelList.reduce(reduceLicenseModelList, []),
78 'name'
79 );
AviZi280f8012017-06-09 02:39:56 +030080
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020081 const fullLicenseModelList = licenseModelList
82 .filter(
83 vlm => !finalizedLicenseModelList.find(fvlm => fvlm.id === vlm.id)
84 )
85 .concat(finalizedLicenseModelList);
talig8e9c0652017-12-20 14:30:43 +020086
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020087 let {
88 activeTab: catalogActiveTab,
89 vendorCatalog: { vspOverlay, selectedVendor }
90 } = onboardingCatalog;
91 if (filter.byVendorView) {
92 catalogActiveTab = tabsMapping.BY_VENDOR;
svishnevea5e43c2018-04-15 09:06:57 +030093 } else if (filter.itemStatus && filter.itemStatus === itemStatus.ARCHIVED) {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020094 catalogActiveTab = tabsMapping.ARCHIVE;
95 }
AviZi280f8012017-06-09 02:39:56 +030096
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020097 return {
98 finalizedLicenseModelList,
99 finalizedSoftwareProductList,
100 licenseModelList,
101 softwareProductList,
102 archivedLicenseModelList,
103 archivedSoftwareProductList,
104 fullLicenseModelList,
105 activeTab,
106 catalogActiveTab,
107 searchValue,
108 vspOverlay,
109 selectedVendor,
svishnevea5e43c2018-04-15 09:06:57 +0300110 users: users.usersList,
111 filteredItems: updatedFilteredItems
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200112 };
AviZi280f8012017-06-09 02:39:56 +0300113};
114
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200115const mapActionsToProps = dispatch => {
116 return {
117 onSelectLicenseModel({ id: licenseModelId, name }, users, tab) {
118 OnboardActionHelper.loadVLMScreen(
119 dispatch,
120 { id: licenseModelId, name },
121 users,
122 tab
123 );
124 },
125 onSelectSoftwareProduct(softwareProduct, users, tab) {
126 OnboardActionHelper.loadVSPScreen(
127 dispatch,
128 softwareProduct,
129 users,
130 tab
131 );
132 },
133 onAddSoftwareProductClick: vendorId =>
134 SoftwareProductCreationActionHelper.open(dispatch, vendorId),
135 onAddLicenseModelClick: () =>
136 LicenseModelCreationActionHelper.open(dispatch),
137 onVspOverlayChange: vendor =>
138 OnboardingCatalogActionHelper.changeVspOverlay(dispatch, vendor),
139 closeVspOverlay: () =>
140 OnboardingCatalogActionHelper.closeVspOverlay(dispatch),
141 onCatalogTabClick: tab =>
142 OnboardingCatalogActionHelper.changeActiveTab(dispatch, tab),
143 onTabClick: tab => OnboardActionHelper.changeActiveTab(dispatch, tab),
144 onSearch: searchValue =>
145 OnboardActionHelper.changeSearchValue(dispatch, searchValue),
146 onVendorSelect: vendor =>
147 OnboardingCatalogActionHelper.onVendorSelect(dispatch, { vendor }),
148 onMigrate: ({ softwareProduct }) =>
149 OnboardingCatalogActionHelper.onMigrate(dispatch, softwareProduct)
150 };
AviZi280f8012017-06-09 02:39:56 +0300151};
152
153export default connect(mapStateToProps, mapActionsToProps)(OnboardView);