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 { tabsMapping as onboardTabsMapping } from './OnboardConstants';
26 import { itemStatus } from 'sdc-app/common/helpers/ItemsHelperConstants.js';
27 import { catalogItemStatuses } from './onboardingCatalog/OnboardingCatalogConstants.js';
29 export const mapStateToProps = ({
30 onboard: { onboardingCatalog, activeTab, searchValue, filter },
33 archivedLicenseModelList,
34 archivedSoftwareProductList,
35 finalizedLicenseModelList,
37 finalizedSoftwareProductList,
40 const activeTabName = Object.keys(onboardTabsMapping).filter(item => {
41 return onboardTabsMapping[item] === activeTab;
43 const fullSoftwareProducts = softwareProductList
46 !finalizedSoftwareProductList.find(fvsp => fvsp.id === vsp.id)
48 .concat(finalizedSoftwareProductList);
50 const reduceLicenseModelList = (accum, vlm) => {
51 let currentSoftwareProductList = sortByStringProperty(
52 fullSoftwareProducts.filter(vsp => vsp.vendorId === vlm.id),
55 accum.push({ ...vlm, softwareProductList: currentSoftwareProductList });
59 const reduceFilteredLicenseModelList = (accum, vlm) => {
60 let currentSoftwareProductList = sortByStringProperty(
61 filteredItems.vspList.filter(vsp => vsp.vendorId === vlm.id),
64 accum.push({ ...vlm, softwareProductList: currentSoftwareProductList });
68 const updatedFilteredItems = {
69 vspList: [...filteredItems.vspList],
70 vlmList: sortByStringProperty(
71 filteredItems.vlmList.reduce(reduceFilteredLicenseModelList, []),
76 licenseModelList = sortByStringProperty(
77 licenseModelList.reduce(reduceLicenseModelList, []),
81 finalizedLicenseModelList = sortByStringProperty(
82 finalizedLicenseModelList.reduce(reduceLicenseModelList, []),
86 const fullLicenseModelList = licenseModelList
88 vlm => !finalizedLicenseModelList.find(fvlm => fvlm.id === vlm.id)
90 .concat(finalizedLicenseModelList);
93 activeTab: catalogActiveTab,
94 vendorCatalog: { vspOverlay, selectedVendor }
95 } = onboardingCatalog;
96 if (filter.byVendorView) {
97 catalogActiveTab = tabsMapping.BY_VENDOR;
98 } else if (filter.itemStatus && filter.itemStatus === itemStatus.ARCHIVED) {
99 catalogActiveTab = tabsMapping.ARCHIVE;
103 isArchived: filter.itemStatus === catalogItemStatuses.ARCHIVED,
104 finalizedLicenseModelList,
105 finalizedSoftwareProductList,
108 archivedLicenseModelList,
109 archivedSoftwareProductList,
110 fullLicenseModelList,
117 users: users.usersList,
118 filteredItems: updatedFilteredItems
122 const mapActionsToProps = dispatch => {
124 onSelectLicenseModel({ id: licenseModelId, name }, users, tab) {
125 OnboardActionHelper.loadVLMScreen(
127 { id: licenseModelId, name },
132 onSelectSoftwareProduct(softwareProduct, users, tab) {
133 OnboardActionHelper.loadVSPScreen(
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),
151 onSearch: (searchValue, activeTab) =>
152 OnboardActionHelper.changeSearchValue(
157 onVendorSelect: vendor =>
158 OnboardingCatalogActionHelper.onVendorSelect(dispatch, { vendor }),
159 onMigrate: ({ softwareProduct }) =>
160 OnboardingCatalogActionHelper.onMigrate(dispatch, softwareProduct)
164 export default connect(mapStateToProps, mapActionsToProps)(OnboardView);