svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2016-2018 European Support Limited |
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 |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [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, |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 12 | * 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 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 TabulatedEditor from 'src/nfvo-components/editor/TabulatedEditor.jsx'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 20 | import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js'; |
| 21 | import {enums, screenTypes} from 'sdc-app/onboarding/OnboardingConstants.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 22 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 23 | import PermissionsActionHelper from './../permissions/PermissionsActionHelper.js'; |
| 24 | import RevisionsActionHelper from './../revisions/RevisionsActionHelper.js'; |
| 25 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 26 | import LicenseModelActionHelper from './LicenseModelActionHelper.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 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'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 30 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 31 | const 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 | { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 40 | id: enums.SCREEN.LICENSE_MODEL_OVERVIEW, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 41 | name: i18n('Overview'), |
| 42 | meta |
| 43 | }, |
| 44 | { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 45 | id: enums.SCREEN.LICENSE_AGREEMENTS, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 46 | name: i18n('License Agreements'), |
| 47 | meta |
| 48 | }, |
| 49 | { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 50 | id: enums.SCREEN.FEATURE_GROUPS, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 51 | name: i18n('Feature Groups'), |
| 52 | meta |
| 53 | }, |
| 54 | { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 55 | id: enums.SCREEN.ENTITLEMENT_POOLS, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 56 | name: i18n('Entitlement Pools'), |
| 57 | meta |
| 58 | }, |
| 59 | { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 60 | id: enums.SCREEN.LICENSE_KEY_GROUPS, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 61 | name: i18n('License Key Groups'), |
| 62 | meta |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 63 | }, |
| 64 | { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 65 | id: enums.SCREEN.ACTIVITY_LOG, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 66 | name: i18n('Activity Log'), |
| 67 | meta |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 68 | } |
| 69 | ] |
| 70 | }]; |
| 71 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 72 | return { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 73 | activeItemId: screen, groups |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 74 | }; |
| 75 | }; |
| 76 | |
| 77 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 78 | const buildVersionControllerProps = ({ |
| 79 | licenseModelEditor = {data: {}}, |
| 80 | versions, |
| 81 | currentVersion, |
| 82 | userInfo, |
| 83 | usersList, |
| 84 | permissions, |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 85 | isArchived, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 86 | itemPermission, |
| 87 | isReadOnlyMode |
| 88 | }) => { |
| 89 | const {isValidityData = true} = licenseModelEditor; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 90 | return { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 91 | version: currentVersion, |
| 92 | viewableVersions: versions, |
| 93 | isFormDataValid: isValidityData, |
| 94 | permissions, |
| 95 | userInfo, |
| 96 | usersList, |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 97 | isArchived, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 98 | itemName: licenseModelEditor.data.vendorName, |
| 99 | itemPermission, |
| 100 | isReadOnlyMode |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 101 | }; |
| 102 | }; |
| 103 | |
| 104 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 105 | const 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 112 | return { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 113 | versionControllerProps: buildVersionControllerProps({ |
| 114 | licenseModelEditor, |
| 115 | versions, |
| 116 | currentVersion, |
| 117 | userInfo, |
| 118 | permissions, |
| 119 | usersList, |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 120 | isArchived: itemPermission.isArchived, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 121 | itemPermission, |
| 122 | isReadOnlyMode |
| 123 | }), |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 124 | navigationBarProps: buildNavigationBarProps(licenseModelEditor.data, screen) |
| 125 | }; |
| 126 | }; |
| 127 | |
| 128 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 129 | const mapActionsToProps = (dispatch, {currentScreen: {screen, props: {licenseModelId, version}}}) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 130 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 131 | return { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 132 | 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 135 | }), |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 136 | |
| 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 |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 146 | } |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 147 | }), |
| 148 | |
| 149 | onVersionSwitching: version => { |
| 150 | ScreensHelper.loadScreen(dispatch, {screen, screenType: screenTypes.LICENSE_MODEL, props: {licenseModelId, version}}); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 151 | }, |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 152 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 153 | 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 172 | } |
| 173 | }; |
| 174 | }; |
| 175 | |
| 176 | export default connect(mapStateToProps, mapActionsToProps)(TabulatedEditor); |