Skip to content

Commit

Permalink
easier tab closing in sqllab (apache#4738)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabe Lyons authored and michellethomas committed May 23, 2018
1 parent 59c6e1b commit 5ddb312
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 1 deletion.
42 changes: 42 additions & 0 deletions superset/assets/javascripts/SqlLab/components/TabStatusIcon.jsx
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}
Expand Down
6 changes: 6 additions & 0 deletions superset/assets/javascripts/SqlLab/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ div.Workspace {
height: 10px;
display: inline-block;
background-color: #ccc;
line-height: 8px;
text-align: center;
vertical-align: middle;
font-size: 15px;
margin-top: -3px;
font-weight: bold;
}
.running {
background-color: lime;
Expand Down
35 changes: 35 additions & 0 deletions superset/assets/spec/javascripts/sqllab/TabStatusIcon_spec.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react';
import sinon from 'sinon';
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { shallow } from 'enzyme';

import TabStatusIcon from '../../../javascripts/SqlLab/components/TabStatusIcon';

function setup() {
const onClose = sinon.spy();
const wrapper = shallow(<TabStatusIcon onClose={onClose} tabState="running" />);
return { wrapper, onClose };
}

describe('TabStatusIcon', () => {
it('renders a circle without an x when hovered', () => {
const { wrapper } = setup();
expect(wrapper.find('div.circle')).to.have.length(1);
expect(wrapper.text()).to.equal('');
});

it('renders a circle with an x when hovered', () => {
const { wrapper } = setup();
wrapper.simulate('mouseOver');
expect(wrapper.find('div.circle')).to.have.length(1);
expect(wrapper.text()).to.equal('×');
});

it('calls onClose from props when clicked', () => {
const { wrapper, onClose } = setup();
wrapper.simulate('click');
// eslint-disable-next-line no-unused-expressions
expect(onClose.calledOnce).to.be.true;
});
});

0 comments on commit 5ddb312

Please sign in to comment.