easier tab closing in sqllab (#4738)

This commit is contained in:
Gabe Lyons
2018-04-02 14:59:08 -07:00
committed by Grace Guo
parent 11c9e67ebb
commit e0f541f486
4 changed files with 85 additions and 1 deletions

View File

@@ -0,0 +1,42 @@
import React from 'react';
import PropTypes from 'prop-types';
const propTypes = {
onClose: PropTypes.func.isRequired,
tabState: PropTypes.string.isRequired,
};
class TabStatusIcon extends React.Component {
constructor(props) {
super(props);
this.onMouseOver = this.onMouseOver.bind(this);
this.onMouseOut = this.onMouseOut.bind(this);
this.state = { isHovered: false };
}
onMouseOver() {
this.setState({ isHovered: true });
}
onMouseOut() {
this.setState({ isHovered: false });
}
render() {
return (
<span
onMouseOver={this.onMouseOver}
onMouseOut={this.onMouseOut}
onClick={this.props.onClose}
>
<div className={'circle ' + this.props.tabState}>
{this.state.isHovered ? '×' : null}
</div>
</span>
);
}
}
TabStatusIcon.propTypes = propTypes;
export default TabStatusIcon;

View File

@@ -10,6 +10,7 @@ import SqlEditor from './SqlEditor';
import CopyQueryTabUrl from './CopyQueryTabUrl';
import { areArraysShallowEqual } from '../../reduxUtils';
import { t } from '../../locales';
import TabStatusIcon from './TabStatusIcon';
const propTypes = {
actions: PropTypes.object.isRequired,
@@ -160,7 +161,7 @@ class TabbedSqlEditors extends React.PureComponent {
const tabTitle = (
<div>
<div className={'circle ' + state} /> {qe.title} {' '}
<TabStatusIcon onClose={this.removeQueryEditor.bind(this, qe)} tabState={state} /> {qe.title} {' '}
<DropdownButton
bsSize="small"
id={'ddbtn-tab-' + i}