blob: c390ecc9b069ef6354469a6c3ec4fbd4c3d82980 [file] [log] [blame]
svishnev091edfd2018-03-19 12:15:19 +02001/*
2 * Copyright © 2016-2018 European Support Limited
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
svishnev091edfd2018-03-19 12:15:19 +02007 *
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,
svishnev091edfd2018-03-19 12:15:19 +020012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * 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 TabulatedEditor from 'src/nfvo-components/editor/TabulatedEditor.jsx';
talig8e9c0652017-12-20 14:30:43 +020020import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js';
21import {enums, screenTypes} from 'sdc-app/onboarding/OnboardingConstants.js';
Michael Landoefa037d2017-02-19 12:57:33 +020022
talig8e9c0652017-12-20 14:30:43 +020023import PermissionsActionHelper from './../permissions/PermissionsActionHelper.js';
24import RevisionsActionHelper from './../revisions/RevisionsActionHelper.js';
25
Michael Landoefa037d2017-02-19 12:57:33 +020026import LicenseModelActionHelper from './LicenseModelActionHelper.js';
talig8e9c0652017-12-20 14:30:43 +020027import {actionTypes as modalActionTypes} from 'nfvo-components/modal/GlobalModalConstants.js';
28import {modalContentMapper} from 'sdc-app/common/modal/ModalContentMapper.js';
29import {CommitModalType} from 'nfvo-components/panel/versionController/components/CommitCommentModal.jsx';
Michael Landoefa037d2017-02-19 12:57:33 +020030
Michael Landoefa037d2017-02-19 12:57:33 +020031const buildNavigationBarProps = (licenseModel, screen) => {
32 const {id, vendorName, version} = licenseModel;
33 const meta = {version};
34
35 const groups = [{
36 id,
37 name: vendorName,
38 items: [
39 {
talig8e9c0652017-12-20 14:30:43 +020040 id: enums.SCREEN.LICENSE_MODEL_OVERVIEW,
AviZi280f8012017-06-09 02:39:56 +030041 name: i18n('Overview'),
42 meta
43 },
44 {
talig8e9c0652017-12-20 14:30:43 +020045 id: enums.SCREEN.LICENSE_AGREEMENTS,
Michael Landoefa037d2017-02-19 12:57:33 +020046 name: i18n('License Agreements'),
47 meta
48 },
49 {
talig8e9c0652017-12-20 14:30:43 +020050 id: enums.SCREEN.FEATURE_GROUPS,
Michael Landoefa037d2017-02-19 12:57:33 +020051 name: i18n('Feature Groups'),
52 meta
53 },
54 {
talig8e9c0652017-12-20 14:30:43 +020055 id: enums.SCREEN.ENTITLEMENT_POOLS,
Michael Landoefa037d2017-02-19 12:57:33 +020056 name: i18n('Entitlement Pools'),
57 meta
58 },
59 {
talig8e9c0652017-12-20 14:30:43 +020060 id: enums.SCREEN.LICENSE_KEY_GROUPS,
Michael Landoefa037d2017-02-19 12:57:33 +020061 name: i18n('License Key Groups'),
62 meta
AviZi280f8012017-06-09 02:39:56 +030063 },
64 {
talig8e9c0652017-12-20 14:30:43 +020065 id: enums.SCREEN.ACTIVITY_LOG,
AviZi280f8012017-06-09 02:39:56 +030066 name: i18n('Activity Log'),
67 meta
Michael Landoefa037d2017-02-19 12:57:33 +020068 }
69 ]
70 }];
71
Michael Landoefa037d2017-02-19 12:57:33 +020072 return {
talig8e9c0652017-12-20 14:30:43 +020073 activeItemId: screen, groups
Michael Landoefa037d2017-02-19 12:57:33 +020074 };
75};
76
77
talig8e9c0652017-12-20 14:30:43 +020078const buildVersionControllerProps = ({
79 licenseModelEditor = {data: {}},
80 versions,
81 currentVersion,
82 userInfo,
83 usersList,
84 permissions,
svishnev091edfd2018-03-19 12:15:19 +020085 isArchived,
talig8e9c0652017-12-20 14:30:43 +020086 itemPermission,
87 isReadOnlyMode
88}) => {
89 const {isValidityData = true} = licenseModelEditor;
Michael Landoefa037d2017-02-19 12:57:33 +020090 return {
talig8e9c0652017-12-20 14:30:43 +020091 version: currentVersion,
92 viewableVersions: versions,
93 isFormDataValid: isValidityData,
94 permissions,
95 userInfo,
96 usersList,
svishnev091edfd2018-03-19 12:15:19 +020097 isArchived,
talig8e9c0652017-12-20 14:30:43 +020098 itemName: licenseModelEditor.data.vendorName,
99 itemPermission,
100 isReadOnlyMode
Michael Landoefa037d2017-02-19 12:57:33 +0200101 };
102};
103
104
talig8e9c0652017-12-20 14:30:43 +0200105const mapStateToProps = ({
106 users: {userInfo, usersList},
107 licenseModel: {licenseModelEditor},
108 versionsPage: {permissions, versionsList: {versions, itemName}}
109}, {
110 currentScreen: {screen, itemPermission, props: {isReadOnlyMode, version: currentVersion}}
111}) => {
Michael Landoefa037d2017-02-19 12:57:33 +0200112 return {
talig8e9c0652017-12-20 14:30:43 +0200113 versionControllerProps: buildVersionControllerProps({
114 licenseModelEditor,
115 versions,
116 currentVersion,
117 userInfo,
118 permissions,
119 usersList,
svishnev091edfd2018-03-19 12:15:19 +0200120 isArchived: itemPermission.isArchived,
talig8e9c0652017-12-20 14:30:43 +0200121 itemPermission,
122 isReadOnlyMode
123 }),
Michael Landoefa037d2017-02-19 12:57:33 +0200124 navigationBarProps: buildNavigationBarProps(licenseModelEditor.data, screen)
125 };
126};
127
128
talig8e9c0652017-12-20 14:30:43 +0200129const mapActionsToProps = (dispatch, {currentScreen: {screen, props: {licenseModelId, version}}}) => {
AviZi280f8012017-06-09 02:39:56 +0300130
Michael Landoefa037d2017-02-19 12:57:33 +0200131 return {
talig8e9c0652017-12-20 14:30:43 +0200132 onVersionControllerAction: (action, version, comment) =>
133 LicenseModelActionHelper.performVCAction(dispatch, {licenseModelId, action, version, comment}).then(updatedVersion => {
134 ScreensHelper.loadScreen(dispatch, {screen, screenType: screenTypes.LICENSE_MODEL, props: {licenseModelId, version: updatedVersion}});
Michael Landoefa037d2017-02-19 12:57:33 +0200135 }),
talig8e9c0652017-12-20 14:30:43 +0200136
137 onOpenCommentCommitModal: ({onCommit, title}) => dispatch({
138 type: modalActionTypes.GLOBAL_MODAL_SHOW,
139 data: {
140 modalComponentName: modalContentMapper.COMMIT_COMMENT,
141 modalComponentProps: {
142 onCommit,
143 type: CommitModalType.COMMIT
144 },
145 title
AviZi280f8012017-06-09 02:39:56 +0300146 }
talig8e9c0652017-12-20 14:30:43 +0200147 }),
148
149 onVersionSwitching: version => {
150 ScreensHelper.loadScreen(dispatch, {screen, screenType: screenTypes.LICENSE_MODEL, props: {licenseModelId, version}});
AviZi280f8012017-06-09 02:39:56 +0300151 },
Michael Landoefa037d2017-02-19 12:57:33 +0200152
talig8e9c0652017-12-20 14:30:43 +0200153 onManagePermissions() {
154 PermissionsActionHelper.openPermissonsManager(dispatch, {itemId: licenseModelId, askForRights: false});
155 },
156
157 onMoreVersionsClick: ({itemName, users}) => {
158 ScreensHelper.loadScreen(dispatch, {screen: enums.SCREEN.VERSIONS_PAGE, screenType: screenTypes.LICENSE_MODEL,
159 props: {licenseModelId, licenseModel: {name: itemName}, usersList: users}});
160 },
161
162 onOpenPermissions: ({users}) => {
163 return PermissionsActionHelper.fetchItemUsers(dispatch, {itemId: licenseModelId, allUsers: users});
164 },
165
166 onOpenRevisionsModal: () => {
167 return RevisionsActionHelper.openRevisionsView(dispatch, {itemId: licenseModelId, version: version, itemType: screenTypes.LICENSE_MODEL});
168 },
169
170 onNavigate: ({id}) => {
171 ScreensHelper.loadScreen(dispatch, {screen: id, screenType: screenTypes.LICENSE_MODEL, props: {licenseModelId, version}});
Michael Landoefa037d2017-02-19 12:57:33 +0200172 }
173 };
174};
175
176export default connect(mapStateToProps, mapActionsToProps)(TabulatedEditor);