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 |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 7 | * |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 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 | */ |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 16 | import { connect } from 'react-redux'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 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'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 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'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +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) => { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 32 | const { id, vendorName, version } = licenseModel; |
| 33 | const meta = { version }; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 34 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 35 | 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 73 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 74 | return { |
| 75 | activeItemId: screen, |
| 76 | groups |
| 77 | }; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 78 | }; |
| 79 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 80 | const buildVersionControllerProps = ({ |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 81 | licenseModelEditor = { data: {} }, |
| 82 | versions, |
| 83 | currentVersion, |
| 84 | userInfo, |
| 85 | usersList, |
| 86 | permissions, |
| 87 | isArchived, |
| 88 | itemPermission, |
| 89 | isReadOnlyMode |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 90 | }) => { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 91 | 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 104 | }; |
| 105 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 106 | const 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 137 | }; |
| 138 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 139 | const 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 157 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 158 | 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 | }), |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 170 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 171 | onVersionSwitching: version => { |
| 172 | ScreensHelper.loadScreen(dispatch, { |
| 173 | screen, |
| 174 | screenType: screenTypes.LICENSE_MODEL, |
| 175 | props: { licenseModelId, version } |
| 176 | }); |
| 177 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 178 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 179 | onManagePermissions() { |
| 180 | PermissionsActionHelper.openPermissonsManager(dispatch, { |
| 181 | itemId: licenseModelId, |
| 182 | askForRights: false |
| 183 | }); |
| 184 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 185 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 186 | 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 197 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 198 | onOpenPermissions: ({ users }) => { |
| 199 | return PermissionsActionHelper.fetchItemUsers(dispatch, { |
| 200 | itemId: licenseModelId, |
| 201 | allUsers: users |
| 202 | }); |
| 203 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 204 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 205 | onOpenRevisionsModal: () => { |
| 206 | return RevisionsActionHelper.openRevisionsView(dispatch, { |
| 207 | itemId: licenseModelId, |
| 208 | version: version, |
| 209 | itemType: screenTypes.LICENSE_MODEL |
| 210 | }); |
| 211 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 212 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 213 | onNavigate: ({ id }) => { |
| 214 | ScreensHelper.loadScreen(dispatch, { |
| 215 | screen: id, |
| 216 | screenType: screenTypes.LICENSE_MODEL, |
| 217 | props: { licenseModelId, version } |
| 218 | }); |
| 219 | } |
| 220 | }; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 221 | }; |
| 222 | |
| 223 | export default connect(mapStateToProps, mapActionsToProps)(TabulatedEditor); |