[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / onboard / Onboard.js
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';
19 import OnboardingActionHelper from '../OnboardingActionHelper.js';
20 import OnboardingCatalogActionHelper from './onboardingCatalog/OnboardingCatalogActionHelper.js';
21 import OnboardActionHelper from './OnboardActionHelper.js';
22 import LicenseModelCreationActionHelper from '../licenseModel/creation/LicenseModelCreationActionHelper.js';
23 import SoftwareProductCreationActionHelper from '../softwareProduct/creation/SoftwareProductCreationActionHelper.js';
24 import sortByStringProperty from 'nfvo-utils/sortByStringProperty.js';
25
26 export const mapStateToProps = ({
27         onboard: {onboardingCatalog, activeTab, searchValue}, licenseModelList, finalizedLicenseModelList, softwareProductList, finalizedSoftwareProductList
28 }) => {
29
30         const reduceLicenseModelList = (accum, vlm)=> {
31                 let currentSoftwareProductList = sortByStringProperty(
32                         finalizedSoftwareProductList
33                                 .filter(vsp => vsp.vendorId === vlm.id),
34                         'name'
35                 );
36                 accum.push({...vlm, softwareProductList: currentSoftwareProductList});
37                 return accum;
38         };
39
40         finalizedLicenseModelList = sortByStringProperty(
41                 licenseModelList
42                         .filter(vlm => finalizedLicenseModelList.map(finalVlm => finalVlm.id).includes(vlm.id))
43                         .reduce(reduceLicenseModelList, []),
44                 'vendorName'
45         );
46
47         finalizedSoftwareProductList = sortByStringProperty(
48                 softwareProductList
49                         .filter(vsp => finalizedSoftwareProductList.map(finalVsp => finalVsp.id).includes(vsp.id)),
50                 'name'
51         );
52
53
54         let {activeTab: catalogActiveTab, vendorCatalog: {vspOverlay, selectedVendor}} = onboardingCatalog;
55
56         return {
57                 finalizedLicenseModelList,
58                 finalizedSoftwareProductList,
59                 licenseModelList,
60                 softwareProductList,
61                 activeTab,
62                 catalogActiveTab,
63                 searchValue,
64                 vspOverlay,
65                 selectedVendor
66         };
67 };
68
69 const mapActionsToProps = (dispatch) => {
70         return {
71                 onSelectLicenseModel({id: licenseModelId, version}) {
72                         OnboardingActionHelper.navigateToLicenseModelOverview(dispatch, {licenseModelId, version});
73                 },
74                 onSelectSoftwareProduct(softwareProduct) {
75                         let {id: softwareProductId, vendorId: licenseModelId, licensingVersion, version} = softwareProduct;
76                         OnboardingActionHelper.navigateToSoftwareProductLandingPage(dispatch, {softwareProductId, version, licenseModelId, licensingVersion});
77                 },
78                 onAddSoftwareProductClick: (vendorId) => SoftwareProductCreationActionHelper.open(dispatch, vendorId),
79                 onAddLicenseModelClick: () => LicenseModelCreationActionHelper.open(dispatch),
80                 onVspOverlayChange: (vendor) => OnboardingCatalogActionHelper.changeVspOverlay(dispatch, vendor),
81                 closeVspOverlay: () => OnboardingCatalogActionHelper.closeVspOverlay(dispatch),
82                 onCatalogTabClick: (tab) => OnboardingCatalogActionHelper.changeActiveTab(dispatch, tab),
83                 onTabClick: (tab) => OnboardActionHelper.changeActiveTab(dispatch, tab),
84                 onSearch: (searchValue) => OnboardActionHelper.changeSearchValue(dispatch, searchValue),
85                 onVendorSelect: (vendor) => OnboardingCatalogActionHelper.onVendorSelect(dispatch, {vendor}),
86                 onMigrate: ({softwareProduct}) => OnboardingCatalogActionHelper.onMigrate(dispatch, softwareProduct)
87         };
88 };
89
90 export default connect(mapStateToProps, mapActionsToProps)(OnboardView);