mirror of
https://github.com/apache/superset.git
synced 2026-04-09 19:35:21 +00:00
* Fixing PropTypes warning message React recently started warning on the upcoming deprecation of React.PropTypes, the new approach is to use the `prop-types` npm package instead. * Fixing the tests
77 lines
1.7 KiB
JavaScript
77 lines
1.7 KiB
JavaScript
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import Button from '../../components/Button';
|
|
|
|
const propTypes = {
|
|
allowAsync: PropTypes.bool.isRequired,
|
|
dbId: PropTypes.number,
|
|
queryState: PropTypes.string.isRequired,
|
|
runQuery: PropTypes.func.isRequired,
|
|
selectedText: PropTypes.string,
|
|
stopQuery: PropTypes.func.isRequired,
|
|
};
|
|
const defaultProps = {
|
|
allowAsync: false,
|
|
};
|
|
|
|
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-refresh" /> {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;
|
|
RunQueryActionButton.defaultProps = defaultProps;
|