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'; |
| 25 | import { itemsType } from './filter/FilterConstants.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, |
| 35 | finalizedSoftwareProductList |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 36 | }) => { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 37 | const fullSoftwareProducts = softwareProductList |
| 38 | .filter( |
| 39 | vsp => |
| 40 | !finalizedSoftwareProductList.find(fvsp => fvsp.id === vsp.id) |
| 41 | ) |
| 42 | .concat(finalizedSoftwareProductList); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 43 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 44 | const reduceLicenseModelList = (accum, vlm) => { |
| 45 | let currentSoftwareProductList = sortByStringProperty( |
| 46 | fullSoftwareProducts.filter(vsp => vsp.vendorId === vlm.id), |
| 47 | 'name' |
| 48 | ); |
| 49 | accum.push({ ...vlm, softwareProductList: currentSoftwareProductList }); |
| 50 | return accum; |
| 51 | }; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 52 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 53 | licenseModelList = sortByStringProperty( |
| 54 | licenseModelList.reduce(reduceLicenseModelList, []), |
| 55 | 'name' |
| 56 | ); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 57 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 58 | finalizedLicenseModelList = sortByStringProperty( |
| 59 | finalizedLicenseModelList.reduce(reduceLicenseModelList, []), |
| 60 | 'name' |
| 61 | ); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 62 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 63 | const fullLicenseModelList = licenseModelList |
| 64 | .filter( |
| 65 | vlm => !finalizedLicenseModelList.find(fvlm => fvlm.id === vlm.id) |
| 66 | ) |
| 67 | .concat(finalizedLicenseModelList); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 68 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 69 | let { |
| 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; |
| 77 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 78 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 79 | return { |
| 80 | finalizedLicenseModelList, |
| 81 | finalizedSoftwareProductList, |
| 82 | licenseModelList, |
| 83 | softwareProductList, |
| 84 | archivedLicenseModelList, |
| 85 | archivedSoftwareProductList, |
| 86 | fullLicenseModelList, |
| 87 | activeTab, |
| 88 | catalogActiveTab, |
| 89 | searchValue, |
| 90 | vspOverlay, |
| 91 | selectedVendor, |
| 92 | users: users.usersList |
| 93 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 94 | }; |
| 95 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 96 | const mapActionsToProps = dispatch => { |
| 97 | return { |
| 98 | onSelectLicenseModel({ id: licenseModelId, name }, users, tab) { |
| 99 | OnboardActionHelper.loadVLMScreen( |
| 100 | dispatch, |
| 101 | { id: licenseModelId, name }, |
| 102 | users, |
| 103 | tab |
| 104 | ); |
| 105 | }, |
| 106 | onSelectSoftwareProduct(softwareProduct, users, tab) { |
| 107 | OnboardActionHelper.loadVSPScreen( |
| 108 | dispatch, |
| 109 | softwareProduct, |
| 110 | users, |
| 111 | tab |
| 112 | ); |
| 113 | }, |
| 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) |
| 131 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | export default connect(mapStateToProps, mapActionsToProps)(OnboardView); |