AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 1 | /*! |
svishnev | f678490 | 2018-02-12 09:10:35 +0200 | [diff] [blame] | 2 | * Copyright © 2016-2018 European Support Limited |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 3 | * |
| 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 |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 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. |
| 15 | */ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 16 | import React from 'react'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 17 | import PropTypes from 'prop-types'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 18 | import i18n from 'nfvo-utils/i18n/i18n.js'; |
| 19 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 20 | import { actionsEnum } from './VersionControllerConstants.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 21 | import ActionButtons from './components/ActionButtons.jsx'; |
| 22 | import NotificationsView from 'sdc-app/onboarding/userNotifications/NotificationsView.jsx'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 23 | |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 24 | class VersionController extends React.Component { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 25 | static propTypes = { |
| 26 | version: PropTypes.object, |
| 27 | viewableVersions: PropTypes.array, |
| 28 | onVersionSwitching: PropTypes.func, |
| 29 | callVCAction: PropTypes.func, |
| 30 | onSave: PropTypes.func, |
| 31 | onClose: PropTypes.func, |
| 32 | isFormDataValid: PropTypes.bool, |
| 33 | onOpenCommentCommitModal: PropTypes.func, |
| 34 | isReadOnlyMode: PropTypes.bool |
| 35 | }; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 36 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 37 | state = { |
| 38 | showPermissions: false, |
| 39 | showRevisions: false |
| 40 | }; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 41 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 42 | render() { |
| 43 | let { |
| 44 | version = {}, |
| 45 | viewableVersions = [], |
| 46 | onVersionSwitching, |
| 47 | onMoreVersionsClick, |
| 48 | callVCAction, |
| 49 | onSave, |
| 50 | isReadOnlyMode, |
| 51 | itemPermission, |
| 52 | isFormDataValid, |
| 53 | onClose, |
| 54 | onManagePermissions, |
| 55 | permissions = {}, |
| 56 | userInfo, |
| 57 | usersList, |
| 58 | itemName, |
| 59 | onOpenCommentCommitModal, |
| 60 | onOpenRevisionsModal, |
| 61 | isManual, |
| 62 | candidateInProcess, |
| 63 | isArchived |
| 64 | } = this.props; |
| 65 | return ( |
| 66 | <div className="version-controller-bar"> |
svishnev | 04783c4 | 2018-04-17 11:32:22 +0300 | [diff] [blame] | 67 | <div className="vc-container"> |
| 68 | <div |
| 69 | className={`version-status-container ${ |
| 70 | candidateInProcess ? 'disabled' : '' |
| 71 | }`}> |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 72 | <VersionSelector |
| 73 | viewableVersions={viewableVersions} |
| 74 | version={version} |
| 75 | onVersionSwitching={onVersionSwitching} |
| 76 | onMoreVersionsClick={() => |
| 77 | onMoreVersionsClick({ |
| 78 | itemName, |
| 79 | users: usersList |
| 80 | }) |
| 81 | } |
| 82 | /> |
| 83 | {isArchived && ( |
| 84 | <div className="depricated-item-status"> |
| 85 | {i18n('Archived')} |
| 86 | </div> |
| 87 | )} |
| 88 | </div> |
| 89 | <div className="save-submit-cancel-container"> |
| 90 | <ActionButtons |
| 91 | onSubmit={ |
| 92 | callVCAction |
| 93 | ? () => this.submit(callVCAction, version) |
| 94 | : undefined |
| 95 | } |
| 96 | onRevert={ |
| 97 | callVCAction |
| 98 | ? () => this.revert(callVCAction, version) |
| 99 | : undefined |
| 100 | } |
| 101 | onOpenRevisionsModal={onOpenRevisionsModal} |
| 102 | onSave={onSave ? () => onSave() : undefined} |
| 103 | permissions={permissions} |
| 104 | userInfo={userInfo} |
| 105 | onManagePermissions={onManagePermissions} |
| 106 | showPermissions={this.state.showPermissions} |
| 107 | onClosePermissions={() => |
| 108 | this.setState({ showPermissions: false }) |
| 109 | } |
| 110 | onClickPermissions={() => this.onClickPermissions()} |
| 111 | onSync={ |
| 112 | callVCAction |
| 113 | ? () => this.sync(callVCAction, version) |
| 114 | : undefined |
| 115 | } |
| 116 | onOpenCommentCommitModal={onOpenCommentCommitModal} |
| 117 | onCommit={ |
| 118 | callVCAction |
| 119 | ? comment => |
| 120 | this.commit( |
| 121 | callVCAction, |
| 122 | version, |
| 123 | comment |
| 124 | ) |
| 125 | : undefined |
| 126 | } |
| 127 | isFormDataValid={isFormDataValid} |
| 128 | itemPermissions={itemPermission} |
| 129 | isArchived={isArchived} |
| 130 | isReadOnlyMode={ |
| 131 | isReadOnlyMode || candidateInProcess |
| 132 | } |
| 133 | isManual={isManual} |
| 134 | /> |
| 135 | <div className="vc-separator" /> |
| 136 | <NotificationsView /> |
| 137 | {onClose && ( |
| 138 | <div |
| 139 | className="vc-nav-item-close" |
| 140 | onClick={() => onClose()} |
| 141 | data-test-id="vc-cancel-btn"> |
| 142 | {' '} |
| 143 | X |
| 144 | </div> |
| 145 | )} |
| 146 | </div> |
| 147 | </div> |
| 148 | </div> |
| 149 | ); |
| 150 | } |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 151 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 152 | onClickPermissions() { |
| 153 | let { onOpenPermissions, usersList } = this.props; |
| 154 | let { showPermissions } = this.state; |
| 155 | let promise = showPermissions |
| 156 | ? Promise.resolve() |
| 157 | : onOpenPermissions({ users: usersList }); |
| 158 | promise.then(() => |
| 159 | this.setState({ showPermissions: !showPermissions }) |
| 160 | ); |
| 161 | } |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 162 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 163 | submit(callVCAction, version) { |
| 164 | const action = actionsEnum.SUBMIT; |
| 165 | callVCAction(action, version); |
| 166 | } |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 167 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 168 | revert(callVCAction, version) { |
| 169 | const action = actionsEnum.REVERT; |
| 170 | callVCAction(action, version); |
| 171 | } |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 172 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 173 | sync(callVCAction, version) { |
| 174 | const action = actionsEnum.SYNC; |
| 175 | callVCAction(action, version); |
| 176 | } |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 177 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 178 | commit(callVCAction, version, comment) { |
| 179 | const action = actionsEnum.COMMIT; |
| 180 | callVCAction(action, version, comment); |
| 181 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 182 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 183 | permissions() {} |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | function VersionSelector(props) { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 187 | let { |
| 188 | version = {}, |
| 189 | onMoreVersionsClick, |
| 190 | viewableVersions = [], |
| 191 | onVersionSwitching |
| 192 | } = props; |
| 193 | const includedVersions = viewableVersions.filter(ver => { |
| 194 | return ver.id === version.id; |
| 195 | }); |
| 196 | return ( |
| 197 | <div className="version-section-wrapper"> |
| 198 | <select |
| 199 | className="version-selector" |
| 200 | onChange={ev => |
| 201 | onVersionSwitching && |
| 202 | onVersionSwitching( |
| 203 | viewableVersions.find( |
| 204 | version => version.id === ev.target.value |
| 205 | ) |
| 206 | ) |
| 207 | } |
| 208 | value={version.id} |
| 209 | data-test-id="vc-versions-select-box"> |
| 210 | {viewableVersions && |
| 211 | viewableVersions.map(viewVersion => { |
| 212 | return ( |
| 213 | <option |
| 214 | key={viewVersion.id} |
| 215 | value={viewVersion.id} |
| 216 | data-test-id="vc-version-option">{`V ${ |
| 217 | viewVersion.name |
| 218 | } ${viewVersion.status}`}</option> |
| 219 | ); |
| 220 | })} |
| 221 | {!includedVersions.length && ( |
| 222 | <option |
| 223 | key={version.id} |
| 224 | value={version.id} |
| 225 | data-test-id="vc-selected-version-option">{`V ${ |
| 226 | version.name |
| 227 | } ${version.status}`}</option> |
| 228 | )} |
| 229 | </select> |
| 230 | <span |
| 231 | onClick={onMoreVersionsClick} |
| 232 | className="version-selector-more-versions" |
| 233 | data-test-id="vc-versions-page-link"> |
| 234 | {i18n('Versions Page')} |
| 235 | </span> |
| 236 | </div> |
| 237 | ); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | export default VersionController; |