Add collaboration feature
[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 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
40         let {vendorName, description, id, version} = licenseModelEditor.data;
41         let counts = [
42                 {name: overviewItems.LICENSE_AGREEMENTS, count: licenseAgreementList.length},
43                 {name: overviewItems.FEATURE_GROUPS, count: featureGroupsList.length},
44                 {name: overviewItems.ENTITLEMENT_POOLS, count: entitlementPoolsList.length},
45                 {name: overviewItems.LICENSE_KEY_GROUPS, count: licenseKeyGroupsList.length},
46         ];
47
48         return {
49                 vendorName,
50                 licenseModelId: id,
51                 description,
52                 counts,
53                 version
54         };
55
56 };
57
58 const mapActionsToProps = (dispatch) => {
59         return {
60                 onEditorOpenClick: (name, licenseModelId, version) => {
61                         switch (name) {
62                                 case overviewItems.ENTITLEMENT_POOLS:
63                                         EntitlementPoolsActionHelper.openEntitlementPoolsEditor(dispatch);
64                                         break;
65                                 case overviewItems.FEATURE_GROUPS:
66                                         FeatureGroupsActionHelper.openFeatureGroupsEditor(dispatch, {licenseModelId, version});
67                                         break;
68                                 case overviewItems.LICENSE_AGREEMENTS:
69                                         LicenseAgreementActionHelper.openLicenseAgreementEditor(dispatch, {licenseModelId, version});
70                                         break;
71                                 case overviewItems.LICENSE_KEY_GROUPS:
72                                         LicenseKeyGroupsActionHelper.openLicenseKeyGroupsEditor(dispatch);
73                                         break;
74                                 default:
75                                         break;
76                         }
77                 },
78                 onNavigateClick: ({name, licenseModelId, version}) => {
79                         let screenToNavigate;
80                         switch (name) {
81                                 case overviewItems.ENTITLEMENT_POOLS:
82                                         screenToNavigate = enums.SCREEN.ENTITLEMENT_POOLS;
83                                         break;
84                                 case overviewItems.FEATURE_GROUPS:
85                                         screenToNavigate = enums.SCREEN.FEATURE_GROUPS;
86                                         break;
87                                 case overviewItems.LICENSE_AGREEMENTS:
88                                         screenToNavigate = enums.SCREEN.LICENSE_AGREEMENTS;
89                                         break;
90                                 case overviewItems.LICENSE_KEY_GROUPS:
91                                         screenToNavigate = enums.SCREEN.LICENSE_KEY_GROUPS;
92                                         break;
93                                 default:
94                                         break;
95                         }
96                         ScreensHelper.loadScreen(dispatch, {
97                                 screen: screenToNavigate, screenType: screenTypes.LICENSE_MODEL,
98                                 props: {licenseModelId, version}
99                         });
100                 }
101         };
102 };
103
104 export class SummaryCountList extends React.Component {
105
106         render() {
107                 let {counts} = this.props;
108                 return(
109                         <div className='summary-count-list'>
110                                 {counts.map(item => this.renderItem(item))}
111                         </div>
112                 );
113         }
114
115         renderItem(item){
116                 const {name, count} = item;
117                 const {isReadOnlyMode} = this.props;
118                 return(
119                         <SummaryCountItem isReadOnlyMode={isReadOnlyMode} name={name} counter={count} onNavigate={() => this.onNavigate(name)} onAdd={() => this.onAdd(name)} key={name} />
120                 );
121         }
122
123         onAdd(name) {
124                 let {onEditorOpenClick, licenseModelId, isReadOnlyMode, version} = this.props;
125                 if (!isReadOnlyMode) {
126                         onEditorOpenClick(name, licenseModelId, version);
127                 }
128         }
129
130         onNavigate(name) {
131                 let {onNavigateClick, licenseModelId, version} = this.props;
132                 onNavigateClick({licenseModelId, name, version});
133         }
134 }
135
136 export default connect(mapStateToProps, mapActionsToProps)(SummaryCountList);