2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 import {connect} from 'react-redux';
17 import LicenseModelActionHelper from 'sdc-app/onboarding/licenseModel/LicenseModelActionHelper.js';
18 import LicenseModelOverviewView from './LicenseModelOverviewView.jsx';
19 import {overviewEditorHeaders, selectedButton} from './LicenseModelOverviewConstants.js';
20 import licenseModelOverviewActionHelper from './licenseModelOverviewActionHelper.js';
22 export const mapStateToProps = ({
33 let modalHeader, licensingDataList;
34 let isDisplayModal = false;
36 const reduceLicenseKeyGroups = (accum, licenseKeyGroupId) => {
37 let curLicenseKeyGroup = licenseKeyGroup.licenseKeyGroupsList.find(item => {return item.id === licenseKeyGroupId;});
38 if (curLicenseKeyGroup) {
40 ...curLicenseKeyGroup,
41 itemType: overviewEditorHeaders.LICENSE_KEY_GROUP
47 const reduceEntitlementPools = (accum, entitlementPoolId) => {
48 let curEntitlementPool = entitlementPool.entitlementPoolsList.find(item => {return item.id === entitlementPoolId;});
49 if (curEntitlementPool) {
51 ...curEntitlementPool,
52 itemType: overviewEditorHeaders.ENTITLEMENT_POOL
58 const reduceFeatureGroups = (accum, featureGroupId) => {
59 let curFeatureGroup = featureGroup.featureGroupsList.find(item => {return item.id === featureGroupId;});
60 if (curFeatureGroup) {
61 let {entitlementPoolsIds = [], licenseKeyGroupsIds = []} = curFeatureGroup;
64 itemType: overviewEditorHeaders.FEATURE_GROUP,
66 ...entitlementPoolsIds.length ? entitlementPoolsIds.reduce(reduceEntitlementPools, []) : [],
67 ...licenseKeyGroupsIds.length ? licenseKeyGroupsIds.reduce(reduceLicenseKeyGroups, []) : []
75 const checkEP = (accum, elem) => {
76 if (!elem.referencingFeatureGroups || !elem.referencingFeatureGroups.length) {
79 itemType: overviewEditorHeaders.ENTITLEMENT_POOL
85 const checkLG = (accum, elem) => {
86 if (!elem.referencingFeatureGroups || !elem.referencingFeatureGroups.length) {
89 itemType: overviewEditorHeaders.LICENSE_KEY_GROUP
95 const checkFG = (accum, elem) => {
96 if (!elem.referencingLicenseAgreements || !elem.referencingLicenseAgreements.length) {
97 let {entitlementPoolsIds = [], licenseKeyGroupsIds = []} = elem;
100 itemType: overviewEditorHeaders.FEATURE_GROUP,
103 ...entitlementPoolsIds.length ? entitlementPoolsIds.reduce(reduceEntitlementPools, []) : [],
104 ...licenseKeyGroupsIds.length ? licenseKeyGroupsIds.reduce(reduceLicenseKeyGroups, []) : []
114 const mapLicenseAgreementData = licenseAgreement => {
115 let {featureGroupsIds = []} = licenseAgreement;
118 itemType: overviewEditorHeaders.LICENSE_AGREEMENT,
119 children: featureGroupsIds.length ? featureGroupsIds.reduce(reduceFeatureGroups, []) : []
123 if (entitlementPool.entitlementPoolEditor && entitlementPool.entitlementPoolEditor.data) {
124 modalHeader = overviewEditorHeaders.ENTITLEMENT_POOL;
125 isDisplayModal = true;
127 if (licenseAgreement.licenseAgreementEditor && licenseAgreement.licenseAgreementEditor.data) {
128 modalHeader = overviewEditorHeaders.LICENSE_AGREEMENT;
129 isDisplayModal = true;
131 if (featureGroup.featureGroupEditor && featureGroup.featureGroupEditor.data) {
132 modalHeader = overviewEditorHeaders.FEATURE_GROUP;
133 isDisplayModal = true;
135 if (licenseKeyGroup.licenseKeyGroupsEditor && licenseKeyGroup.licenseKeyGroupsEditor.data) {
136 modalHeader = overviewEditorHeaders.LICENSE_KEY_GROUP;
137 isDisplayModal = true;
140 let orphanDataList = [
141 ...featureGroup.featureGroupsList.reduce(checkFG, []),
142 ...entitlementPool.entitlementPoolsList.reduce(checkEP, []),
143 ...licenseKeyGroup.licenseKeyGroupsList.reduce(checkLG, [])
146 licensingDataList = licenseAgreement.licenseAgreementList && licenseAgreement.licenseAgreementList.length ? licenseAgreement.licenseAgreementList.map(mapLicenseAgreementData) : [];
147 let selectedTab = licenseModelOverview.selectedTab;
148 // on first entry, we will decide what tab to open depending on data. if there are no connections, we will open the orphans
149 if (selectedTab === null) {
150 selectedTab = (licensingDataList.length) ? selectedButton.VLM_LIST_VIEW : selectedButton.NOT_IN_USE;
156 licenseModelId: licenseModelEditor.data.id,
157 version: licenseModelEditor.data.version,
164 const mapActionsToProps = (dispatch, {licenseModelId}) => {
166 onCallVCAction: action => {
167 LicenseModelActionHelper.performVCAction(dispatch, {licenseModelId, action});
169 onTabSelect: (buttonTab) => licenseModelOverviewActionHelper.selectVLMListView(dispatch,{buttonTab})
173 export default connect(mapStateToProps, mapActionsToProps)(LicenseModelOverviewView);