blob: 2b10e426d1037849ad886194b5b5386a0d9c7ff8 [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 */
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020016import { connect } from 'react-redux';
AviZi280f8012017-06-09 02:39:56 +030017import LicenseModelActionHelper from 'sdc-app/onboarding/licenseModel/LicenseModelActionHelper.js';
AviZi280f8012017-06-09 02:39:56 +030018import LicenseModelOverviewView from './LicenseModelOverviewView.jsx';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020019import {
20 overviewEditorHeaders,
21 selectedButton
22} from './LicenseModelOverviewConstants.js';
AviZi280f8012017-06-09 02:39:56 +030023import licenseModelOverviewActionHelper from './licenseModelOverviewActionHelper.js';
24
talig8e9c0652017-12-20 14:30:43 +020025export const mapStateToProps = ({
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020026 licenseModel: {
27 licenseModelEditor,
28 entitlementPool,
29 licenseAgreement,
30 featureGroup,
31 licenseKeyGroup,
32 licenseModelOverview
33 }
talig8e9c0652017-12-20 14:30:43 +020034}) => {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020035 let modalHeader, licensingDataList;
36 let isDisplayModal = false;
AviZi280f8012017-06-09 02:39:56 +030037
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020038 const reduceLicenseKeyGroups = (accum, licenseKeyGroupId) => {
39 let curLicenseKeyGroup = licenseKeyGroup.licenseKeyGroupsList.find(
40 item => {
41 return item.id === licenseKeyGroupId;
42 }
43 );
44 if (curLicenseKeyGroup) {
45 accum.push({
46 ...curLicenseKeyGroup,
47 itemType: overviewEditorHeaders.LICENSE_KEY_GROUP
48 });
49 }
50 return accum;
51 };
AviZi280f8012017-06-09 02:39:56 +030052
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020053 const reduceEntitlementPools = (accum, entitlementPoolId) => {
54 let curEntitlementPool = entitlementPool.entitlementPoolsList.find(
55 item => {
56 return item.id === entitlementPoolId;
57 }
58 );
59 if (curEntitlementPool) {
60 accum.push({
61 ...curEntitlementPool,
62 itemType: overviewEditorHeaders.ENTITLEMENT_POOL
63 });
64 }
65 return accum;
66 };
AviZi280f8012017-06-09 02:39:56 +030067
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020068 const reduceFeatureGroups = (accum, featureGroupId) => {
69 let curFeatureGroup = featureGroup.featureGroupsList.find(item => {
70 return item.id === featureGroupId;
71 });
72 if (curFeatureGroup) {
73 let {
74 entitlementPoolsIds = [],
75 licenseKeyGroupsIds = []
76 } = curFeatureGroup;
77 accum.push({
78 ...curFeatureGroup,
79 itemType: overviewEditorHeaders.FEATURE_GROUP,
80 children: [
81 ...(entitlementPoolsIds.length
82 ? entitlementPoolsIds.reduce(reduceEntitlementPools, [])
83 : []),
84 ...(licenseKeyGroupsIds.length
85 ? licenseKeyGroupsIds.reduce(reduceLicenseKeyGroups, [])
86 : [])
87 ]
88 });
89 }
90 return accum;
91 };
AviZi280f8012017-06-09 02:39:56 +030092
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020093 const checkEP = (accum, elem) => {
94 if (
95 !elem.referencingFeatureGroups ||
96 !elem.referencingFeatureGroups.length
97 ) {
98 accum.push({
99 ...elem,
100 itemType: overviewEditorHeaders.ENTITLEMENT_POOL
101 });
102 }
103 return accum;
104 };
AviZi280f8012017-06-09 02:39:56 +0300105
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200106 const checkLG = (accum, elem) => {
107 if (
108 !elem.referencingFeatureGroups ||
109 !elem.referencingFeatureGroups.length
110 ) {
111 accum.push({
112 ...elem,
113 itemType: overviewEditorHeaders.LICENSE_KEY_GROUP
114 });
115 }
116 return accum;
117 };
AviZi280f8012017-06-09 02:39:56 +0300118
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200119 const checkFG = (accum, elem) => {
120 if (
121 !elem.referencingLicenseAgreements ||
122 !elem.referencingLicenseAgreements.length
123 ) {
124 let { entitlementPoolsIds = [], licenseKeyGroupsIds = [] } = elem;
125 accum.push({
126 ...elem,
127 itemType: overviewEditorHeaders.FEATURE_GROUP,
AviZi280f8012017-06-09 02:39:56 +0300128
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200129 children: [
130 ...(entitlementPoolsIds.length
131 ? entitlementPoolsIds.reduce(reduceEntitlementPools, [])
132 : []),
133 ...(licenseKeyGroupsIds.length
134 ? licenseKeyGroupsIds.reduce(reduceLicenseKeyGroups, [])
135 : [])
136 ]
137 });
138 }
139 return accum;
140 };
AviZi280f8012017-06-09 02:39:56 +0300141
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200142 const mapLicenseAgreementData = licenseAgreement => {
143 let { featureGroupsIds = [] } = licenseAgreement;
144 return {
145 ...licenseAgreement,
146 itemType: overviewEditorHeaders.LICENSE_AGREEMENT,
147 children: featureGroupsIds.length
148 ? featureGroupsIds.reduce(reduceFeatureGroups, [])
149 : []
150 };
151 };
AviZi280f8012017-06-09 02:39:56 +0300152
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200153 if (
154 entitlementPool.entitlementPoolEditor &&
155 entitlementPool.entitlementPoolEditor.data
156 ) {
157 modalHeader = overviewEditorHeaders.ENTITLEMENT_POOL;
158 isDisplayModal = true;
159 } else if (
160 licenseAgreement.licenseAgreementEditor &&
161 licenseAgreement.licenseAgreementEditor.data
162 ) {
163 modalHeader = overviewEditorHeaders.LICENSE_AGREEMENT;
164 isDisplayModal = true;
165 } else if (
166 featureGroup.featureGroupEditor &&
167 featureGroup.featureGroupEditor.data
168 ) {
169 modalHeader = overviewEditorHeaders.FEATURE_GROUP;
170 isDisplayModal = true;
171 } else if (
172 licenseKeyGroup.licenseKeyGroupsEditor &&
173 licenseKeyGroup.licenseKeyGroupsEditor.data
174 ) {
175 modalHeader = overviewEditorHeaders.LICENSE_KEY_GROUP;
176 isDisplayModal = true;
177 }
AviZi280f8012017-06-09 02:39:56 +0300178
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200179 let orphanDataList = [
180 ...featureGroup.featureGroupsList.reduce(checkFG, []),
181 ...entitlementPool.entitlementPoolsList.reduce(checkEP, []),
182 ...licenseKeyGroup.licenseKeyGroupsList.reduce(checkLG, [])
183 ];
AviZi280f8012017-06-09 02:39:56 +0300184
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200185 licensingDataList =
186 licenseAgreement.licenseAgreementList &&
187 licenseAgreement.licenseAgreementList.length
188 ? licenseAgreement.licenseAgreementList.map(mapLicenseAgreementData)
189 : [];
190 let selectedTab = licenseModelOverview.selectedTab;
191 // on first entry, we will decide what tab to open depending on data. if there are no connections, we will open the orphans
192 if (selectedTab === null) {
193 selectedTab = licensingDataList.length
194 ? selectedButton.VLM_LIST_VIEW
195 : selectedButton.NOT_IN_USE;
196 }
AviZi280f8012017-06-09 02:39:56 +0300197
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200198 return {
199 isDisplayModal,
200 modalHeader,
201 licenseModelId: licenseModelEditor.data.id,
202 version: licenseModelEditor.data.version,
203 licensingDataList,
204 orphanDataList,
205 selectedTab
206 };
AviZi280f8012017-06-09 02:39:56 +0300207};
208
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200209const mapActionsToProps = (dispatch, { licenseModelId }) => {
210 return {
211 onCallVCAction: action => {
212 LicenseModelActionHelper.performVCAction(dispatch, {
213 licenseModelId,
214 action
215 });
216 },
217 onTabSelect: buttonTab =>
218 licenseModelOverviewActionHelper.selectVLMListView(dispatch, {
219 buttonTab
220 })
221 };
AviZi280f8012017-06-09 02:39:56 +0300222};
223
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200224export default connect(mapStateToProps, mapActionsToProps)(
225 LicenseModelOverviewView
226);