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