blob: f8417fafbf2bf7187a8afab9fa17d2b477562d54 [file] [log] [blame]
talig8e9c0652017-12-20 14:30:43 +02001/*!
svishnev091edfd2018-03-19 12:15:19 +02002 * Copyright © 2016-2018 European Support Limited
talig8e9c0652017-12-20 14:30:43 +02003 *
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 */
16import React from 'react';
17import VersionList from './components/VersionList.jsx';
18import PermissionsView from './components/PermissionsView.jsx';
19import Tree from 'nfvo-components/tree/Tree.jsx';
20import SVGIcon from 'sdc-ui/lib/react/SVGIcon.js';
svishnev091edfd2018-03-19 12:15:19 +020021import Button from 'sdc-ui/lib/react/Button.js';
talig8e9c0652017-12-20 14:30:43 +020022import i18n from 'nfvo-utils/i18n/i18n.js';
svishnev091edfd2018-03-19 12:15:19 +020023import featureToggle from 'sdc-app/features/featureToggle.js';
24
25const DepricateButton = ({depricateAction, title}) => (
26 <div className='depricate-btn-wrapper'>
27 <Button data-test-id='depricate-action-btn' className='depricate-btn' onClick={depricateAction}>{title}</Button>
28 </div>
29);
30
31const FeatureDepricatedButton = featureToggle('ARCHIVE_ITEM')(DepricateButton);
32
33const VersionPageTitle = ({itemName, depricatedTitle, isArchived, onRestore, onArchive}) => {
34 return (
35 <div className='version-page-header'>
36 <div className='versions-page-title'>{`${i18n('Available Versions')} - ${itemName} ${depricatedTitle}`}</div>
37 <FeatureDepricatedButton depricateAction={isArchived ? () => onRestore() : () => onArchive() } title={i18n(isArchived ? 'RESTORE' : 'ARCHIVE')}/>
38 </div>
39 );
40};
talig8e9c0652017-12-20 14:30:43 +020041
42class VersionsPage extends React.Component {
43 state = {
44 showExpanded : false
45 }
46 render() {
47 let { versions, owner, contributors, currentUser, isCollaborator, itemName = '', viewers, onSelectVersion, onNavigateToVersion,
svishnev091edfd2018-03-19 12:15:19 +020048 onTreeFullScreen, onManagePermissions, onCreateVersion, selectedVersion, onModalNodeClick, isManual, isArchived, onArchive, onRestore} = this.props;
49 const depricatedTitle = isArchived ? i18n('(Archived)') : '';
talig8e9c0652017-12-20 14:30:43 +020050 return (
51 <div className='versions-page-view'>
svishnev091edfd2018-03-19 12:15:19 +020052 <VersionPageTitle
53 itemName={itemName}
54 depricatedTitle={depricatedTitle}
55 onArchive={onArchive}
56 isArchived={isArchived}
57 onRestore={onRestore}/>
talig8e9c0652017-12-20 14:30:43 +020058 <PermissionsView
59 owner={owner}
60 contributors={contributors}
61 viewers={viewers}
62 currentUser={currentUser}
63 isManual={isManual}
64 onManagePermissions={onManagePermissions}/>
65 <div className='versions-page-list-and-tree'>
66 <div className='version-tree-wrapper'>
67 <div className='version-tree-title-container'>
68 <div className='version-tree-title'>{i18n('Version Tree')}</div>
69 {this.state.showExpanded && <SVGIcon name='expand' className='version-tree-full-screen' onClick={() => onTreeFullScreen({
70 name: 'versions-tree-popup',
71 width: 798,
72 height: 500,
73 nodes: versions.map(version => ({id: version.id, name: version.name, parent: version.baseId || ''})),
74 onNodeClick: (version) => onModalNodeClick({version}),
75 selectedNodeId: selectedVersion,
76 scrollable: true,
77 toWiden: true
78 })} />}
79 </div>
80 <Tree
81 name={'versions-tree'}
82 width={200}
83 allowScaleWidth={false}
84 nodes={versions.map(version => ({id: version.id, name: version.name, parent: version.baseId || ''}))}
85 onNodeClick={version => onSelectVersion({version})}
86 onRenderedBeyondWidth={() => {this.setState({showExpanded : true});}}
87 selectedNodeId={selectedVersion}/>
88 </div>
89 <VersionList
90 versions={versions}
91 onSelectVersion={onSelectVersion}
92 onNavigateToVersion={onNavigateToVersion}
svishnev091edfd2018-03-19 12:15:19 +020093 onCreateVersion={isArchived ? false : onCreateVersion}
talig8e9c0652017-12-20 14:30:43 +020094 selectedVersion={selectedVersion}
95 isCollaborator={isCollaborator} />
96 </div>
97 </div>
98 );
99 }
100}
101
102export default VersionsPage;