<commit_before>React = require 'react'
MachineDetails = require './machinedetails'
immutable = require 'immutable'

module.exports = class MachinesListItem extends React.Component

  @propTypes =
    machine              : React.PropTypes.instanceOf(immutable.Map).isRequired
    stack                : React.PropTypes.instanceOf(immutable.Map).isRequired
    shouldRenderDetails  : React.PropTypes.bool
    shouldRenderSpecs    : React.PropTypes.bool
    shouldRenderPower    : React.PropTypes.bool
    shouldRenderAlwaysOn : React.PropTypes.bool
    shouldRenderSharing  : React.PropTypes.bool

  @defaultProps =
    shouldRenderDetails  : yes
    shouldRenderSpecs    : no
    shouldRenderPower    : yes
    shouldRenderAlwaysOn : no
    shouldRenderSharing  : no


  constructor: (props) ->
    super props
    @state = {isDetailOpen: no}


  renderMachineDetails: ->
    return null  unless @props.shouldRenderDetails
    return null  unless @state.isDetailOpen

    <main className="MachinesListItem-machineDetails">
      <MachineDetails
        machine={@props.machine}
        shouldRenderSpecs={@props.shouldRenderSpecs}
        shouldRenderPower={@props.shouldRenderPower}
        shouldRenderAlwaysOn={@props.shouldRenderAlwaysOn}
        shouldRenderSharing={@props.shouldRenderSharing} />
    </main>

  toggle: (event) -> @setState { isDetailOpen: not @state.isDetailOpen }



  renderDetailToggle: ->

    return null  unless @props.shouldRenderDetails

    <div className="MachinesListItem-detailToggle#{if @state.isDetailOpen then ' expanded' else ''}">
      <button onClick={@bound 'toggle'}></button>
    </div>


  render: ->

    <div className="MachinesListItem#{if @state.isDetailOpen then ' expanded' else ''}">
      <header>
        <div className="MachinesListItem-hostName">{@props.machine.get 'ipAddress'}</div>
        <div
          className="MachinesListItem-machineLabel #{@props.machine.getIn ['status', 'state']}"
          onClick={@bound 'toggle'}>
          {@props.machine.get 'label'}
        </div>
        <div className="MachinesListItem-stackLabel">
          <a href="#" className="HomeAppView--button primary">{@props.stack.get 'title'}</a>
        </div>
        {@renderDetailToggle()}
      </header>
      {@renderMachineDetails()}
    </div>


<commit_msg>client: home: machine item default ip address rendering<commit_after>React = require 'react'
MachineDetails = require './machinedetails'
immutable = require 'immutable'

module.exports = class MachinesListItem extends React.Component

  @propTypes =
    machine              : React.PropTypes.instanceOf(immutable.Map).isRequired
    stack                : React.PropTypes.instanceOf(immutable.Map).isRequired
    shouldRenderDetails  : React.PropTypes.bool
    shouldRenderSpecs    : React.PropTypes.bool
    shouldRenderPower    : React.PropTypes.bool
    shouldRenderAlwaysOn : React.PropTypes.bool
    shouldRenderSharing  : React.PropTypes.bool

  @defaultProps =
    shouldRenderDetails  : yes
    shouldRenderSpecs    : no
    shouldRenderPower    : yes
    shouldRenderAlwaysOn : no
    shouldRenderSharing  : no


  constructor: (props) ->
    super props
    @state = {isDetailOpen: no}


  renderMachineDetails: ->
    return null  unless @props.shouldRenderDetails
    return null  unless @state.isDetailOpen

    <main className="MachinesListItem-machineDetails">
      <MachineDetails
        machine={@props.machine}
        shouldRenderSpecs={@props.shouldRenderSpecs}
        shouldRenderPower={@props.shouldRenderPower}
        shouldRenderAlwaysOn={@props.shouldRenderAlwaysOn}
        shouldRenderSharing={@props.shouldRenderSharing} />
    </main>

  toggle: (event) -> @setState { isDetailOpen: not @state.isDetailOpen }


  renderIpAddress: ->

    hasIp = @props.machine.get 'ipAddress'
    ip    = hasIp or '0.0.0.0'
    title = if hasIp then '' else 'Actual IP address will appear here when this VM is powered on.'

    <div title={title} className="MachinesListItem-hostName">{ip}</div>


  renderDetailToggle: ->

    return null  unless @props.shouldRenderDetails

    <div className="MachinesListItem-detailToggle#{if @state.isDetailOpen then ' expanded' else ''}">
      <button onClick={@bound 'toggle'}></button>
    </div>


  render: ->

    <div className="MachinesListItem#{if @state.isDetailOpen then ' expanded' else ''}">
      <header>
        <div
          className="MachinesListItem-machineLabel #{@props.machine.getIn ['status', 'state']}"
          onClick={@bound 'toggle'}>
          {@props.machine.get 'label'}
        </div>
        {@renderIpAddress()}
        <div className="MachinesListItem-stackLabel">
          <a href="#" className="HomeAppView--button primary">{@props.stack.get 'title'}</a>
        </div>
        {@renderDetailToggle()}
      </header>
      {@renderMachineDetails()}
    </div>



{'fraction_non_alphanumeric': 0.11619790597413263, 'fraction_numerical': 0.000821186614658181, 'mean_word_length': 3.221837088388215, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '6441417', 'n_tokens_mistral': 1419, 'n_tokens_neox': 1388, 'n_words': 271}