blob: 572b0292d7fb437af9ab97fd0853cd6ce141dfb0 [file] [log] [blame]
svishnevc72587e2018-09-12 13:25:42 +03001/*
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*/
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020016import { connect } from 'react-redux';
svishnevc72587e2018-09-12 13:25:42 +030017import sortByStringProperty from 'nfvo-utils/sortByStringProperty.js';
AviZi280f8012017-06-09 02:39:56 +030018import LicenseModelActionHelper from 'sdc-app/onboarding/licenseModel/LicenseModelActionHelper.js';
AviZi280f8012017-06-09 02:39:56 +030019import LicenseModelOverviewView from './LicenseModelOverviewView.jsx';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020020import {
21 overviewEditorHeaders,
22 selectedButton
23} from './LicenseModelOverviewConstants.js';
AviZi280f8012017-06-09 02:39:56 +030024import licenseModelOverviewActionHelper from './licenseModelOverviewActionHelper.js';
svishnevc72587e2018-09-12 13:25:42 +030025import { SORTING_PROPERTY_NAME } from 'sdc-app/onboarding/licenseModel/LicenseModelConstants.js';
AviZi280f8012017-06-09 02:39:56 +030026
talig8e9c0652017-12-20 14:30:43 +020027export const mapStateToProps = ({
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020028 licenseModel: {
29 licenseModelEditor,
30 entitlementPool,
31 licenseAgreement,
32 featureGroup,
33 licenseKeyGroup,
34 licenseModelOverview
35 }
talig8e9c0652017-12-20 14:30:43 +020036}) => {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020037 let modalHeader, licensingDataList;
38 let isDisplayModal = false;
AviZi280f8012017-06-09 02:39:56 +030039
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020040 const reduceLicenseKeyGroups = (accum, licenseKeyGroupId) => {
41 let curLicenseKeyGroup = licenseKeyGroup.licenseKeyGroupsList.find(
42 item => {
43 return item.id === licenseKeyGroupId;
44 }
45 );
46 if (curLicenseKeyGroup) {
47 accum.push({
48 ...curLicenseKeyGroup,
49 itemType: overviewEditorHeaders.LICENSE_KEY_GROUP
50 });
51 }
52 return accum;
53 };
AviZi280f8012017-06-09 02:39:56 +030054
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020055 const reduceEntitlementPools = (accum, entitlementPoolId) => {
56 let curEntitlementPool = entitlementPool.entitlementPoolsList.find(
57 item => {
58 return item.id === entitlementPoolId;
59 }
60 );
61 if (curEntitlementPool) {
62 accum.push({
63 ...curEntitlementPool,
64 itemType: overviewEditorHeaders.ENTITLEMENT_POOL
65 });
66 }
67 return accum;
68 };
AviZi280f8012017-06-09 02:39:56 +030069
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020070 const reduceFeatureGroups = (accum, featureGroupId) => {
71 let curFeatureGroup = featureGroup.featureGroupsList.find(item => {
72 return item.id === featureGroupId;
73 });
74 if (curFeatureGroup) {
75 let {
76 entitlementPoolsIds = [],
77 licenseKeyGroupsIds = []
78 } = curFeatureGroup;
79 accum.push({
80 ...curFeatureGroup,
81 itemType: overviewEditorHeaders.FEATURE_GROUP,
82 children: [
svishnevc72587e2018-09-12 13:25:42 +030083 ...sortByStringProperty(
84 entitlementPoolsIds.length
85 ? entitlementPoolsIds.reduce(
86 reduceEntitlementPools,
87 []
88 )
89 : [],
90 SORTING_PROPERTY_NAME
91 ),
92 ...sortByStringProperty(
93 licenseKeyGroupsIds.length
94 ? licenseKeyGroupsIds.reduce(
95 reduceLicenseKeyGroups,
96 []
97 )
98 : [],
99 SORTING_PROPERTY_NAME
100 )
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200101 ]
102 });
103 }
104 return accum;
105 };
AviZi280f8012017-06-09 02:39:56 +0300106
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200107 const checkEP = (accum, elem) => {
108 if (
109 !elem.referencingFeatureGroups ||
110 !elem.referencingFeatureGroups.length
111 ) {
112 accum.push({
113 ...elem,
114 itemType: overviewEditorHeaders.ENTITLEMENT_POOL
115 });
116 }
117 return accum;
118 };
AviZi280f8012017-06-09 02:39:56 +0300119
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200120 const checkLG = (accum, elem) => {
121 if (
122 !elem.referencingFeatureGroups ||
123 !elem.referencingFeatureGroups.length
124 ) {
125 accum.push({
126 ...elem,
127 itemType: overviewEditorHeaders.LICENSE_KEY_GROUP
128 });
129 }
130 return accum;
131 };
AviZi280f8012017-06-09 02:39:56 +0300132
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200133 const checkFG = (accum, elem) => {
134 if (
135 !elem.referencingLicenseAgreements ||
136 !elem.referencingLicenseAgreements.length
137 ) {
138 let { entitlementPoolsIds = [], licenseKeyGroupsIds = [] } = elem;
139 accum.push({
140 ...elem,
141 itemType: overviewEditorHeaders.FEATURE_GROUP,
AviZi280f8012017-06-09 02:39:56 +0300142
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200143 children: [
144 ...(entitlementPoolsIds.length
145 ? entitlementPoolsIds.reduce(reduceEntitlementPools, [])
146 : []),
147 ...(licenseKeyGroupsIds.length
148 ? licenseKeyGroupsIds.reduce(reduceLicenseKeyGroups, [])
149 : [])
150 ]
151 });
152 }
153 return accum;
154 };
AviZi280f8012017-06-09 02:39:56 +0300155
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200156 const mapLicenseAgreementData = licenseAgreement => {
157 let { featureGroupsIds = [] } = licenseAgreement;
158 return {
159 ...licenseAgreement,
160 itemType: overviewEditorHeaders.LICENSE_AGREEMENT,
161 children: featureGroupsIds.length
svishnevc72587e2018-09-12 13:25:42 +0300162 ? sortByStringProperty(
163 featureGroupsIds.reduce(reduceFeatureGroups, []),
164 SORTING_PROPERTY_NAME
165 )
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200166 : []
167 };
168 };
AviZi280f8012017-06-09 02:39:56 +0300169
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200170 if (
171 entitlementPool.entitlementPoolEditor &&
172 entitlementPool.entitlementPoolEditor.data
173 ) {
174 modalHeader = overviewEditorHeaders.ENTITLEMENT_POOL;
175 isDisplayModal = true;
176 } else if (
177 licenseAgreement.licenseAgreementEditor &&
178 licenseAgreement.licenseAgreementEditor.data
179 ) {
180 modalHeader = overviewEditorHeaders.LICENSE_AGREEMENT;
181 isDisplayModal = true;
182 } else if (
183 featureGroup.featureGroupEditor &&
184 featureGroup.featureGroupEditor.data
185 ) {
186 modalHeader = overviewEditorHeaders.FEATURE_GROUP;
187 isDisplayModal = true;
188 } else if (
189 licenseKeyGroup.licenseKeyGroupsEditor &&
190 licenseKeyGroup.licenseKeyGroupsEditor.data
191 ) {
192 modalHeader = overviewEditorHeaders.LICENSE_KEY_GROUP;
193 isDisplayModal = true;
194 }
AviZi280f8012017-06-09 02:39:56 +0300195
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200196 let orphanDataList = [
svishnevc72587e2018-09-12 13:25:42 +0300197 ...sortByStringProperty(
198 featureGroup.featureGroupsList.reduce(checkFG, []),
199 SORTING_PROPERTY_NAME
200 ),
201 ...sortByStringProperty(
202 entitlementPool.entitlementPoolsList.reduce(checkEP, []),
203 SORTING_PROPERTY_NAME
204 ),
205 ...sortByStringProperty(
206 licenseKeyGroup.licenseKeyGroupsList.reduce(checkLG, []),
207 SORTING_PROPERTY_NAME
208 )
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200209 ];
AviZi280f8012017-06-09 02:39:56 +0300210
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200211 licensingDataList =
212 licenseAgreement.licenseAgreementList &&
213 licenseAgreement.licenseAgreementList.length
svishnevc72587e2018-09-12 13:25:42 +0300214 ? sortByStringProperty(
215 licenseAgreement.licenseAgreementList.map(
216 mapLicenseAgreementData
217 ),
218 SORTING_PROPERTY_NAME
219 )
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200220 : [];
221 let selectedTab = licenseModelOverview.selectedTab;
222 // on first entry, we will decide what tab to open depending on data. if there are no connections, we will open the orphans
223 if (selectedTab === null) {
224 selectedTab = licensingDataList.length
225 ? selectedButton.VLM_LIST_VIEW
226 : selectedButton.NOT_IN_USE;
227 }
AviZi280f8012017-06-09 02:39:56 +0300228
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200229 return {
230 isDisplayModal,
231 modalHeader,
232 licenseModelId: licenseModelEditor.data.id,
233 version: licenseModelEditor.data.version,
234 licensingDataList,
235 orphanDataList,
236 selectedTab
237 };
AviZi280f8012017-06-09 02:39:56 +0300238};
239
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200240const mapActionsToProps = (dispatch, { licenseModelId }) => {
241 return {
242 onCallVCAction: action => {
243 LicenseModelActionHelper.performVCAction(dispatch, {
244 licenseModelId,
245 action
246 });
247 },
248 onTabSelect: buttonTab =>
249 licenseModelOverviewActionHelper.selectVLMListView(dispatch, {
250 buttonTab
251 })
252 };
AviZi280f8012017-06-09 02:39:56 +0300253};
254
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200255export default connect(mapStateToProps, mapActionsToProps)(
256 LicenseModelOverviewView
257);