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 | import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js'; |
| 25 | import {enums, screenTypes} from 'sdc-app/onboarding/OnboardingConstants.js'; |
| 26 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 27 | |
| 28 | export const mapStateToProps = ({ |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 29 | onboard: { |
| 30 | onboardingCatalog, |
| 31 | activeTab, |
| 32 | searchValue |
| 33 | }, |
| 34 | licenseModelList, |
| 35 | users, |
| 36 | finalizedLicenseModelList, |
| 37 | softwareProductList, |
| 38 | finalizedSoftwareProductList |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 39 | }) => { |
| 40 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 41 | const fullSoftwareProducts = softwareProductList.filter(vsp => |
| 42 | !finalizedSoftwareProductList |
| 43 | .find(fvsp => fvsp.id === vsp.id) |
| 44 | ).concat(finalizedSoftwareProductList); |
| 45 | |
| 46 | const reduceLicenseModelList = (accum, vlm) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 47 | let currentSoftwareProductList = sortByStringProperty( |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 48 | fullSoftwareProducts |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 49 | .filter(vsp => vsp.vendorId === vlm.id), |
| 50 | 'name' |
| 51 | ); |
| 52 | accum.push({...vlm, softwareProductList: currentSoftwareProductList}); |
| 53 | return accum; |
| 54 | }; |
| 55 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 56 | licenseModelList = sortByStringProperty( |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 57 | licenseModelList |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 58 | .reduce(reduceLicenseModelList, []), |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 59 | 'name' |
| 60 | ); |
| 61 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 62 | finalizedLicenseModelList = sortByStringProperty( |
| 63 | finalizedLicenseModelList |
| 64 | .reduce(reduceLicenseModelList, []), |
| 65 | 'name' |
| 66 | ); |
| 67 | |
| 68 | const fullLicenseModelList = licenseModelList.filter(vlm => |
| 69 | !finalizedLicenseModelList |
| 70 | .find(fvlm => fvlm.id === vlm.id) |
| 71 | ).concat(finalizedLicenseModelList); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 72 | |
| 73 | let {activeTab: catalogActiveTab, vendorCatalog: {vspOverlay, selectedVendor}} = onboardingCatalog; |
| 74 | |
| 75 | return { |
| 76 | finalizedLicenseModelList, |
| 77 | finalizedSoftwareProductList, |
| 78 | licenseModelList, |
| 79 | softwareProductList, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 80 | fullLicenseModelList, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 81 | activeTab, |
| 82 | catalogActiveTab, |
| 83 | searchValue, |
| 84 | vspOverlay, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 85 | selectedVendor, |
| 86 | users: users.usersList |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 87 | }; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 88 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | const mapActionsToProps = (dispatch) => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 92 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 93 | return { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 94 | onSelectLicenseModel({id: licenseModelId, name}, users) { |
| 95 | ScreensHelper.loadScreen(dispatch, { |
| 96 | screen: enums.SCREEN.VERSIONS_PAGE, screenType: screenTypes.LICENSE_MODEL, |
| 97 | props: {licenseModelId, licenseModel: {name}, usersList: users} |
| 98 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 99 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 100 | onSelectSoftwareProduct(softwareProduct, users) { |
| 101 | let {id: softwareProductId, vendorId: licenseModelId, licensingVersion, name} = softwareProduct; |
| 102 | ScreensHelper.loadScreen(dispatch, { |
| 103 | screen: enums.SCREEN.SOFTWARE_PRODUCT_VERSIONS_PAGE, screenType: screenTypes.SOFTWARE_PRODUCT, |
| 104 | props: {softwareProductId, softwareProduct: {name, vendorId: licenseModelId, licensingVersion}, usersList: users} |
| 105 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 106 | }, |
| 107 | onAddSoftwareProductClick: (vendorId) => SoftwareProductCreationActionHelper.open(dispatch, vendorId), |
| 108 | onAddLicenseModelClick: () => LicenseModelCreationActionHelper.open(dispatch), |
| 109 | onVspOverlayChange: (vendor) => OnboardingCatalogActionHelper.changeVspOverlay(dispatch, vendor), |
| 110 | closeVspOverlay: () => OnboardingCatalogActionHelper.closeVspOverlay(dispatch), |
| 111 | onCatalogTabClick: (tab) => OnboardingCatalogActionHelper.changeActiveTab(dispatch, tab), |
| 112 | onTabClick: (tab) => OnboardActionHelper.changeActiveTab(dispatch, tab), |
| 113 | onSearch: (searchValue) => OnboardActionHelper.changeSearchValue(dispatch, searchValue), |
| 114 | onVendorSelect: (vendor) => OnboardingCatalogActionHelper.onVendorSelect(dispatch, {vendor}), |
| 115 | onMigrate: ({softwareProduct}) => OnboardingCatalogActionHelper.onMigrate(dispatch, softwareProduct) |
| 116 | }; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 117 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | export default connect(mapStateToProps, mapActionsToProps)(OnboardView); |