<commit_before>import React, { PropTypes } from 'react'
import classnames from 'classnames'
import { Block, Loading, Navbar } from './../components'
import reactMixin from 'react-mixin'
import { Navigation } from 'react-router'
import * as Paths from '../Paths'
import { connect } from 'react-redux'
import { fetchWidgets } from './../reducers/widgets'

@connect(state => ({
  scrolledToBottom: false,
  widgetsCount: state.widgets.length,
  mobilizationEditor: state.mobilizationEditor
}))
@reactMixin.decorate(Navigation)

export default class EditMobilization extends React.Component {
  static propTypes = {
    mobilization: PropTypes.object.isRequired,
    dispatch: PropTypes.func.isRequired,
    blocks: PropTypes.object.isRequired,
    widgets: PropTypes.object.isRequired,
    location: PropTypes.object
  }

  constructor(props, context) {
    super(props, context)
    this.state = {
      scrolledToBottom: props.scrolledToBottom,
      widgetsCount: props.widgetsCount
    }
  }

  componentDidMount() {
    const {dispatch, mobilization} = this.props
    dispatch(fetchWidgets({mobilization_id: mobilization.id}))
  }

  componentDidUpdate() {
    const { mobilization, blocks, widgets } = this.props
    if (!this.newBlock() && blocks.data.length === 0 && blocks.loaded === true) {
      this.transitionTo(Paths.newMobilizationBlock(mobilization.id))
    }
    if (!this.state.scrolledToBottom &&
        this.newBlock() &&
        blocks.data.length > 0 &&
        widgets.data.length > 0 &&
        widgets.data.length > this.state.widgetsCount
        ) {
      window.scrollTo(0, document.body.scrollHeight)
      this.setState({scrolledToBottom: true})
    }
  }

  newBlock() {
    const {location} = this.props
    return location.query && location.query.newBlock && location.query.newBlock === 'true'
  }

  renderBlocks() {
    const { mobilization, blocks, mobilizationEditor } = this.props
    const { color_scheme: colorScheme } = mobilization

    return (
      <div className={classnames(colorScheme, 'flex flex-column flex-auto relative')}>
        {
          !mobilizationEditor.isEditingBlock
            && <Navbar blocks={blocks} mobilization={mobilization} />
        }
        <div id='blocks-list' className='flex-auto' style={{overflowY: 'scroll'}}>
          {
            blocks.data.map(function(block, index) {
              return (
                <Block
                  {...this.props}
                  key={'block-' + block.id}
                  block={block}
                  canMoveUp={index !== 0}
                  canMoveDown={index !== blocks.length - 1}
                  editable
                />
              )
            }.bind(this))
          }
        </div>
      </div>
    )
  }

  renderLoader() {
    return <Loading />
  }
<commit_msg>[#102391524] render Navbar component on edit mode in EditMobilization<commit_after>import React, { PropTypes } from 'react'
import classnames from 'classnames'
import { Block, Loading, Navbar } from './../components'
import reactMixin from 'react-mixin'
import { Navigation } from 'react-router'
import * as Paths from '../Paths'
import { connect } from 'react-redux'
import { fetchWidgets } from './../reducers/widgets'

@connect(state => ({
  scrolledToBottom: false,
  widgetsCount: state.widgets.length,
  mobilizationEditor: state.mobilizationEditor
}))
@reactMixin.decorate(Navigation)

export default class EditMobilization extends React.Component {
  static propTypes = {
    mobilization: PropTypes.object.isRequired,
    dispatch: PropTypes.func.isRequired,
    blocks: PropTypes.object.isRequired,
    widgets: PropTypes.object.isRequired,
    location: PropTypes.object
  }

  constructor(props, context) {
    super(props, context)
    this.state = {
      scrolledToBottom: props.scrolledToBottom,
      widgetsCount: props.widgetsCount
    }
  }

  componentDidMount() {
    const {dispatch, mobilization} = this.props
    dispatch(fetchWidgets({mobilization_id: mobilization.id}))
  }

  componentDidUpdate() {
    const { mobilization, blocks, widgets } = this.props
    if (!this.newBlock() && blocks.data.length === 0 && blocks.loaded === true) {
      this.transitionTo(Paths.newMobilizationBlock(mobilization.id))
    }
    if (!this.state.scrolledToBottom &&
        this.newBlock() &&
        blocks.data.length > 0 &&
        widgets.data.length > 0 &&
        widgets.data.length > this.state.widgetsCount
        ) {
      window.scrollTo(0, document.body.scrollHeight)
      this.setState({scrolledToBottom: true})
    }
  }

  newBlock() {
    const {location} = this.props
    return location.query && location.query.newBlock && location.query.newBlock === 'true'
  }

  renderBlocks() {
    const { mobilization, blocks, mobilizationEditor } = this.props
    const { color_scheme: colorScheme } = mobilization

    return (
      <div className={classnames(colorScheme, 'flex flex-column flex-auto relative')}>
        {
          !mobilizationEditor.isEditingBlock
            && <Navbar blocks={blocks} mobilization={mobilization} editable />
        }
        <div id='blocks-list' className='flex-auto' style={{overflowY: 'scroll'}}>
          {
            blocks.data.map(function(block, index) {
              return (
                <Block
                  {...this.props}
                  key={'block-' + block.id}
                  block={block}
                  canMoveUp={index !== 0}
                  canMoveDown={index !== blocks.length - 1}
                  editable
                />
              )
            }.bind(this))
          }
        </div>
      </div>
    )
  }

  renderLoader() {
    return <Loading />
  }

{'fraction_non_alphanumeric': 0.12467030068577457, 'fraction_numerical': 0.0036926323193247758, 'mean_word_length': 2.511111111111111, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 25, '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': '1067026', 'n_tokens_mistral': 1670, 'n_tokens_neox': 1591, 'n_words': 327}