blob: cea369d2ecd7b800b04bc1e5a25e952e29bb76ec [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
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +02007 *
svishnev091edfd2018-03-19 12:15:19 +02008 * http://www.apache.org/licenses/LICENSE-2.0
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +02009 *
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 */
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020016import { connect } from 'react-redux';
Michael Landoefa037d2017-02-19 12:57:33 +020017
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';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020021import { 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';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +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) => {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020032 const { id, vendorName, version } = licenseModel;
33 const meta = { version };
Michael Landoefa037d2017-02-19 12:57:33 +020034
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020035 const groups = [
36 {
37 id,
38 name: vendorName,
39 items: [
40 {
41 id: enums.SCREEN.LICENSE_MODEL_OVERVIEW,
42 name: i18n('Overview'),
43 meta
44 },
45 {
46 id: enums.SCREEN.LICENSE_AGREEMENTS,
47 name: i18n('License Agreements'),
48 meta
49 },
50 {
51 id: enums.SCREEN.FEATURE_GROUPS,
52 name: i18n('Feature Groups'),
53 meta
54 },
55 {
56 id: enums.SCREEN.ENTITLEMENT_POOLS,
57 name: i18n('Entitlement Pools'),
58 meta
59 },
60 {
61 id: enums.SCREEN.LICENSE_KEY_GROUPS,
62 name: i18n('License Key Groups'),
63 meta
64 },
65 {
66 id: enums.SCREEN.ACTIVITY_LOG,
67 name: i18n('Activity Log'),
68 meta
69 }
70 ]
71 }
72 ];
Michael Landoefa037d2017-02-19 12:57:33 +020073
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020074 return {
75 activeItemId: screen,
76 groups
77 };
Michael Landoefa037d2017-02-19 12:57:33 +020078};
79
talig8e9c0652017-12-20 14:30:43 +020080const buildVersionControllerProps = ({
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020081 licenseModelEditor = { data: {} },
82 versions,
83 currentVersion,
84 userInfo,
85 usersList,
86 permissions,
87 isArchived,
88 itemPermission,
89 isReadOnlyMode
talig8e9c0652017-12-20 14:30:43 +020090}) => {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020091 const { isValidityData = true } = licenseModelEditor;
92 return {
93 version: currentVersion,
94 viewableVersions: versions,
95 isFormDataValid: isValidityData,
96 permissions,
97 userInfo,
98 usersList,
99 isArchived,
100 itemName: licenseModelEditor.data.vendorName,
101 itemPermission,
102 isReadOnlyMode
103 };
Michael Landoefa037d2017-02-19 12:57:33 +0200104};
105
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200106const mapStateToProps = (
107 {
108 users: { userInfo, usersList },
109 licenseModel: { licenseModelEditor },
110 versionsPage: { permissions, versionsList: { versions } }
111 },
112 {
113 currentScreen: {
114 screen,
115 itemPermission,
116 props: { isReadOnlyMode, version: currentVersion }
117 }
118 }
119) => {
120 return {
121 versionControllerProps: buildVersionControllerProps({
122 licenseModelEditor,
123 versions,
124 currentVersion,
125 userInfo,
126 permissions,
127 usersList,
128 isArchived: itemPermission.isArchived,
129 itemPermission,
130 isReadOnlyMode
131 }),
132 navigationBarProps: buildNavigationBarProps(
133 licenseModelEditor.data,
134 screen
135 )
136 };
Michael Landoefa037d2017-02-19 12:57:33 +0200137};
138
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200139const mapActionsToProps = (
140 dispatch,
141 { currentScreen: { screen, props: { licenseModelId, version } } }
142) => {
143 return {
144 onVersionControllerAction: (action, version, comment) =>
145 LicenseModelActionHelper.performVCAction(dispatch, {
146 licenseModelId,
147 action,
148 version,
149 comment
150 }).then(updatedVersion => {
151 ScreensHelper.loadScreen(dispatch, {
152 screen,
153 screenType: screenTypes.LICENSE_MODEL,
154 props: { licenseModelId, version: updatedVersion }
155 });
156 }),
Michael Landoefa037d2017-02-19 12:57:33 +0200157
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200158 onOpenCommentCommitModal: ({ onCommit, title }) =>
159 dispatch({
160 type: modalActionTypes.GLOBAL_MODAL_SHOW,
161 data: {
162 modalComponentName: modalContentMapper.COMMIT_COMMENT,
163 modalComponentProps: {
164 onCommit,
165 type: CommitModalType.COMMIT
166 },
167 title
168 }
169 }),
AviZi280f8012017-06-09 02:39:56 +0300170
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200171 onVersionSwitching: version => {
172 ScreensHelper.loadScreen(dispatch, {
173 screen,
174 screenType: screenTypes.LICENSE_MODEL,
175 props: { licenseModelId, version }
176 });
177 },
talig8e9c0652017-12-20 14:30:43 +0200178
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200179 onManagePermissions() {
180 PermissionsActionHelper.openPermissonsManager(dispatch, {
181 itemId: licenseModelId,
182 askForRights: false
183 });
184 },
talig8e9c0652017-12-20 14:30:43 +0200185
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200186 onMoreVersionsClick: ({ itemName, users }) => {
187 ScreensHelper.loadScreen(dispatch, {
188 screen: enums.SCREEN.VERSIONS_PAGE,
189 screenType: screenTypes.LICENSE_MODEL,
190 props: {
191 licenseModelId,
192 licenseModel: { name: itemName },
193 usersList: users
194 }
195 });
196 },
Michael Landoefa037d2017-02-19 12:57:33 +0200197
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200198 onOpenPermissions: ({ users }) => {
199 return PermissionsActionHelper.fetchItemUsers(dispatch, {
200 itemId: licenseModelId,
201 allUsers: users
202 });
203 },
talig8e9c0652017-12-20 14:30:43 +0200204
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200205 onOpenRevisionsModal: () => {
206 return RevisionsActionHelper.openRevisionsView(dispatch, {
207 itemId: licenseModelId,
208 version: version,
209 itemType: screenTypes.LICENSE_MODEL
210 });
211 },
talig8e9c0652017-12-20 14:30:43 +0200212
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200213 onNavigate: ({ id }) => {
214 ScreensHelper.loadScreen(dispatch, {
215 screen: id,
216 screenType: screenTypes.LICENSE_MODEL,
217 props: { licenseModelId, version }
218 });
219 }
220 };
Michael Landoefa037d2017-02-19 12:57:33 +0200221};
222
223export default connect(mapStateToProps, mapActionsToProps)(TabulatedEditor);