blob: fdc86d417d3f39014c0d6ba088d22b7afbd35f58 [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
svishnevf6784902018-02-12 09:10:35 +02002 * Copyright © 2016-2018 European Support Limited
AviZi280f8012017-06-09 02:39:56 +03003 *
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 Landoefa037d2017-02-19 12:57:33 +020016import React from 'react';
talig8e9c0652017-12-20 14:30:43 +020017import PropTypes from 'prop-types';
Michael Landoefa037d2017-02-19 12:57:33 +020018import i18n from 'nfvo-utils/i18n/i18n.js';
19
talig8e9c0652017-12-20 14:30:43 +020020import {actionsEnum} from './VersionControllerConstants.js';
21import ActionButtons from './components/ActionButtons.jsx';
22import NotificationsView from 'sdc-app/onboarding/userNotifications/NotificationsView.jsx';
Michael Landoefa037d2017-02-19 12:57:33 +020023
24
25class VersionController extends React.Component {
26
27 static propTypes = {
talig8e9c0652017-12-20 14:30:43 +020028 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 Landoefa037d2017-02-19 12:57:33 +020042 };
43
44 render() {
talig8e9c0652017-12-20 14:30:43 +020045 let {version = {}, viewableVersions = [], onVersionSwitching, onMoreVersionsClick, callVCAction, onSave, isReadOnlyMode, itemPermission,
svishnevf6784902018-02-12 09:10:35 +020046 isFormDataValid, onClose, onManagePermissions, permissions = {}, userInfo, usersList, itemName,
47 onOpenCommentCommitModal, onOpenRevisionsModal, isManual, candidateInProcess} = this.props;
Michael Landoefa037d2017-02-19 12:57:33 +020048 return (
49 <div className='version-controller-bar'>
svishnevf6784902018-02-12 09:10:35 +020050 <div className={`vc-container ${candidateInProcess ? 'disabled' : ''}`}>
AviZi280f8012017-06-09 02:39:56 +030051 <div className='version-status-container'>
talig8e9c0652017-12-20 14:30:43 +020052 <VersionSelector
53 viewableVersions={viewableVersions}
54 version={version}
55 onVersionSwitching={onVersionSwitching}
56 onMoreVersionsClick={() => onMoreVersionsClick({itemName, users: usersList})}/>
AviZi280f8012017-06-09 02:39:56 +030057 </div>
58 <div className='save-submit-cancel-container'>
59 <ActionButtons onSubmit={callVCAction ? () => this.submit(callVCAction, version) : undefined}
talig8e9c0652017-12-20 14:30:43 +020060 onRevert={callVCAction ? () => this.revert(callVCAction, version) : undefined}
61 onOpenRevisionsModal={onOpenRevisionsModal}
svishnevf6784902018-02-12 09:10:35 +020062 onSave={onSave ? () => onSave() : undefined}
talig8e9c0652017-12-20 14:30:43 +020063 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}
svishnevf6784902018-02-12 09:10:35 +020074 isReadOnlyMode={isReadOnlyMode || candidateInProcess}
talig8e9c0652017-12-20 14:30:43 +020075 isManual={isManual} />
76 <div className='vc-separator'></div>
77 <NotificationsView />
AviZi280f8012017-06-09 02:39:56 +030078 {onClose && <div className='vc-nav-item-close' onClick={() => onClose()} data-test-id='vc-cancel-btn'> X</div>}
79 </div>
80 </div>
Michael Landoefa037d2017-02-19 12:57:33 +020081 </div>
82 );
83 }
84
talig8e9c0652017-12-20 14:30:43 +020085 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
AviZi280f8012017-06-09 02:39:56 +030093 submit(callVCAction, version) {
94 const action = actionsEnum.SUBMIT;
95 callVCAction(action, version);
Michael Landoefa037d2017-02-19 12:57:33 +020096 }
97
talig8e9c0652017-12-20 14:30:43 +020098 revert(callVCAction, version) {
99 const action = actionsEnum.REVERT;
AviZi280f8012017-06-09 02:39:56 +0300100 callVCAction(action, version);
101 }
102
talig8e9c0652017-12-20 14:30:43 +0200103 sync(callVCAction, version) {
104 const action = actionsEnum.SYNC;
AviZi280f8012017-06-09 02:39:56 +0300105 callVCAction(action, version);
Michael Landoefa037d2017-02-19 12:57:33 +0200106 }
107
talig8e9c0652017-12-20 14:30:43 +0200108 commit(callVCAction, version, comment) {
109 const action = actionsEnum.COMMIT;
110 callVCAction(action, version, comment);
Michael Landoefa037d2017-02-19 12:57:33 +0200111 }
112
talig8e9c0652017-12-20 14:30:43 +0200113 permissions() {
AviZi280f8012017-06-09 02:39:56 +0300114
talig8e9c0652017-12-20 14:30:43 +0200115 }
AviZi280f8012017-06-09 02:39:56 +0300116}
117
118function VersionSelector(props) {
talig8e9c0652017-12-20 14:30:43 +0200119 let {version = {}, onMoreVersionsClick, viewableVersions = [], onVersionSwitching} = props;
AviZi280f8012017-06-09 02:39:56 +0300120 const includedVersions = viewableVersions.filter(ver => {return ver.id === version.id;});
121 return (<div className='version-section-wrapper'>
122 <select className='version-selector'
talig8e9c0652017-12-20 14:30:43 +0200123 onChange={ev => onVersionSwitching && onVersionSwitching(viewableVersions.find(version => version.id === ev.target.value))}
124 value={version.id}
125 data-test-id='vc-versions-select-box'>
AviZi280f8012017-06-09 02:39:56 +0300126 {viewableVersions && viewableVersions.map(viewVersion => {
127 return (
talig8e9c0652017-12-20 14:30:43 +0200128 <option key={viewVersion.id} value={viewVersion.id} data-test-id='vc-version-option'>{`V ${viewVersion.name} ${viewVersion.status}`}</option>
AviZi280f8012017-06-09 02:39:56 +0300129 );
130 })
131 }
132 {!includedVersions.length &&
talig8e9c0652017-12-20 14:30:43 +0200133 <option key={version.id} value={version.id} data-test-id='vc-selected-version-option'>{`V ${version.name} ${version.status}`}</option>}
AviZi280f8012017-06-09 02:39:56 +0300134 </select>
talig8e9c0652017-12-20 14:30:43 +0200135 <span onClick={onMoreVersionsClick} className='version-selector-more-versions' data-test-id='vc-versions-page-link'>{i18n('Versions Page')}</span>
AviZi280f8012017-06-09 02:39:56 +0300136 </div>);
Michael Landoefa037d2017-02-19 12:57:33 +0200137}
138
139export default VersionController;