react 16 upgrade
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / licenseModel / overview / summary / SummaryCountList.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 import React from 'react';
17 import { connect } from 'react-redux';
18
19 import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js';
20 import { enums, screenTypes } from 'sdc-app/onboarding/OnboardingConstants.js';
21
22 import EntitlementPoolsActionHelper from '../../entitlementPools/EntitlementPoolsActionHelper.js';
23 import LicenseAgreementActionHelper from '../../licenseAgreement/LicenseAgreementActionHelper.js';
24 import LicenseKeyGroupsActionHelper from '../../licenseKeyGroups/LicenseKeyGroupsActionHelper.js';
25 import FeatureGroupsActionHelper from '../../featureGroups/FeatureGroupsActionHelper.js';
26
27 import { overviewItems } from '../LicenseModelOverviewConstants.js';
28 import SummaryCountItem from './SummaryCountItem.jsx';
29
30 export const mapStateToProps = ({
31     licenseModel: {
32         licenseModelEditor,
33         licenseAgreement: { licenseAgreementList },
34         featureGroup: { featureGroupsList },
35         entitlementPool: { entitlementPoolsList },
36         licenseKeyGroup: { licenseKeyGroupsList }
37     }
38 }) => {
39     let { vendorName, description, id, version } = licenseModelEditor.data;
40     let counts = [
41         {
42             name: overviewItems.LICENSE_AGREEMENTS,
43             count: licenseAgreementList.length
44         },
45         { name: overviewItems.FEATURE_GROUPS, count: featureGroupsList.length },
46         {
47             name: overviewItems.ENTITLEMENT_POOLS,
48             count: entitlementPoolsList.length
49         },
50         {
51             name: overviewItems.LICENSE_KEY_GROUPS,
52             count: licenseKeyGroupsList.length
53         }
54     ];
55
56     return {
57         vendorName,
58         licenseModelId: id,
59         description,
60         counts,
61         version
62     };
63 };
64
65 const mapActionsToProps = dispatch => {
66     return {
67         onEditorOpenClick: (name, licenseModelId, version) => {
68             switch (name) {
69                 case overviewItems.ENTITLEMENT_POOLS:
70                     EntitlementPoolsActionHelper.openEntitlementPoolsEditor(
71                         dispatch,
72                         {
73                             licenseModelId,
74                             version,
75                             isReadOnlyMode: false
76                         }
77                     );
78                     break;
79                 case overviewItems.FEATURE_GROUPS:
80                     FeatureGroupsActionHelper.openFeatureGroupsEditor(
81                         dispatch,
82                         {
83                             licenseModelId,
84                             version,
85                             isReadOnlyMode: false
86                         }
87                     );
88                     break;
89                 case overviewItems.LICENSE_AGREEMENTS:
90                     LicenseAgreementActionHelper.openLicenseAgreementEditor(
91                         dispatch,
92                         {
93                             licenseModelId,
94                             version,
95                             isReadOnlyMode: false
96                         }
97                     );
98                     break;
99                 case overviewItems.LICENSE_KEY_GROUPS:
100                     LicenseKeyGroupsActionHelper.openLicenseKeyGroupsEditor(
101                         dispatch,
102                         {
103                             licenseModelId,
104                             version,
105                             isReadOnlyMode: false
106                         }
107                     );
108                     break;
109                 default:
110                     break;
111             }
112         },
113         onNavigateClick: ({ name, licenseModelId, version }) => {
114             let screenToNavigate;
115             switch (name) {
116                 case overviewItems.ENTITLEMENT_POOLS:
117                     screenToNavigate = enums.SCREEN.ENTITLEMENT_POOLS;
118                     break;
119                 case overviewItems.FEATURE_GROUPS:
120                     screenToNavigate = enums.SCREEN.FEATURE_GROUPS;
121                     break;
122                 case overviewItems.LICENSE_AGREEMENTS:
123                     screenToNavigate = enums.SCREEN.LICENSE_AGREEMENTS;
124                     break;
125                 case overviewItems.LICENSE_KEY_GROUPS:
126                     screenToNavigate = enums.SCREEN.LICENSE_KEY_GROUPS;
127                     break;
128                 default:
129                     break;
130             }
131             ScreensHelper.loadScreen(dispatch, {
132                 screen: screenToNavigate,
133                 screenType: screenTypes.LICENSE_MODEL,
134                 props: { licenseModelId, version }
135             });
136         }
137     };
138 };
139
140 export class SummaryCountList extends React.Component {
141     render() {
142         let { counts } = this.props;
143         return (
144             <div className="summary-count-list">
145                 {counts.map(item => this.renderItem(item))}
146             </div>
147         );
148     }
149
150     renderItem(item) {
151         const { name, count } = item;
152         const { isReadOnlyMode } = this.props;
153         return (
154             <SummaryCountItem
155                 isReadOnlyMode={isReadOnlyMode}
156                 name={name}
157                 counter={count}
158                 onNavigate={() => this.onNavigate(name)}
159                 onAdd={() => this.onAdd(name)}
160                 key={name}
161             />
162         );
163     }
164
165     onAdd(name) {
166         let {
167             onEditorOpenClick,
168             licenseModelId,
169             isReadOnlyMode,
170             version
171         } = this.props;
172         if (!isReadOnlyMode) {
173             onEditorOpenClick(name, licenseModelId, version);
174         }
175     }
176
177     onNavigate(name) {
178         let { onNavigateClick, licenseModelId, version } = this.props;
179         onNavigateClick({ licenseModelId, name, version });
180     }
181 }
182
183 export default connect(mapStateToProps, mapActionsToProps)(SummaryCountList);