<commit_before>kd          = require 'kd'
React       = require 'kd-react'
classnames  = require 'classnames'
toImmutable = require 'app/util/toImmutable'
Link        = require 'app/components/common/link'

module.exports = class SidebarMachinesListItem extends React.Component

  constructor: (props) ->

    super

    status = @props.machine.getIn ['status', 'state']

    @state = {
      collapsed : status isnt 'Running' and not @props.active
      status
    }


  machine: (key) -> @props.machine.get key


  getClassName: ->
    classnames
      SidebarListItem : yes
      active          : @props.active
      machine         : yes


  handleMachineClick: (event) ->

    kd.utils.stopDOMEvent event
    console.log @state.collapsed
    @setState { collapsed: not @state.collapsed }


  renderUnreadCount: ->
    return null  unless @props.unreadCount > 0

    return \
      <cite className='SidebarListItem-unreadCount'>
        {@props.unreadCount}
      </cite>


  renderProgressbar: ->

    <div className="SidebarListItem-progressbar" />


  renderWorkspaces: ->

    @machine('workspaces').toList().map (workspace) =>
      <Link
        key={workspace.get '_id'}
        className='Workspace-link'
        href={"/IDE/#{@machine 'slug'}/#{workspace.get 'slug'}"}
        >
        <cite className='Workspace-icon' />
        <span className='Workspace-title'>{workspace.get 'name'}</span>
      </Link>


  renderWorkspaceSection: ->

    return null  if @state.collapsed

    <section className='Workspaces-section'>
      <h3>WORKSPACES</h3>
      {@renderWorkspaces()}
    </section>


  render: ->
    status = @state.status
    <div className="SidebarMachinesListItem #{status}">
      <Link
        className={@getClassName()}
        # make this link dynamic pointing to latest open workspace
        href={"/IDE/#{@machine 'slug'}"}
        onClick={@bound 'handleMachineClick'}
        >
        <cite className={"SidebarListItem-icon"} title={"Machine status: #{status}"}/>
        <span className='SidebarListItem-title'>{@machine 'label'}</span>
        {@renderUnreadCount()}
        {@renderProgressbar()}
      </Link>
      <Link
        className='MachineSettings'
        href={"/Machines/#{@machine 'slug'}"}
        />
      {@renderWorkspaceSection()}
    </div>

<commit_msg>sidebar: minor: machine list item helper update<commit_after>kd          = require 'kd'
React       = require 'kd-react'
classnames  = require 'classnames'
toImmutable = require 'app/util/toImmutable'
Link        = require 'app/components/common/link'

module.exports = class SidebarMachinesListItem extends React.Component

  constructor: (props) ->

    super

    status = @props.machine.getIn ['status', 'state']

    @state = {
      collapsed : status isnt 'Running' and not @props.active
      status
    }


  machine: (key) ->

    if typeof key is 'string'
    then @props.machine.get key
    else @props.machine.getIn key


  getClassName: ->
    classnames
      SidebarListItem : yes
      active          : @props.active
      machine         : yes


  handleMachineClick: (event) ->

    kd.utils.stopDOMEvent event
    console.log @state.collapsed
    @setState { collapsed: not @state.collapsed }


  renderUnreadCount: ->
    return null  unless @props.unreadCount > 0

    return \
      <cite className='SidebarListItem-unreadCount'>
        {@props.unreadCount}
      </cite>


  renderProgressbar: ->

    <div className="SidebarListItem-progressbar" />


  renderWorkspaces: ->

    @machine('workspaces').toList().map (workspace) =>
      <Link
        key={workspace.get '_id'}
        className='Workspace-link'
        href={"/IDE/#{@machine 'slug'}/#{workspace.get 'slug'}"}
        >
        <cite className='Workspace-icon' />
        <span className='Workspace-title'>{workspace.get 'name'}</span>
      </Link>


  renderWorkspaceSection: ->

    return null  if @state.collapsed

    <section className='Workspaces-section'>
      <h3>WORKSPACES</h3>
      {@renderWorkspaces()}
    </section>


  render: ->

    status = @machine ['status', 'state']
    <div className="SidebarMachinesListItem #{status}">
      <Link
        className={@getClassName()}
        # make this link dynamic pointing to latest open workspace
        href={"/IDE/#{@machine 'slug'}"}
        onClick={@bound 'handleMachineClick'}
        >
        <cite className={"SidebarListItem-icon"} title={"Machine status: #{status}"}/>
        <span className='SidebarListItem-title'>{@machine 'label'}</span>
        {@renderUnreadCount()}
        {@renderProgressbar()}
      </Link>
      <Link
        className='MachineSettings'
        href={"/Machines/#{@machine 'slug'}"}
        />
      {@renderWorkspaceSection()}
    </div>


{'fraction_non_alphanumeric': 0.13892391761244222, 'fraction_numerical': 0.0012610340479192938, 'mean_word_length': 2.635599694423224, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 65, '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': '5935136', 'n_tokens_mistral': 1450, 'n_tokens_neox': 1420, 'n_words': 289}