2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 import {connect} from 'react-redux';
18 import i18n from 'nfvo-utils/i18n/i18n.js';
19 import TabulatedEditor from 'src/nfvo-components/editor/TabulatedEditor.jsx';
20 import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js';
21 import {enums, screenTypes} from 'sdc-app/onboarding/OnboardingConstants.js';
23 import PermissionsActionHelper from './../permissions/PermissionsActionHelper.js';
24 import RevisionsActionHelper from './../revisions/RevisionsActionHelper.js';
26 import LicenseModelActionHelper from './LicenseModelActionHelper.js';
27 import {actionTypes as modalActionTypes} from 'nfvo-components/modal/GlobalModalConstants.js';
28 import {modalContentMapper} from 'sdc-app/common/modal/ModalContentMapper.js';
29 import {CommitModalType} from 'nfvo-components/panel/versionController/components/CommitCommentModal.jsx';
32 const buildNavigationBarProps = (licenseModel, screen) => {
33 const {id, vendorName, version} = licenseModel;
34 const meta = {version};
41 id: enums.SCREEN.LICENSE_MODEL_OVERVIEW,
42 name: i18n('Overview'),
46 id: enums.SCREEN.LICENSE_AGREEMENTS,
47 name: i18n('License Agreements'),
51 id: enums.SCREEN.FEATURE_GROUPS,
52 name: i18n('Feature Groups'),
56 id: enums.SCREEN.ENTITLEMENT_POOLS,
57 name: i18n('Entitlement Pools'),
61 id: enums.SCREEN.LICENSE_KEY_GROUPS,
62 name: i18n('License Key Groups'),
66 id: enums.SCREEN.ACTIVITY_LOG,
67 name: i18n('Activity Log'),
74 activeItemId: screen, groups
79 const buildVersionControllerProps = ({
80 licenseModelEditor = {data: {}},
89 const {isValidityData = true} = licenseModelEditor;
91 version: currentVersion,
92 viewableVersions: versions,
93 isFormDataValid: isValidityData,
97 itemName: licenseModelEditor.data.vendorName,
104 const mapStateToProps = ({
105 users: {userInfo, usersList},
106 licenseModel: {licenseModelEditor},
107 versionsPage: {permissions, versionsList: {versions, itemName}}
109 currentScreen: {screen, itemPermission, props: {isReadOnlyMode, version: currentVersion}}
112 versionControllerProps: buildVersionControllerProps({
122 navigationBarProps: buildNavigationBarProps(licenseModelEditor.data, screen)
127 const mapActionsToProps = (dispatch, {currentScreen: {screen, props: {licenseModelId, version}}}) => {
130 onVersionControllerAction: (action, version, comment) =>
131 LicenseModelActionHelper.performVCAction(dispatch, {licenseModelId, action, version, comment}).then(updatedVersion => {
132 ScreensHelper.loadScreen(dispatch, {screen, screenType: screenTypes.LICENSE_MODEL, props: {licenseModelId, version: updatedVersion}});
135 onOpenCommentCommitModal: ({onCommit, title}) => dispatch({
136 type: modalActionTypes.GLOBAL_MODAL_SHOW,
138 modalComponentName: modalContentMapper.COMMIT_COMMENT,
139 modalComponentProps: {
141 type: CommitModalType.COMMIT
147 onVersionSwitching: version => {
148 ScreensHelper.loadScreen(dispatch, {screen, screenType: screenTypes.LICENSE_MODEL, props: {licenseModelId, version}});
151 onManagePermissions() {
152 PermissionsActionHelper.openPermissonsManager(dispatch, {itemId: licenseModelId, askForRights: false});
155 onMoreVersionsClick: ({itemName, users}) => {
156 ScreensHelper.loadScreen(dispatch, {screen: enums.SCREEN.VERSIONS_PAGE, screenType: screenTypes.LICENSE_MODEL,
157 props: {licenseModelId, licenseModel: {name: itemName}, usersList: users}});
160 onOpenPermissions: ({users}) => {
161 return PermissionsActionHelper.fetchItemUsers(dispatch, {itemId: licenseModelId, allUsers: users});
164 onOpenRevisionsModal: () => {
165 return RevisionsActionHelper.openRevisionsView(dispatch, {itemId: licenseModelId, version: version, itemType: screenTypes.LICENSE_MODEL});
168 onNavigate: ({id}) => {
169 ScreensHelper.loadScreen(dispatch, {screen: id, screenType: screenTypes.LICENSE_MODEL, props: {licenseModelId, version}});
174 export default connect(mapStateToProps, mapActionsToProps)(TabulatedEditor);