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 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 20 | import {actionsEnum} from './VersionControllerConstants.js'; |
| 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 | |
| 24 | |
| 25 | class VersionController extends React.Component { |
| 26 | |
| 27 | static propTypes = { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 28 | version: PropTypes.object, |
| 29 | viewableVersions: PropTypes.array, |
| 30 | onVersionSwitching: PropTypes.func, |
| 31 | callVCAction: PropTypes.func, |
| 32 | onSave: PropTypes.func, |
| 33 | onClose: PropTypes.func, |
| 34 | isFormDataValid: PropTypes.bool, |
| 35 | onOpenCommentCommitModal: PropTypes.func, |
| 36 | isReadOnlyMode: PropTypes.bool |
| 37 | }; |
| 38 | |
| 39 | state = { |
| 40 | showPermissions: false, |
| 41 | showRevisions: false |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | render() { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 45 | let {version = {}, viewableVersions = [], onVersionSwitching, onMoreVersionsClick, callVCAction, onSave, isReadOnlyMode, itemPermission, |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 46 | isFormDataValid, onClose, onManagePermissions, permissions = {}, userInfo, usersList, itemName, |
| 47 | onOpenCommentCommitModal, onOpenRevisionsModal, isManual, candidateInProcess, isArchived} = this.props; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 48 | return ( |
| 49 | <div className='version-controller-bar'> |
svishnev | f678490 | 2018-02-12 09:10:35 +0200 | [diff] [blame] | 50 | <div className={`vc-container ${candidateInProcess ? 'disabled' : ''}`}> |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 51 | <div className='version-status-container'> |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 52 | <VersionSelector |
| 53 | viewableVersions={viewableVersions} |
| 54 | version={version} |
| 55 | onVersionSwitching={onVersionSwitching} |
| 56 | onMoreVersionsClick={() => onMoreVersionsClick({itemName, users: usersList})}/> |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 57 | {isArchived && <div className='depricated-item-status'>{i18n('Archived')}</div>} |
| 58 | </div> |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 59 | <div className='save-submit-cancel-container'> |
| 60 | <ActionButtons onSubmit={callVCAction ? () => this.submit(callVCAction, version) : undefined} |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 61 | onRevert={callVCAction ? () => this.revert(callVCAction, version) : undefined} |
| 62 | onOpenRevisionsModal={onOpenRevisionsModal} |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 63 | onSave={onSave ? () => onSave() : undefined} |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 64 | permissions={permissions} |
| 65 | userInfo={userInfo} |
| 66 | onManagePermissions={onManagePermissions} |
| 67 | showPermissions={this.state.showPermissions} |
| 68 | onClosePermissions={()=>this.setState({showPermissions: false})} |
| 69 | onClickPermissions={() => this.onClickPermissions()} |
| 70 | onSync={callVCAction ? () => this.sync(callVCAction, version) : undefined} |
| 71 | onOpenCommentCommitModal={onOpenCommentCommitModal} |
| 72 | onCommit={callVCAction ? (comment) => this.commit(callVCAction, version, comment) : undefined} |
| 73 | isFormDataValid={isFormDataValid} |
| 74 | itemPermissions={itemPermission} |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 75 | isArchived={isArchived} |
svishnev | f678490 | 2018-02-12 09:10:35 +0200 | [diff] [blame] | 76 | isReadOnlyMode={isReadOnlyMode || candidateInProcess} |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 77 | isManual={isManual} /> |
| 78 | <div className='vc-separator'></div> |
| 79 | <NotificationsView /> |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 80 | {onClose && <div className='vc-nav-item-close' onClick={() => onClose()} data-test-id='vc-cancel-btn'> X</div>} |
| 81 | </div> |
| 82 | </div> |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 83 | </div> |
| 84 | ); |
| 85 | } |
| 86 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 87 | onClickPermissions() { |
| 88 | let {onOpenPermissions, usersList} = this.props; |
| 89 | let {showPermissions} = this.state; |
| 90 | let promise = showPermissions ? Promise.resolve() : onOpenPermissions({users: usersList}); |
| 91 | promise.then(() => this.setState({showPermissions: !showPermissions})); |
| 92 | } |
| 93 | |
| 94 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 95 | submit(callVCAction, version) { |
| 96 | const action = actionsEnum.SUBMIT; |
| 97 | callVCAction(action, version); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 98 | } |
| 99 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 100 | revert(callVCAction, version) { |
| 101 | const action = actionsEnum.REVERT; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 102 | callVCAction(action, version); |
| 103 | } |
| 104 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 105 | sync(callVCAction, version) { |
| 106 | const action = actionsEnum.SYNC; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 107 | callVCAction(action, version); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 108 | } |
| 109 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 110 | commit(callVCAction, version, comment) { |
| 111 | const action = actionsEnum.COMMIT; |
| 112 | callVCAction(action, version, comment); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 113 | } |
| 114 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 115 | permissions() { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 116 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 117 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | function VersionSelector(props) { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 121 | let {version = {}, onMoreVersionsClick, viewableVersions = [], onVersionSwitching} = props; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 122 | const includedVersions = viewableVersions.filter(ver => {return ver.id === version.id;}); |
| 123 | return (<div className='version-section-wrapper'> |
| 124 | <select className='version-selector' |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 125 | onChange={ev => onVersionSwitching && onVersionSwitching(viewableVersions.find(version => version.id === ev.target.value))} |
| 126 | value={version.id} |
| 127 | data-test-id='vc-versions-select-box'> |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 128 | {viewableVersions && viewableVersions.map(viewVersion => { |
| 129 | return ( |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 130 | <option key={viewVersion.id} value={viewVersion.id} data-test-id='vc-version-option'>{`V ${viewVersion.name} ${viewVersion.status}`}</option> |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 131 | ); |
| 132 | }) |
| 133 | } |
| 134 | {!includedVersions.length && |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 135 | <option key={version.id} value={version.id} data-test-id='vc-selected-version-option'>{`V ${version.name} ${version.status}`}</option>} |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 136 | </select> |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 137 | <span onClick={onMoreVersionsClick} className='version-selector-more-versions' data-test-id='vc-versions-page-link'>{i18n('Versions Page')}</span> |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 138 | </div>); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | export default VersionController; |