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 | |
| 17 | import {connect} from 'react-redux'; |
| 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'; |
svishnev | 091edfd | 2018-03-19 12:15:19 +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 = ({ |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 28 | onboard: { |
| 29 | onboardingCatalog, |
| 30 | activeTab, |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 31 | searchValue, |
| 32 | filter |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 33 | }, |
| 34 | licenseModelList, |
| 35 | users, |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 36 | archivedLicenseModelList, |
| 37 | archivedSoftwareProductList, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 38 | finalizedLicenseModelList, |
| 39 | softwareProductList, |
| 40 | finalizedSoftwareProductList |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 41 | }) => { |
| 42 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 43 | const fullSoftwareProducts = softwareProductList.filter(vsp => |
| 44 | !finalizedSoftwareProductList |
| 45 | .find(fvsp => fvsp.id === vsp.id) |
| 46 | ).concat(finalizedSoftwareProductList); |
| 47 | |
| 48 | const reduceLicenseModelList = (accum, vlm) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 49 | let currentSoftwareProductList = sortByStringProperty( |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 50 | fullSoftwareProducts |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 51 | .filter(vsp => vsp.vendorId === vlm.id), |
| 52 | 'name' |
| 53 | ); |
| 54 | accum.push({...vlm, softwareProductList: currentSoftwareProductList}); |
| 55 | return accum; |
| 56 | }; |
| 57 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 58 | licenseModelList = sortByStringProperty( |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 59 | licenseModelList |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 60 | .reduce(reduceLicenseModelList, []), |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 61 | 'name' |
| 62 | ); |
| 63 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 64 | finalizedLicenseModelList = sortByStringProperty( |
| 65 | finalizedLicenseModelList |
| 66 | .reduce(reduceLicenseModelList, []), |
| 67 | 'name' |
| 68 | ); |
| 69 | |
| 70 | const fullLicenseModelList = licenseModelList.filter(vlm => |
| 71 | !finalizedLicenseModelList |
| 72 | .find(fvlm => fvlm.id === vlm.id) |
| 73 | ).concat(finalizedLicenseModelList); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 74 | |
| 75 | let {activeTab: catalogActiveTab, vendorCatalog: {vspOverlay, selectedVendor}} = onboardingCatalog; |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 76 | if (filter.byVendorView) { |
| 77 | catalogActiveTab = tabsMapping.BY_VENDOR; |
| 78 | } |
| 79 | else if (filter.itemsType && filter.itemsType === itemsType.ARCHIVED) { |
| 80 | catalogActiveTab = tabsMapping.ARCHIVE; |
| 81 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 82 | |
| 83 | return { |
| 84 | finalizedLicenseModelList, |
| 85 | finalizedSoftwareProductList, |
| 86 | licenseModelList, |
| 87 | softwareProductList, |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 88 | archivedLicenseModelList, |
| 89 | archivedSoftwareProductList, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 90 | fullLicenseModelList, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 91 | activeTab, |
| 92 | catalogActiveTab, |
| 93 | searchValue, |
| 94 | vspOverlay, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 95 | selectedVendor, |
| 96 | users: users.usersList |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 97 | }; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 98 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | const mapActionsToProps = (dispatch) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 102 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 103 | return { |
miriame | d411d15 | 2018-01-02 15:35:55 +0200 | [diff] [blame] | 104 | onSelectLicenseModel({id: licenseModelId, name}, users, tab) { |
| 105 | OnboardActionHelper.loadVLMScreen(dispatch, {id: licenseModelId, name}, users, tab); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 106 | }, |
miriame | d411d15 | 2018-01-02 15:35:55 +0200 | [diff] [blame] | 107 | onSelectSoftwareProduct(softwareProduct, users, tab) { |
| 108 | OnboardActionHelper.loadVSPScreen(dispatch, softwareProduct, users, tab); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 109 | }, |
| 110 | onAddSoftwareProductClick: (vendorId) => SoftwareProductCreationActionHelper.open(dispatch, vendorId), |
| 111 | onAddLicenseModelClick: () => LicenseModelCreationActionHelper.open(dispatch), |
| 112 | onVspOverlayChange: (vendor) => OnboardingCatalogActionHelper.changeVspOverlay(dispatch, vendor), |
| 113 | closeVspOverlay: () => OnboardingCatalogActionHelper.closeVspOverlay(dispatch), |
| 114 | onCatalogTabClick: (tab) => OnboardingCatalogActionHelper.changeActiveTab(dispatch, tab), |
| 115 | onTabClick: (tab) => OnboardActionHelper.changeActiveTab(dispatch, tab), |
| 116 | onSearch: (searchValue) => OnboardActionHelper.changeSearchValue(dispatch, searchValue), |
| 117 | onVendorSelect: (vendor) => OnboardingCatalogActionHelper.onVendorSelect(dispatch, {vendor}), |
| 118 | onMigrate: ({softwareProduct}) => OnboardingCatalogActionHelper.onMigrate(dispatch, softwareProduct) |
| 119 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | export default connect(mapStateToProps, mapActionsToProps)(OnboardView); |