All files / javascripts/SqlLab/components RunQueryActionButton.jsx

80% Statements 20/25
37.5% Branches 3/8
60% Functions 3/5
86.96% Lines 20/23
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 761x 1x   1x               1x         2x 2x 2x 2x   2x             2x   2x               2x   2x                 2x               2x 2x 2x             2x             1x 1x  
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 = (
    <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;
  Eif (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;