<commit_before>import React, { Component } from 'react';
import PropTypes from 'prop-types';
import conductor from '@virtuous/conductor';
import appConfig from '@shopgate/pwa-common/helpers/config';
import I18n from '@shopgate/pwa-common/components/I18n';
import {
  FILTER_TYPE_RANGE,
  FILTER_TYPE_MULTISELECT,
} from '@shopgate/pwa-common-commerce/filter/constants';
import Chip from '@shopgate/pwa-ui-shared/Chip';
import ChipLayout from 'Components/ChipLayout';
import connect from './connector';
import styles from './style';

/**
 * The FilterChips component.
 */
class FilterChips extends Component {
  static propTypes = {
    openFilters: PropTypes.func.isRequired,
    routeId: PropTypes.string.isRequired,
    currentPathname: PropTypes.string,
    filters: PropTypes.shape(),
  };

  static defaultProps = {
    currentPathname: '',
    filters: null,
  };

  /**
   * Removes the given filter id from the route state.
   * @param {string} id The id of the filter to remove.
   * @param {number} index The index of the value to remove (multiselect).
   */
  handleRemove = (id, index = null) => {
    const { filters, routeId } = this.props;
    const { [id]: filterId, ...rest } = filters;

    if (filters[id].type === FILTER_TYPE_MULTISELECT) {
      // Check for one key, just remove all in that case
      // remove index from key, if it exists
    }

    conductor.update(routeId, { filters: rest });
  }

  /**
   * @returns {JSX}
   */
  render() {
    const { currentPathname, filters, openFilters } = this.props;

    if (filters === null || !Object.keys(filters).length) {
      return null;
    }

    const chips = [];

    Object.keys(filters).forEach((key) => {
      const filter = filters[key];

      switch (filter.type) {
        case FILTER_TYPE_RANGE: {
          /**
           * The min and max price need to be rounded before they are passed to the I18n component,
           * since it rounds to the full nearest number when fractions are deactivated.
           */
          const [minimum, maximum] = filter.value;<commit_msg>PWA-922 Removing all filter chips now sets the route state key to be null<commit_after>import React, { Component } from 'react';
import PropTypes from 'prop-types';
import conductor from '@virtuous/conductor';
import appConfig from '@shopgate/pwa-common/helpers/config';
import I18n from '@shopgate/pwa-common/components/I18n';
import {
  FILTER_TYPE_RANGE,
  FILTER_TYPE_MULTISELECT,
} from '@shopgate/pwa-common-commerce/filter/constants';
import Chip from '@shopgate/pwa-ui-shared/Chip';
import ChipLayout from 'Components/ChipLayout';
import connect from './connector';
import styles from './style';

/**
 * The FilterChips component.
 */
class FilterChips extends Component {
  static propTypes = {
    openFilters: PropTypes.func.isRequired,
    routeId: PropTypes.string.isRequired,
    currentPathname: PropTypes.string,
    filters: PropTypes.shape(),
  };

  static defaultProps = {
    currentPathname: '',
    filters: null,
  };

  /**
   * Removes the given filter id from the route state.
   * @param {string} id The id of the filter to remove.
   * @param {number} index The index of the value to remove (multiselect).
   */
  handleRemove = (id, index = null) => {
    const { filters, routeId } = this.props;
    const { [id]: filterId, ...rest } = filters;

    if (filters[id].type === FILTER_TYPE_MULTISELECT) {
      // Check for one key, just remove all in that case
      // remove index from key, if it exists
    }

    const newFilters = (Object.keys(rest).length) ? rest : null;
    conductor.update(routeId, { filters: newFilters });
  }

  /**
   * @returns {JSX}
   */
  render() {
    const { currentPathname, filters, openFilters } = this.props;

    if (filters === null || !Object.keys(filters).length) {
      return null;
    }

    const chips = [];

    Object.keys(filters).forEach((key) => {
      const filter = filters[key];

      switch (filter.type) {
        case FILTER_TYPE_RANGE: {
          /**
           * The min and max price need to be rounded before they are passed to the I18n component,
           * since it rounds to the full nearest number when fractions are deactivated.
           */
          const [minimum, maximum] = filter.value;
{'fraction_non_alphanumeric': 0.11934349355216882, 'fraction_numerical': 0.0035169988276670576, 'mean_word_length': 3.0359508041627246, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4155576', 'n_tokens_mistral': 1283, 'n_tokens_neox': 1246, 'n_words': 391}