<commit_before>import React, { Component, PropTypes } from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { List } from 'immutable';
import styled from 'styled-components';
import Dialog from 'material-ui/Dialog';
import Slick from 'react-slick';

import SimilarProductBadge from './SimilarProductBadge';

const Slide = styled.div`
  width: 830px;
  margin-right: 40px;
`;

export default class SimilarProductsDialog extends Component {
  static propTypes = {
    similarProducts: ImmutablePropTypes.list,
    isOpen: PropTypes.bool.isRequired,
    handleClose: PropTypes.func.isRequired,
    selectedProduct: PropTypes.string.isRequired
  }

  static defaultProps = {
    similarProducts: List()
  }

  constructor(props) {
    super(props);
    this.state = {
      initialRender: true
    };
  }

  // HACK this fixes a bug with slick
  componentDidUpdate() {
    window.requestAnimationFrame(() => {
      window.dispatchEvent(new Event('resize'));
    });
  }

  initializeSlick() {
    const { similarProducts, selectedProduct } = this.props;

    const selectedIndex = similarProducts.findIndex(p => p.get('code') === selectedProduct) || 0;

    return {
      centerMode: true,
      arrows: false,
      variableWidth: true,
      dots: false,
      initialSlide: selectedIndex
    };
  }

  renderProducts() {
    const { similarProducts } = this.props;

    return similarProducts.map(p => (
      <Slide key={p.get('code')}>
        <SimilarProductBadge productInfo={p} />
      </Slide>
    ));
  }


  render() {
    const { handleClose, isOpen } = this.props;<commit_msg>no infinite slick if products < 2<commit_after>import React, { Component, PropTypes } from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { List } from 'immutable';
import styled from 'styled-components';
import Dialog from 'material-ui/Dialog';
import Slick from 'react-slick';

import SimilarProductBadge from './SimilarProductBadge';

const Slide = styled.div`
  width: 830px;
  margin-right: 40px;
`;

export default class SimilarProductsDialog extends Component {
  static propTypes = {
    similarProducts: ImmutablePropTypes.list,
    isOpen: PropTypes.bool.isRequired,
    handleClose: PropTypes.func.isRequired,
    selectedProduct: PropTypes.string.isRequired
  }

  static defaultProps = {
    similarProducts: List()
  }

  constructor(props) {
    super(props);
    this.state = {
      initialRender: true
    };
  }

  // HACK this fixes a bug with slick
  componentDidUpdate() {
    window.requestAnimationFrame(() => {
      window.dispatchEvent(new Event('resize'));
    });
  }

  initializeSlick() {
    const { similarProducts, selectedProduct } = this.props;

    const selectedIndex = similarProducts.findIndex(p => p.get('code') === selectedProduct) || 0;
    const infinite = similarProducts.size > 1;

    return {
      centerMode: true,
      arrows: false,
      variableWidth: true,
      dots: false,
      initialSlide: selectedIndex,
      infinite
    };
  }

  renderProducts() {
    const { similarProducts } = this.props;

    return similarProducts.map(p => (
      <Slide key={p.get('code')}>
        <SimilarProductBadge productInfo={p} />
      </Slide>
    ));
  }


  render() {
    const { handleClose, isOpen } = this.props;
{'fraction_non_alphanumeric': 0.11832176275279203, 'fraction_numerical': 0.004225777241171144, 'mean_word_length': 3.354796320630749, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 16, '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': '4027426', 'n_tokens_mistral': 1019, 'n_tokens_neox': 972, 'n_words': 231}