blob: 3c9ceed0d8a3fa737b30c0a9cb5e93725337f528 [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 {
23
24 render() {
talig8e9c0652017-12-20 14:30:43 +020025 const {navigationBarProps, onToggle, onVersionSwitching, onMoreVersionsClick, onCreate, onSave, onClose,
26 onVersionControllerAction, onNavigate, children, meta, onManagePermissions, onOpenCommentCommitModal, onOpenPermissions, onOpenRevisionsModal} = this.props;
AviZi280f8012017-06-09 02:39:56 +030027 let {versionControllerProps} = this.props;
Michael Landoefa037d2017-02-19 12:57:33 +020028 const {className = ''} = React.Children.only(children).props;
29 const child = this.prepareChild();
30
AviZi280f8012017-06-09 02:39:56 +030031 if(onClose) {
32 versionControllerProps = {
33 ...versionControllerProps,
34 onClose: () => onClose(versionControllerProps)
35 };
36 }
Michael Landoefa037d2017-02-19 12:57:33 +020037 return (
38 <div className='software-product-view'>
39 <div className='software-product-navigation-side-bar'>
40 <NavigationSideBar {...navigationBarProps} onSelect={onNavigate} onToggle={onToggle}/>
41 </div>
42 <div className='software-product-landing-view-right-side flex-column'>
43 <VersionController
44 {...versionControllerProps}
AviZi280f8012017-06-09 02:39:56 +030045 onVersionSwitching={version => onVersionSwitching(version, meta)}
talig8e9c0652017-12-20 14:30:43 +020046 onMoreVersionsClick={onMoreVersionsClick}
47 onManagePermissions={onManagePermissions}
48 onOpenCommentCommitModal={onOpenCommentCommitModal}
49 onOpenPermissions={onOpenPermissions}
50 onOpenRevisionsModal={onOpenRevisionsModal}
51 callVCAction={(action, version, comment) => onVersionControllerAction(action, version, comment, meta)}
Michael Landoefa037d2017-02-19 12:57:33 +020052 onCreate={onCreate && this.handleCreate}
AviZi280f8012017-06-09 02:39:56 +030053 onSave={onSave && this.handleSave}/>
Michael Landoefa037d2017-02-19 12:57:33 +020054 <div className={classnames('content-area', `${className}`)}>
55 {
56 child
57 }
58 </div>
59 </div>
60 </div>
61 );
62 }
63
64 prepareChild() {
65 const {onSave, onCreate, children} = this.props;
66
67 const additionalChildProps = {ref: 'editor'};
68 if (onSave) {
69 additionalChildProps.onSave = onSave;
70 }
71 if (onCreate) {
72 additionalChildProps.onCreate = onCreate;
73 }
74
75 const child = React.cloneElement(React.Children.only(children), additionalChildProps);
76 return child;
77 }
78
79
80
81 handleSave = () => {
82 const childInstance = this.refs.editor.getWrappedInstance();
83 if (childInstance.save) {
84 return childInstance.save();
85 } else {
86 return this.props.onSave();
87 }
88 };
89
90 handleCreate = () => {
91 const childInstance = this.refs.editor.getWrappedInstance();
92 if (childInstance.create) {
93 childInstance.create();
94 } else {
95 this.props.onCreate();
96 }
97 }
98}