blob: 57fa86f5613c29f178cdf7c160f6f91bc05cebaf [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,
svishnev091edfd2018-03-19 12:15:19 +020046 isFormDataValid, onClose, onManagePermissions, permissions = {}, userInfo, usersList, itemName,
47 onOpenCommentCommitModal, onOpenRevisionsModal, isManual, candidateInProcess, isArchived} = 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})}/>
svishnev091edfd2018-03-19 12:15:19 +020057 {isArchived && <div className='depricated-item-status'>{i18n('Archived')}</div>}
58 </div>
AviZi280f8012017-06-09 02:39:56 +030059 <div className='save-submit-cancel-container'>
60 <ActionButtons onSubmit={callVCAction ? () => this.submit(callVCAction, version) : undefined}
talig8e9c0652017-12-20 14:30:43 +020061 onRevert={callVCAction ? () => this.revert(callVCAction, version) : undefined}
62 onOpenRevisionsModal={onOpenRevisionsModal}
svishnev091edfd2018-03-19 12:15:19 +020063 onSave={onSave ? () => onSave() : undefined}
talig8e9c0652017-12-20 14:30:43 +020064 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}
svishnev091edfd2018-03-19 12:15:19 +020075 isArchived={isArchived}
svishnevf6784902018-02-12 09:10:35 +020076 isReadOnlyMode={isReadOnlyMode || candidateInProcess}
talig8e9c0652017-12-20 14:30:43 +020077 isManual={isManual} />
78 <div className='vc-separator'></div>
79 <NotificationsView />
AviZi280f8012017-06-09 02:39:56 +030080 {onClose && <div className='vc-nav-item-close' onClick={() => onClose()} data-test-id='vc-cancel-btn'> X</div>}
81 </div>
82 </div>
Michael Landoefa037d2017-02-19 12:57:33 +020083 </div>
84 );
85 }
86
talig8e9c0652017-12-20 14:30:43 +020087 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
AviZi280f8012017-06-09 02:39:56 +030095 submit(callVCAction, version) {
96 const action = actionsEnum.SUBMIT;
97 callVCAction(action, version);
Michael Landoefa037d2017-02-19 12:57:33 +020098 }
99
talig8e9c0652017-12-20 14:30:43 +0200100 revert(callVCAction, version) {
101 const action = actionsEnum.REVERT;
AviZi280f8012017-06-09 02:39:56 +0300102 callVCAction(action, version);
103 }
104
talig8e9c0652017-12-20 14:30:43 +0200105 sync(callVCAction, version) {
106 const action = actionsEnum.SYNC;
AviZi280f8012017-06-09 02:39:56 +0300107 callVCAction(action, version);
Michael Landoefa037d2017-02-19 12:57:33 +0200108 }
109
talig8e9c0652017-12-20 14:30:43 +0200110 commit(callVCAction, version, comment) {
111 const action = actionsEnum.COMMIT;
112 callVCAction(action, version, comment);
Michael Landoefa037d2017-02-19 12:57:33 +0200113 }
114
talig8e9c0652017-12-20 14:30:43 +0200115 permissions() {
AviZi280f8012017-06-09 02:39:56 +0300116
talig8e9c0652017-12-20 14:30:43 +0200117 }
AviZi280f8012017-06-09 02:39:56 +0300118}
119
120function VersionSelector(props) {
talig8e9c0652017-12-20 14:30:43 +0200121 let {version = {}, onMoreVersionsClick, viewableVersions = [], onVersionSwitching} = props;
AviZi280f8012017-06-09 02:39:56 +0300122 const includedVersions = viewableVersions.filter(ver => {return ver.id === version.id;});
123 return (<div className='version-section-wrapper'>
124 <select className='version-selector'
talig8e9c0652017-12-20 14:30:43 +0200125 onChange={ev => onVersionSwitching && onVersionSwitching(viewableVersions.find(version => version.id === ev.target.value))}
126 value={version.id}
127 data-test-id='vc-versions-select-box'>
AviZi280f8012017-06-09 02:39:56 +0300128 {viewableVersions && viewableVersions.map(viewVersion => {
129 return (
talig8e9c0652017-12-20 14:30:43 +0200130 <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 +0300131 );
132 })
133 }
134 {!includedVersions.length &&
talig8e9c0652017-12-20 14:30:43 +0200135 <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 +0300136 </select>
talig8e9c0652017-12-20 14:30:43 +0200137 <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 +0300138 </div>);
Michael Landoefa037d2017-02-19 12:57:33 +0200139}
140
141export default VersionController;