[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / licenseModel / overview / summary / SummaryCountList.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 import React from 'react';
17 import {connect} from 'react-redux';
18
19 import VersionControllerUtils from 'nfvo-components/panel/versionController/VersionControllerUtils.js';
20
21 import OnboardingActionHelper from '../../../OnboardingActionHelper.js';
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 = ({licenseModel: {licenseModelEditor, licenseAgreement: {licenseAgreementList},
31         featureGroup: {featureGroupsList}, entitlementPool: {entitlementPoolsList}, licenseKeyGroup: {licenseKeyGroupsList}}}) => {
32
33         let {vendorName, description, id, version} = licenseModelEditor.data;
34
35         let isReadOnlyMode = VersionControllerUtils.isReadOnly(licenseModelEditor.data);
36
37         let counts = [
38                 {name: overviewItems.LICENSE_AGREEMENTS, count: licenseAgreementList.length},
39                 {name: overviewItems.FEATURE_GROUPS, count: featureGroupsList.length},
40                 {name: overviewItems.ENTITLEMENT_POOLS, count: entitlementPoolsList.length},
41                 {name: overviewItems.LICENSE_KEY_GROUPS, count: licenseKeyGroupsList.length},
42         ];
43         return {
44                 vendorName,
45                 licenseModelId: id,
46                 description,
47                 counts,
48                 isReadOnlyMode,
49                 version
50         };
51 };
52
53 const mapActionsToProps = (dispatch) => {
54         return {
55                 onEditorOpenClick: (name, licenseModelId, version) => {
56                         switch (name) {
57                                 case overviewItems.ENTITLEMENT_POOLS:
58                                         EntitlementPoolsActionHelper.openEntitlementPoolsEditor(dispatch);
59                                         break;
60                                 case overviewItems.FEATURE_GROUPS:
61                                         FeatureGroupsActionHelper.openFeatureGroupsEditor(dispatch, {licenseModelId, version});
62                                         break;
63                                 case overviewItems.LICENSE_AGREEMENTS:
64                                         LicenseAgreementActionHelper.openLicenseAgreementEditor(dispatch, {licenseModelId, version});
65                                         break;
66                                 case overviewItems.LICENSE_KEY_GROUPS:
67                                         LicenseKeyGroupsActionHelper.openLicenseKeyGroupsEditor(dispatch);
68                                         break;
69                                 default:
70                                         break;
71                         }
72                 },
73                 onNavigateClick: ({name, licenseModelId, version}) => {
74                         switch (name) {
75                                 case overviewItems.ENTITLEMENT_POOLS:
76                                         OnboardingActionHelper.navigateToEntitlementPools(dispatch, {licenseModelId, version});
77                                         break;
78                                 case overviewItems.FEATURE_GROUPS:
79                                         OnboardingActionHelper.navigateToFeatureGroups(dispatch, {licenseModelId, version});
80                                         break;
81                                 case overviewItems.LICENSE_AGREEMENTS:
82                                         OnboardingActionHelper.navigateToLicenseAgreements(dispatch, {licenseModelId, version});
83                                         break;
84                                 case overviewItems.LICENSE_KEY_GROUPS:
85                                         OnboardingActionHelper.navigateToLicenseKeyGroups(dispatch, {licenseModelId, version});
86                                         break;
87                                 default:
88                                         break;
89                         }
90                 }
91         };
92 };
93
94 export class SummaryCountList extends React.Component {
95
96         render() {
97                 let {counts} = this.props;
98                 return(
99                         <div className='summary-count-list'>
100                                 {counts.map(item => this.renderItem(item))}
101                         </div>
102                 );
103         }
104
105         renderItem(item){
106                 const {name, count} = item;
107                 const {isReadOnlyMode} = this.props;
108                 return(
109                         <SummaryCountItem isReadOnlyMode={isReadOnlyMode} name={name} counter={count} onNavigate={() => this.onNavigate(name)} onAdd={() => this.onAdd(name)} key={name} />
110                 );
111         }
112
113         onAdd(name) {
114                 let {onEditorOpenClick, licenseModelId, isReadOnlyMode, version} = this.props;
115                 if (!isReadOnlyMode) {
116                         onEditorOpenClick(name, licenseModelId, version);
117                 }
118         }
119
120         onNavigate(name) {
121                 let {onNavigateClick, licenseModelId, version} = this.props;
122                 onNavigateClick({licenseModelId, name, version});
123         }
124 }
125
126 export default connect(mapStateToProps, mapActionsToProps)(SummaryCountList);