From 2e4e6a3381abb5a49d3d195543726584c1723fbd Mon Sep 17 00:00:00 2001 From: Pascal Precht Date: Sun, 28 Oct 2018 16:07:41 +0100 Subject: [PATCH] fix(cockpit/TextEditorToolbar): set active state on selected tabs This commit ensures that the `activeTab` state for the Editor toolbar tabs is properly passed down to `TextEditorToolbar` component, so it can be used to set the active state accordingly. --- embark-ui/src/components/TextEditorToolbar.js | 95 +++++++++++-------- embark-ui/src/containers/EditorContainer.js | 3 +- .../containers/TextEditorToolbarContainer.js | 6 +- 3 files changed, 64 insertions(+), 40 deletions(-) diff --git a/embark-ui/src/components/TextEditorToolbar.js b/embark-ui/src/components/TextEditorToolbar.js index c0c9f537..57fc711f 100644 --- a/embark-ui/src/components/TextEditorToolbar.js +++ b/embark-ui/src/components/TextEditorToolbar.js @@ -1,51 +1,72 @@ -import React from 'react'; +import React, { Component } from 'react'; import PropTypes from 'prop-types'; import {Button, Nav, NavLink} from 'reactstrap'; +import classnames from 'classnames'; import FontAwesomeIcon from 'react-fontawesome'; -const TextEditorToolbar = (props) => ( -
    -
  1. - - -
  2. -
  3. - +const TextEditorToolbarTabs = { + Overview: 'overview', + Detail: 'detail', + Logger: 'logger', + Debugger: 'debugger', + Browser: 'browser' +}; -
  4. -
-); +class TextEditorToolbar extends Component { + + isActiveTab(tab) { + return this.props.activeTab === tab; + } + + render() { + return ( +
    +
  1. + + +
  2. +
  3. + + +
  4. +
+ ); + } +} TextEditorToolbar.propTypes = { isContract: PropTypes.bool, save: PropTypes.func, remove: PropTypes.func, toggleShowHiddenFiles: PropTypes.func, - openAsideTab: PropTypes.func + openAsideTab: PropTypes.func, + activeTab: PropTypes.string }; export default TextEditorToolbar; diff --git a/embark-ui/src/containers/EditorContainer.js b/embark-ui/src/containers/EditorContainer.js index c1afb9ba..cec5950a 100644 --- a/embark-ui/src/containers/EditorContainer.js +++ b/embark-ui/src/containers/EditorContainer.js @@ -62,7 +62,8 @@ class EditorContainer extends React.Component { this.openAsideTab(newTab)} isContract={this.isContract()} - currentFile={this.props.currentFile} /> + currentFile={this.props.currentFile} + activeTab={this.state.currentAsideTab}/> this.toggleShowHiddenFiles()} /> diff --git a/embark-ui/src/containers/TextEditorToolbarContainer.js b/embark-ui/src/containers/TextEditorToolbarContainer.js index ffce2b65..0c229c21 100644 --- a/embark-ui/src/containers/TextEditorToolbarContainer.js +++ b/embark-ui/src/containers/TextEditorToolbarContainer.js @@ -22,7 +22,8 @@ class TextEditorToolbarContainer extends Component { toggleShowHiddenFiles={this.props.toggleShowHiddenFiles} openAsideTab={this.props.openAsideTab} save={() => this.save()} - remove={() => this.remove()} />; + remove={() => this.remove()} + activeTab={this.props.activeTab} />; } } @@ -32,7 +33,8 @@ TextEditorToolbarContainer.propTypes = { saveFile: PropTypes.func, removeFile: PropTypes.func, toggleShowHiddenFiles: PropTypes.func, - openAsideTab: PropTypes.func + openAsideTab: PropTypes.func, + activeTab: PropTypes.string }; export default connect(