talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 1 | /*! |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame^] | 2 | * Copyright © 2016-2018 European Support Limited |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 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 | */ |
| 16 | import React from 'react'; |
| 17 | import VersionList from './components/VersionList.jsx'; |
| 18 | import PermissionsView from './components/PermissionsView.jsx'; |
| 19 | import Tree from 'nfvo-components/tree/Tree.jsx'; |
| 20 | import SVGIcon from 'sdc-ui/lib/react/SVGIcon.js'; |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame^] | 21 | import Button from 'sdc-ui/lib/react/Button.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 22 | import i18n from 'nfvo-utils/i18n/i18n.js'; |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame^] | 23 | import featureToggle from 'sdc-app/features/featureToggle.js'; |
| 24 | |
| 25 | const 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 | |
| 31 | const FeatureDepricatedButton = featureToggle('ARCHIVE_ITEM')(DepricateButton); |
| 32 | |
| 33 | const 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 | }; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 41 | |
| 42 | class VersionsPage extends React.Component { |
| 43 | state = { |
| 44 | showExpanded : false |
| 45 | } |
| 46 | render() { |
| 47 | let { versions, owner, contributors, currentUser, isCollaborator, itemName = '', viewers, onSelectVersion, onNavigateToVersion, |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame^] | 48 | onTreeFullScreen, onManagePermissions, onCreateVersion, selectedVersion, onModalNodeClick, isManual, isArchived, onArchive, onRestore} = this.props; |
| 49 | const depricatedTitle = isArchived ? i18n('(Archived)') : ''; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 50 | return ( |
| 51 | <div className='versions-page-view'> |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame^] | 52 | <VersionPageTitle |
| 53 | itemName={itemName} |
| 54 | depricatedTitle={depricatedTitle} |
| 55 | onArchive={onArchive} |
| 56 | isArchived={isArchived} |
| 57 | onRestore={onRestore}/> |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 58 | <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} |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame^] | 93 | onCreateVersion={isArchived ? false : onCreateVersion} |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 94 | selectedVersion={selectedVersion} |
| 95 | isCollaborator={isCollaborator} /> |
| 96 | </div> |
| 97 | </div> |
| 98 | ); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | export default VersionsPage; |