AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 1 | /*! |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 2 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 3 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 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 |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 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. |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 15 | */ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 16 | import {connect} from 'react-redux'; |
| 17 | |
| 18 | import i18n from 'nfvo-utils/i18n/i18n.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 19 | import VersionControllerUtils from 'nfvo-components/panel/versionController/VersionControllerUtils.js'; |
| 20 | import TabulatedEditor from 'src/nfvo-components/editor/TabulatedEditor.jsx'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 21 | import ActivityLogActionHelper from 'nfvo-components/activity-log/ActivityLogActionHelper.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 22 | import {enums} from 'sdc-app/onboarding/OnboardingConstants.js'; |
| 23 | import OnboardingActionHelper from 'sdc-app/onboarding/OnboardingActionHelper.js'; |
| 24 | |
| 25 | import {navigationItems} from './LicenseModelConstants.js'; |
| 26 | import LicenseModelActionHelper from './LicenseModelActionHelper.js'; |
| 27 | import LicenseAgreementActionHelper from './licenseAgreement/LicenseAgreementActionHelper.js'; |
| 28 | import FeatureGroupsActionHelper from './featureGroups/FeatureGroupsActionHelper.js'; |
| 29 | import EntitlementPoolsActionHelper from './entitlementPools/EntitlementPoolsActionHelper.js'; |
| 30 | import LicenseKeyGroupsActionHelper from './licenseKeyGroups/LicenseKeyGroupsActionHelper.js'; |
| 31 | |
| 32 | |
| 33 | const buildNavigationBarProps = (licenseModel, screen) => { |
| 34 | const {id, vendorName, version} = licenseModel; |
| 35 | const meta = {version}; |
| 36 | |
| 37 | const groups = [{ |
| 38 | id, |
| 39 | name: vendorName, |
| 40 | items: [ |
| 41 | { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 42 | id: navigationItems.LICENSE_MODEL_OVERVIEW, |
| 43 | name: i18n('Overview'), |
| 44 | meta |
| 45 | }, |
| 46 | { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 47 | id: navigationItems.LICENSE_AGREEMENTS, |
| 48 | name: i18n('License Agreements'), |
| 49 | meta |
| 50 | }, |
| 51 | { |
| 52 | id: navigationItems.FEATURE_GROUPS, |
| 53 | name: i18n('Feature Groups'), |
| 54 | meta |
| 55 | }, |
| 56 | { |
| 57 | id: navigationItems.ENTITLEMENT_POOLS, |
| 58 | name: i18n('Entitlement Pools'), |
| 59 | meta |
| 60 | }, |
| 61 | { |
| 62 | id: navigationItems.LICENSE_KEY_GROUPS, |
| 63 | name: i18n('License Key Groups'), |
| 64 | meta |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 65 | }, |
| 66 | { |
| 67 | id: navigationItems.ACTIVITY_LOG, |
| 68 | name: i18n('Activity Log'), |
| 69 | meta |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 70 | } |
| 71 | ] |
| 72 | }]; |
| 73 | |
| 74 | const activeItemId = ({ |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 75 | [enums.SCREEN.LICENSE_MODEL_OVERVIEW]: navigationItems.LICENSE_MODEL_OVERVIEW, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 76 | [enums.SCREEN.LICENSE_AGREEMENTS]: navigationItems.LICENSE_AGREEMENTS, |
| 77 | [enums.SCREEN.FEATURE_GROUPS]: navigationItems.FEATURE_GROUPS, |
| 78 | [enums.SCREEN.ENTITLEMENT_POOLS]: navigationItems.ENTITLEMENT_POOLS, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 79 | [enums.SCREEN.LICENSE_KEY_GROUPS]: navigationItems.LICENSE_KEY_GROUPS, |
| 80 | [enums.SCREEN.ACTIVITY_LOG]: navigationItems.ACTIVITY_LOG |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 81 | })[screen]; |
| 82 | |
| 83 | return { |
| 84 | activeItemId, groups |
| 85 | }; |
| 86 | }; |
| 87 | |
| 88 | |
| 89 | const buildVersionControllerProps = (licenseModel) => { |
| 90 | let {version, viewableVersions, status: currentStatus, lockingUser} = licenseModel; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 91 | let {status, isCheckedOut} = VersionControllerUtils.getCheckOutStatusKindByUserID(currentStatus, lockingUser); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 92 | |
| 93 | return { |
| 94 | version, |
| 95 | viewableVersions, |
| 96 | status, |
| 97 | isCheckedOut |
| 98 | }; |
| 99 | }; |
| 100 | |
| 101 | |
| 102 | const mapStateToProps = ({licenseModel: {licenseModelEditor}}, {currentScreen: {screen}}) => { |
| 103 | return { |
| 104 | versionControllerProps: buildVersionControllerProps(licenseModelEditor.data), |
| 105 | navigationBarProps: buildNavigationBarProps(licenseModelEditor.data, screen) |
| 106 | }; |
| 107 | }; |
| 108 | |
| 109 | |
| 110 | const mapActionsToProps = (dispatch, {currentScreen: {screen, props: {licenseModelId}}}) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 111 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 112 | return { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 113 | onVersionControllerAction: (action, version) => |
| 114 | LicenseModelActionHelper.performVCAction(dispatch, {licenseModelId, action, version}).then((newVersion) => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 115 | switch(screen) { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 116 | case enums.SCREEN.LICENSE_MODEL_OVERVIEW: |
| 117 | /** |
| 118 | * TODO change to specific rest |
| 119 | */ |
| 120 | LicenseAgreementActionHelper.fetchLicenseAgreementList(dispatch, {licenseModelId, version: newVersion}); |
| 121 | break; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 122 | case enums.SCREEN.LICENSE_AGREEMENTS: |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 123 | LicenseAgreementActionHelper.fetchLicenseAgreementList(dispatch, {licenseModelId, version: newVersion}); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 124 | break; |
| 125 | case enums.SCREEN.FEATURE_GROUPS: |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 126 | FeatureGroupsActionHelper.fetchFeatureGroupsList(dispatch, {licenseModelId, version: newVersion}); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 127 | break; |
| 128 | case enums.SCREEN.ENTITLEMENT_POOLS: |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 129 | EntitlementPoolsActionHelper.fetchEntitlementPoolsList(dispatch, {licenseModelId, version: newVersion}); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 130 | break; |
| 131 | case enums.SCREEN.LICENSE_KEY_GROUPS: |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 132 | LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(dispatch, {licenseModelId, version: newVersion}); |
| 133 | break; |
| 134 | case enums.SCREEN.ACTIVITY_LOG: |
| 135 | ActivityLogActionHelper.fetchActivityLog(dispatch, {itemId: licenseModelId, versionId: newVersion.id}); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 136 | break; |
| 137 | } |
| 138 | }), |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 139 | onVersionSwitching: version => { |
| 140 | LicenseModelActionHelper.switchVersion(dispatch, {licenseModelId, version}); |
| 141 | if(screen === enums.SCREEN.ACTIVITY_LOG) { |
| 142 | ActivityLogActionHelper.fetchActivityLog(dispatch, {itemId: licenseModelId, versionId: version.id}); |
| 143 | } |
| 144 | }, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 145 | |
| 146 | onNavigate: ({id, meta: {version}}) => { |
| 147 | switch(id) { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 148 | case navigationItems.LICENSE_MODEL_OVERVIEW: |
| 149 | OnboardingActionHelper.navigateToLicenseModelOverview(dispatch, {licenseModelId, version}); |
| 150 | break; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 151 | case navigationItems.LICENSE_AGREEMENTS: |
| 152 | OnboardingActionHelper.navigateToLicenseAgreements(dispatch, {licenseModelId, version}); |
| 153 | break; |
| 154 | case navigationItems.FEATURE_GROUPS: |
| 155 | OnboardingActionHelper.navigateToFeatureGroups(dispatch, {licenseModelId, version}); |
| 156 | break; |
| 157 | case navigationItems.ENTITLEMENT_POOLS: |
| 158 | OnboardingActionHelper.navigateToEntitlementPools(dispatch, {licenseModelId, version}); |
| 159 | break; |
| 160 | case navigationItems.LICENSE_KEY_GROUPS: |
| 161 | OnboardingActionHelper.navigateToLicenseKeyGroups(dispatch, {licenseModelId, version}); |
| 162 | break; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame^] | 163 | case navigationItems.ACTIVITY_LOG: |
| 164 | OnboardingActionHelper.navigateToLicenseModelActivityLog(dispatch, {licenseModelId, version}); |
| 165 | break; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 166 | } |
| 167 | } |
| 168 | }; |
| 169 | }; |
| 170 | |
| 171 | export default connect(mapStateToProps, mapActionsToProps)(TabulatedEditor); |