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.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 ? 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 = ( ); const asyncBtn = ( ); const stopBtn = ( ); let button; if (shouldShowStopBtn) { button = stopBtn; } else if (props.allowAsync) { button = asyncBtn; } else { button = syncBtn; } return (