<commit_before>React = require 'react'
_ = require 'underscore'
classnames = require 'classnames'

Breadcrumb = React.createClass
  displayName: 'Breadcrumb'
  propTypes:
    crumb: React.PropTypes.object.isRequired
    goToStep: React.PropTypes.func.isRequired
    step: React.PropTypes.object.isRequired
    canReview: React.PropTypes.bool
    currentStep: React.PropTypes.number
    onMouseEnter: React.PropTypes.func
    onMouseLeave: React.PropTypes.func

  getDefaultProps: ->
    canReview: true
    step: {}

  getInitialState: ->
    @getState(@props)

  componentWillReceiveProps: (nextProps) ->
    nextState = @getState(nextProps)
    @setState(nextState)

  getState: ({crumb, currentStep, step, canReview}) ->
    isCorrect = false
    isIncorrect = false
    isCurrent = crumb.key is currentStep
    isCompleted = step?.is_completed
    isEnd = crumb.type is 'end'
    crumbType = if isEnd then crumb.type else step?.type

    if isCompleted
      if canReview and step.correct_answer_id?
        if step.is_correct
          isCorrect = true
        else if step.answer_id
          isIncorrect = true

    {isCorrect, isIncorrect, isCurrent, isCompleted, isEnd, crumbType}

  render: ->
    {step, crumb, goToStep, className} = @props
    {isCorrect, isIncorrect, isCurrent, isCompleted, isEnd, crumbType} = @state

    propsToPassOn = _.pick(@props, 'onMouseEnter', 'onMouseLeave', 'style')

    if isCurrent
      title = "Current Step (#{crumbType})"

    if isCompleted
      title ?= "Step Completed (#{crumbType}). Click to review"

    if isCorrect
      status = <i className='icon-lg icon-correct'></i>

    if isIncorrect
      status = <i className='icon-lg icon-incorrect'></i>

    if isEnd
      title = "#{step.title} Completion"

    classes = classnames 'openstax-breadcrumbs-step', 'icon-stack', 'icon-lg', step.group, "breadcrumb-#{crumbType}", className,
      current: isCurrent
      active: isCurrent
      completed: isCompleted
      'status-correct': isCorrect
      'status-incorrect': isIncorrect

    # build list of icon classes from the crumb type and the step labels
    crumbClasses = _.map(crumb.data.labels, (label) -> "icon-#{label}") if crumb.data.labels?
    iconClasses = classnames "icon-#{crumbType}", crumbClasses

    <span
      {...propsToPassOn}
      className={classes}
      title={title}
      onClick={_.partial(goToStep, crumb.key)}
      data-chapter={crumb.sectionLabel}
      key="step-#{crumb.key}">
      <i className="icon-lg #{iconClasses}"></i>
      {status}
    </span>

module.exports = Breadcrumb
<commit_msg>sneak in quick update for passing on tab index to breadcrumbs<commit_after>React = require 'react'
_ = require 'underscore'
classnames = require 'classnames'

Breadcrumb = React.createClass
  displayName: 'Breadcrumb'
  propTypes:
    crumb: React.PropTypes.object.isRequired
    goToStep: React.PropTypes.func.isRequired
    step: React.PropTypes.object.isRequired
    canReview: React.PropTypes.bool
    currentStep: React.PropTypes.number
    onMouseEnter: React.PropTypes.func
    onMouseLeave: React.PropTypes.func

  getDefaultProps: ->
    canReview: true
    step: {}

  getInitialState: ->
    @getState(@props)

  componentWillReceiveProps: (nextProps) ->
    nextState = @getState(nextProps)
    @setState(nextState)

  getState: ({crumb, currentStep, step, canReview}) ->
    isCorrect = false
    isIncorrect = false
    isCurrent = crumb.key is currentStep
    isCompleted = step?.is_completed
    isEnd = crumb.type is 'end'
    crumbType = if isEnd then crumb.type else step?.type

    if isCompleted
      if canReview and step.correct_answer_id?
        if step.is_correct
          isCorrect = true
        else if step.answer_id
          isIncorrect = true

    {isCorrect, isIncorrect, isCurrent, isCompleted, isEnd, crumbType}

  render: ->
    {step, crumb, goToStep, className} = @props
    {isCorrect, isIncorrect, isCurrent, isCompleted, isEnd, crumbType} = @state

    propsToPassOn = _.pick(@props, 'onMouseEnter', 'onMouseLeave', 'style', 'tabIndex')

    if isCurrent
      title = "Current Step (#{crumbType})"

    if isCompleted
      title ?= "Step Completed (#{crumbType}). Click to review"

    if isCorrect
      status = <i className='icon-lg icon-correct'></i>

    if isIncorrect
      status = <i className='icon-lg icon-incorrect'></i>

    if isEnd
      title = "#{step.title} Completion"

    classes = classnames 'openstax-breadcrumbs-step', 'icon-stack', 'icon-lg', step.group, "breadcrumb-#{crumbType}", className,
      current: isCurrent
      active: isCurrent
      completed: isCompleted
      'status-correct': isCorrect
      'status-incorrect': isIncorrect

    # build list of icon classes from the crumb type and the step labels
    crumbClasses = _.map(crumb.data.labels, (label) -> "icon-#{label}") if crumb.data.labels?
    iconClasses = classnames "icon-#{crumbType}", crumbClasses

    <span
      {...propsToPassOn}
      className={classes}
      title={title}
      onClick={_.partial(goToStep, crumb.key)}
      data-chapter={crumb.sectionLabel}
      key="step-#{crumb.key}">
      <i className="icon-lg #{iconClasses}"></i>
      {status}
    </span>

module.exports = Breadcrumb

{'fraction_non_alphanumeric': 0.11622137404580153, 'fraction_numerical': 0.0, 'mean_word_length': 3.2402912621359223, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 31, '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': '3502197', 'n_tokens_mistral': 1679, 'n_tokens_neox': 1647, 'n_words': 393}