blob: 95c7530063127f4c6b947c95bd358b804e572f2f [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';
Arielka51eac02019-07-07 12:56:11 +030020import SVGIcon from 'onap-ui-react/lib/components/SVGIcon.js';
21import { Button } from 'onap-ui-react';
talig8e9c0652017-12-20 14:30:43 +020022import i18n from 'nfvo-utils/i18n/i18n.js';
svishnev091edfd2018-03-19 12:15:19 +020023
KrupaNagabhushan881438c2022-04-04 17:49:50 +010024const ArchiveRestoreButton = ({
25 deprecateAction,
26 title,
27 isArchived,
28 deleteAction
29}) => (
svishnevfa538a12018-05-31 15:01:00 +030030 <div className="deprecate-btn-wrapper">
KrupaNagabhushan881438c2022-04-04 17:49:50 +010031 ,
svishnevfa538a12018-05-31 15:01:00 +030032 {isArchived ? (
KrupaNagabhushan881438c2022-04-04 17:49:50 +010033 <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>
svishnevfa538a12018-05-31 15:01:00 +030047 ) : (
48 <SVGIcon
svishneve52b1dc2018-07-16 14:17:01 +030049 data-test-id="deprecate-action-btn"
svishnevfa538a12018-05-31 15:01:00 +030050 name="archiveBox"
svishnev8ae8f7e2018-07-02 14:05:17 +030051 title={i18n('Archive')}
svishnevfa538a12018-05-31 15:01:00 +030052 color="secondary"
KrupaNagabhushan881438c2022-04-04 17:49:50 +010053 onClick={deprecateAction}
svishnevfa538a12018-05-31 15:01:00 +030054 />
55 )}
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020056 </div>
svishnev091edfd2018-03-19 12:15:19 +020057);
58
svishnevfa538a12018-05-31 15:01:00 +030059const ArchivedTitle = () => (
60 <div className="archived-title">{i18n('Archived')}</div>
61);
62
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020063const VersionPageTitle = ({
64 itemName,
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020065 isArchived,
66 onRestore,
KrupaNagabhushan881438c2022-04-04 17:49:50 +010067 onDelete,
svishnev69a1b382018-05-21 18:24:05 +030068 onArchive,
69 isCollaborator
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020070}) => {
71 return (
72 <div className="version-page-header">
svishnevfa538a12018-05-31 15:01:00 +030073 <div className="versions-page-title">
74 {`${i18n('Available Versions')} - ${itemName}`}
75 {isArchived ? <ArchivedTitle /> : null}
76 </div>
svishnev69a1b382018-05-21 18:24:05 +030077 {isCollaborator && (
svishnev8ae8f7e2018-07-02 14:05:17 +030078 <ArchiveRestoreButton
svishnevfa538a12018-05-31 15:01:00 +030079 isArchived={isArchived}
KrupaNagabhushan881438c2022-04-04 17:49:50 +010080 deprecateAction={
svishnev69a1b382018-05-21 18:24:05 +030081 isArchived ? () => onRestore() : () => onArchive()
82 }
KrupaNagabhushan881438c2022-04-04 17:49:50 +010083 deleteAction={isArchived ? () => onDelete() : null}
svishnev69a1b382018-05-21 18:24:05 +030084 title={i18n(isArchived ? 'RESTORE' : 'ARCHIVE')}
85 />
86 )}
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020087 </div>
88 );
svishnev091edfd2018-03-19 12:15:19 +020089};
talig8e9c0652017-12-20 14:30:43 +020090
91class VersionsPage extends React.Component {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020092 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,
KrupaNagabhushan881438c2022-04-04 17:49:50 +0100114 onRestore,
115 onDelete
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200116 } = 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}
KrupaNagabhushan881438c2022-04-04 17:49:50 +0100126 onDelete={onDelete}
svishnev69a1b382018-05-21 18:24:05 +0300127 isCollaborator={isCollaborator}
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200128 />
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 }
talig8e9c0652017-12-20 14:30:43 +0200197}
198
199export default VersionsPage;