forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
easier tab closing in sqllab (apache#4738)
- Loading branch information
1 parent
59c6e1b
commit 5ddb312
Showing
4 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
superset/assets/javascripts/SqlLab/components/TabStatusIcon.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
superset/assets/spec/javascripts/sqllab/TabStatusIcon_spec.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); | ||
}); |