<commit_before>import React from "react";
import axios from "axios";
import Dropzone from "react-dropzone";
// import { first } from "lodash";
import uniqid from "uniqid";
import classnames from "classnames";

function noop() {}
function emptyPromise() {
  //wink wink
  return Promise.resolve;
}
export default props => {
  const {
    accept,
    contentOverride,
    innerIcon,
    innerText,
    action,
    className = "",
    fileLimit,
    uploadInBulk, //tnr: not yet implemented
    showUploadList = true,
    beforeUpload,
    fileList,
    fileListItemRenderer, // handle rendering the file list items yourself :)
    onFileSuccess = emptyPromise, //called each time a file is finished and before the file.loading gets set to false, needs to return a promise!
    onFieldSubmit = noop, //called when all files have successfully uploaded
    onRemove = noop, //called when a file has been selected to be removed
    onChange = noop, //this is almost always getting passed by redux-form, no need to pass this handler manually
    ...rest //everything else gets spread on the <Dropzone/> https://react-dropzone.js.org/
  } = props;

  let acceptToUse = Array.isArray(accept) ? accept.join(", ") : accept;
  let fileListToUse = fileList ? fileList : [];
  return (
    <div>
      <Dropzone
        className={"tg-dropzone " + className}
        multiple={fileLimit !== 1}
        activeClassName={"tg-dropzone-active"}
        rejectClassName={"tg-dropzone-reject"}
        //acceptClassName={"tg-dropzone-accept"} //tnr: commenting these out temporarily until https://github.com/react-dropzone/react-dropzone/pull/504 gets merged
        //disabledClassName={"tg-dropzone-disabled"}
        accept={acceptToUse}
        {...{
          onDrop: acceptedFiles => {
            if (fileLimit) {
              acceptedFiles = acceptedFiles.slice(0, fileLimit);
            }
            acceptedFiles.forEach(file => {
              file.loading = true;
              if (!file.id) {
                file.id = uniqid();
              }
            });
            if (beforeUpload) {
              const keepGoing = beforeUpload(acceptedFiles);
              if (keepGoing === false) {
                return;
              }
            }
            fileListToUse = [
              ...acceptedFiles.map(file => {
                return {
                  id: file.id,
                  lastModified: file.lastModified,
                  lastModifiedDate: file.lastModifiedDate,
                  loading: file.loading,
                  name: file.name,<commit_msg>adding in start of Uploader enhancements<commit_after>import React from "react";
import axios from "axios";
import Dropzone from "react-dropzone";
// import { first } from "lodash";
import uniqid from "uniqid";
import classnames from "classnames";

function noop() {}
function emptyPromise() {
  //wink wink
  return Promise.resolve;
}
export default props => {
  const {
    accept,
    contentOverride,
    innerIcon,
    innerText,
    action,
    className = "",
    fileLimit,
    readBeforeUpload,
    uploadInBulk, //tnr: not yet implemented
    showUploadList = true,
    beforeUpload,
    fileList, //list of files with options: {name, loading, error, url, originalName, downloadName}
    fileListItemRenderer, // handle rendering the file list items yourself :)
    onFileSuccess = emptyPromise, //called each time a file is finished and before the file.loading gets set to false, needs to return a promise!
    onFieldSubmit = noop, //called when all files have successfully uploaded
    onRemove = noop, //called when a file has been selected to be removed
    onChange = noop, //this is almost always getting passed by redux-form, no need to pass this handler manually
    ...rest //everything else gets spread on the <Dropzone/> https://react-dropzone.js.org/
  } = props;

  let acceptToUse = Array.isArray(accept) ? accept.join(", ") : accept;
  let fileListToUse = fileList ? fileList : [];
  return (
    <div>
      <Dropzone
        className={"tg-dropzone " + className}
        multiple={fileLimit !== 1}
        activeClassName={"tg-dropzone-active"}
        rejectClassName={"tg-dropzone-reject"}
        //acceptClassName={"tg-dropzone-accept"} //tnr: commenting these out temporarily until https://github.com/react-dropzone/react-dropzone/pull/504 gets merged
        //disabledClassName={"tg-dropzone-disabled"}
        accept={acceptToUse}
        {...{
          onDrop: acceptedFiles => {
            if (fileLimit) {
              acceptedFiles = acceptedFiles.slice(0, fileLimit);
            }
            acceptedFiles.forEach(file => {
              file.loading = true;
              if (!file.id) {
                file.id = uniqid();
              }
            });
            if (beforeUpload) {
              if (readBeforeUpload) {
                /* const file = files[0];
                let reader = new FileReader();
                reader.readAsText(file, "UTF-8");
                reader.onload = function(evt: Object) {
                  const content: string = evt.target.result;
                  anyToJson(content, result => {
                    const parsedSequence: SequenceJson = processSequenceJson(
                      result[0].parsedSequence
                    );
                    onCreateSubmit({ parsedSequence });
                  });
                }; 
                reader.onerror = function() {
                  window.toastr.error("Failure reading file.");
                };
                */
              }
              const keepGoing = beforeUpload(acceptedFiles, onChange);
              if (keepGoing === false) {
                return;
              }
            }
            fileListToUse = [
              ...acceptedFiles.map(file => {
                return {
                  id: file.id,
                  lastModified: file.lastModified,
                  lastModifiedDate: file.lastModifiedDate,
                  loading: file.loading,
                  name: file.name,
{'fraction_non_alphanumeric': 0.10373924553275976, 'fraction_numerical': 0.0021508934480476507, 'mean_word_length': 1.9416058394160585, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 16, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2989348', 'n_tokens_mistral': 1591, 'n_tokens_neox': 1548, 'n_words': 441}