<commit_before>package ui.pages

import api.{ConfigStore, DockerClient}
import japgolly.scalajs.react.vdom.prefix_<^._
import japgolly.scalajs.react.{BackendScope, ReactComponentB}
import model.{Connection, ConnectionError, Container, ContainersInfo}
import ui.Workbench
import util.logger._

import scala.concurrent.ExecutionContext.Implicits.global

object ContainersPage extends Page {

  val id = "Containers"

  case class State(info: ContainersInfo = ContainersInfo())

  case class Props(connection: Connection)

  case class Backend(t: BackendScope[Props, State]) {
    def willStart(): Unit = {
      DockerClient(t.props.connection).containersInfo().map { info =>
        t.modState(s => State(info))
      }.onFailure {
        case ex: Exception =>
          log.error("Unable to get containers", ex)
          Workbench.error(ConnectionError(ex.getMessage))
      }
    }
  }

  def component() = {
    val props = Props(ConfigStore.connection)
    ContainersPageRender.component(props)
  }
}

object ContainersPageRender {

  import ui.pages.ContainersPage._

  val component = ReactComponentB[Props]("ContainerPage")
    .initialState(State())
    .backend(new Backend(_))
    .render((P, S, B) => {
    vdom(S)
  }).componentWillMount(_.backend.willStart())
    .build

  def vdom(state: State) = <.div(
    table(true,"Container Running", state.info.running),
    table(false,"History", state.info.history)
  )

  def table(showLinks: Boolean, title: String, containers: Seq[Container]) = <.div(^.className := "container  col-sm-12",
    <.div(^.className := "panel panel-default  bootcards-summary",
      <.div(^.className := "panel-heading clearfix",
        <.h3(^.className := "panel-title pull-left")(title),
        <.a(^.className := "btn pull-right glyphicon glyphicon-refresh", ^.href := "#")
      ),
      <.table(^.className := "table table-hover",
        <.thead(
          <.tr(
            <.th("Id"),
            <.th("Image"),
            <.th("Command"),
            <.th("Ports"),
            <.th("Created"),
            <.th("Status")
          )
        ),
        <.tbody(
          containers.map { c =>
            <.tr(
              <.td(if(showLinks) Workbench.link(ContainerPage(c.Id))(c.id) else None),
              <.td(c.Image),
              <.td(c.Command),
              <.td(c.ports.map(<.div(_))),
              <.td(c.created),
              <.td(c.Status)
            )
          }
        )
      )
    )
  )


}<commit_msg>Hide Id column when the container is not running.<commit_after>package ui.pages

import api.{ConfigStore, DockerClient}
import japgolly.scalajs.react.vdom.prefix_<^._
import japgolly.scalajs.react.{BackendScope, ReactComponentB}
import model.{Connection, ConnectionError, Container, ContainersInfo}
import ui.Workbench
import util.logger._

import scala.concurrent.ExecutionContext.Implicits.global

object ContainersPage extends Page {

  val id = "Containers"

  case class State(info: ContainersInfo = ContainersInfo())

  case class Props(connection: Connection)

  case class Backend(t: BackendScope[Props, State]) {
    def willStart(): Unit = {
      DockerClient(t.props.connection).containersInfo().map { info =>
        t.modState(s => State(info))
      }.onFailure {
        case ex: Exception =>
          log.error("Unable to get containers", ex)
          Workbench.error(ConnectionError(ex.getMessage))
      }
    }
  }

  def component() = {
    val props = Props(ConfigStore.connection)
    ContainersPageRender.component(props)
  }
}

object ContainersPageRender {

  import ui.pages.ContainersPage._

  val component = ReactComponentB[Props]("ContainerPage")
    .initialState(State())
    .backend(new Backend(_))
    .render((P, S, B) => {
    vdom(S)
  }).componentWillMount(_.backend.willStart())
    .build

  def vdom(state: State) = <.div(
    table(true, "Container Running", state.info.running),
    table(false, "History", state.info.history)
  )

  def table(showLinks: Boolean, title: String, containers: Seq[Container]) = <.div(^.className := "container  col-sm-12",
    <.div(^.className := "panel panel-default  bootcards-summary",
      <.div(^.className := "panel-heading clearfix",
        <.h3(^.className := "panel-title pull-left")(title),
        <.a(^.className := "btn pull-right glyphicon glyphicon-refresh", ^.href := "#")
      ),
      <.table(^.className := "table table-hover",
        <.thead(
          <.tr(
            Some(<.th("Id")).filter(_ => showLinks),
            <.th("Image"),
            <.th("Command"),
            <.th("Ports"),
            <.th("Created"),
            <.th("Status")
          )
        ),
        <.tbody(
          containers.map { c =>
            <.tr(
              Some(<.td(Workbench.link(ContainerPage(c.Id))(c.id))).filter(_ => showLinks),
              <.td(c.Image),
              <.td(c.Command),
              <.td(c.ports.map(<.div(_))),
              <.td(c.created),
              <.td(c.Status)
            )
          }
        )
      )
    )
  )


}
{'fraction_non_alphanumeric': 0.15734126984126984, 'fraction_numerical': 0.0011904761904761906, 'mean_word_length': 2.455106237148732, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 15, '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': '521254', 'n_tokens_mistral': 1605, 'n_tokens_neox': 1566, 'n_words': 289}