<commit_before>import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import includes from 'lodash/includes';
import { createStructuredSelector } from 'reselect';
import moment from 'moment';
import { Tabs, Tab } from 'material-ui/Tabs';
import RaisedButton from 'material-ui/RaisedButton';
import Paper from 'material-ui/Paper';
import { loadFournisseurs, createCommande, loadRelais } from 'containers/Commande/actions';
import {
  selectFournisseursRelais,
  selectFournisseursCommande,
  selectCommandeLivraisons,
  selectCommandeCommandeUtilisateurs,
} from 'containers/Commande/selectors';
import { selectToken } from 'containers/CompteUtilisateur/selectors';
import NouvelleCommandeListeFournisseurs from './components/NouvelleCommandeListeFournisseurs';
import NouvelleCommandeParametres from './components/NouvelleCommandeParametres';
import NouvelleCommandeDistribution from './components/NouvelleCommandeDistribution';
import { post, del } from 'utils/apiClient';
import styles from './styles.css';

class NouvelleCommande extends Component {
  // eslint-disable-line
  static propTypes = {
    commande: PropTypes.object,
    params: PropTypes.object.isRequired,
    relais: PropTypes.object.isRequired,
    fournisseurs: PropTypes.array.isRequired,
    fournisseursCommande: PropTypes.array,
    commandeUtilisateurs: PropTypes.array.isRequired,
    token: PropTypes.string.isRequired,
    livraisonsCommande: PropTypes.array,
    create: PropTypes.func.isRequired,
  };

  static contextTypes = {
    muiTheme: PropTypes.object.isRequired,
  };

  state = {
    cdeFourns: [],
    parametres: {},
    distributions: [],
  };

  componentDidMount() {
    const {
      fournisseursCommande,
      commande,
      livraisonsCommande,
    } = this.props;

    if (fournisseursCommande && fournisseursCommande.length) {
      this.initCmde(fournisseursCommande, commande, livraisonsCommande);
    }
  }

  initCmde = (fournisseursCommande, commande, livraisonsCommande) => {
    const { montantMin, montantMinRelai, qteMin, qteMinRelai } = commande;
    this.setState({
      ...this.state,
      cdeFourns: fournisseursCommande,
      parametres: {
        dateLimite: new Date(commande.dateCommande),
        heureLimite: new Date(commande.dateCommande),
        montantMin,
        montantMinRelai,
        qteMin,
        qteMinRelai,
      },
      distributions: livraisonsCommande,
    });
  };

  addDistrib = value => {
    this.setState({ ...this.state, distributions: [...this.state.distributions, value] });
  };

  delDistrib = index => {
    this.setState({
      ...this.state,
      distributions: this.state.distributions.filter((dist, idx) => idx !== index),
    });
  };

  addFourn = value => {
    const { commande, token } = this.props;
    if (includes(this.state.cdeFourns, value)) return;
    if (!commande.id) {
      this.setState({ ...this.state, cdeFourns: [...this.state.cdeFourns, value] });
      return;
    }<commit_msg>correction bug ajout fournisseur nouvelle commande<commit_after>import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import includes from 'lodash/includes';
import { createStructuredSelector } from 'reselect';
import moment from 'moment';
import { Tabs, Tab } from 'material-ui/Tabs';
import RaisedButton from 'material-ui/RaisedButton';
import Paper from 'material-ui/Paper';
import { loadFournisseurs, createCommande, loadRelais } from 'containers/Commande/actions';
import {
  selectFournisseursRelais,
  selectFournisseursCommande,
  selectCommandeLivraisons,
  selectCommandeCommandeUtilisateurs,
} from 'containers/Commande/selectors';
import { selectToken } from 'containers/CompteUtilisateur/selectors';
import NouvelleCommandeListeFournisseurs from './components/NouvelleCommandeListeFournisseurs';
import NouvelleCommandeParametres from './components/NouvelleCommandeParametres';
import NouvelleCommandeDistribution from './components/NouvelleCommandeDistribution';
import { post, del } from 'utils/apiClient';
import styles from './styles.css';

class NouvelleCommande extends Component {
  // eslint-disable-line
  static propTypes = {
    commande: PropTypes.object,
    params: PropTypes.object.isRequired,
    relais: PropTypes.object.isRequired,
    fournisseurs: PropTypes.array.isRequired,
    fournisseursCommande: PropTypes.array,
    commandeUtilisateurs: PropTypes.array.isRequired,
    token: PropTypes.string.isRequired,
    livraisonsCommande: PropTypes.array,
    create: PropTypes.func.isRequired,
  };

  static contextTypes = {
    muiTheme: PropTypes.object.isRequired,
  };

  state = {
    cdeFourns: [],
    parametres: {},
    distributions: [],
  };

  componentDidMount() {
    const {
      fournisseursCommande,
      commande,
      livraisonsCommande,
    } = this.props;

    if (fournisseursCommande && fournisseursCommande.length) {
      this.initCmde(fournisseursCommande, commande, livraisonsCommande);
    }
  }

  initCmde = (fournisseursCommande, commande, livraisonsCommande) => {
    const { montantMin, montantMinRelai, qteMin, qteMinRelai } = commande;
    this.setState({
      ...this.state,
      cdeFourns: fournisseursCommande,
      parametres: {
        dateLimite: new Date(commande.dateCommande),
        heureLimite: new Date(commande.dateCommande),
        montantMin,
        montantMinRelai,
        qteMin,
        qteMinRelai,
      },
      distributions: livraisonsCommande,
    });
  };

  addDistrib = value => {
    this.setState({ ...this.state, distributions: [...this.state.distributions, value] });
  };

  delDistrib = index => {
    this.setState({
      ...this.state,
      distributions: this.state.distributions.filter((dist, idx) => idx !== index),
    });
  };

  addFourn = value => {
    const { commande, token } = this.props;
    if (includes(this.state.cdeFourns, value)) return;
    if (!commande || !commande.id) {
      this.setState({ ...this.state, cdeFourns: [...this.state.cdeFourns, value] });
      return;
    }
{'fraction_non_alphanumeric': 0.11550993809058326, 'fraction_numerical': 0.0, 'mean_word_length': 3.8722222222222222, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3861103', 'n_tokens_mistral': 1938, 'n_tokens_neox': 1935, 'n_words': 372}