Add collaboration feature
[sdc.git] / openecomp-ui / src / nfvo-components / editor / TabulatedEditor.jsx
1 /*!
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  */
16 import React from 'react';
17 import classnames from 'classnames';
18
19 import VersionController from 'nfvo-components/panel/versionController/VersionController.jsx';
20 import NavigationSideBar from 'nfvo-components/panel/NavigationSideBar.jsx';
21
22 export default class TabulatedEditor extends React.Component {
23
24         render() {
25                 const {navigationBarProps, onToggle, onVersionSwitching, onMoreVersionsClick, onCreate, onSave, onClose,
26                                 onVersionControllerAction, onNavigate, children, meta, onManagePermissions, onOpenCommentCommitModal, onOpenPermissions, onOpenRevisionsModal} = this.props;
27                 let {versionControllerProps} = this.props;
28                 const {className = ''} = React.Children.only(children).props;
29                 const child = this.prepareChild();
30
31                 if(onClose) {
32                         versionControllerProps = {
33                                 ...versionControllerProps,
34                                 onClose: () => onClose(versionControllerProps)
35                         };
36                 }
37                 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}
45                                                 onVersionSwitching={version => onVersionSwitching(version, meta)}
46                                                 onMoreVersionsClick={onMoreVersionsClick}
47                                                 onManagePermissions={onManagePermissions}
48                                                 onOpenCommentCommitModal={onOpenCommentCommitModal}
49                                                 onOpenPermissions={onOpenPermissions}
50                                                 onOpenRevisionsModal={onOpenRevisionsModal}
51                                                 callVCAction={(action, version, comment) => onVersionControllerAction(action, version, comment, meta)}
52                                                 onCreate={onCreate && this.handleCreate}
53                                                 onSave={onSave && this.handleSave}/>
54                                         <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 }