<commit_before>React = require 'react'
BS = require 'react-bootstrap'
_ = require 'underscore'

{History, Link} = require 'react-router'
{TransitionActions, TransitionStore} = require '../../flux/transition'

BackButton = React.createClass
  displayName: 'BackButton'

  propTypes:
    fallbackLink: React.PropTypes.shape(
      to: React.PropTypes.string
      params: React.PropTypes.object
      text: React.PropTypes.string
    ).isRequired

  contextTypes:
    router: React.PropTypes.func

  render: ->
    # Gets route to last path that was not the same as the current one
    # See TransitionStore for more detail.
    historyInfo = TransitionStore.getPrevious(@context.router)
    hasHistory = historyInfo.path?
    {fallbackLink, className} = @props
    {text} = fallbackLink

    if hasHistory
      backText = if historyInfo.name then "Back to #{historyInfo.name}"  else 'Back'
      backButton = <BS.Button className={className}
        onClick={=> @context.router.transitionTo(historyInfo.path)}>
        {backText}
      </BS.Button>
    else
      fallbackLink = _.omit(fallbackLink, 'text')
      classes = 'btn btn-default'
      classes += " #{className}" if className?

      backButton = <Link {...fallbackLink} className={classes}>
        {text}
      </Link>

    backButton

module.exports = BackButton<commit_msg>Style button the same regardless of history status<commit_after>React = require 'react'
BS = require 'react-bootstrap'
_ = require 'underscore'

{History, Link} = require 'react-router'
{TransitionActions, TransitionStore} = require '../../flux/transition'

BackButton = React.createClass
  displayName: 'BackButton'

  propTypes:
    fallbackLink: React.PropTypes.shape(
      to: React.PropTypes.string
      params: React.PropTypes.object
      text: React.PropTypes.string
    ).isRequired

  contextTypes:
    router: React.PropTypes.func

  navigate: ->
    historyInfo = TransitionStore.getPrevious(@context.router)
    if historyInfo.path
      @context.router.transitionTo(historyInfo.path)
    else
      @context.router.transitionTo(@props.fallbackLink.to, @props.fallbackLink.params)

  render: ->
    # Gets route to last path that was not the same as the current one
    # See TransitionStore for more detail.
    historyInfo = TransitionStore.getPrevious(@context.router)
    {fallbackLink, className} = @props
    {text} = fallbackLink

    backText = if historyInfo.name then "Back to #{historyInfo.name}"  else fallbackLink.text

    <BS.Button className={className} {...@props}
      onClick={@navigate}>
      {backText}
    </BS.Button>

module.exports = BackButton
{'fraction_non_alphanumeric': 0.11085714285714286, 'fraction_numerical': 0.0, 'mean_word_length': 3.420875420875421, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '4769248', 'n_tokens_mistral': 767, 'n_tokens_neox': 749, 'n_words': 192}