Files
superset2/superset/assets/javascripts/SqlLab/components/RunQueryActionButton.jsx
Denny Biasiolli 3df3e0d681 Fixing some warnings during tests (#3648)
* ColorSchemeControl: fixing bad use of PropTypes

Accessing PropTypes via the main React package is deprecated, and will be
removed in React v16.0. Use the latest available v15.* prop-types package from
npm instead. For info on usage, compatibility, migration and more, see
https://fb.me/prop-types-docs

* Control: adding PropTypes.func in types allowed inside `value` prop

This removes a warning during yarn tests

Fix #3589

* tests(QueryStateLabel): removing missing prop warning

```
Warning: Failed prop type: The prop `query` is marked as required in
`QueryStateLabel`, but its value is `undefined`.
    in QueryStateLabel
```

* SaveQuery: removing invalid prop `target` supplied to `Overlay`.

This removes a warning during yarn tests:

```
Warning: Failed prop type: Invalid prop `target` supplied to `Overlay`.
```

* RunQueryActionButton: removing `isRequired` from queryState props

This removes a warning during yarn tests:
```
Warning: Failed prop type: The prop `queryState` is marked as required in
`RunQueryActionButton`, but its value is `null`.
```
2017-10-11 21:07:52 -07:00

79 lines
1.8 KiB
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
import Button from '../../components/Button';
import { t } from '../../locales';
const propTypes = {
allowAsync: PropTypes.bool.isRequired,
dbId: PropTypes.number,
queryState: PropTypes.string,
runQuery: PropTypes.func.isRequired,
selectedText: PropTypes.string,
stopQuery: PropTypes.func.isRequired,
};
const defaultProps = {
allowAsync: false,
};
export default function RunQueryActionButton(props) {
const runBtnText = props.selectedText ? t('Run Selected Query') : t('Run Query');
const btnStyle = props.selectedText ? 'warning' : 'primary';
const shouldShowStopBtn = ['running', 'pending'].indexOf(props.queryState) > -1;
const asyncToolTip = t('Run query asynchronously');
const commonBtnProps = {
bsSize: 'small',
bsStyle: btnStyle,
disabled: !(props.dbId),
};
const syncBtn = (
<Button
{...commonBtnProps}
onClick={() => props.runQuery(false)}
key="run-btn"
tooltip={asyncToolTip}
>
<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" /> {t('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;