svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2016-2018 European Support Limited |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 3 | * |
| 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 |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 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. |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 15 | */ |
| 16 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 17 | import { connect } from 'react-redux'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 18 | import OnboardView from './OnboardView.jsx'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 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'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 24 | import { tabsMapping } from './onboardingCatalog/OnboardingCatalogConstants.js'; |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 25 | import { itemStatus } from 'sdc-app/common/helpers/ItemsHelperConstants.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 26 | |
| 27 | export const mapStateToProps = ({ |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 28 | onboard: { onboardingCatalog, activeTab, searchValue, filter }, |
| 29 | licenseModelList, |
| 30 | users, |
| 31 | archivedLicenseModelList, |
| 32 | archivedSoftwareProductList, |
| 33 | finalizedLicenseModelList, |
| 34 | softwareProductList, |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 35 | finalizedSoftwareProductList, |
| 36 | filteredItems |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 37 | }) => { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 38 | const fullSoftwareProducts = softwareProductList |
| 39 | .filter( |
| 40 | vsp => |
| 41 | !finalizedSoftwareProductList.find(fvsp => fvsp.id === vsp.id) |
| 42 | ) |
| 43 | .concat(finalizedSoftwareProductList); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 44 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 45 | 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 | }; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 53 | |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 54 | 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 Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 71 | licenseModelList = sortByStringProperty( |
| 72 | licenseModelList.reduce(reduceLicenseModelList, []), |
| 73 | 'name' |
| 74 | ); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 75 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 76 | finalizedLicenseModelList = sortByStringProperty( |
| 77 | finalizedLicenseModelList.reduce(reduceLicenseModelList, []), |
| 78 | 'name' |
| 79 | ); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 80 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 81 | const fullLicenseModelList = licenseModelList |
| 82 | .filter( |
| 83 | vlm => !finalizedLicenseModelList.find(fvlm => fvlm.id === vlm.id) |
| 84 | ) |
| 85 | .concat(finalizedLicenseModelList); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 86 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 87 | let { |
| 88 | activeTab: catalogActiveTab, |
| 89 | vendorCatalog: { vspOverlay, selectedVendor } |
| 90 | } = onboardingCatalog; |
| 91 | if (filter.byVendorView) { |
| 92 | catalogActiveTab = tabsMapping.BY_VENDOR; |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 93 | } else if (filter.itemStatus && filter.itemStatus === itemStatus.ARCHIVED) { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 94 | catalogActiveTab = tabsMapping.ARCHIVE; |
| 95 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 96 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 97 | 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, |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 110 | users: users.usersList, |
| 111 | filteredItems: updatedFilteredItems |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 112 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 113 | }; |
| 114 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 115 | const 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 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 151 | }; |
| 152 | |
| 153 | export default connect(mapStateToProps, mapActionsToProps)(OnboardView); |