<commit_before>import { difference, reduce, values } from 'lodash';
import React, { Component, PropTypes } from 'react';
import { Button, Panel } from 'react-bootstrap';
import { Link } from 'react-router';

export default class StatusItem extends Component {
  getWaitingOnUsers() {
    const {
      remoteResult: {
        usernames: allUsernames,
        pluginState: {
          'group-step': groupStep,
        },
      },
    } = this.props;
    const currentUsernames = Object.keys(groupStep.userStep);
    const currentStep = groupStep.step;

    if (allUsernames.length !== Object.keys(groupStep.userStep).length) {
      return difference(allUsernames, currentUsernames);
    } else if (values(groupStep.userStep).some(step => step !== currentStep)) {
      return reduce(groupStep.userStep, (memo, step, username) => (
        step !== currentStep ? memo.concat(username) : memo
      ), []);
    }

    return [];
  }

  maybeRenderButton() {
    const {
      allowRun,
      runComputation,
      showRunButton,
    } = this.props;

    if (showRunButton) {
      return (
        <Button
          bsStyle="primary"
          disabled={!allowRun}
          onClick={runComputation}
        >
          <span
            className="glyphicon glyphicon-repeat"
            aria-hidden="true"
          >
          </span>
          {' '}
          Run Computation
        </Button>
      );
    }
  }

  renderStatus() {
    const { status } = this.props;
    let className = 'project-status';
    let icon;
    let text;

    switch (status) {
      case 'active':
        className += ' is-active text-muted';
        icon = 'refresh';
        text = 'Running';
        break;
      case 'complete':
        className += ' text-success';
        icon = 'ok';
        text = 'Complete';
        break;
      case 'error':
        className += ' text-danger';
        icon = 'alert';
        text = 'Error';
        break;
      case 'waiting':
        className += ' text-muted';
        icon = 'alert';
        text = 'Waiting to start';
        break;
      default:
        icon = 'question-sign';
        text = 'Unknown status';
    }

    return (
      <div className={className}>
        <span>
          <span aria-hidden="true" className={`glyphicon glyphicon-${icon}`}></span>
          {' '}
          {text}
        </span>
      </div>
    );
  }

  render() {
    const {
      computation,
      consortium,
      remoteResult,
    } = this.props;

    let iteration;
    let waitingOn;
    let users;

    if (computation.name === 'laplacian-noise-ridge-regression' && remoteResult) {
      iteration = (
        <li>
          <strong>Iteration:</strong><commit_msg>Ensure undefined remote result prop doesn't explode :boom:<commit_after>import { difference, get, reduce, values } from 'lodash';
import React, { Component, PropTypes } from 'react';
import { Button, Panel } from 'react-bootstrap';
import { Link } from 'react-router';

export default class StatusItem extends Component {
  getWaitingOnUsers() {
    const {
      remoteResult: {
        usernames: allUsernames,
        pluginState: {
          'group-step': groupStep,
        },
      },
    } = this.props;
    const currentUsernames = Object.keys(groupStep.userStep);
    const currentStep = groupStep.step;

    if (allUsernames.length !== Object.keys(groupStep.userStep).length) {
      return difference(allUsernames, currentUsernames);
    } else if (values(groupStep.userStep).some(step => step !== currentStep)) {
      return reduce(groupStep.userStep, (memo, step, username) => (
        step !== currentStep ? memo.concat(username) : memo
      ), []);
    }

    return [];
  }

  maybeRenderButton() {
    const {
      allowRun,
      runComputation,
      showRunButton,
    } = this.props;

    if (showRunButton) {
      return (
        <Button
          bsStyle="primary"
          disabled={!allowRun}
          onClick={runComputation}
        >
          <span
            className="glyphicon glyphicon-repeat"
            aria-hidden="true"
          >
          </span>
          {' '}
          Run Computation
        </Button>
      );
    }
  }

  renderStatus() {
    const { status } = this.props;
    let className = 'project-status';
    let icon;
    let text;

    switch (status) {
      case 'active':
        className += ' is-active text-muted';
        icon = 'refresh';
        text = 'Running';
        break;
      case 'complete':
        className += ' text-success';
        icon = 'ok';
        text = 'Complete';
        break;
      case 'error':
        className += ' text-danger';
        icon = 'alert';
        text = 'Error';
        break;
      case 'waiting':
        className += ' text-muted';
        icon = 'alert';
        text = 'Waiting to start';
        break;
      default:
        icon = 'question-sign';
        text = 'Unknown status';
    }

    return (
      <div className={className}>
        <span>
          <span aria-hidden="true" className={`glyphicon glyphicon-${icon}`}></span>
          {' '}
          {text}
        </span>
      </div>
    );
  }

  render() {
    const {
      computation,
      consortium,
      remoteResult,
    } = this.props;

    let iteration;
    let waitingOn;
    let users;

    if (
      computation.name === 'laplacian-noise-ridge-regression' &&
      remoteResult &&
      get(remoteResult, 'pluginState.inputs[0][1]')
    ) {
      iteration = (
        <li>
          <strong>Iteration:</strong>
{'fraction_non_alphanumeric': 0.13149791704401376, 'fraction_numerical': 0.0003622532149972831, 'mean_word_length': 1.9109119662625198, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 33, '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': '370773', 'n_tokens_mistral': 1617, 'n_tokens_neox': 1597, 'n_words': 353}