<commit_before>{div, a, i, span} = React.DOM
window.ValidationErrors = class ValidationErrors extends React.Component
  constructor: (props, context) ->
    super(props, context)
    @state = {
      data: @props.validationErrors,
      numToShow: 5
      showAll: false
      hideAll: false
      ignored: @props.ignored
    }
    @toggleBox = @toggleBox.bind(@)
    @showMoreErrors = @showMore.bind(@)
    @showLessErrors = @showLess.bind(@)

  render: ->
    div(
      { className: 'validation-errors-box' }
      @renderHeader()
      @renderBody()
    )

  renderHeader: ->
    borderBottom = if @state.hideAll then '' else 'border-btm'
    errors = if @state.ignored then I18n.t('ignored_validation_errors') else I18n.t('validation_errors')
    div(
      { className: "validation-errors-header #{borderBottom}" }
      span(
        { className: 'errors-count bold' }
        "#{errors} (#{@state.data.length})"
      )
      a(
        {
          className: 'toggle-errors button'
          onClick: @toggleBox
        }
        if @state.hideAll
          i({ className: 'fa fa-angle-down' })
        else
          i({ className: 'fa fa-angle-up'})
      )
    )

  renderBody: ->
    div(
      { className: 'validation-errors-body' }
      unless @state.hideAll
        [
          @renderInfoBox()
          @renderValidationErrors()
          if @state.showAll then @renderShowLess() else @renderShowMore()
        ]
    )

  renderInfoBox: ->
    div(
      { className: 'info-box validation-errors-info' }
      i({ className: 'fa fa-info-circle' })
      span(
        {}
        I18n.t('errors_info')
      )
    )

  renderValidationErrors: ->
    for validationError, idx in @state.data
      hidden = if @state.showAll then false else idx >= @state.numToShow
      unless hidden
        React.createElement(ValidationError,
          {
            key: validationError.id
            data: validationError
          }
        )

  renderShowMore: ->
    span(
      {
        className: 'show-more'
        onClick: @showMoreErrors
      }
      i({ className: 'fa fa-plus-circle' })
      I18n.t('show_more_errors')
    )

  renderShowLess: ->
    span(
      {
        className: 'show-more'
        onClick: @showLessErrors
      }
      i({ className: 'fa fa-minus-circle' })
      I18n.t('show_less_errors')
    )


  toggleBox: ->
    @setState({ hideAll: !@state.hideAll})

  showMore: ->
    @setState({ showAll: true })

  showLess: ->
    @setState({ showAll: false })
<commit_msg>Show more errors link only if needed<commit_after>{div, a, i, span} = React.DOM
window.ValidationErrors = class ValidationErrors extends React.Component
  constructor: (props, context) ->
    super(props, context)
    @state = {
      data: @props.validationErrors,
      numToShow: 5
      showAllErrors: false
      hideAll: false
      ignored: @props.ignored
    }
    @toggleBox = @toggleBox.bind(@)
    @showMoreErrors = @showMore.bind(@)
    @showLessErrors = @showLess.bind(@)

  render: ->
    div(
      { className: 'validation-errors-box' }
      @renderHeader()
      @renderBody()
    )

  renderHeader: ->
    borderBottom = if @state.hideAll then '' else 'border-btm'
    errors = if @state.ignored then I18n.t('ignored_validation_errors') else I18n.t('validation_errors')
    div(
      { className: "validation-errors-header #{borderBottom}" }
      span(
        { className: 'errors-count bold' }
        "#{errors} (#{@state.data.length})"
      )
      a(
        {
          className: 'toggle-errors button'
          onClick: @toggleBox
        }
        if @state.hideAll
          i({ className: 'fa fa-angle-down' })
        else
          i({ className: 'fa fa-angle-up'})
      )
    )

  renderBody: ->
    div(
      { className: 'validation-errors-body' }
      unless @state.hideAll
        [
          @renderInfoBox()
          @renderValidationErrors()
          if @state.data.length > @state.numToShow
            if @state.showAllErrors then @renderShowLess() else @renderShowMore()
        ]
    )

  renderInfoBox: ->
    div(
      { className: 'info-box validation-errors-info' }
      i({ className: 'fa fa-info-circle' })
      span(
        {}
        I18n.t('errors_info')
      )
    )

  renderValidationErrors: ->
    for validationError, idx in @state.data
      hidden = if @state.showAllErrors then false else idx >= @state.numToShow
      unless hidden
        React.createElement(ValidationError,
          {
            key: validationError.id
            data: validationError
          }
        )

  renderShowMore: ->
    span(
      {
        className: 'show-more'
        onClick: @showMoreErrors
      }
      i({ className: 'fa fa-plus-circle' })
      I18n.t('show_more_errors')
    )

  renderShowLess: ->
    span(
      {
        className: 'show-more'
        onClick: @showLessErrors
      }
      i({ className: 'fa fa-minus-circle' })
      I18n.t('show_less_errors')
    )


  toggleBox: ->
    @setState({ hideAll: !@state.hideAll})

  showMore: ->
    @setState({ showAllErrors: true })

  showLess: ->
    @setState({ showAllErrors: false })

{'fraction_non_alphanumeric': 0.12933385274639658, 'fraction_numerical': 0.004285157771717959, 'mean_word_length': 2.0601907032181166, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 28, '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': '4938391', 'n_tokens_mistral': 1602, 'n_tokens_neox': 1583, 'n_words': 327}