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