blob: e21b0a81b04b0546c0da71e2b3d4c34f720cdb73 [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
Michael Landoefa037d2017-02-19 12:57:33 +02002 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
AviZi280f8012017-06-09 02:39:56 +03003 *
Michael Landoefa037d2017-02-19 12:57:33 +02004 * 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
AviZi280f8012017-06-09 02:39:56 +03007 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
Michael Landoefa037d2017-02-19 12:57:33 +020010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
AviZi280f8012017-06-09 02:39:56 +030012 * 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 Landoefa037d2017-02-19 12:57:33 +020015 */
Michael Landoefa037d2017-02-19 12:57:33 +020016import {connect} from 'react-redux';
17
18import i18n from 'nfvo-utils/i18n/i18n.js';
Michael Landoefa037d2017-02-19 12:57:33 +020019import VersionControllerUtils from 'nfvo-components/panel/versionController/VersionControllerUtils.js';
20import TabulatedEditor from 'src/nfvo-components/editor/TabulatedEditor.jsx';
AviZi280f8012017-06-09 02:39:56 +030021import ActivityLogActionHelper from 'nfvo-components/activity-log/ActivityLogActionHelper.js';
Michael Landoefa037d2017-02-19 12:57:33 +020022import {enums} from 'sdc-app/onboarding/OnboardingConstants.js';
23import OnboardingActionHelper from 'sdc-app/onboarding/OnboardingActionHelper.js';
24
25import {navigationItems} from './LicenseModelConstants.js';
26import LicenseModelActionHelper from './LicenseModelActionHelper.js';
27import LicenseAgreementActionHelper from './licenseAgreement/LicenseAgreementActionHelper.js';
28import FeatureGroupsActionHelper from './featureGroups/FeatureGroupsActionHelper.js';
29import EntitlementPoolsActionHelper from './entitlementPools/EntitlementPoolsActionHelper.js';
30import LicenseKeyGroupsActionHelper from './licenseKeyGroups/LicenseKeyGroupsActionHelper.js';
31
32
33const 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 {
AviZi280f8012017-06-09 02:39:56 +030042 id: navigationItems.LICENSE_MODEL_OVERVIEW,
43 name: i18n('Overview'),
44 meta
45 },
46 {
Michael Landoefa037d2017-02-19 12:57:33 +020047 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
AviZi280f8012017-06-09 02:39:56 +030065 },
66 {
67 id: navigationItems.ACTIVITY_LOG,
68 name: i18n('Activity Log'),
69 meta
Michael Landoefa037d2017-02-19 12:57:33 +020070 }
71 ]
72 }];
73
74 const activeItemId = ({
AviZi280f8012017-06-09 02:39:56 +030075 [enums.SCREEN.LICENSE_MODEL_OVERVIEW]: navigationItems.LICENSE_MODEL_OVERVIEW,
Michael Landoefa037d2017-02-19 12:57:33 +020076 [enums.SCREEN.LICENSE_AGREEMENTS]: navigationItems.LICENSE_AGREEMENTS,
77 [enums.SCREEN.FEATURE_GROUPS]: navigationItems.FEATURE_GROUPS,
78 [enums.SCREEN.ENTITLEMENT_POOLS]: navigationItems.ENTITLEMENT_POOLS,
AviZi280f8012017-06-09 02:39:56 +030079 [enums.SCREEN.LICENSE_KEY_GROUPS]: navigationItems.LICENSE_KEY_GROUPS,
80 [enums.SCREEN.ACTIVITY_LOG]: navigationItems.ACTIVITY_LOG
Michael Landoefa037d2017-02-19 12:57:33 +020081 })[screen];
82
83 return {
84 activeItemId, groups
85 };
86};
87
88
89const buildVersionControllerProps = (licenseModel) => {
90 let {version, viewableVersions, status: currentStatus, lockingUser} = licenseModel;
AviZi280f8012017-06-09 02:39:56 +030091 let {status, isCheckedOut} = VersionControllerUtils.getCheckOutStatusKindByUserID(currentStatus, lockingUser);
Michael Landoefa037d2017-02-19 12:57:33 +020092
93 return {
94 version,
95 viewableVersions,
96 status,
97 isCheckedOut
98 };
99};
100
101
102const mapStateToProps = ({licenseModel: {licenseModelEditor}}, {currentScreen: {screen}}) => {
103 return {
104 versionControllerProps: buildVersionControllerProps(licenseModelEditor.data),
105 navigationBarProps: buildNavigationBarProps(licenseModelEditor.data, screen)
106 };
107};
108
109
110const mapActionsToProps = (dispatch, {currentScreen: {screen, props: {licenseModelId}}}) => {
AviZi280f8012017-06-09 02:39:56 +0300111
Michael Landoefa037d2017-02-19 12:57:33 +0200112 return {
AviZi280f8012017-06-09 02:39:56 +0300113 onVersionControllerAction: (action, version) =>
114 LicenseModelActionHelper.performVCAction(dispatch, {licenseModelId, action, version}).then((newVersion) => {
Michael Landoefa037d2017-02-19 12:57:33 +0200115 switch(screen) {
AviZi280f8012017-06-09 02:39:56 +0300116 case enums.SCREEN.LICENSE_MODEL_OVERVIEW:
117 /**
118 * TODO change to specific rest
119 */
120 LicenseAgreementActionHelper.fetchLicenseAgreementList(dispatch, {licenseModelId, version: newVersion});
121 break;
Michael Landoefa037d2017-02-19 12:57:33 +0200122 case enums.SCREEN.LICENSE_AGREEMENTS:
AviZi280f8012017-06-09 02:39:56 +0300123 LicenseAgreementActionHelper.fetchLicenseAgreementList(dispatch, {licenseModelId, version: newVersion});
Michael Landoefa037d2017-02-19 12:57:33 +0200124 break;
125 case enums.SCREEN.FEATURE_GROUPS:
AviZi280f8012017-06-09 02:39:56 +0300126 FeatureGroupsActionHelper.fetchFeatureGroupsList(dispatch, {licenseModelId, version: newVersion});
Michael Landoefa037d2017-02-19 12:57:33 +0200127 break;
128 case enums.SCREEN.ENTITLEMENT_POOLS:
AviZi280f8012017-06-09 02:39:56 +0300129 EntitlementPoolsActionHelper.fetchEntitlementPoolsList(dispatch, {licenseModelId, version: newVersion});
Michael Landoefa037d2017-02-19 12:57:33 +0200130 break;
131 case enums.SCREEN.LICENSE_KEY_GROUPS:
AviZi280f8012017-06-09 02:39:56 +0300132 LicenseKeyGroupsActionHelper.fetchLicenseKeyGroupsList(dispatch, {licenseModelId, version: newVersion});
133 break;
134 case enums.SCREEN.ACTIVITY_LOG:
135 ActivityLogActionHelper.fetchActivityLog(dispatch, {itemId: licenseModelId, versionId: newVersion.id});
Michael Landoefa037d2017-02-19 12:57:33 +0200136 break;
137 }
138 }),
AviZi280f8012017-06-09 02:39:56 +0300139 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 Landoefa037d2017-02-19 12:57:33 +0200145
146 onNavigate: ({id, meta: {version}}) => {
147 switch(id) {
AviZi280f8012017-06-09 02:39:56 +0300148 case navigationItems.LICENSE_MODEL_OVERVIEW:
149 OnboardingActionHelper.navigateToLicenseModelOverview(dispatch, {licenseModelId, version});
150 break;
Michael Landoefa037d2017-02-19 12:57:33 +0200151 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;
AviZi280f8012017-06-09 02:39:56 +0300163 case navigationItems.ACTIVITY_LOG:
164 OnboardingActionHelper.navigateToLicenseModelActivityLog(dispatch, {licenseModelId, version});
165 break;
Michael Landoefa037d2017-02-19 12:57:33 +0200166 }
167 }
168 };
169};
170
171export default connect(mapStateToProps, mapActionsToProps)(TabulatedEditor);