<commit_before>package blended.mgmt.ui.components

import japgolly.scalajs.react.ReactComponentB
import japgolly.scalajs.react.ReactEventI
import japgolly.scalajs.react.vdom.prefix_<^._
import blended.mgmt.ui.util.I18n
import blended.mgmt.ui.components.filter.Filter
import blended.updater.config.ContainerInfo
import blended.mgmt.ui.util.Logger
import japgolly.scalajs.react.Callback
import japgolly.scalajs.react.BackendScope
import blended.mgmt.ui.components.filter.ContainerInfoFilter
import blended.mgmt.ui.components.filter.And

object CompViewFilter {

  private[this] val i18n = I18n()
  private[this] val log: Logger = Logger[CompViewFilter.type]

  case class Props(
    filter: And[ContainerInfo],
    removeFilter: Filter[ContainerInfo] => Unit,
    removeAllFilter: () => Unit)

  class Backend(scope: BackendScope[Props, Unit]) {

    def removeFilter(filter: Filter[ContainerInfo])(e: ReactEventI): Callback = {
      scope.props.map(_.removeFilter(filter))
    }

    def removeAllFilter(e: ReactEventI): Callback = {
      scope.props.map(_.removeAllFilter())
    }

    def render(props: Props) = {
      val divs = props.filter.filters.map { filter =>
        <.span(
          <.span(filter.toString()),
          <.span("X", ^.onClick ==> removeFilter(filter)
          )
        )
      }

      <.span(
        (divs ++
          Seq(<.span("Remove All", ^.onClick ==> removeAllFilter))
        ): _*
      )
    }
  }

  val CompViewFilter = ReactComponentB[Props]("ContainerViewFilter")
    .backend(new Backend(_))
    .renderBackend
    .build

}<commit_msg>Only show clear filters option if a filter was set<commit_after>package blended.mgmt.ui.components

import japgolly.scalajs.react.ReactComponentB
import japgolly.scalajs.react.ReactEventI
import japgolly.scalajs.react.vdom.prefix_<^._
import blended.mgmt.ui.util.I18n
import blended.mgmt.ui.components.filter.Filter
import blended.updater.config.ContainerInfo
import blended.mgmt.ui.util.Logger
import japgolly.scalajs.react.Callback
import japgolly.scalajs.react.BackendScope
import blended.mgmt.ui.components.filter.ContainerInfoFilter
import blended.mgmt.ui.components.filter.And

object CompViewFilter {

  private[this] val i18n = I18n()
  private[this] val log: Logger = Logger[CompViewFilter.type]

  case class Props(
    filter: And[ContainerInfo],
    removeFilter: Filter[ContainerInfo] => Unit,
    removeAllFilter: () => Unit)

  class Backend(scope: BackendScope[Props, Unit]) {

    def removeFilter(filter: Filter[ContainerInfo])(e: ReactEventI): Callback = {
      scope.props.map(_.removeFilter(filter))
    }

    def removeAllFilter(e: ReactEventI): Callback = {
      scope.props.map(_.removeAllFilter())
    }

    def render(props: Props) = {
      val filters = props.filter.filters

      val selectedFilters = filters.map { filter =>
        <.span(
          <.span(filter.toString()),
          <.span(
            i18n.trc("Remove filter", "X"),
            ^.onClick ==> removeFilter(filter)
          )
        )
      }

      val clearFilters = filters.headOption.map(_ => <.span(
        i18n.tr("Clear Filter"),
        ^.onClick ==> removeAllFilter))

      <.span((selectedFilters ++ clearFilters): _*)
    }
  }

  val CompViewFilter = ReactComponentB[Props]("ContainerViewFilter")
    .backend(new Backend(_))
    .renderBackend
    .build

}
{'fraction_non_alphanumeric': 0.12388591800356506, 'fraction_numerical': 0.004753416518122401, 'mean_word_length': 3.3784135240572173, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 14, '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': '3143493', 'n_tokens_mistral': 1094, 'n_tokens_neox': 1076, 'n_words': 189}