This is an automated email from the ASF dual-hosted git repository.
erikrit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
The following commit(s) were added to refs/heads/master by this push:
new 1cbd955 [SIP-36] Migrate RunQueryActionButton.jsx to
RunQueryActionButton.tsx (#9290) (#9291)
1cbd955 is described below
commit 1cbd955e794136ef51b773aa781912b906693a84
Author: Asif Iqbal <[email protected]>
AuthorDate: Fri Mar 13 07:06:55 2020 +0530
[SIP-36] Migrate RunQueryActionButton.jsx to RunQueryActionButton.tsx
(#9290) (#9291)
---
...ryActionButton.jsx => RunQueryActionButton.tsx} | 62 +++++++++++-----------
superset-frontend/src/components/Button.jsx | 5 ++
2 files changed, 37 insertions(+), 30 deletions(-)
diff --git a/superset-frontend/src/SqlLab/components/RunQueryActionButton.jsx
b/superset-frontend/src/SqlLab/components/RunQueryActionButton.tsx
similarity index 61%
rename from superset-frontend/src/SqlLab/components/RunQueryActionButton.jsx
rename to superset-frontend/src/SqlLab/components/RunQueryActionButton.tsx
index 218d66a..2d94c73 100644
--- a/superset-frontend/src/SqlLab/components/RunQueryActionButton.jsx
+++ b/superset-frontend/src/SqlLab/components/RunQueryActionButton.tsx
@@ -17,53 +17,56 @@
* under the License.
*/
import React from 'react';
-import PropTypes from 'prop-types';
import { t } from '@superset-ui/translation';
import Button from '../../components/Button';
-const propTypes = {
- allowAsync: PropTypes.bool.isRequired,
- dbId: PropTypes.number,
- queryState: PropTypes.string,
- runQuery: PropTypes.func.isRequired,
- selectedText: PropTypes.string,
- stopQuery: PropTypes.func.isRequired,
- sql: PropTypes.string.isRequired,
-};
-const defaultProps = {
- allowAsync: false,
- sql: '',
-};
+const NO_OP = () => undefined;
+
+interface Props {
+ allowAsync: boolean;
+ dbId?: number;
+ queryState?: string;
+ runQuery: (c?: boolean) => void;
+ selectedText?: string;
+ stopQuery: () => void;
+ sql: string;
+}
-export default function RunQueryActionButton(props) {
- const runBtnText = props.selectedText
- ? t('Run Selected Query')
- : t('Run Query');
- const btnStyle = props.selectedText ? 'warning' : 'primary';
+const RunQueryActionButton = ({
+ allowAsync = false,
+ dbId,
+ queryState,
+ runQuery = NO_OP,
+ selectedText,
+ stopQuery = NO_OP,
+ sql,
+}: Props) => {
+ const runBtnText = selectedText ? t('Run Selected Query') : t('Run Query');
+ const btnStyle = selectedText ? 'warning' : 'primary';
const shouldShowStopBtn =
- ['running', 'pending'].indexOf(props.queryState) > -1;
+ !!queryState && ['running', 'pending'].indexOf(queryState) > -1;
const commonBtnProps = {
bsSize: 'small',
bsStyle: btnStyle,
- disabled: !props.dbId,
+ disabled: !dbId,
};
if (shouldShowStopBtn) {
return (
- <Button {...commonBtnProps} onClick={props.stopQuery}>
+ <Button {...commonBtnProps} onClick={stopQuery}>
<i className="fa fa-stop" /> {t('Stop')}
</Button>
);
- } else if (props.allowAsync) {
+ } else if (allowAsync) {
return (
<Button
{...commonBtnProps}
- onClick={() => props.runQuery(true)}
+ onClick={() => runQuery(true)}
key="run-async-btn"
tooltip={t('Run query asynchronously (Ctrl + ↵)')}
- disabled={!props.sql.trim()}
+ disabled={!sql.trim()}
>
<i className="fa fa-table" /> {runBtnText}
</Button>
@@ -72,15 +75,14 @@ export default function RunQueryActionButton(props) {
return (
<Button
{...commonBtnProps}
- onClick={() => props.runQuery(false)}
+ onClick={() => runQuery(false)}
key="run-btn"
tooltip={t('Run query synchronously (Ctrl + ↵)')}
- disabled={!props.sql.trim()}
+ disabled={!sql.trim()}
>
<i className="fa fa-refresh" /> {runBtnText}
</Button>
);
-}
+};
-RunQueryActionButton.propTypes = propTypes;
-RunQueryActionButton.defaultProps = defaultProps;
+export default RunQueryActionButton;
diff --git a/superset-frontend/src/components/Button.jsx
b/superset-frontend/src/components/Button.jsx
index 818040f..43fe49b 100644
--- a/superset-frontend/src/components/Button.jsx
+++ b/superset-frontend/src/components/Button.jsx
@@ -26,8 +26,13 @@ import {
} from 'react-bootstrap';
const propTypes = {
+ children: PropTypes.node,
tooltip: PropTypes.node,
placement: PropTypes.string,
+ onClick: PropTypes.func,
+ disabled: PropTypes.bool,
+ bsSize: PropTypes.string,
+ btnStyles: PropTypes.string,
};
const defaultProps = {
bsSize: 'sm',