-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sql lab] only show single run query button (#1858)
* only show single run query button, allow async if possible * only pass the needed props, rather than entire objects to the component * add simple test * fix linting
- Loading branch information
Alanna Scott
authored
Jan 4, 2017
1 parent
8924bb7
commit 242869d
Showing
3 changed files
with
114 additions
and
61 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
superset/assets/javascripts/SqlLab/components/RunQueryActionButton.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,71 @@ | ||
import React, { PropTypes } from 'react'; | ||
import Button from '../../components/Button'; | ||
|
||
const propTypes = { | ||
allowAsync: PropTypes.bool.isRequired, | ||
dbId: PropTypes.number.isRequired, | ||
queryState: PropTypes.string.isRequired, | ||
runQuery: PropTypes.func.isRequired, | ||
selectedText: PropTypes.string, | ||
stopQuery: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default function RunQueryActionButton(props) { | ||
const runBtnText = props.selectedText ? 'Run Selected Query' : 'Run Query'; | ||
const btnStyle = props.selectedText ? 'warning' : 'primary'; | ||
const shouldShowStopBtn = ['running', 'pending'].indexOf(props.queryState) > -1; | ||
const asyncToolTip = 'Run query asynchronously'; | ||
|
||
const commonBtnProps = { | ||
bsSize: 'small', | ||
bsStyle: btnStyle, | ||
disabled: !(props.dbId), | ||
}; | ||
|
||
const syncBtn = ( | ||
<Button | ||
{...commonBtnProps} | ||
onClick={() => props.runQuery(false)} | ||
key="run-btn" | ||
> | ||
<i className="fa fa-table" /> {runBtnText} | ||
</Button> | ||
); | ||
|
||
const asyncBtn = ( | ||
<Button | ||
{...commonBtnProps} | ||
onClick={() => props.runQuery(true)} | ||
key="run-async-btn" | ||
tooltip={asyncToolTip} | ||
> | ||
<i className="fa fa-table" /> {runBtnText} | ||
</Button> | ||
); | ||
|
||
const stopBtn = ( | ||
<Button | ||
{...commonBtnProps} | ||
onClick={props.stopQuery} | ||
> | ||
<i className="fa fa-stop" /> Stop | ||
</Button> | ||
); | ||
|
||
let button; | ||
if (shouldShowStopBtn) { | ||
button = stopBtn; | ||
} else if (props.allowAsync) { | ||
button = asyncBtn; | ||
} else { | ||
button = syncBtn; | ||
} | ||
|
||
return ( | ||
<div className="inline m-r-5 pull-left"> | ||
{button} | ||
</div> | ||
); | ||
} | ||
|
||
RunQueryActionButton.propTypes = propTypes; |
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
34 changes: 34 additions & 0 deletions
34
superset/assets/spec/javascripts/explorev2/components/RunQueryActionButton_spec.js
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,34 @@ | ||
import React from 'react'; | ||
import { expect } from 'chai'; | ||
import { describe, it, beforeEach } from 'mocha'; | ||
import { shallow } from 'enzyme'; | ||
|
||
import RunQueryActionButton | ||
from '../../../../javascripts/SqlLab/components/RunQueryActionButton'; | ||
import Button from '../../../../javascripts/components/Button'; | ||
|
||
describe('RunQueryActionButton', () => { | ||
let wrapper; | ||
const defaultProps = { | ||
allowAsync: false, | ||
dbId: 1, | ||
queryState: 'pending', | ||
runQuery: () => {}, // eslint-disable-line | ||
selectedText: null, | ||
stopQuery: () => {}, // eslint-disable-line | ||
}; | ||
|
||
beforeEach(() => { | ||
wrapper = shallow(<RunQueryActionButton {...defaultProps} />); | ||
}); | ||
|
||
it('is a valid react element', () => { | ||
expect( | ||
React.isValidElement(<RunQueryActionButton {...defaultProps} />) | ||
).to.equal(true); | ||
}); | ||
|
||
it('renders a single Button', () => { | ||
expect(wrapper.find(Button)).to.have.lengthOf(1); | ||
}); | ||
}); |