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 VersionControllerUtils from 'nfvo-components/panel/versionController/VersionControllerUtils.js';
19 import LicenseModelOverviewView from './LicenseModelOverviewView.jsx';
20 import {overviewEditorHeaders, selectedButton} from './LicenseModelOverviewConstants.js';
21 import licenseModelOverviewActionHelper from './licenseModelOverviewActionHelper.js';
23 export const mapStateToProps = ({licenseModel: {licenseModelEditor, entitlementPool, licenseAgreement, featureGroup, licenseKeyGroup, licenseModelOverview}}) => {
25 let modalHeader, licensingDataList;
26 let isDisplayModal = false;
28 const reduceLicenseKeyGroups = (accum, licenseKeyGroupId) => {
29 let curLicenseKeyGroup = licenseKeyGroup.licenseKeyGroupsList.find(item => {return item.id === licenseKeyGroupId;});
30 if (curLicenseKeyGroup) {
32 ...curLicenseKeyGroup,
33 itemType: overviewEditorHeaders.LICENSE_KEY_GROUP
39 const reduceEntitlementPools = (accum, entitlementPoolId) => {
40 let curEntitlementPool = entitlementPool.entitlementPoolsList.find(item => {return item.id === entitlementPoolId;});
41 if (curEntitlementPool) {
43 ...curEntitlementPool,
44 itemType: overviewEditorHeaders.ENTITLEMENT_POOL
50 const reduceFeatureGroups = (accum, featureGroupId) => {
51 let curFeatureGroup = featureGroup.featureGroupsList.find(item => {return item.id === featureGroupId;});
52 if (curFeatureGroup) {
53 let {entitlementPoolsIds = [], licenseKeyGroupsIds = []} = curFeatureGroup;
56 itemType: overviewEditorHeaders.FEATURE_GROUP,
58 ...entitlementPoolsIds.length ? entitlementPoolsIds.reduce(reduceEntitlementPools, []) : [],
59 ...licenseKeyGroupsIds.length ? licenseKeyGroupsIds.reduce(reduceLicenseKeyGroups, []) : []
67 const checkEP = (accum, elem) => {
68 if (!elem.referencingFeatureGroups || !elem.referencingFeatureGroups.length) {
71 itemType: overviewEditorHeaders.ENTITLEMENT_POOL
77 const checkLG = (accum, elem) => {
78 if (!elem.referencingFeatureGroups || !elem.referencingFeatureGroups.length) {
81 itemType: overviewEditorHeaders.LICENSE_KEY_GROUP
87 const checkFG = (accum, elem) => {
88 if (!elem.referencingLicenseAgreements || !elem.referencingLicenseAgreements.length) {
89 let {entitlementPoolsIds = [], licenseKeyGroupsIds = []} = elem;
92 itemType: overviewEditorHeaders.FEATURE_GROUP,
95 ...entitlementPoolsIds.length ? entitlementPoolsIds.reduce(reduceEntitlementPools, []) : [],
96 ...licenseKeyGroupsIds.length ? licenseKeyGroupsIds.reduce(reduceLicenseKeyGroups, []) : []
106 const mapLicenseAgreementData = licenseAgreement => {
107 let {featureGroupsIds = []} = licenseAgreement;
110 itemType: overviewEditorHeaders.LICENSE_AGREEMENT,
111 children: featureGroupsIds.length ? featureGroupsIds.reduce(reduceFeatureGroups, []) : []
115 if (entitlementPool.entitlementPoolEditor && entitlementPool.entitlementPoolEditor.data) {
116 modalHeader = overviewEditorHeaders.ENTITLEMENT_POOL;
117 isDisplayModal = true;
119 if (licenseAgreement.licenseAgreementEditor && licenseAgreement.licenseAgreementEditor.data) {
120 modalHeader = overviewEditorHeaders.LICENSE_AGREEMENT;
121 isDisplayModal = true;
123 if (featureGroup.featureGroupEditor && featureGroup.featureGroupEditor.data) {
124 modalHeader = overviewEditorHeaders.FEATURE_GROUP;
125 isDisplayModal = true;
127 if (licenseKeyGroup.licenseKeyGroupsEditor && licenseKeyGroup.licenseKeyGroupsEditor.data) {
128 modalHeader = overviewEditorHeaders.LICENSE_KEY_GROUP;
129 isDisplayModal = true;
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, [])
139 licensingDataList = licenseAgreement.licenseAgreementList && licenseAgreement.licenseAgreementList.length ? licenseAgreement.licenseAgreementList.map(mapLicenseAgreementData) : [];
143 isReadOnlyMode: VersionControllerUtils.isReadOnly(licenseModelEditor.data),
146 licenseModelId: licenseModelEditor.data.id,
147 version: licenseModelEditor.data.version,
149 selectedTab: licenseModelOverview.selectedTab
154 const mapActionsToProps = (dispatch, {licenseModelId}) => {
156 onCallVCAction: action => {
157 LicenseModelActionHelper.performVCAction(dispatch, {licenseModelId, action});
159 onTabSelect: (buttonTab) => licenseModelOverviewActionHelper.selectVLMListView(dispatch,{buttonTab})
163 export default connect(mapStateToProps, mapActionsToProps)(LicenseModelOverviewView);