<commit_before>import React from 'react';
import Upload from 'rc-upload';
import assign from 'object-assign';
import UploadList from './uploadList';
import getFileItem from './getFileItem';
const prefixCls = 'ant-upload';

function noop() {
}

const AntUpload = React.createClass({
  getInitialState() {
    return {
      fileList: this.props.fileList || this.props.defaultFileList || []
    };
  },
  onStart(file) {
    file.status = 'uploading';
    this.onChange({
      file: file,
      add: true
    });
  },
  removeFile(file) {
    file.status = 'removed';
    let fileList = this.state.fileList.concat();
    let targetItem = getFileItem(file, fileList);
    let index = fileList.indexOf(targetItem);
    if (index !== -1) {
      fileList.splice(index, 1);
      return fileList;
    }
    return null;
  },
  onSuccess(response, file) {
    let fileList = this.state.fileList.concat();
    let targetItem = getFileItem(file, fileList);
    // 之前已经删除
    if (targetItem) {
      targetItem.status = 'done';
      targetItem.response = response;
      this.onChange({
        file: targetItem,
        fileList: this.state.fileList
      });
    }
  },
  onProgress(e, file) {
    let fileList = this.state.fileList;
    let targetItem = getFileItem(file, fileList);
    if (targetItem) {
      this.onChange({
        event: e,
        file: file,
        fileList: this.state.fileList
      });
    }
  },
  onError(error, response, file) {
    file.error = error;
    file.response = response;
    this.handleRemove(file);
  },
  handleRemove(file) {
    let fileList = this.removeFile(file);
    if (fileList) {
      this.onChange({
        file: file,
        fileList: fileList
      });
    }
  },
  onChange(info) {
    // 1. 有设置外部属性时不改变 fileList
    // 2. 上传中状态（info.event）不改变 fileList
    if (!('fileList' in this.props) && !info.event) {
      // 新增文件时，使用 multiple 属性会造成同时 setState
      if (info.add) {
        this.setState((prevState) => {
          return {
            fileList: prevState.fileList.concat(info.file)
          };
        });
      } else {
        this.setState({
          fileList: info.fileList
        });
      }
    }
    this.props.onChange(info);
  },
  getDefaultProps() {
    return {
      type: 'select',
      name: '',
      multipart: false,
      action: '',
      data: {},
      accept: '',<commit_msg>Fix info.fileList in multiple upload<commit_after>import React from 'react';
import Upload from 'rc-upload';
import assign from 'object-assign';
import UploadList from './uploadList';
import getFileItem from './getFileItem';
const prefixCls = 'ant-upload';

function noop() {
}

const AntUpload = React.createClass({
  getInitialState() {
    return {
      fileList: this.props.fileList || this.props.defaultFileList || []
    };
  },
  onStart(file) {
    file.status = 'uploading';
    this.onChange({
      file: file,
      add: true
    });
  },
  removeFile(file) {
    file.status = 'removed';
    let fileList = this.state.fileList.concat();
    let targetItem = getFileItem(file, fileList);
    let index = fileList.indexOf(targetItem);
    if (index !== -1) {
      fileList.splice(index, 1);
      return fileList;
    }
    return null;
  },
  onSuccess(response, file) {
    let fileList = this.state.fileList.concat();
    let targetItem = getFileItem(file, fileList);
    // 之前已经删除
    if (targetItem) {
      targetItem.status = 'done';
      targetItem.response = response;
      this.onChange({
        file: targetItem,
        fileList: this.state.fileList
      });
    }
  },
  onProgress(e, file) {
    let fileList = this.state.fileList;
    let targetItem = getFileItem(file, fileList);
    if (targetItem) {
      this.onChange({
        event: e,
        file: file,
        fileList: this.state.fileList
      });
    }
  },
  onError(error, response, file) {
    file.error = error;
    file.response = response;
    this.handleRemove(file);
  },
  handleRemove(file) {
    let fileList = this.removeFile(file);
    if (fileList) {
      this.onChange({
        file: file,
        fileList: fileList
      });
    }
  },
  onChange(info) {
    // 1. 有设置外部属性时不改变 fileList
    // 2. 上传中状态（info.event）不改变 fileList
    if (!('fileList' in this.props) && !info.event) {
      // 新增文件时，使用 multiple 属性会造成同时 setState
      if (info.add) {
        this.setState((prevState) => {
          return {
            fileList: prevState.fileList.concat(info.file)
          };
        }, function() {
          info.fileList = this.state.fileList;
          this.props.onChange(info);
        });
      } else {
        this.setState({
          fileList: info.fileList
        }, function() {
          info.fileList = this.state.fileList;
          this.props.onChange(info);
        });
      }
    }
  },
  getDefaultProps() {
    return {
      type: 'select',
      name: '',
      multipart: false,
      action: '',
      data: {},
      accept: '',
{'fraction_non_alphanumeric': 0.13816855753646679, 'fraction_numerical': 0.0016207455429497568, 'mean_word_length': 2.2121014964216004, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '745095', 'n_tokens_mistral': 1631, 'n_tokens_neox': 1642, 'n_words': 327}