<commit_before>import { useEffect } from 'react';
import PropTypes from 'prop-types';
import { attempt } from 'lodash-es';
import { findIndex } from 'lodash-es';
import { getEventsConfig, useChart } from 'react-jsx-highcharts';

const RangeSelectorButton = ({
  count=1,
  offsetMin=0,
  offsetMax=0,
  ...restProps
}) => {
  const props = { count, offsetMin, offsetMax, ...restProps};

  const chart = useChart();

  useEffect(() => {

    const button = getButtonIndex(props, chart);
    if (button > -1) return; // Button already present

    const { count, type, offsetMin, offsetMax, dataGrouping, children: text, ...rest } = props;
    const opts = {
      count,
      type,
      offsetMin,
      offsetMax,
      dataGrouping,
      text,
      events: getEventsConfig(rest)
    };

    addButton(opts, chart);

    return () => {
      attempt(removeButton, props, chart);
    }
  }, []);

  return null;
}

const getButtons = (chart) => {
  const chartObj = chart.object;
  if (chartObj && chartObj.options) {
    const { buttons = [] } = chartObj.options.rangeSelector;
    return buttons;
  }

  return [];
}

const getButtonIndex = (props, chart) => {
  const { count, type } = props;
  return findIndex(getButtons(chart), b => {
    return (b.count === count && b.type === type);
  });
}

const addButton = (config, chart) => {
  // Add button to array
  const buttons = [
    ...getButtons(),
    config
  ];<commit_msg>Use [].findIndex instead of lodash.findIndex<commit_after>import { useEffect } from 'react';
import PropTypes from 'prop-types';
import { attempt } from 'lodash-es';
import { getEventsConfig, useChart } from 'react-jsx-highcharts';

const RangeSelectorButton = ({
  count=1,
  offsetMin=0,
  offsetMax=0,
  ...restProps
}) => {
  const props = { count, offsetMin, offsetMax, ...restProps};

  const chart = useChart();

  useEffect(() => {

    const button = getButtonIndex(props, chart);
    if (button > -1) return; // Button already present

    const { count, type, offsetMin, offsetMax, dataGrouping, children: text, ...rest } = props;
    const opts = {
      count,
      type,
      offsetMin,
      offsetMax,
      dataGrouping,
      text,
      events: getEventsConfig(rest)
    };

    addButton(opts, chart);

    return () => {
      attempt(removeButton, props, chart);
    }
  }, []);

  return null;
}

const getButtons = (chart) => {
  const chartObj = chart.object;
  if (chartObj && chartObj.options) {
    const { buttons = [] } = chartObj.options.rangeSelector;
    return buttons;
  }

  return [];
}

const getButtonIndex = (props, chart) => {
  const { count, type } = props;
  return getButtons(chart).findIndex(b => {
    return (b.count === count && b.type === type);
  });
}

const addButton = (config, chart) => {
  // Add button to array
  const buttons = [
    ...getButtons(),
    config
  ];
{'fraction_non_alphanumeric': 0.15019210618232623, 'fraction_numerical': 0.0027942717429269995, 'mean_word_length': 2.934065934065934, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '1119516', 'n_tokens_mistral': 916, 'n_tokens_neox': 902, 'n_words': 237}