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 | |
svishnev | fa538a1 | 2018-05-31 15:01:00 +0300 | [diff] [blame] | 24 | const ArchiveRestoreButton = ({ depricateAction, title, isArchived }) => ( |
| 25 | <div className="deprecate-btn-wrapper"> |
| 26 | {isArchived ? ( |
| 27 | <Button |
| 28 | data-test-id="deprecate-action-btn" |
| 29 | className="depricate-btn" |
| 30 | onClick={depricateAction}> |
| 31 | {title} |
| 32 | </Button> |
| 33 | ) : ( |
| 34 | <SVGIcon |
svishnev | e52b1dc | 2018-07-16 14:17:01 +0300 | [diff] [blame^] | 35 | data-test-id="deprecate-action-btn" |
svishnev | fa538a1 | 2018-05-31 15:01:00 +0300 | [diff] [blame] | 36 | name="archiveBox" |
svishnev | 8ae8f7e | 2018-07-02 14:05:17 +0300 | [diff] [blame] | 37 | title={i18n('Archive')} |
svishnev | fa538a1 | 2018-05-31 15:01:00 +0300 | [diff] [blame] | 38 | color="secondary" |
| 39 | onClick={depricateAction} |
| 40 | /> |
| 41 | )} |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 42 | </div> |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 43 | ); |
| 44 | |
svishnev | fa538a1 | 2018-05-31 15:01:00 +0300 | [diff] [blame] | 45 | const ArchivedTitle = () => ( |
| 46 | <div className="archived-title">{i18n('Archived')}</div> |
| 47 | ); |
| 48 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 49 | const VersionPageTitle = ({ |
| 50 | itemName, |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 51 | isArchived, |
| 52 | onRestore, |
svishnev | 69a1b38 | 2018-05-21 18:24:05 +0300 | [diff] [blame] | 53 | onArchive, |
| 54 | isCollaborator |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 55 | }) => { |
| 56 | return ( |
| 57 | <div className="version-page-header"> |
svishnev | fa538a1 | 2018-05-31 15:01:00 +0300 | [diff] [blame] | 58 | <div className="versions-page-title"> |
| 59 | {`${i18n('Available Versions')} - ${itemName}`} |
| 60 | {isArchived ? <ArchivedTitle /> : null} |
| 61 | </div> |
svishnev | 69a1b38 | 2018-05-21 18:24:05 +0300 | [diff] [blame] | 62 | {isCollaborator && ( |
svishnev | 8ae8f7e | 2018-07-02 14:05:17 +0300 | [diff] [blame] | 63 | <ArchiveRestoreButton |
svishnev | fa538a1 | 2018-05-31 15:01:00 +0300 | [diff] [blame] | 64 | isArchived={isArchived} |
svishnev | 69a1b38 | 2018-05-21 18:24:05 +0300 | [diff] [blame] | 65 | depricateAction={ |
| 66 | isArchived ? () => onRestore() : () => onArchive() |
| 67 | } |
| 68 | title={i18n(isArchived ? 'RESTORE' : 'ARCHIVE')} |
| 69 | /> |
| 70 | )} |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 71 | </div> |
| 72 | ); |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 73 | }; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 74 | |
| 75 | class VersionsPage extends React.Component { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 76 | state = { |
| 77 | showExpanded: false |
| 78 | }; |
| 79 | render() { |
| 80 | let { |
| 81 | versions, |
| 82 | owner, |
| 83 | contributors, |
| 84 | currentUser, |
| 85 | isCollaborator, |
| 86 | itemName = '', |
| 87 | viewers, |
| 88 | onSelectVersion, |
| 89 | onNavigateToVersion, |
| 90 | onTreeFullScreen, |
| 91 | onManagePermissions, |
| 92 | onCreateVersion, |
| 93 | selectedVersion, |
| 94 | onModalNodeClick, |
| 95 | isManual, |
| 96 | isArchived, |
| 97 | onArchive, |
| 98 | onRestore |
| 99 | } = this.props; |
| 100 | const depricatedTitle = isArchived ? i18n('(Archived)') : ''; |
| 101 | return ( |
| 102 | <div className="versions-page-view"> |
| 103 | <VersionPageTitle |
| 104 | itemName={itemName} |
| 105 | depricatedTitle={depricatedTitle} |
| 106 | onArchive={onArchive} |
| 107 | isArchived={isArchived} |
| 108 | onRestore={onRestore} |
svishnev | 69a1b38 | 2018-05-21 18:24:05 +0300 | [diff] [blame] | 109 | isCollaborator={isCollaborator} |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 110 | /> |
| 111 | <PermissionsView |
| 112 | owner={owner} |
| 113 | contributors={contributors} |
| 114 | viewers={viewers} |
| 115 | currentUser={currentUser} |
| 116 | isManual={isManual} |
| 117 | onManagePermissions={onManagePermissions} |
| 118 | /> |
| 119 | <div className="versions-page-list-and-tree"> |
| 120 | <div className="version-tree-wrapper"> |
| 121 | <div className="version-tree-title-container"> |
| 122 | <div className="version-tree-title"> |
| 123 | {i18n('Version Tree')} |
| 124 | </div> |
| 125 | {this.state.showExpanded && ( |
| 126 | <SVGIcon |
| 127 | name="expand" |
| 128 | className="version-tree-full-screen" |
| 129 | onClick={() => |
| 130 | onTreeFullScreen({ |
| 131 | name: 'versions-tree-popup', |
| 132 | width: 798, |
| 133 | height: 500, |
| 134 | nodes: versions.map(version => ({ |
| 135 | id: version.id, |
| 136 | name: version.name, |
| 137 | parent: version.baseId || '' |
| 138 | })), |
| 139 | onNodeClick: version => |
| 140 | onModalNodeClick({ version }), |
| 141 | selectedNodeId: selectedVersion, |
| 142 | scrollable: true, |
| 143 | toWiden: true |
| 144 | }) |
| 145 | } |
| 146 | /> |
| 147 | )} |
| 148 | </div> |
| 149 | <Tree |
| 150 | name={'versions-tree'} |
| 151 | width={200} |
| 152 | allowScaleWidth={false} |
| 153 | nodes={versions.map(version => ({ |
| 154 | id: version.id, |
| 155 | name: version.name, |
| 156 | parent: version.baseId || '' |
| 157 | }))} |
| 158 | onNodeClick={version => |
| 159 | onSelectVersion({ version }) |
| 160 | } |
| 161 | onRenderedBeyondWidth={() => { |
| 162 | this.setState({ showExpanded: true }); |
| 163 | }} |
| 164 | selectedNodeId={selectedVersion} |
| 165 | /> |
| 166 | </div> |
| 167 | <VersionList |
| 168 | versions={versions} |
| 169 | onSelectVersion={onSelectVersion} |
| 170 | onNavigateToVersion={onNavigateToVersion} |
| 171 | onCreateVersion={isArchived ? false : onCreateVersion} |
| 172 | selectedVersion={selectedVersion} |
| 173 | isCollaborator={isCollaborator} |
| 174 | /> |
| 175 | </div> |
| 176 | </div> |
| 177 | ); |
| 178 | } |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | export default VersionsPage; |