blob: 9fcd7042bcadf0a50ba89377d2a62451af2b6c9b [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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 */
Michael Landoefa037d2017-02-19 12:57:33 +020016import React from 'react';
17import classnames from 'classnames';
18
19import VersionController from 'nfvo-components/panel/versionController/VersionController.jsx';
20import NavigationSideBar from 'nfvo-components/panel/NavigationSideBar.jsx';
21
22export default class TabulatedEditor extends React.Component {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020023 render() {
24 const {
25 navigationBarProps,
26 onToggle,
27 onVersionSwitching,
28 onMoreVersionsClick,
29 onCreate,
30 onSave,
31 onClose,
32 onVersionControllerAction,
33 onNavigate,
34 children,
35 meta,
36 onManagePermissions,
37 onOpenCommentCommitModal,
38 onOpenPermissions,
39 onOpenRevisionsModal
40 } = this.props;
41 let { versionControllerProps } = this.props;
42 const { className = '' } = React.Children.only(children).props;
43 const child = this.prepareChild();
Michael Landoefa037d2017-02-19 12:57:33 +020044
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020045 if (onClose) {
46 versionControllerProps = {
47 ...versionControllerProps,
48 onClose: () => onClose(versionControllerProps)
49 };
50 }
51 return (
52 <div className="software-product-view">
53 <div className="software-product-navigation-side-bar">
54 <NavigationSideBar
55 {...navigationBarProps}
56 onSelect={onNavigate}
57 onToggle={onToggle}
58 />
59 </div>
60 <div className="software-product-landing-view-right-side flex-column">
61 <VersionController
62 {...versionControllerProps}
63 onVersionSwitching={version =>
64 onVersionSwitching(version, meta)
65 }
66 onMoreVersionsClick={onMoreVersionsClick}
67 onManagePermissions={onManagePermissions}
68 onOpenCommentCommitModal={onOpenCommentCommitModal}
69 onOpenPermissions={onOpenPermissions}
70 onOpenRevisionsModal={onOpenRevisionsModal}
71 callVCAction={(action, version, comment) =>
72 onVersionControllerAction(
73 action,
74 version,
75 comment,
76 meta
77 )
78 }
79 onCreate={onCreate && this.handleCreate}
80 onSave={onSave && this.handleSave}
81 />
82 <div className={classnames('content-area', `${className}`)}>
83 {child}
84 </div>
85 </div>
86 </div>
87 );
88 }
Michael Landoefa037d2017-02-19 12:57:33 +020089
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020090 prepareChild() {
91 const { onSave, onCreate, children } = this.props;
Michael Landoefa037d2017-02-19 12:57:33 +020092
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020093 const additionalChildProps = { ref: 'editor' };
94 if (onSave) {
95 additionalChildProps.onSave = onSave;
96 }
97 if (onCreate) {
98 additionalChildProps.onCreate = onCreate;
99 }
Michael Landoefa037d2017-02-19 12:57:33 +0200100
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200101 const child = React.cloneElement(
102 React.Children.only(children),
103 additionalChildProps
104 );
105 return child;
106 }
Michael Landoefa037d2017-02-19 12:57:33 +0200107
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200108 handleSave = () => {
109 const childInstance = this.refs.editor.getWrappedInstance();
110 if (childInstance.save) {
111 return childInstance.save();
112 } else {
113 return this.props.onSave();
114 }
115 };
Michael Landoefa037d2017-02-19 12:57:33 +0200116
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200117 handleCreate = () => {
118 const childInstance = this.refs.editor.getWrappedInstance();
119 if (childInstance.create) {
120 childInstance.create();
121 } else {
122 this.props.onCreate();
123 }
124 };
Michael Landoefa037d2017-02-19 12:57:33 +0200125}