blob: 504de99e12bb644d4c7f75dd89f60b8a11fa50e0 [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 +020023import featureToggle from 'sdc-app/features/featureToggle.js';
24
svishnevfa538a12018-05-31 15:01:00 +030025const ArchiveRestoreButton = ({ depricateAction, title, isArchived }) => (
26 <div className="deprecate-btn-wrapper">
27 {isArchived ? (
28 <Button
29 data-test-id="deprecate-action-btn"
30 className="depricate-btn"
31 onClick={depricateAction}>
32 {title}
33 </Button>
34 ) : (
35 <SVGIcon
36 name="archiveBox"
37 title={i18n('Archive item')}
38 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
49const FeatureDepricatedButton = featureToggle('ARCHIVE_ITEM')(
50 ArchiveRestoreButton
51);
svishnev091edfd2018-03-19 12:15:19 +020052
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020053const VersionPageTitle = ({
54 itemName,
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020055 isArchived,
56 onRestore,
svishnev69a1b382018-05-21 18:24:05 +030057 onArchive,
58 isCollaborator
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020059}) => {
60 return (
61 <div className="version-page-header">
svishnevfa538a12018-05-31 15:01:00 +030062 <div className="versions-page-title">
63 {`${i18n('Available Versions')} - ${itemName}`}
64 {isArchived ? <ArchivedTitle /> : null}
65 </div>
svishnev69a1b382018-05-21 18:24:05 +030066 {isCollaborator && (
67 <FeatureDepricatedButton
svishnevfa538a12018-05-31 15:01:00 +030068 isArchived={isArchived}
svishnev69a1b382018-05-21 18:24:05 +030069 depricateAction={
70 isArchived ? () => onRestore() : () => onArchive()
71 }
72 title={i18n(isArchived ? 'RESTORE' : 'ARCHIVE')}
73 />
74 )}
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020075 </div>
76 );
svishnev091edfd2018-03-19 12:15:19 +020077};
talig8e9c0652017-12-20 14:30:43 +020078
79class VersionsPage extends React.Component {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020080 state = {
81 showExpanded: false
82 };
83 render() {
84 let {
85 versions,
86 owner,
87 contributors,
88 currentUser,
89 isCollaborator,
90 itemName = '',
91 viewers,
92 onSelectVersion,
93 onNavigateToVersion,
94 onTreeFullScreen,
95 onManagePermissions,
96 onCreateVersion,
97 selectedVersion,
98 onModalNodeClick,
99 isManual,
100 isArchived,
101 onArchive,
102 onRestore
103 } = this.props;
104 const depricatedTitle = isArchived ? i18n('(Archived)') : '';
105 return (
106 <div className="versions-page-view">
107 <VersionPageTitle
108 itemName={itemName}
109 depricatedTitle={depricatedTitle}
110 onArchive={onArchive}
111 isArchived={isArchived}
112 onRestore={onRestore}
svishnev69a1b382018-05-21 18:24:05 +0300113 isCollaborator={isCollaborator}
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200114 />
115 <PermissionsView
116 owner={owner}
117 contributors={contributors}
118 viewers={viewers}
119 currentUser={currentUser}
120 isManual={isManual}
121 onManagePermissions={onManagePermissions}
122 />
123 <div className="versions-page-list-and-tree">
124 <div className="version-tree-wrapper">
125 <div className="version-tree-title-container">
126 <div className="version-tree-title">
127 {i18n('Version Tree')}
128 </div>
129 {this.state.showExpanded && (
130 <SVGIcon
131 name="expand"
132 className="version-tree-full-screen"
133 onClick={() =>
134 onTreeFullScreen({
135 name: 'versions-tree-popup',
136 width: 798,
137 height: 500,
138 nodes: versions.map(version => ({
139 id: version.id,
140 name: version.name,
141 parent: version.baseId || ''
142 })),
143 onNodeClick: version =>
144 onModalNodeClick({ version }),
145 selectedNodeId: selectedVersion,
146 scrollable: true,
147 toWiden: true
148 })
149 }
150 />
151 )}
152 </div>
153 <Tree
154 name={'versions-tree'}
155 width={200}
156 allowScaleWidth={false}
157 nodes={versions.map(version => ({
158 id: version.id,
159 name: version.name,
160 parent: version.baseId || ''
161 }))}
162 onNodeClick={version =>
163 onSelectVersion({ version })
164 }
165 onRenderedBeyondWidth={() => {
166 this.setState({ showExpanded: true });
167 }}
168 selectedNodeId={selectedVersion}
169 />
170 </div>
171 <VersionList
172 versions={versions}
173 onSelectVersion={onSelectVersion}
174 onNavigateToVersion={onNavigateToVersion}
175 onCreateVersion={isArchived ? false : onCreateVersion}
176 selectedVersion={selectedVersion}
177 isCollaborator={isCollaborator}
178 />
179 </div>
180 </div>
181 );
182 }
talig8e9c0652017-12-20 14:30:43 +0200183}
184
185export default VersionsPage;