blob: 1ca4f379888596958d9071099ebdbd00a7427147 [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
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 */
16import {connect} from 'react-redux';
17import LicenseModelActionHelper from 'sdc-app/onboarding/licenseModel/LicenseModelActionHelper.js';
18import VersionControllerUtils from 'nfvo-components/panel/versionController/VersionControllerUtils.js';
19import LicenseModelOverviewView from './LicenseModelOverviewView.jsx';
20import {overviewEditorHeaders, selectedButton} from './LicenseModelOverviewConstants.js';
21import licenseModelOverviewActionHelper from './licenseModelOverviewActionHelper.js';
22
23export const mapStateToProps = ({licenseModel: {licenseModelEditor, entitlementPool, licenseAgreement, featureGroup, licenseKeyGroup, licenseModelOverview}}) => {
24
25 let modalHeader, licensingDataList;
26 let isDisplayModal = false;
27
28 const reduceLicenseKeyGroups = (accum, licenseKeyGroupId) => {
29 let curLicenseKeyGroup = licenseKeyGroup.licenseKeyGroupsList.find(item => {return item.id === licenseKeyGroupId;});
30 if (curLicenseKeyGroup) {
31 accum.push({
32 ...curLicenseKeyGroup,
33 itemType: overviewEditorHeaders.LICENSE_KEY_GROUP
34 });
35 }
36 return accum;
37 };
38
39 const reduceEntitlementPools = (accum, entitlementPoolId) => {
40 let curEntitlementPool = entitlementPool.entitlementPoolsList.find(item => {return item.id === entitlementPoolId;});
41 if (curEntitlementPool) {
42 accum.push ({
43 ...curEntitlementPool,
44 itemType: overviewEditorHeaders.ENTITLEMENT_POOL
45 });
46 }
47 return accum;
48 };
49
50 const reduceFeatureGroups = (accum, featureGroupId) => {
51 let curFeatureGroup = featureGroup.featureGroupsList.find(item => {return item.id === featureGroupId;});
52 if (curFeatureGroup) {
53 let {entitlementPoolsIds = [], licenseKeyGroupsIds = []} = curFeatureGroup;
54 accum.push({
55 ...curFeatureGroup,
56 itemType: overviewEditorHeaders.FEATURE_GROUP,
57 children: [
58 ...entitlementPoolsIds.length ? entitlementPoolsIds.reduce(reduceEntitlementPools, []) : [],
59 ...licenseKeyGroupsIds.length ? licenseKeyGroupsIds.reduce(reduceLicenseKeyGroups, []) : []
60 ]
61 });
62 }
63 return accum;
64 };
65
66
67 const checkEP = (accum, elem) => {
68 if (!elem.referencingFeatureGroups || !elem.referencingFeatureGroups.length) {
69 accum.push({
70 ...elem,
71 itemType: overviewEditorHeaders.ENTITLEMENT_POOL
72 });
73 }
74 return accum;
75 };
76
77 const checkLG = (accum, elem) => {
78 if (!elem.referencingFeatureGroups || !elem.referencingFeatureGroups.length) {
79 accum.push({
80 ...elem,
81 itemType: overviewEditorHeaders.LICENSE_KEY_GROUP
82 });
83 }
84 return accum;
85 };
86
87 const checkFG = (accum, elem) => {
88 if (!elem.referencingLicenseAgreements || !elem.referencingLicenseAgreements.length) {
89 let {entitlementPoolsIds = [], licenseKeyGroupsIds = []} = elem;
90 accum.push({
91 ...elem,
92 itemType: overviewEditorHeaders.FEATURE_GROUP,
93
94 children: [
95 ...entitlementPoolsIds.length ? entitlementPoolsIds.reduce(reduceEntitlementPools, []) : [],
96 ...licenseKeyGroupsIds.length ? licenseKeyGroupsIds.reduce(reduceLicenseKeyGroups, []) : []
97 ]
98
99 });
100 }
101 return accum;
102 };
103
104
105
106 const mapLicenseAgreementData = licenseAgreement => {
107 let {featureGroupsIds = []} = licenseAgreement;
108 return {
109 ...licenseAgreement,
110 itemType: overviewEditorHeaders.LICENSE_AGREEMENT,
111 children: featureGroupsIds.length ? featureGroupsIds.reduce(reduceFeatureGroups, []) : []
112 };
113 };
114
115 if (entitlementPool.entitlementPoolEditor && entitlementPool.entitlementPoolEditor.data) {
116 modalHeader = overviewEditorHeaders.ENTITLEMENT_POOL;
117 isDisplayModal = true;
118 }else
119 if (licenseAgreement.licenseAgreementEditor && licenseAgreement.licenseAgreementEditor.data) {
120 modalHeader = overviewEditorHeaders.LICENSE_AGREEMENT;
121 isDisplayModal = true;
122 }else
123 if (featureGroup.featureGroupEditor && featureGroup.featureGroupEditor.data) {
124 modalHeader = overviewEditorHeaders.FEATURE_GROUP;
125 isDisplayModal = true;
126 }else
127 if (licenseKeyGroup.licenseKeyGroupsEditor && licenseKeyGroup.licenseKeyGroupsEditor.data) {
128 modalHeader = overviewEditorHeaders.LICENSE_KEY_GROUP;
129 isDisplayModal = true;
130 }
131
132 if (licenseModelOverview.selectedTab === selectedButton.NOT_IN_USE) {
133 licensingDataList = [
134 ...featureGroup.featureGroupsList.reduce(checkFG, []),
135 ...entitlementPool.entitlementPoolsList.reduce(checkEP, []),
136 ...licenseKeyGroup.licenseKeyGroupsList.reduce(checkLG, [])
137 ];
138 }else {
139 licensingDataList = licenseAgreement.licenseAgreementList && licenseAgreement.licenseAgreementList.length ? licenseAgreement.licenseAgreementList.map(mapLicenseAgreementData) : [];
140 }
141
142 return {
143 isReadOnlyMode: VersionControllerUtils.isReadOnly(licenseModelEditor.data),
144 isDisplayModal,
145 modalHeader,
146 licenseModelId: licenseModelEditor.data.id,
147 version: licenseModelEditor.data.version,
148 licensingDataList,
149 selectedTab: licenseModelOverview.selectedTab
150
151 };
152};
153
154const mapActionsToProps = (dispatch, {licenseModelId}) => {
155 return {
156 onCallVCAction: action => {
157 LicenseModelActionHelper.performVCAction(dispatch, {licenseModelId, action});
158 },
159 onTabSelect: (buttonTab) => licenseModelOverviewActionHelper.selectVLMListView(dispatch,{buttonTab})
160 };
161};
162
163export default connect(mapStateToProps, mapActionsToProps)(LicenseModelOverviewView);