Adding Prettier and fixing up eslint version
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / onboard / Onboard.js
1 /*
2  * Copyright © 2016-2018 European Support Limited
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 or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 import { connect } from 'react-redux';
18 import OnboardView from './OnboardView.jsx';
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';
24 import { tabsMapping } from './onboardingCatalog/OnboardingCatalogConstants.js';
25 import { itemsType } from './filter/FilterConstants.js';
26
27 export const mapStateToProps = ({
28     onboard: { onboardingCatalog, activeTab, searchValue, filter },
29     licenseModelList,
30     users,
31     archivedLicenseModelList,
32     archivedSoftwareProductList,
33     finalizedLicenseModelList,
34     softwareProductList,
35     finalizedSoftwareProductList
36 }) => {
37     const fullSoftwareProducts = softwareProductList
38         .filter(
39             vsp =>
40                 !finalizedSoftwareProductList.find(fvsp => fvsp.id === vsp.id)
41         )
42         .concat(finalizedSoftwareProductList);
43
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     };
52
53     licenseModelList = sortByStringProperty(
54         licenseModelList.reduce(reduceLicenseModelList, []),
55         'name'
56     );
57
58     finalizedLicenseModelList = sortByStringProperty(
59         finalizedLicenseModelList.reduce(reduceLicenseModelList, []),
60         'name'
61     );
62
63     const fullLicenseModelList = licenseModelList
64         .filter(
65             vlm => !finalizedLicenseModelList.find(fvlm => fvlm.id === vlm.id)
66         )
67         .concat(finalizedLicenseModelList);
68
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     }
78
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     };
94 };
95
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     };
132 };
133
134 export default connect(mapStateToProps, mapActionsToProps)(OnboardView);