<commit_before>/* global window */

import React, { Component, PropTypes } from 'react';
import ReactCSSTransitionGroup from 'react-addons-css-transition-group';
import classnames from 'classnames';
import InteriorLeftNavList from './InteriorLeftNavList';
import InteriorLeftNavItem from './InteriorLeftNavItem';
import Icon from './Icon';
if (!process.env.EXCLUDE_SASS) {
  import('@console/bluemix-components/consumables/scss/components/inline-left-nav/inline-left-nav.scss');
}

class InteriorLeftNav extends Component {

  static propTypes = {
    children: PropTypes.node,
    className: PropTypes.string,
  };

  state = {
    activeHref: '#',
    open: true,
  };

  componentDidMount = () => {
    this.setState({ activeHref: window.location.pathname });
  };

  handleItemClick = (evt, href) => {
    evt.stopPropagation();

    // 13 = Enter, 32 = Spacebar
    const acceptableEvent = (evt.which === 13 || evt.which === 32 || evt.type === 'click');
    const diffHref = (href !== this.state.activeHref);
    if (acceptableEvent && diffHref) {
      this.setState({ activeHref: href });
    }
  };

  handleListClick = (id) => {
    this.props.children.forEach((child, index) => {
      if (child.type === InteriorLeftNavList) {
        const childId = `list-${index}`;
        if (childId !== id) {
          this.refs[childId].close();
        }
      }
    });
  };

  toggle = (evt) => {
    evt.stopPropagation();
    this.setState({ open: !this.state.open });
  };

  buildNewListChild = (child, index) => {
    const key = `list-${index}`;
    return (
      <InteriorLeftNavList
        {...child.props}
        key={key}
        ref={key}
        id={key}
        onListClick={this.handleListClick}
        onItemClick={this.handleItemClick}
        activeHref={this.state.activeHref}
      />
    );
  };

  buildNewItemChild = (child, index) => {
    const key = `item-${index}`;
    return (
      <InteriorLeftNavItem
        {...child.props}
        key={key}
        onClick={this.handleItemClick}
        activeHref={this.state.activeHref}
      />
    );
  };

  render() {
    const {
      className,
      children,
      ...other,
    } = this.props;

    const newChildren = React.Children.map(children, (child, index) => {
      let newChild;
      if (child.type === InteriorLeftNavList) {
        newChild = this.buildNewListChild(child, index);
      } else {
        newChild = this.buildNewItemChild(child, index);<commit_msg>fix(ILN): update ILN props to include `activeHref` (#460)<commit_after>/* global window */

import React, { Component, PropTypes } from 'react';
import ReactCSSTransitionGroup from 'react-addons-css-transition-group';
import classnames from 'classnames';
import InteriorLeftNavList from './InteriorLeftNavList';
import InteriorLeftNavItem from './InteriorLeftNavItem';
import Icon from './Icon';
if (!process.env.EXCLUDE_SASS) {
  import('@console/bluemix-components/consumables/scss/components/inline-left-nav/inline-left-nav.scss');
}

class InteriorLeftNav extends Component {

  static propTypes = {
    children: PropTypes.node,
    className: PropTypes.string,
    activeHref: PropTypes.string,
  };

  state = {
    activeHref: this.props.activeHref || '#',
    open: true,
  };

  componentDidMount = () => {
    this.setState({ activeHref: window.location.pathname });
  };

  componentWillReceiveProps = (nextProps) => {
    if (nextProps.activeHref) {
      this.setState({ activeHref: nextProps.activeHref });
    }
  };

  handleItemClick = (evt, href) => {
    evt.stopPropagation();

    // 13 = Enter, 32 = Spacebar
    const acceptableEvent = (evt.which === 13 || evt.which === 32 || evt.type === 'click');
    const diffHref = (href !== this.state.activeHref);
    if (acceptableEvent && diffHref) {
      this.setState({ activeHref: href });
    }
  };

  handleListClick = (id) => {
    this.props.children.forEach((child, index) => {
      if (child.type === InteriorLeftNavList) {
        const childId = `list-${index}`;
        if (childId !== id) {
          this.refs[childId].close();
        }
      }
    });
  };

  toggle = (evt) => {
    evt.stopPropagation();
    this.setState({ open: !this.state.open });
  };

  buildNewListChild = (child, index) => {
    const key = `list-${index}`;
    return (
      <InteriorLeftNavList
        {...child.props}
        key={key}
        ref={key}
        id={key}
        onListClick={this.handleListClick}
        onItemClick={this.handleItemClick}
        activeHref={this.state.activeHref}
      />
    );
  };

  buildNewItemChild = (child, index) => {
    const key = `item-${index}`;
    return (
      <InteriorLeftNavItem
        {...child.props}
        key={key}
        onClick={this.handleItemClick}
        activeHref={this.state.activeHref}
      />
    );
  };

  render() {
    const {
      className,
      children,
      activeHref, // eslint-disable-line no-unused-vars
      ...other,
    } = this.props;

    const newChildren = React.Children.map(children, (child, index) => {
      let newChild;
      if (child.type === InteriorLeftNavList) {
        newChild = this.buildNewListChild(child, index);
      } else {
        newChild = this.buildNewItemChild(child, index);
{'fraction_non_alphanumeric': 0.15224450811843362, 'fraction_numerical': 0.003629417382999045, 'mean_word_length': 2.705590941259731, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 24, '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': '2948524', 'n_tokens_mistral': 1678, 'n_tokens_neox': 1666, 'n_words': 311}