<commit_before>import PropTypes from 'prop-types';
import queryString from 'query-string';
import React from 'react';
import { Helmet } from 'react-helmet';
import { injectIntl } from 'react-intl';
import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import { createLoadProductCategories, createLoadProducts, createSetFilterCategories } from '../actions';
import MainSpinner from '../layout/mainSpinner.jsx';
import ProductList from '../products/productList.jsx';
import { ProductCategoryPropType, ProductPropType } from '../propTypes';
import ProductFilter from './productfilter/productFilter.jsx';

class Products extends React.Component {
  componentWillMount() {
    if (!this.props.products.length) {
      this.props.loadProducts();
    }
    if (!this.props.productCategories.length) {
      this.props.loadProductCategories();
    }
    this._updateFilter(this.props.location.search, this.props.productCategories);
  }

  componentWillReceiveProps(nextProps) {
    if (this.props.location.search !== nextProps.location.search
      || this.props.productCategories.length !== nextProps.productCategories.length) {
      this._updateFilter(nextProps.location.search, nextProps.productCategories);
    }
  }

  _updateFilter(locationSearch, productCategories) {
    const query = queryString.parse(locationSearch);
    if (query.categories && productCategories.length) {
      const categories = query.categories.split(',');
      this.props.setFilterCategories(
        productCategories.filter(category => categories.includes(category._id))
      );
    }
  }

  render() {
    const {
      products,
      filteredProducts,
      filterShown,
      intl,
    } = this.props;

    return (
      <div>
        <Helmet>
          <title>{intl.formatMessage({ id: 'COMMON.PRODUCTS' })}</title><commit_msg>refactor different method naming style<commit_after>import PropTypes from 'prop-types';
import queryString from 'query-string';
import React from 'react';
import { Helmet } from 'react-helmet';
import { injectIntl } from 'react-intl';
import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import { createLoadProductCategories, createLoadProducts, createSetFilterCategories } from '../actions';
import MainSpinner from '../layout/mainSpinner.jsx';
import ProductList from '../products/productList.jsx';
import { ProductCategoryPropType, ProductPropType } from '../propTypes';
import ProductFilter from './productfilter/productFilter.jsx';

class Products extends React.Component {
  componentWillMount() {
    if (!this.props.products.length) {
      this.props.loadProducts();
    }
    if (!this.props.productCategories.length) {
      this.props.loadProductCategories();
    }
    this.updateFilter(this.props.location.search, this.props.productCategories);
  }

  componentWillReceiveProps(nextProps) {
    if (this.props.location.search !== nextProps.location.search
      || this.props.productCategories.length !== nextProps.productCategories.length) {
      this.updateFilter(nextProps.location.search, nextProps.productCategories);
    }
  }

  updateFilter(locationSearch, productCategories) {
    const query = queryString.parse(locationSearch);
    if (query.categories && productCategories.length) {
      const categories = query.categories.split(',');
      this.props.setFilterCategories(
        productCategories.filter(category => categories.includes(category._id))
      );
    }
  }

  render() {
    const {
      products,
      filteredProducts,
      filterShown,
      intl,
    } = this.props;

    return (
      <div>
        <Helmet>
          <title>{intl.formatMessage({ id: 'COMMON.PRODUCTS' })}</title>
{'fraction_non_alphanumeric': 0.12452830188679245, 'fraction_numerical': 0.0, 'mean_word_length': 3.850980392156863, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '906595', 'n_tokens_mistral': 1055, 'n_tokens_neox': 1015, 'n_words': 203}