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 { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 23 | 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 44 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 45 | 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 89 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 90 | prepareChild() { |
| 91 | const { onSave, onCreate, children } = this.props; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 92 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 93 | const additionalChildProps = { ref: 'editor' }; |
| 94 | if (onSave) { |
| 95 | additionalChildProps.onSave = onSave; |
| 96 | } |
| 97 | if (onCreate) { |
| 98 | additionalChildProps.onCreate = onCreate; |
| 99 | } |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 100 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 101 | const child = React.cloneElement( |
| 102 | React.Children.only(children), |
| 103 | additionalChildProps |
| 104 | ); |
| 105 | return child; |
| 106 | } |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 107 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 108 | 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 116 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 117 | handleCreate = () => { |
| 118 | const childInstance = this.refs.editor.getWrappedInstance(); |
| 119 | if (childInstance.create) { |
| 120 | childInstance.create(); |
| 121 | } else { |
| 122 | this.props.onCreate(); |
| 123 | } |
| 124 | }; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 125 | } |