<commit_before>'use strict';

var _      = require('lodash');
var React  = require('react');
var Reflux = require('reflux/src');

var ButtonMenu          = require('component/ButtonMenu.jsx');
var Chart               = require('component/Chart.jsx');
var ChartBuilderActions = require('actions/ChartBuilderActions');
var ChartBuilderStore   = require("stores/ChartBuilderStore");
var ChartSelect         = require('./ChartSelect.jsx');
var List                = require('component/list/List.jsx');
var MenuItem            = require('component/MenuItem.jsx');
var RadioGroup          = require('component/radio-group/RadioGroup.jsx');

function findMatches(item, re) {
  var matches = [];

  if (re.test(_.get(item, 'title'))) {
    matches.push(item);
  }

  if (!_.isEmpty(_.get(item, 'children'))) {
    matches = matches.concat(findMatches(item.children, re));
  }

  return matches;
};

function filterMenu(items, pattern) {
  if (_.size(pattern) < 3) {
    return items;
  }

  var filtered = [];
  var re = new RegExp(pattern, 'gi');

  _.each(items, function (item) {
    filtered = filtered.concat(findMatches(item, re));
  });

  return filtered;
}

module.exports = React.createClass({
  mixins: [Reflux.connect(ChartBuilderStore,"store")],

  _updateTitle: function(e){
    ChartBuilderActions.updateTitle(e.target.value);<commit_msg>Fix the recursive search for hierarchical menus<commit_after>'use strict';

var _      = require('lodash');
var React  = require('react');
var Reflux = require('reflux/src');

var ButtonMenu          = require('component/ButtonMenu.jsx');
var Chart               = require('component/Chart.jsx');
var ChartBuilderActions = require('actions/ChartBuilderActions');
var ChartBuilderStore   = require("stores/ChartBuilderStore");
var ChartSelect         = require('./ChartSelect.jsx');
var List                = require('component/list/List.jsx');
var MenuItem            = require('component/MenuItem.jsx');
var RadioGroup          = require('component/radio-group/RadioGroup.jsx');

function findMatches(item, re) {
  var matches = [];

  if (re.test(_.get(item, 'title'))) {
    matches.push(item);
  }

  if (!_.isEmpty(_.get(item, 'children'))) {
    _.each(item.children, function (child) {
      matches = matches.concat(findMatches(child, re));
    })
  }

  return matches;
};

function filterMenu(items, pattern) {
  if (_.size(pattern) < 3) {
    return items;
  }

  var match = _.partial(findMatches, _, new RegExp(pattern, 'gi'));

  return _(items).map(match).flatten().value();
}

module.exports = React.createClass({
  mixins: [Reflux.connect(ChartBuilderStore,"store")],

  _updateTitle: function(e){
    ChartBuilderActions.updateTitle(e.target.value);
{'fraction_non_alphanumeric': 0.15597345132743362, 'fraction_numerical': 0.0007374631268436578, 'mean_word_length': 3.7513134851138354, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '3094438', 'n_tokens_mistral': 842, 'n_tokens_neox': 812, 'n_words': 163}