blob: 5273785f07bf7d07bf7c3103607032d0570f2d2c [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
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 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,
46 isFormDataValid, onClose, onManagePermissions, permissions = {}, userInfo, usersList, itemName, onOpenCommentCommitModal, onOpenRevisionsModal, isManual} = this.props;
Michael Landoefa037d2017-02-19 12:57:33 +020047 return (
48 <div className='version-controller-bar'>
AviZi280f8012017-06-09 02:39:56 +030049 <div className='vc-container'>
50 <div className='version-status-container'>
talig8e9c0652017-12-20 14:30:43 +020051 <VersionSelector
52 viewableVersions={viewableVersions}
53 version={version}
54 onVersionSwitching={onVersionSwitching}
55 onMoreVersionsClick={() => onMoreVersionsClick({itemName, users: usersList})}/>
AviZi280f8012017-06-09 02:39:56 +030056 </div>
57 <div className='save-submit-cancel-container'>
58 <ActionButtons onSubmit={callVCAction ? () => this.submit(callVCAction, version) : undefined}
talig8e9c0652017-12-20 14:30:43 +020059 onRevert={callVCAction ? () => this.revert(callVCAction, version) : undefined}
60 onOpenRevisionsModal={onOpenRevisionsModal}
AviZi280f8012017-06-09 02:39:56 +030061 onSave={onSave ? () => onSave() : undefined}
talig8e9c0652017-12-20 14:30:43 +020062 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 />
AviZi280f8012017-06-09 02:39:56 +030077 {onClose && <div className='vc-nav-item-close' onClick={() => onClose()} data-test-id='vc-cancel-btn'> X</div>}
78 </div>
79 </div>
Michael Landoefa037d2017-02-19 12:57:33 +020080 </div>
81 );
82 }
83
talig8e9c0652017-12-20 14:30:43 +020084 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
AviZi280f8012017-06-09 02:39:56 +030092 submit(callVCAction, version) {
93 const action = actionsEnum.SUBMIT;
94 callVCAction(action, version);
Michael Landoefa037d2017-02-19 12:57:33 +020095 }
96
talig8e9c0652017-12-20 14:30:43 +020097 revert(callVCAction, version) {
98 const action = actionsEnum.REVERT;
AviZi280f8012017-06-09 02:39:56 +030099 callVCAction(action, version);
100 }
101
talig8e9c0652017-12-20 14:30:43 +0200102 sync(callVCAction, version) {
103 const action = actionsEnum.SYNC;
AviZi280f8012017-06-09 02:39:56 +0300104 callVCAction(action, version);
Michael Landoefa037d2017-02-19 12:57:33 +0200105 }
106
talig8e9c0652017-12-20 14:30:43 +0200107 commit(callVCAction, version, comment) {
108 const action = actionsEnum.COMMIT;
109 callVCAction(action, version, comment);
Michael Landoefa037d2017-02-19 12:57:33 +0200110 }
111
talig8e9c0652017-12-20 14:30:43 +0200112 permissions() {
AviZi280f8012017-06-09 02:39:56 +0300113
talig8e9c0652017-12-20 14:30:43 +0200114 }
AviZi280f8012017-06-09 02:39:56 +0300115}
116
117function VersionSelector(props) {
talig8e9c0652017-12-20 14:30:43 +0200118 let {version = {}, onMoreVersionsClick, viewableVersions = [], onVersionSwitching} = props;
AviZi280f8012017-06-09 02:39:56 +0300119 const includedVersions = viewableVersions.filter(ver => {return ver.id === version.id;});
120 return (<div className='version-section-wrapper'>
121 <select className='version-selector'
talig8e9c0652017-12-20 14:30:43 +0200122 onChange={ev => onVersionSwitching && onVersionSwitching(viewableVersions.find(version => version.id === ev.target.value))}
123 value={version.id}
124 data-test-id='vc-versions-select-box'>
AviZi280f8012017-06-09 02:39:56 +0300125 {viewableVersions && viewableVersions.map(viewVersion => {
126 return (
talig8e9c0652017-12-20 14:30:43 +0200127 <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 +0300128 );
129 })
130 }
131 {!includedVersions.length &&
talig8e9c0652017-12-20 14:30:43 +0200132 <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 +0300133 </select>
talig8e9c0652017-12-20 14:30:43 +0200134 <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 +0300135 </div>);
Michael Landoefa037d2017-02-19 12:57:33 +0200136}
137
138export default VersionController;