blob: b61abea5209c9b2af6e080ada57a77ef6c52b246 [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
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020025const DepricateButton = ({ depricateAction, title }) => (
26 <div className="depricate-btn-wrapper">
27 <Button
28 data-test-id="depricate-action-btn"
29 className="depricate-btn"
30 onClick={depricateAction}>
31 {title}
32 </Button>
33 </div>
svishnev091edfd2018-03-19 12:15:19 +020034);
35
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020036const FeatureDepricatedButton = featureToggle('ARCHIVE_ITEM')(DepricateButton);
svishnev091edfd2018-03-19 12:15:19 +020037
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020038const VersionPageTitle = ({
39 itemName,
40 depricatedTitle,
41 isArchived,
42 onRestore,
svishnev69a1b382018-05-21 18:24:05 +030043 onArchive,
44 isCollaborator
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020045}) => {
46 return (
47 <div className="version-page-header">
48 <div className="versions-page-title">{`${i18n(
49 'Available Versions'
50 )} - ${itemName} ${depricatedTitle}`}</div>
svishnev69a1b382018-05-21 18:24:05 +030051 {isCollaborator && (
52 <FeatureDepricatedButton
53 depricateAction={
54 isArchived ? () => onRestore() : () => onArchive()
55 }
56 title={i18n(isArchived ? 'RESTORE' : 'ARCHIVE')}
57 />
58 )}
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020059 </div>
60 );
svishnev091edfd2018-03-19 12:15:19 +020061};
talig8e9c0652017-12-20 14:30:43 +020062
63class VersionsPage extends React.Component {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020064 state = {
65 showExpanded: false
66 };
67 render() {
68 let {
69 versions,
70 owner,
71 contributors,
72 currentUser,
73 isCollaborator,
74 itemName = '',
75 viewers,
76 onSelectVersion,
77 onNavigateToVersion,
78 onTreeFullScreen,
79 onManagePermissions,
80 onCreateVersion,
81 selectedVersion,
82 onModalNodeClick,
83 isManual,
84 isArchived,
85 onArchive,
86 onRestore
87 } = this.props;
88 const depricatedTitle = isArchived ? i18n('(Archived)') : '';
89 return (
90 <div className="versions-page-view">
91 <VersionPageTitle
92 itemName={itemName}
93 depricatedTitle={depricatedTitle}
94 onArchive={onArchive}
95 isArchived={isArchived}
96 onRestore={onRestore}
svishnev69a1b382018-05-21 18:24:05 +030097 isCollaborator={isCollaborator}
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020098 />
99 <PermissionsView
100 owner={owner}
101 contributors={contributors}
102 viewers={viewers}
103 currentUser={currentUser}
104 isManual={isManual}
105 onManagePermissions={onManagePermissions}
106 />
107 <div className="versions-page-list-and-tree">
108 <div className="version-tree-wrapper">
109 <div className="version-tree-title-container">
110 <div className="version-tree-title">
111 {i18n('Version Tree')}
112 </div>
113 {this.state.showExpanded && (
114 <SVGIcon
115 name="expand"
116 className="version-tree-full-screen"
117 onClick={() =>
118 onTreeFullScreen({
119 name: 'versions-tree-popup',
120 width: 798,
121 height: 500,
122 nodes: versions.map(version => ({
123 id: version.id,
124 name: version.name,
125 parent: version.baseId || ''
126 })),
127 onNodeClick: version =>
128 onModalNodeClick({ version }),
129 selectedNodeId: selectedVersion,
130 scrollable: true,
131 toWiden: true
132 })
133 }
134 />
135 )}
136 </div>
137 <Tree
138 name={'versions-tree'}
139 width={200}
140 allowScaleWidth={false}
141 nodes={versions.map(version => ({
142 id: version.id,
143 name: version.name,
144 parent: version.baseId || ''
145 }))}
146 onNodeClick={version =>
147 onSelectVersion({ version })
148 }
149 onRenderedBeyondWidth={() => {
150 this.setState({ showExpanded: true });
151 }}
152 selectedNodeId={selectedVersion}
153 />
154 </div>
155 <VersionList
156 versions={versions}
157 onSelectVersion={onSelectVersion}
158 onNavigateToVersion={onNavigateToVersion}
159 onCreateVersion={isArchived ? false : onCreateVersion}
160 selectedVersion={selectedVersion}
161 isCollaborator={isCollaborator}
162 />
163 </div>
164 </div>
165 );
166 }
talig8e9c0652017-12-20 14:30:43 +0200167}
168
169export default VersionsPage;