AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 1 | /*! |
| 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 | */ |
| 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'; |
| 22 | |
| 23 | export 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 | } |
ilanap | c6a41de | 2017-11-07 11:54:10 +0200 | [diff] [blame^] | 131 | let orphanDataList = [ |
| 132 | ...featureGroup.featureGroupsList.reduce(checkFG, []), |
| 133 | ...entitlementPool.entitlementPoolsList.reduce(checkEP, []), |
| 134 | ...licenseKeyGroup.licenseKeyGroupsList.reduce(checkLG, []) |
| 135 | ]; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 136 | |
ilanap | c6a41de | 2017-11-07 11:54:10 +0200 | [diff] [blame^] | 137 | licensingDataList = licenseAgreement.licenseAgreementList && licenseAgreement.licenseAgreementList.length ? licenseAgreement.licenseAgreementList.map(mapLicenseAgreementData) : []; |
| 138 | let selectedTab = licenseModelOverview.selectedTab; |
| 139 | // on first entry, we will decide what tab to open depending on data. if there are no connections, we will open the orphans |
| 140 | if (selectedTab === null) { |
| 141 | selectedTab = (licensingDataList.length) ? selectedButton.VLM_LIST_VIEW : selectedButton.NOT_IN_USE; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 142 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 143 | return { |
| 144 | isReadOnlyMode: VersionControllerUtils.isReadOnly(licenseModelEditor.data), |
| 145 | isDisplayModal, |
| 146 | modalHeader, |
| 147 | licenseModelId: licenseModelEditor.data.id, |
| 148 | version: licenseModelEditor.data.version, |
| 149 | licensingDataList, |
ilanap | c6a41de | 2017-11-07 11:54:10 +0200 | [diff] [blame^] | 150 | orphanDataList, |
| 151 | selectedTab |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 152 | }; |
| 153 | }; |
| 154 | |
| 155 | const mapActionsToProps = (dispatch, {licenseModelId}) => { |
| 156 | return { |
| 157 | onCallVCAction: action => { |
| 158 | LicenseModelActionHelper.performVCAction(dispatch, {licenseModelId, action}); |
| 159 | }, |
| 160 | onTabSelect: (buttonTab) => licenseModelOverviewActionHelper.selectVLMListView(dispatch,{buttonTab}) |
| 161 | }; |
| 162 | }; |
| 163 | |
| 164 | export default connect(mapStateToProps, mapActionsToProps)(LicenseModelOverviewView); |