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 |
Yarin Dekel | 811fb48 | 2018-11-04 15:00:34 +0200 | [diff] [blame] | 7 | * |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Yarin Dekel | 811fb48 | 2018-11-04 15:00:34 +0200 | [diff] [blame] | 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'; |
Yarin Dekel | 811fb48 | 2018-11-04 15:00:34 +0200 | [diff] [blame] | 25 | import { tabsMapping as onboardTabsMapping } from './OnboardConstants'; |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 26 | import { itemStatus } from 'sdc-app/common/helpers/ItemsHelperConstants.js'; |
svishnev | 768f706 | 2018-10-18 14:34:47 +0300 | [diff] [blame] | 27 | import { catalogItemStatuses } from './onboardingCatalog/OnboardingCatalogConstants.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 28 | |
| 29 | export const mapStateToProps = ({ |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 30 | onboard: { onboardingCatalog, activeTab, searchValue, filter }, |
| 31 | licenseModelList, |
| 32 | users, |
| 33 | archivedLicenseModelList, |
| 34 | archivedSoftwareProductList, |
| 35 | finalizedLicenseModelList, |
| 36 | softwareProductList, |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 37 | finalizedSoftwareProductList, |
| 38 | filteredItems |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 39 | }) => { |
Yarin Dekel | 811fb48 | 2018-11-04 15:00:34 +0200 | [diff] [blame] | 40 | const activeTabName = Object.keys(onboardTabsMapping).filter(item => { |
| 41 | return onboardTabsMapping[item] === activeTab; |
| 42 | })[0]; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 43 | const fullSoftwareProducts = softwareProductList |
| 44 | .filter( |
| 45 | vsp => |
| 46 | !finalizedSoftwareProductList.find(fvsp => fvsp.id === vsp.id) |
| 47 | ) |
| 48 | .concat(finalizedSoftwareProductList); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 49 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 50 | 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 | }; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 58 | |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 59 | 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 Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 76 | licenseModelList = sortByStringProperty( |
| 77 | licenseModelList.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 | finalizedLicenseModelList = sortByStringProperty( |
| 82 | finalizedLicenseModelList.reduce(reduceLicenseModelList, []), |
| 83 | 'name' |
| 84 | ); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 85 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 86 | const fullLicenseModelList = licenseModelList |
| 87 | .filter( |
| 88 | vlm => !finalizedLicenseModelList.find(fvlm => fvlm.id === vlm.id) |
| 89 | ) |
| 90 | .concat(finalizedLicenseModelList); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 91 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 92 | let { |
| 93 | activeTab: catalogActiveTab, |
| 94 | vendorCatalog: { vspOverlay, selectedVendor } |
| 95 | } = onboardingCatalog; |
| 96 | if (filter.byVendorView) { |
| 97 | catalogActiveTab = tabsMapping.BY_VENDOR; |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 98 | } else if (filter.itemStatus && filter.itemStatus === itemStatus.ARCHIVED) { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 99 | catalogActiveTab = tabsMapping.ARCHIVE; |
| 100 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 101 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 102 | return { |
svishnev | 768f706 | 2018-10-18 14:34:47 +0300 | [diff] [blame] | 103 | isArchived: filter.itemStatus === catalogItemStatuses.ARCHIVED, |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 104 | finalizedLicenseModelList, |
| 105 | finalizedSoftwareProductList, |
| 106 | licenseModelList, |
| 107 | softwareProductList, |
| 108 | archivedLicenseModelList, |
| 109 | archivedSoftwareProductList, |
| 110 | fullLicenseModelList, |
Yarin Dekel | 811fb48 | 2018-11-04 15:00:34 +0200 | [diff] [blame] | 111 | activeTabName, |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 112 | activeTab, |
| 113 | catalogActiveTab, |
| 114 | searchValue, |
| 115 | vspOverlay, |
| 116 | selectedVendor, |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 117 | users: users.usersList, |
| 118 | filteredItems: updatedFilteredItems |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 119 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 120 | }; |
| 121 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 122 | const 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 Dekel | 811fb48 | 2018-11-04 15:00:34 +0200 | [diff] [blame] | 151 | onSearch: (searchValue, activeTab) => |
| 152 | OnboardActionHelper.changeSearchValue( |
| 153 | dispatch, |
| 154 | searchValue, |
| 155 | activeTab |
| 156 | ), |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 157 | onVendorSelect: vendor => |
| 158 | OnboardingCatalogActionHelper.onVendorSelect(dispatch, { vendor }), |
| 159 | onMigrate: ({ softwareProduct }) => |
| 160 | OnboardingCatalogActionHelper.onMigrate(dispatch, softwareProduct) |
| 161 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 162 | }; |
| 163 | |
| 164 | export default connect(mapStateToProps, mapActionsToProps)(OnboardView); |