<commit_before>import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import isEmpty from 'lodash/isEmpty';
import remove from 'lodash/remove';

import NoContent from 'components/ui/no-content';

import LayerToggle from 'components/map/components/legend/components/layer-toggle';
import MenuBlock from 'pages/map/menu/components/menu-block';
import Pill from 'components/ui/pill';
import Dropdown from 'components/ui/dropdown';

import './styles.scss';

class Datasets extends PureComponent {
  render() {
    const {
      datasets,
      subCategories,
      onToggleLayer,
      onInfoClick,
      countries,
      selectedCountries,
      setMenuSettings
    } = this.props;

    return (
      <div className="c-datasets">
        <div className="countries-selection">
          <span className="sub-title">country-specific data</span>
          <div className="pills">
            {selectedCountries &&
              selectedCountries.map(c => (
                <Pill
                  key={c.value}
                  label={c.label}
                  onRemove={() => {
                    const newCountries = remove(
                      selectedCountries,
                      sc => sc.value !== c.value
                    );
                    setMenuSettings({
                      selectedCountries: newCountries
                        ? newCountries.map(nc => nc.value)
                        : []
                    });
                  }}
                >
                  {c.label}
                </Pill>
              ))}
            {countries && (
              <Dropdown
                className="country-dropdown"
                theme="theme-dropdown-button theme-dropdown-button-small"
                placeholder="+ Add country"
                noItemsFound="No country found"
                noSelectedValue="+ Add country"
                options={countries}
                onChange={e => {
                  setMenuSettings({
                    selectedCountries: [
                      ...selectedCountries.map(c => c.value),
                      e.value
                    ]
                  });
                }}
                searchable
              />
            )}
          </div>
        </div>
        {subCategories
          ? subCategories.map(subCat => (
            <MenuBlock key={subCat.slug} {...subCat}>
              {!isEmpty(subCat.datasets) ? (
                subCat.datasets.map(d => (
                  <LayerToggle
                    key={d.id}
                    className="dataset-toggle"
                    data={{ ...d, dataset: d.id }}
                    onToggle={onToggleLayer}
                    onInfoClick={onInfoClick}
                  />
                ))
              ) : (
                <NoContent
                  className="no-datasets"
                  message="No datasets available"
                /><commit_msg>move tags add remove function to class fn<commit_after>import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import isEmpty from 'lodash/isEmpty';

import NoContent from 'components/ui/no-content';

import LayerToggle from 'components/map/components/legend/components/layer-toggle';
import MenuBlock from 'pages/map/menu/components/menu-block';
import Pill from 'components/ui/pill';
import Dropdown from 'components/ui/dropdown';

import './styles.scss';

class Datasets extends PureComponent {
  handleRemoveCountry = iso => {
    const { selectedCountries, setMenuSettings } = this.props;
    const newCountries = selectedCountries.filter(c => c.value !== iso);
    setMenuSettings({
      selectedCountries: newCountries ? newCountries.map(nc => nc.value) : []
    });
  };

  handleAddCountry = country => {
    const { selectedCountries, setMenuSettings } = this.props;
    setMenuSettings({
      selectedCountries: [...selectedCountries.map(c => c.value), country.value]
    });
  };

  render() {
    const {
      datasets,
      subCategories,
      onToggleLayer,
      onInfoClick,
      countries,
      selectedCountries
    } = this.props;

    return (
      <div className="c-datasets">
        <div className="countries-selection">
          <span className="sub-title">country-specific data</span>
          <div className="pills">
            {selectedCountries &&
              selectedCountries.map(c => (
                <Pill
                  key={c.value}
                  label={c.label}
                  onRemove={() => this.handleRemoveCountry(c.value)}
                >
                  {c.label}
                </Pill>
              ))}
            {countries && (
              <Dropdown
                className="country-dropdown"
                theme="theme-dropdown-button theme-dropdown-button-small"
                placeholder="+ Add country"
                noItemsFound="No country found"
                noSelectedValue="+ Add country"
                options={countries}
                onChange={this.handleAddCountry}
                searchable
              />
            )}
          </div>
        </div>
        {subCategories
          ? subCategories.map(subCat => (
            <MenuBlock key={subCat.slug} {...subCat}>
              {!isEmpty(subCat.datasets) ? (
                subCat.datasets.map(d => (
                  <LayerToggle
                    key={d.id}
                    className="dataset-toggle"
                    data={{ ...d, dataset: d.id }}
                    onToggle={onToggleLayer}
                    onInfoClick={onInfoClick}
                  />
                ))
              ) : (
                <NoContent
                  className="no-datasets"
                  message="No datasets available"
                />
{'fraction_non_alphanumeric': 0.10928867403314917, 'fraction_numerical': 0.0, 'mean_word_length': 1.4077306733167083, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 46, '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': '2145183', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1407, 'n_words': 269}