AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 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 | */ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 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() { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 25 | const {navigationBarProps, onToggle, onVersionSwitching, onMoreVersionsClick, onCreate, onSave, onClose, |
| 26 | onVersionControllerAction, onNavigate, children, meta, onManagePermissions, onOpenCommentCommitModal, onOpenPermissions, onOpenRevisionsModal} = this.props; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 27 | let {versionControllerProps} = this.props; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 28 | const {className = ''} = React.Children.only(children).props; |
| 29 | const child = this.prepareChild(); |
| 30 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 31 | if(onClose) { |
| 32 | versionControllerProps = { |
| 33 | ...versionControllerProps, |
| 34 | onClose: () => onClose(versionControllerProps) |
| 35 | }; |
| 36 | } |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 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} |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 45 | onVersionSwitching={version => onVersionSwitching(version, meta)} |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 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)} |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 52 | onCreate={onCreate && this.handleCreate} |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 53 | onSave={onSave && this.handleSave}/> |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 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 | } |