<commit_before>import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import { withRouter } from 'react-router';

import { Button, DropdownButton, MenuItem } from 'react-bootstrap';
import { Link } from 'react-router';

import JSONButton from '../../common/JSONButton';

import { FetchRequest, FetchRequestShuffleOptOut } from '../../../actions/api/requests';
import {
  FetchActiveTasksForRequest,
  FetchRequestHistory
} from '../../../actions/api/history';

import RunNowButton from '../../common/modalButtons/RunNowButton';
import RemoveButton from '../../common/modalButtons/RemoveButton';
import PauseButton from '../../common/modalButtons/PauseButton';
import UnpauseButton from '../../common/modalButtons/UnpauseButton';
import BounceButton from '../../common/modalButtons/BounceButton';
import ScaleButton from '../../common/modalButtons/ScaleButton';
import ExitCooldownButton from '../../common/modalButtons/ExitCooldownButton';
import EnableHealthchecksButton from '../../common/modalButtons/EnableHealthchecksButton';
import DisableHealthchecksButton from '../../common/modalButtons/DisableHealthchecksButton';

import Utils from '../../../utils';
import ShuffleOptOutButton from '../../common/modalButtons/ShuffleOptOutButton';
import PriorityButton from '../../common/modalButtons/PriorityButton';

const RequestActionButtons = ({ showRequestEdit, requestParent, fetchingShuffleOptOut, fetchRequest, fetchRequestHistory, fetchActiveTasks, fetchRequestShuffleOptOut, router }) => {
  let fetchRequestAndHistoryAndActiveTasks = () => {
    return Promise.all([
      fetchRequest(),
      fetchActiveTasks(),
      fetchRequestHistory(5, 1),
    ]);
  }

  let fetchRequestAndHistory = () => {
    return Promise.all([
      fetchRequest(),
      fetchRequestHistory(5, 1),
    ]);
  }

  if (!requestParent || !requestParent.request || fetchingShuffleOptOut) {
    return <div></div>;
  }
  const { request, state } = requestParent;

  let maybeNewDeployButton;
  if (!config.hideNewDeployButton) {
    maybeNewDeployButton = (
      <Link to={`request/${request.id}/deploy`}>
        <Button bsStyle="success">
          Deploy
        </Button>
      </Link>
    );
  }

  let maybeRunNowButton;
  if (Utils.request.canBeRunNow(requestParent)) {
    maybeRunNowButton = (
      <RunNowButton requestId={request.id} then={fetchRequestAndHistoryAndActiveTasks}>
        <Button bsStyle="primary">
          Run now
        </Button>
      </RunNowButton>
    );
  }

  let maybeExitCooldownButton;
  if (state === 'SYSTEM_COOLDOWN') {
    maybeExitCooldownButton = (
      <ExitCooldownButton requestId={request.id} then={fetchRequestAndHistoryAndActiveTasks}>
        <Button bsStyle="primary">
          Exit Cooldown
        </Button>
      </ExitCooldownButton>
    );
  }

  let maybeScaleButton;
  if (Utils.request.canBeScaled(requestParent)) {
    maybeScaleButton = (
      <ScaleButton
        requestId={request.id}
        currentInstances={request.instances}
        then={fetchRequestAndHistoryAndActiveTasks}
        bounceAfterScaleDefault={Utils.maybe(request, ['bounceAfterScale'], false)}
      >
        <Button bsStyle="primary" disabled={Utils.request.scaleDisabled(requestParent)}>
          Scale
        </Button>
      </ScaleButton>
    );
  }

  let maybePriorityButton;
  if (this.props.showRequestEdit || !config.hideNewRequestButton) {
    maybePriorityButton = (
      <PriorityButton
        requestId={request.id}
        current={request.taskPriorityLevel}
        then={fetchRequestAndHistoryAndActiveTasks}
      >
        <Button bsStyle="primary">
          Priority<commit_msg>ui fix<commit_after>import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import { withRouter } from 'react-router';

import { Button, DropdownButton, MenuItem } from 'react-bootstrap';
import { Link } from 'react-router';

import JSONButton from '../../common/JSONButton';

import { FetchRequest, FetchRequestShuffleOptOut } from '../../../actions/api/requests';
import {
  FetchActiveTasksForRequest,
  FetchRequestHistory
} from '../../../actions/api/history';

import RunNowButton from '../../common/modalButtons/RunNowButton';
import RemoveButton from '../../common/modalButtons/RemoveButton';
import PauseButton from '../../common/modalButtons/PauseButton';
import UnpauseButton from '../../common/modalButtons/UnpauseButton';
import BounceButton from '../../common/modalButtons/BounceButton';
import ScaleButton from '../../common/modalButtons/ScaleButton';
import ExitCooldownButton from '../../common/modalButtons/ExitCooldownButton';
import EnableHealthchecksButton from '../../common/modalButtons/EnableHealthchecksButton';
import DisableHealthchecksButton from '../../common/modalButtons/DisableHealthchecksButton';

import Utils from '../../../utils';
import ShuffleOptOutButton from '../../common/modalButtons/ShuffleOptOutButton';
import PriorityButton from '../../common/modalButtons/PriorityButton';

const RequestActionButtons = ({ showRequestEdit, requestParent, fetchingShuffleOptOut, fetchRequest, fetchRequestHistory, fetchActiveTasks, fetchRequestShuffleOptOut, router }) => {
  let fetchRequestAndHistoryAndActiveTasks = () => {
    return Promise.all([
      fetchRequest(),
      fetchActiveTasks(),
      fetchRequestHistory(5, 1),
    ]);
  }

  let fetchRequestAndHistory = () => {
    return Promise.all([
      fetchRequest(),
      fetchRequestHistory(5, 1),
    ]);
  }

  if (!requestParent || !requestParent.request || fetchingShuffleOptOut) {
    return <div></div>;
  }
  const { request, state } = requestParent;

  let maybeNewDeployButton;
  if (!config.hideNewDeployButton) {
    maybeNewDeployButton = (
      <Link to={`request/${request.id}/deploy`}>
        <Button bsStyle="success">
          Deploy
        </Button>
      </Link>
    );
  }

  let maybeRunNowButton;
  if (Utils.request.canBeRunNow(requestParent)) {
    maybeRunNowButton = (
      <RunNowButton requestId={request.id} then={fetchRequestAndHistoryAndActiveTasks}>
        <Button bsStyle="primary">
          Run now
        </Button>
      </RunNowButton>
    );
  }

  let maybeExitCooldownButton;
  if (state === 'SYSTEM_COOLDOWN') {
    maybeExitCooldownButton = (
      <ExitCooldownButton requestId={request.id} then={fetchRequestAndHistoryAndActiveTasks}>
        <Button bsStyle="primary">
          Exit Cooldown
        </Button>
      </ExitCooldownButton>
    );
  }

  let maybeScaleButton;
  if (Utils.request.canBeScaled(requestParent)) {
    maybeScaleButton = (
      <ScaleButton
        requestId={request.id}
        currentInstances={request.instances}
        then={fetchRequestAndHistoryAndActiveTasks}
        bounceAfterScaleDefault={Utils.maybe(request, ['bounceAfterScale'], false)}
      >
        <Button bsStyle="primary" disabled={Utils.request.scaleDisabled(requestParent)}>
          Scale
        </Button>
      </ScaleButton>
    );
  }

  let maybePriorityButton;
  if (showRequestEdit || !config.hideNewRequestButton) {
    maybePriorityButton = (
      <PriorityButton
        requestId={request.id}
        current={request.taskPriorityLevel}
        then={fetchRequestAndHistoryAndActiveTasks}
      >
        <Button bsStyle="primary">
          Priority
{'fraction_non_alphanumeric': 0.13130482456140352, 'fraction_numerical': 0.0010964912280701754, 'mean_word_length': 3.5210656753407683, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5938199', 'n_tokens_mistral': 2018, 'n_tokens_neox': 2021, 'n_words': 384}