<commit_before>'use strict';

import React, { Component } from 'react';
import cx from 'react-classset';

import BuildPicker from './BuildPicker';
import GitModal from './git_modal';

const maybeCallMethod = (obj, method, ...args) => {
  obj[method] && obj[method](...args);
};

export default class EditorHeader extends Component {

  constructor(props) {
    super(props);
    this.state = {
      gitModalIsVisible: null
    };
  }

  onUpdateName = () => {
    const nameInputNode = React.findDOMNode(this.refs.nameInput);
    maybeCallMethod(this.props, 'onUpdateName', nameInputNode.value);
  }

  handleOnSubmit = (e)  => {
    e.preventDefault();
    const method = this.belongsToCurrentUser() ? 'onSave' : 'onFork';
    this[method](e);
  }

  onSave = (e) => {
    e.preventDefault();
    maybeCallMethod(this.props, 'onSave');
  }

  onFork = (e) => {
    e.preventDefault();
    maybeCallMethod(this.props, 'onFork');
  }

  onPick = (e) => {
    e.preventDefault();
    maybeCallMethod(this.props, 'onPick');
  }

  onUpdateBuild = (value) => {
    maybeCallMethod(this.props, 'onUpdateBuild', value);
  }

  belongsToCurrentUser() {
    const { currentUser, app : { creatorId} } = this.props;
    return currentUser && currentUser.id === creatorId;
  }

  currentUserIsAdmin() {
    const { currentUser } = this.props;
    return currentUser && currentUser.admin;
  }

  showGitModal = (e) => {
    e.preventDefault();
    this.setState({gitModalIsVisible: true});
  }

  hideGitModal = (e) => {
    e.preventDefault();
    this.setState({gitModalIsVisible: false});
  }

  renderGitModal = () => {
    return (
      <GitModal app={this.props.app}
               onClickBackdrop={this.hideGitModal}
               isOpen={this.state.gitModalIsVisible} />
    )
  }

  renderGitButton() {
      return (
        <button
          onClick={this.showGitModal}
          className="btn-info editor-header__button"
        >
          Clone
        </button>
      );
  }

  renderForkButton() {
      return (
        <button
          onClick={this.onFork}
          className="btn-info editor-header__button"
        >
          Fork
        </button>
      );
  }

  renderPickButton() {
    if (this.currentUserIsAdmin()) {
      return (
        <button
          onClick={this.onPick}
          className="btn-info editor-header__button"
        >
          {this.props.picked ? 'Unpick' : 'Pick'}
        </button>
      );
    }
  }

  renderSaveButton() {

    if (this.belongsToCurrentUser()) {
      return (
        <button
          onClick={this.onSave}
          className="btn-info editor-header__button"
        >
          Save
        </button>
      );
    }
  }<commit_msg>use the correct attribute for pick<commit_after>'use strict';

import React, { Component } from 'react';
import cx from 'react-classset';

import BuildPicker from './BuildPicker';
import GitModal from './git_modal';

const maybeCallMethod = (obj, method, ...args) => {
  obj[method] && obj[method](...args);
};

export default class EditorHeader extends Component {

  constructor(props) {
    super(props);
    this.state = {
      gitModalIsVisible: null
    };
  }

  onUpdateName = () => {
    const nameInputNode = React.findDOMNode(this.refs.nameInput);
    maybeCallMethod(this.props, 'onUpdateName', nameInputNode.value);
  }

  handleOnSubmit = (e)  => {
    e.preventDefault();
    const method = this.belongsToCurrentUser() ? 'onSave' : 'onFork';
    this[method](e);
  }

  onSave = (e) => {
    e.preventDefault();
    maybeCallMethod(this.props, 'onSave');
  }

  onFork = (e) => {
    e.preventDefault();
    maybeCallMethod(this.props, 'onFork');
  }

  onPick = (e) => {
    e.preventDefault();
    maybeCallMethod(this.props, 'onPick');
  }

  onUpdateBuild = (value) => {
    maybeCallMethod(this.props, 'onUpdateBuild', value);
  }

  belongsToCurrentUser() {
    const { currentUser, app : { creatorId} } = this.props;
    return currentUser && currentUser.id === creatorId;
  }

  currentUserIsAdmin() {
    const { currentUser } = this.props;
    return currentUser && currentUser.admin;
  }

  showGitModal = (e) => {
    e.preventDefault();
    this.setState({gitModalIsVisible: true});
  }

  hideGitModal = (e) => {
    e.preventDefault();
    this.setState({gitModalIsVisible: false});
  }

  renderGitModal = () => {
    return (
      <GitModal app={this.props.app}
               onClickBackdrop={this.hideGitModal}
               isOpen={this.state.gitModalIsVisible} />
    )
  }

  renderGitButton() {
      return (
        <button
          onClick={this.showGitModal}
          className="btn-info editor-header__button"
        >
          Clone
        </button>
      );
  }

  renderForkButton() {
      return (
        <button
          onClick={this.onFork}
          className="btn-info editor-header__button"
        >
          Fork
        </button>
      );
  }

  renderPickButton() {
    if (this.currentUserIsAdmin()) {
      return (
        <button
          onClick={this.onPick}
          className="btn-info editor-header__button"
        >
          {this.props.app.picked ? 'Unpick' : 'Pick'}
        </button>
      );
    }
  }

  renderSaveButton() {

    if (this.belongsToCurrentUser()) {
      return (
        <button
          onClick={this.onSave}
          className="btn-info editor-header__button"
        >
          Save
        </button>
      );
    }
  }
{'fraction_non_alphanumeric': 0.14259429622815087, 'fraction_numerical': 0.0, 'mean_word_length': 2.3329245861434704, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 41, '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': '2883934', 'n_tokens_mistral': 1744, 'n_tokens_neox': 1710, 'n_words': 293}