import React, { PropTypes } from 'react'; 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 = ( ); const asyncBtn = ( ); const stopBtn = ( ); let button; if (shouldShowStopBtn) { button = stopBtn; } else if (props.allowAsync) { button = asyncBtn; } else { button = syncBtn; } return (
{button}
); } RunQueryActionButton.propTypes = propTypes; RunQueryActionButton.defaultProps = defaultProps;