blob: 5a20c494990c595dc9f7abdee3ee6bc0c395283b [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 +020023
svishnevfa538a12018-05-31 15:01:00 +030024const 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
svishneve52b1dc2018-07-16 14:17:01 +030035 data-test-id="deprecate-action-btn"
svishnevfa538a12018-05-31 15:01:00 +030036 name="archiveBox"
svishnev8ae8f7e2018-07-02 14:05:17 +030037 title={i18n('Archive')}
svishnevfa538a12018-05-31 15:01:00 +030038 color="secondary"
39 onClick={depricateAction}
40 />
41 )}
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020042 </div>
svishnev091edfd2018-03-19 12:15:19 +020043);
44
svishnevfa538a12018-05-31 15:01:00 +030045const ArchivedTitle = () => (
46 <div className="archived-title">{i18n('Archived')}</div>
47);
48
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020049const VersionPageTitle = ({
50 itemName,
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020051 isArchived,
52 onRestore,
svishnev69a1b382018-05-21 18:24:05 +030053 onArchive,
54 isCollaborator
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020055}) => {
56 return (
57 <div className="version-page-header">
svishnevfa538a12018-05-31 15:01:00 +030058 <div className="versions-page-title">
59 {`${i18n('Available Versions')} - ${itemName}`}
60 {isArchived ? <ArchivedTitle /> : null}
61 </div>
svishnev69a1b382018-05-21 18:24:05 +030062 {isCollaborator && (
svishnev8ae8f7e2018-07-02 14:05:17 +030063 <ArchiveRestoreButton
svishnevfa538a12018-05-31 15:01:00 +030064 isArchived={isArchived}
svishnev69a1b382018-05-21 18:24:05 +030065 depricateAction={
66 isArchived ? () => onRestore() : () => onArchive()
67 }
68 title={i18n(isArchived ? 'RESTORE' : 'ARCHIVE')}
69 />
70 )}
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020071 </div>
72 );
svishnev091edfd2018-03-19 12:15:19 +020073};
talig8e9c0652017-12-20 14:30:43 +020074
75class VersionsPage extends React.Component {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020076 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}
svishnev69a1b382018-05-21 18:24:05 +0300109 isCollaborator={isCollaborator}
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200110 />
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 }
talig8e9c0652017-12-20 14:30:43 +0200179}
180
181export default VersionsPage;