blob: c3e29634120cad0fde2dd8097e0ef4386011dc90 [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
Yarin Dekel811fb482018-11-04 15:00:34 +02007 *
svishnev091edfd2018-03-19 12:15:19 +02008 * http://www.apache.org/licenses/LICENSE-2.0
Yarin Dekel811fb482018-11-04 15:00:34 +02009 *
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';
Yarin Dekel811fb482018-11-04 15:00:34 +020025import { tabsMapping as onboardTabsMapping } from './OnboardConstants';
svishnevea5e43c2018-04-15 09:06:57 +030026import { itemStatus } from 'sdc-app/common/helpers/ItemsHelperConstants.js';
svishnev768f7062018-10-18 14:34:47 +030027import { catalogItemStatuses } from './onboardingCatalog/OnboardingCatalogConstants.js';
AviZi280f8012017-06-09 02:39:56 +030028
29export const mapStateToProps = ({
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020030 onboard: { onboardingCatalog, activeTab, searchValue, filter },
31 licenseModelList,
32 users,
33 archivedLicenseModelList,
34 archivedSoftwareProductList,
35 finalizedLicenseModelList,
36 softwareProductList,
svishnevea5e43c2018-04-15 09:06:57 +030037 finalizedSoftwareProductList,
38 filteredItems
AviZi280f8012017-06-09 02:39:56 +030039}) => {
Yarin Dekel811fb482018-11-04 15:00:34 +020040 const activeTabName = Object.keys(onboardTabsMapping).filter(item => {
41 return onboardTabsMapping[item] === activeTab;
42 })[0];
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020043 const fullSoftwareProducts = softwareProductList
44 .filter(
45 vsp =>
46 !finalizedSoftwareProductList.find(fvsp => fvsp.id === vsp.id)
47 )
48 .concat(finalizedSoftwareProductList);
AviZi280f8012017-06-09 02:39:56 +030049
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020050 const reduceLicenseModelList = (accum, vlm) => {
51 let currentSoftwareProductList = sortByStringProperty(
52 fullSoftwareProducts.filter(vsp => vsp.vendorId === vlm.id),
53 'name'
54 );
55 accum.push({ ...vlm, softwareProductList: currentSoftwareProductList });
56 return accum;
57 };
talig8e9c0652017-12-20 14:30:43 +020058
svishnevea5e43c2018-04-15 09:06:57 +030059 const reduceFilteredLicenseModelList = (accum, vlm) => {
60 let currentSoftwareProductList = sortByStringProperty(
61 filteredItems.vspList.filter(vsp => vsp.vendorId === vlm.id),
62 'name'
63 );
64 accum.push({ ...vlm, softwareProductList: currentSoftwareProductList });
65 return accum;
66 };
67
68 const updatedFilteredItems = {
69 vspList: [...filteredItems.vspList],
70 vlmList: sortByStringProperty(
71 filteredItems.vlmList.reduce(reduceFilteredLicenseModelList, []),
72 'name'
73 )
74 };
75
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020076 licenseModelList = sortByStringProperty(
77 licenseModelList.reduce(reduceLicenseModelList, []),
78 'name'
79 );
AviZi280f8012017-06-09 02:39:56 +030080
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020081 finalizedLicenseModelList = sortByStringProperty(
82 finalizedLicenseModelList.reduce(reduceLicenseModelList, []),
83 'name'
84 );
AviZi280f8012017-06-09 02:39:56 +030085
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020086 const fullLicenseModelList = licenseModelList
87 .filter(
88 vlm => !finalizedLicenseModelList.find(fvlm => fvlm.id === vlm.id)
89 )
90 .concat(finalizedLicenseModelList);
talig8e9c0652017-12-20 14:30:43 +020091
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020092 let {
93 activeTab: catalogActiveTab,
94 vendorCatalog: { vspOverlay, selectedVendor }
95 } = onboardingCatalog;
96 if (filter.byVendorView) {
97 catalogActiveTab = tabsMapping.BY_VENDOR;
svishnevea5e43c2018-04-15 09:06:57 +030098 } else if (filter.itemStatus && filter.itemStatus === itemStatus.ARCHIVED) {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020099 catalogActiveTab = tabsMapping.ARCHIVE;
100 }
AviZi280f8012017-06-09 02:39:56 +0300101
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200102 return {
svishnev768f7062018-10-18 14:34:47 +0300103 isArchived: filter.itemStatus === catalogItemStatuses.ARCHIVED,
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200104 finalizedLicenseModelList,
105 finalizedSoftwareProductList,
106 licenseModelList,
107 softwareProductList,
108 archivedLicenseModelList,
109 archivedSoftwareProductList,
110 fullLicenseModelList,
Yarin Dekel811fb482018-11-04 15:00:34 +0200111 activeTabName,
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200112 activeTab,
113 catalogActiveTab,
114 searchValue,
115 vspOverlay,
116 selectedVendor,
svishnevea5e43c2018-04-15 09:06:57 +0300117 users: users.usersList,
118 filteredItems: updatedFilteredItems
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200119 };
AviZi280f8012017-06-09 02:39:56 +0300120};
121
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200122const mapActionsToProps = dispatch => {
123 return {
124 onSelectLicenseModel({ id: licenseModelId, name }, users, tab) {
125 OnboardActionHelper.loadVLMScreen(
126 dispatch,
127 { id: licenseModelId, name },
128 users,
129 tab
130 );
131 },
132 onSelectSoftwareProduct(softwareProduct, users, tab) {
133 OnboardActionHelper.loadVSPScreen(
134 dispatch,
135 softwareProduct,
136 users,
137 tab
138 );
139 },
140 onAddSoftwareProductClick: vendorId =>
141 SoftwareProductCreationActionHelper.open(dispatch, vendorId),
142 onAddLicenseModelClick: () =>
143 LicenseModelCreationActionHelper.open(dispatch),
144 onVspOverlayChange: vendor =>
145 OnboardingCatalogActionHelper.changeVspOverlay(dispatch, vendor),
146 closeVspOverlay: () =>
147 OnboardingCatalogActionHelper.closeVspOverlay(dispatch),
148 onCatalogTabClick: tab =>
149 OnboardingCatalogActionHelper.changeActiveTab(dispatch, tab),
150 onTabClick: tab => OnboardActionHelper.changeActiveTab(dispatch, tab),
Yarin Dekel811fb482018-11-04 15:00:34 +0200151 onSearch: (searchValue, activeTab) =>
152 OnboardActionHelper.changeSearchValue(
153 dispatch,
154 searchValue,
155 activeTab
156 ),
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200157 onVendorSelect: vendor =>
158 OnboardingCatalogActionHelper.onVendorSelect(dispatch, { vendor }),
159 onMigrate: ({ softwareProduct }) =>
160 OnboardingCatalogActionHelper.onMigrate(dispatch, softwareProduct)
161 };
AviZi280f8012017-06-09 02:39:56 +0300162};
163
164export default connect(mapStateToProps, mapActionsToProps)(OnboardView);