AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 1 | /*! |
| 2 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
| 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 |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 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 |
| 13 | * or implied. See the License for the specific language governing |
| 14 | * permissions and limitations under the License. |
| 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'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 24 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 25 | |
| 26 | export const mapStateToProps = ({ |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 27 | onboard: { |
| 28 | onboardingCatalog, |
| 29 | activeTab, |
| 30 | searchValue |
| 31 | }, |
| 32 | licenseModelList, |
| 33 | users, |
| 34 | finalizedLicenseModelList, |
| 35 | softwareProductList, |
| 36 | finalizedSoftwareProductList |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 37 | }) => { |
| 38 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 39 | const fullSoftwareProducts = softwareProductList.filter(vsp => |
| 40 | !finalizedSoftwareProductList |
| 41 | .find(fvsp => fvsp.id === vsp.id) |
| 42 | ).concat(finalizedSoftwareProductList); |
| 43 | |
| 44 | const reduceLicenseModelList = (accum, vlm) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 45 | let currentSoftwareProductList = sortByStringProperty( |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 46 | fullSoftwareProducts |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 47 | .filter(vsp => vsp.vendorId === vlm.id), |
| 48 | 'name' |
| 49 | ); |
| 50 | accum.push({...vlm, softwareProductList: currentSoftwareProductList}); |
| 51 | return accum; |
| 52 | }; |
| 53 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 54 | licenseModelList = sortByStringProperty( |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 55 | licenseModelList |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 56 | .reduce(reduceLicenseModelList, []), |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 57 | 'name' |
| 58 | ); |
| 59 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 60 | finalizedLicenseModelList = sortByStringProperty( |
| 61 | finalizedLicenseModelList |
| 62 | .reduce(reduceLicenseModelList, []), |
| 63 | 'name' |
| 64 | ); |
| 65 | |
| 66 | const fullLicenseModelList = licenseModelList.filter(vlm => |
| 67 | !finalizedLicenseModelList |
| 68 | .find(fvlm => fvlm.id === vlm.id) |
| 69 | ).concat(finalizedLicenseModelList); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 70 | |
| 71 | let {activeTab: catalogActiveTab, vendorCatalog: {vspOverlay, selectedVendor}} = onboardingCatalog; |
| 72 | |
| 73 | return { |
| 74 | finalizedLicenseModelList, |
| 75 | finalizedSoftwareProductList, |
| 76 | licenseModelList, |
| 77 | softwareProductList, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 78 | fullLicenseModelList, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 79 | activeTab, |
| 80 | catalogActiveTab, |
| 81 | searchValue, |
| 82 | vspOverlay, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 83 | selectedVendor, |
| 84 | users: users.usersList |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 85 | }; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 86 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | const mapActionsToProps = (dispatch) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 90 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 91 | return { |
miriame | d411d15 | 2018-01-02 15:35:55 +0200 | [diff] [blame] | 92 | onSelectLicenseModel({id: licenseModelId, name}, users, tab) { |
| 93 | OnboardActionHelper.loadVLMScreen(dispatch, {id: licenseModelId, name}, users, tab); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 94 | }, |
miriame | d411d15 | 2018-01-02 15:35:55 +0200 | [diff] [blame] | 95 | onSelectSoftwareProduct(softwareProduct, users, tab) { |
| 96 | OnboardActionHelper.loadVSPScreen(dispatch, softwareProduct, users, tab); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 97 | }, |
| 98 | onAddSoftwareProductClick: (vendorId) => SoftwareProductCreationActionHelper.open(dispatch, vendorId), |
| 99 | onAddLicenseModelClick: () => LicenseModelCreationActionHelper.open(dispatch), |
| 100 | onVspOverlayChange: (vendor) => OnboardingCatalogActionHelper.changeVspOverlay(dispatch, vendor), |
| 101 | closeVspOverlay: () => OnboardingCatalogActionHelper.closeVspOverlay(dispatch), |
| 102 | onCatalogTabClick: (tab) => OnboardingCatalogActionHelper.changeActiveTab(dispatch, tab), |
| 103 | onTabClick: (tab) => OnboardActionHelper.changeActiveTab(dispatch, tab), |
| 104 | onSearch: (searchValue) => OnboardActionHelper.changeSearchValue(dispatch, searchValue), |
| 105 | onVendorSelect: (vendor) => OnboardingCatalogActionHelper.onVendorSelect(dispatch, {vendor}), |
| 106 | onMigrate: ({softwareProduct}) => OnboardingCatalogActionHelper.onMigrate(dispatch, softwareProduct) |
| 107 | }; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 108 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | export default connect(mapStateToProps, mapActionsToProps)(OnboardView); |