<commit_before>import React, { PureComponent } from 'react';
import { FormattedMessage, injectIntl } from 'react-intl';
import _ from 'lodash';
import { compose } from 'redux';
import { connect } from 'react-redux';
import { Button, Icon, Intent, Menu, MenuItem } from '@blueprintjs/core';

import { GROUP_FIELDS, getGroupField } from 'components/SearchField/util';
import SearchField from 'components/SearchField/SearchField';
import { SelectWrapper } from 'components/common';
import { selectModel } from 'selectors';

import './SearchFieldSelect.scss'

class SearchFieldSelect extends PureComponent {
  constructor(props) {
    super(props);

    this.getItemLabel = this.getItemLabel.bind(this);
    this.isSelected = this.isSelected.bind(this);
  }

  itemPredicate = (query, item) => {
    return this.getItemLabel(item).toLowerCase().includes(query.toLowerCase());
  }

  itemRenderer = (item, { modifiers, handleClick }) => {
    if (!modifiers.matchesPredicate) {
      return null;
    }
    const isSelected = this.isSelected(item);

    return (
      <MenuItem
        active={modifiers.active}
        disabled={modifiers.disabled}
        onClick={handleClick}
        intent={isSelected && Intent.SUCCESS}
        label={isSelected && <Icon icon="tick" />}
        text={<SearchField.Label field={item} icon />}
        key={item.field}
      />
    );
  }

  getItemLabel(item) {
    return item.isProperty ? item.label : this.props.intl.formatMessage(item.label, { count: 0 })
  }

  isSelected(item) {
    return this.props.selected.find(({ name }) => name === item.name)
  }

  itemListRenderer = ({ items, itemsParentRef, renderItem }) => {
    const { properties, groups, onReset } = this.props;
    const [selectedGroups, availableGroups] = _.partition(groups, this.isSelected);
    const [selectedProps, availableProps] = _.partition(properties, this.isSelected);

    return (
      <>
        <Menu ulRef={itemsParentRef}>
          <li className="bp3-menu-header">
            <h6 className="bp3-heading">
              <FormattedMessage id="search.config.groups" defaultMessage="Property groups" />
            </h6>
          </li>
          {selectedGroups.map(renderItem)}
          {availableGroups.map(renderItem)}
          <li className="bp3-menu-header"><commit_msg>fixed duplicate key warning in SearchFieldSelect component<commit_after>import React, { PureComponent } from 'react';
import { FormattedMessage, injectIntl } from 'react-intl';
import _ from 'lodash';
import { compose } from 'redux';
import { connect } from 'react-redux';
import { Button, Icon, Intent, Menu, MenuItem } from '@blueprintjs/core';

import { GROUP_FIELDS, getGroupField } from 'components/SearchField/util';
import SearchField from 'components/SearchField/SearchField';
import { SelectWrapper } from 'components/common';
import { selectModel } from 'selectors';

import './SearchFieldSelect.scss'

class SearchFieldSelect extends PureComponent {
  constructor(props) {
    super(props);

    this.getItemLabel = this.getItemLabel.bind(this);
    this.isSelected = this.isSelected.bind(this);
  }

  itemPredicate = (query, item) => {
    return this.getItemLabel(item).toLowerCase().includes(query.toLowerCase());
  }

  itemRenderer = (item, { modifiers, handleClick }) => {
    if (!modifiers.matchesPredicate) {
      return null;
    }
    const isSelected = this.isSelected(item);

    return (
      <MenuItem
        active={modifiers.active}
        disabled={modifiers.disabled}
        onClick={handleClick}
        intent={isSelected && Intent.SUCCESS}
        label={isSelected && <Icon icon="tick" />}
        text={<SearchField.Label field={item} icon />}
        key={item.name}
      />
    );
  }

  getItemLabel(item) {
    return item.isProperty ? item.label : this.props.intl.formatMessage(item.label, { count: 0 })
  }

  isSelected(item) {
    return this.props.selected.find(({ name }) => name === item.name)
  }

  itemListRenderer = ({ items, itemsParentRef, renderItem }) => {
    const { properties, groups, onReset } = this.props;
    const [selectedGroups, availableGroups] = _.partition(groups, this.isSelected);
    const [selectedProps, availableProps] = _.partition(properties, this.isSelected);

    return (
      <>
        <Menu ulRef={itemsParentRef}>
          <li className="bp3-menu-header">
            <h6 className="bp3-heading">
              <FormattedMessage id="search.config.groups" defaultMessage="Property groups" />
            </h6>
          </li>
          {selectedGroups.map(renderItem)}
          {availableGroups.map(renderItem)}
          <li className="bp3-menu-header">
{'fraction_non_alphanumeric': 0.1346815834767642, 'fraction_numerical': 0.0025817555938037868, 'mean_word_length': 3.365258215962441, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 33, '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': '2363164', 'n_tokens_mistral': 1350, 'n_tokens_neox': 1333, 'n_words': 279}