<commit_before>import React from 'react';
import {findDOMNode} from 'react-dom';
import {getSelectKeys} from './util';
import Menu from 'rc-menu';

const DropdownMenu = React.createClass({
  propTypes: {
    prefixCls: React.PropTypes.string,
    menuItems: React.PropTypes.any,
    search: React.PropTypes.any,
  },

  componentDidMount() {
    this.scrollActiveItemToView();
  },

  shouldComponentUpdate(nextProps) {
    // freeze when hide
    return nextProps.visible;
  },

  componentDidUpdate(prevProps) {
    const props = this.props;
    if (!prevProps.visible && props.visible) {
      this.scrollActiveItemToView();
    }
  },

  scrollActiveItemToView() {
    // scroll into view
    const itemComponent = findDOMNode(this).querySelectorAll('[aria-selected=true]')[0];
    if (itemComponent) {
      const target = findDOMNode(itemComponent);
      target.parentNode.scrollTop = target.offsetTop;
    }
  },

  renderMenu() {
    const props = this.props;
    const { menuItems,
      defaultActiveFirstOption, value,
      dropdownMenuStyle, prefixCls,
      multiple, onMenuDeselect,
      onMenuSelect } = props;
    if (menuItems && menuItems.length) {
      const menuProps = {};
      if (multiple) {
        menuProps.onDeselect = onMenuDeselect;
        menuProps.onSelect = onMenuSelect;
      } else {
        menuProps.onClick = onMenuSelect;
      }
      const selectedKeys = getSelectKeys(menuItems, value);
      const activeKeyProps = {};
      if (!multiple) {
        activeKeyProps.activeKey = selectedKeys[0];
      }
      return (<Menu
        ref="menu"
        defaultActiveFirst={defaultActiveFirstOption}
        style={dropdownMenuStyle}
        {...activeKeyProps}
        multiple={multiple}
        focusable={false}
        {...menuProps}
        selectedKeys={selectedKeys}
        prefixCls={`${prefixCls}-menu`}>
        {menuItems}
      </Menu>);
    }
    return null;
  },
  render() {
    return (<div>
      {this.props.search}<commit_msg>use ref replace dom query<commit_after>import React, {cloneElement} from 'react';
import {findDOMNode} from 'react-dom';
import {getSelectKeys} from './util';
import Menu from 'rc-menu';

const DropdownMenu = React.createClass({
  propTypes: {
    prefixCls: React.PropTypes.string,
    menuItems: React.PropTypes.any,
    search: React.PropTypes.any,
  },

  componentDidMount() {
    this.scrollActiveItemToView();
  },

  shouldComponentUpdate(nextProps) {
    // freeze when hide
    return nextProps.visible;
  },

  componentDidUpdate(prevProps) {
    const props = this.props;
    if (!prevProps.visible && props.visible) {
      this.scrollActiveItemToView();
    }
  },

  scrollActiveItemToView() {
    // scroll into view
    const itemComponent = findDOMNode(this.firstActiveItem);
    if (itemComponent) {
      const target = findDOMNode(itemComponent);
      target.parentNode.scrollTop = target.offsetTop;
    }
  },

  renderMenu() {
    const props = this.props;
    const { menuItems,
      defaultActiveFirstOption, value,
      dropdownMenuStyle, prefixCls,
      multiple, onMenuDeselect,
      onMenuSelect } = props;
    if (menuItems && menuItems.length) {
      const menuProps = {};
      if (multiple) {
        menuProps.onDeselect = onMenuDeselect;
        menuProps.onSelect = onMenuSelect;
      } else {
        menuProps.onClick = onMenuSelect;
      }
      const selectedKeys = getSelectKeys(menuItems, value);
      const activeKeyProps = {};
      if (!multiple) {
        activeKeyProps.activeKey = selectedKeys[0];
      }
      // set firstActiveItem via cloning menus
      // for scroll into view
      const clonedMenuItems = menuItems.map(item => {
        if (selectedKeys.indexOf(item.key) === 0) {
          return cloneElement(item, {
            ref: (ref) => { this.firstActiveItem = ref; },
          });
        }
        return item;
      });
      return (<Menu
        ref="menu"
        defaultActiveFirst={defaultActiveFirstOption}
        style={dropdownMenuStyle}
        {...activeKeyProps}
        multiple={multiple}
        focusable={false}
        {...menuProps}
        selectedKeys={selectedKeys}
        prefixCls={`${prefixCls}-menu`}>
        {clonedMenuItems}
      </Menu>);
    }
    return null;
  },
  render() {
    return (<div>
      {this.props.search}
{'fraction_non_alphanumeric': 0.11861271676300578, 'fraction_numerical': 0.0009248554913294797, 'mean_word_length': 2.6383515559293524, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '4079422', 'n_tokens_mistral': 1280, 'n_tokens_neox': 1267, 'n_words': 253}