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 | f678490 | 2018-02-12 09:10:35 +0200 | [diff] [blame^] | 46 | isFormDataValid, onClose, onManagePermissions, permissions = {}, userInfo, usersList, itemName, |
| 47 | onOpenCommentCommitModal, onOpenRevisionsModal, isManual, candidateInProcess} = 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})}/> |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 57 | </div> |
| 58 | <div className='save-submit-cancel-container'> |
| 59 | <ActionButtons onSubmit={callVCAction ? () => this.submit(callVCAction, version) : undefined} |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 60 | onRevert={callVCAction ? () => this.revert(callVCAction, version) : undefined} |
| 61 | onOpenRevisionsModal={onOpenRevisionsModal} |
svishnev | f678490 | 2018-02-12 09:10:35 +0200 | [diff] [blame^] | 62 | onSave={onSave ? () => onSave() : undefined} |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 63 | permissions={permissions} |
| 64 | userInfo={userInfo} |
| 65 | onManagePermissions={onManagePermissions} |
| 66 | showPermissions={this.state.showPermissions} |
| 67 | onClosePermissions={()=>this.setState({showPermissions: false})} |
| 68 | onClickPermissions={() => this.onClickPermissions()} |
| 69 | onSync={callVCAction ? () => this.sync(callVCAction, version) : undefined} |
| 70 | onOpenCommentCommitModal={onOpenCommentCommitModal} |
| 71 | onCommit={callVCAction ? (comment) => this.commit(callVCAction, version, comment) : undefined} |
| 72 | isFormDataValid={isFormDataValid} |
| 73 | itemPermissions={itemPermission} |
svishnev | f678490 | 2018-02-12 09:10:35 +0200 | [diff] [blame^] | 74 | isReadOnlyMode={isReadOnlyMode || candidateInProcess} |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 75 | isManual={isManual} /> |
| 76 | <div className='vc-separator'></div> |
| 77 | <NotificationsView /> |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 78 | {onClose && <div className='vc-nav-item-close' onClick={() => onClose()} data-test-id='vc-cancel-btn'> X</div>} |
| 79 | </div> |
| 80 | </div> |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 81 | </div> |
| 82 | ); |
| 83 | } |
| 84 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 85 | onClickPermissions() { |
| 86 | let {onOpenPermissions, usersList} = this.props; |
| 87 | let {showPermissions} = this.state; |
| 88 | let promise = showPermissions ? Promise.resolve() : onOpenPermissions({users: usersList}); |
| 89 | promise.then(() => this.setState({showPermissions: !showPermissions})); |
| 90 | } |
| 91 | |
| 92 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 93 | submit(callVCAction, version) { |
| 94 | const action = actionsEnum.SUBMIT; |
| 95 | callVCAction(action, version); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 96 | } |
| 97 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 98 | revert(callVCAction, version) { |
| 99 | const action = actionsEnum.REVERT; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 100 | callVCAction(action, version); |
| 101 | } |
| 102 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 103 | sync(callVCAction, version) { |
| 104 | const action = actionsEnum.SYNC; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 105 | callVCAction(action, version); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 106 | } |
| 107 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 108 | commit(callVCAction, version, comment) { |
| 109 | const action = actionsEnum.COMMIT; |
| 110 | callVCAction(action, version, comment); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 111 | } |
| 112 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 113 | permissions() { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 114 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 115 | } |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | function VersionSelector(props) { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 119 | let {version = {}, onMoreVersionsClick, viewableVersions = [], onVersionSwitching} = props; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 120 | const includedVersions = viewableVersions.filter(ver => {return ver.id === version.id;}); |
| 121 | return (<div className='version-section-wrapper'> |
| 122 | <select className='version-selector' |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 123 | onChange={ev => onVersionSwitching && onVersionSwitching(viewableVersions.find(version => version.id === ev.target.value))} |
| 124 | value={version.id} |
| 125 | data-test-id='vc-versions-select-box'> |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 126 | {viewableVersions && viewableVersions.map(viewVersion => { |
| 127 | return ( |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 128 | <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] | 129 | ); |
| 130 | }) |
| 131 | } |
| 132 | {!includedVersions.length && |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 133 | <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] | 134 | </select> |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 135 | <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] | 136 | </div>); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | export default VersionController; |