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 | */ |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 16 | import { connect } from 'react-redux'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 17 | import LicenseModelActionHelper from 'sdc-app/onboarding/licenseModel/LicenseModelActionHelper.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 18 | import LicenseModelOverviewView from './LicenseModelOverviewView.jsx'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 19 | import { |
| 20 | overviewEditorHeaders, |
| 21 | selectedButton |
| 22 | } from './LicenseModelOverviewConstants.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 23 | import licenseModelOverviewActionHelper from './licenseModelOverviewActionHelper.js'; |
| 24 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 25 | export const mapStateToProps = ({ |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 26 | licenseModel: { |
| 27 | licenseModelEditor, |
| 28 | entitlementPool, |
| 29 | licenseAgreement, |
| 30 | featureGroup, |
| 31 | licenseKeyGroup, |
| 32 | licenseModelOverview |
| 33 | } |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 34 | }) => { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 35 | let modalHeader, licensingDataList; |
| 36 | let isDisplayModal = false; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 37 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 38 | 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 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 52 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 53 | 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 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 67 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 68 | 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 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 92 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 93 | 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 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 105 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 106 | 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 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 118 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 119 | 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, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 128 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 129 | children: [ |
| 130 | ...(entitlementPoolsIds.length |
| 131 | ? entitlementPoolsIds.reduce(reduceEntitlementPools, []) |
| 132 | : []), |
| 133 | ...(licenseKeyGroupsIds.length |
| 134 | ? licenseKeyGroupsIds.reduce(reduceLicenseKeyGroups, []) |
| 135 | : []) |
| 136 | ] |
| 137 | }); |
| 138 | } |
| 139 | return accum; |
| 140 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 141 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 142 | 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 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 152 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 153 | 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 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 178 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 179 | let orphanDataList = [ |
| 180 | ...featureGroup.featureGroupsList.reduce(checkFG, []), |
| 181 | ...entitlementPool.entitlementPoolsList.reduce(checkEP, []), |
| 182 | ...licenseKeyGroup.licenseKeyGroupsList.reduce(checkLG, []) |
| 183 | ]; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 184 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 185 | 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 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 197 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 198 | return { |
| 199 | isDisplayModal, |
| 200 | modalHeader, |
| 201 | licenseModelId: licenseModelEditor.data.id, |
| 202 | version: licenseModelEditor.data.version, |
| 203 | licensingDataList, |
| 204 | orphanDataList, |
| 205 | selectedTab |
| 206 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 207 | }; |
| 208 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 209 | const 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 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 222 | }; |
| 223 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 224 | export default connect(mapStateToProps, mapActionsToProps)( |
| 225 | LicenseModelOverviewView |
| 226 | ); |