2 * Copyright © 2016-2018 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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 or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 import { connect } from 'react-redux';
18 import OnboardView from './OnboardView.jsx';
19 import OnboardingCatalogActionHelper from './onboardingCatalog/OnboardingCatalogActionHelper.js';
20 import OnboardActionHelper from './OnboardActionHelper.js';
21 import LicenseModelCreationActionHelper from '../licenseModel/creation/LicenseModelCreationActionHelper.js';
22 import SoftwareProductCreationActionHelper from '../softwareProduct/creation/SoftwareProductCreationActionHelper.js';
23 import sortByStringProperty from 'nfvo-utils/sortByStringProperty.js';
24 import { tabsMapping } from './onboardingCatalog/OnboardingCatalogConstants.js';
25 import { itemsType } from './filter/FilterConstants.js';
27 export const mapStateToProps = ({
28 onboard: { onboardingCatalog, activeTab, searchValue, filter },
31 archivedLicenseModelList,
32 archivedSoftwareProductList,
33 finalizedLicenseModelList,
35 finalizedSoftwareProductList
37 const fullSoftwareProducts = softwareProductList
40 !finalizedSoftwareProductList.find(fvsp => fvsp.id === vsp.id)
42 .concat(finalizedSoftwareProductList);
44 const reduceLicenseModelList = (accum, vlm) => {
45 let currentSoftwareProductList = sortByStringProperty(
46 fullSoftwareProducts.filter(vsp => vsp.vendorId === vlm.id),
49 accum.push({ ...vlm, softwareProductList: currentSoftwareProductList });
53 licenseModelList = sortByStringProperty(
54 licenseModelList.reduce(reduceLicenseModelList, []),
58 finalizedLicenseModelList = sortByStringProperty(
59 finalizedLicenseModelList.reduce(reduceLicenseModelList, []),
63 const fullLicenseModelList = licenseModelList
65 vlm => !finalizedLicenseModelList.find(fvlm => fvlm.id === vlm.id)
67 .concat(finalizedLicenseModelList);
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;
80 finalizedLicenseModelList,
81 finalizedSoftwareProductList,
84 archivedLicenseModelList,
85 archivedSoftwareProductList,
92 users: users.usersList
96 const mapActionsToProps = dispatch => {
98 onSelectLicenseModel({ id: licenseModelId, name }, users, tab) {
99 OnboardActionHelper.loadVLMScreen(
101 { id: licenseModelId, name },
106 onSelectSoftwareProduct(softwareProduct, users, tab) {
107 OnboardActionHelper.loadVSPScreen(
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)
134 export default connect(mapStateToProps, mapActionsToProps)(OnboardView);