<commit_before>import React, { PureComponent } from 'react';
import { Button, Checkbox, Icon, Intent } from '@blueprintjs/core';
import { defineMessages, injectIntl } from 'react-intl';
import { FileSize } from '@alephdata/react-ftm';

import convertPathsToTree from 'util/convertPathsToTree';

import './DocumentUploadView.scss';

const messages = defineMessages({
  save: {
    id: 'document.upload.save',
    defaultMessage: 'Upload',
  },
  summary: {
    id: 'document.upload.summary',
    defaultMessage: '{numberOfFiles, number} files, {totalSize}'
  }
});

export class DocumentUploadView extends PureComponent {
  constructor(props) {
    super(props);

    this.state = {
      filesToUpload: props.files,
    };

    this.toggleFile = this.toggleFile.bind(this);
    this.submit = this.submit.bind(this);
  }

  submit() {
    const { filesToUpload } = this.state;

    this.props.onSubmit(filesToUpload);
  }

  toggleFile(file) {
    this.setState(({ filesToUpload }) => ({
      filesToUpload: filesToUpload.includes(file)
        ? filesToUpload.filter(f => f !== file)
        : [...filesToUpload, ...[file]],
    }));
  }

  renderFolder(folder) {
    return Object.entries(folder).map(([key, value]) => {
      if (value instanceof File) {
        return this.renderFile(value);
      }

      return (
        <div className="DocumentUploadView__folder" key={key}>
          <h6 className="DocumentUploadView__folder__label bp3-heading">
            <Icon icon="folder-open" className="left-icon" />
            {key}
          </h6>
          <div className="DocumentUploadView__folder__content">
            {this.renderFolder(value)}
          </div>
        </div>
      );
    });
  }

  renderFile(file) {
    return (
      <Checkbox
        defaultChecked
        key={file.name}
        label={file.name}
        onChange={() => this.toggleFile(file)}
      />
    );
  }

  render() {
    const { files, intl } = this.props;
    const { filesToUpload } = this.state;

    const fileTree = convertPathsToTree(files);
    const totalFileSize = files.reduce((totalSize, file) => totalSize + file.size, 0);

    return (
      <div className="DocumentUploadView">
        <div className="DocumentUploadView__content">
          {this.renderFolder(fileTree)}
        </div>
        <p>{intl.formatMessage(messages.summary, {
          numberOfFiles: filesToUpload.length,
          totalSize: <FileSize value={totalFileSize} />
        })}</p>
        <div className="bp3-dialog-footer">
          <div className="bp3-dialog-footer-actions">
            <Button
              type="submit"
              intent={Intent.PRIMARY}
              text={intl.formatMessage(messages.save)}
              onClick={this.submit}
            />
          </div>
        </div>
      </div>
    );
  }
}

export default injectIntl(DocumentUploadView);<commit_msg>Fixed doc upload dialog footer class nested within dialog-body<commit_after>import React, { PureComponent } from 'react';
import { Button, Checkbox, Icon, Intent } from '@blueprintjs/core';
import { defineMessages, injectIntl } from 'react-intl';
import { FileSize } from '@alephdata/react-ftm';

import convertPathsToTree from 'util/convertPathsToTree';

import './DocumentUploadView.scss';

const messages = defineMessages({
  save: {
    id: 'document.upload.save',
    defaultMessage: 'Upload',
  },
  summary: {
    id: 'document.upload.summary',
    defaultMessage: '{numberOfFiles, number} files, {totalSize}'
  }
});

export class DocumentUploadView extends PureComponent {
  constructor(props) {
    super(props);

    this.state = {
      filesToUpload: props.files,
    };

    this.toggleFile = this.toggleFile.bind(this);
    this.submit = this.submit.bind(this);
  }

  submit() {
    const { filesToUpload } = this.state;

    this.props.onSubmit(filesToUpload);
  }

  toggleFile(file) {
    this.setState(({ filesToUpload }) => ({
      filesToUpload: filesToUpload.includes(file)
        ? filesToUpload.filter(f => f !== file)
        : [...filesToUpload, ...[file]],
    }));
  }

  renderFolder(folder) {
    return Object.entries(folder).map(([key, value]) => {
      if (value instanceof File) {
        return this.renderFile(value);
      }

      return (
        <div className="DocumentUploadView__folder" key={key}>
          <h6 className="DocumentUploadView__folder__label bp3-heading">
            <Icon icon="folder-open" className="left-icon" />
            {key}
          </h6>
          <div className="DocumentUploadView__folder__content">
            {this.renderFolder(value)}
          </div>
        </div>
      );
    });
  }

  renderFile(file) {
    return (
      <Checkbox
        defaultChecked
        key={file.name}
        label={file.name}
        onChange={() => this.toggleFile(file)}
      />
    );
  }

  render() {
    const { files, intl } = this.props;
    const { filesToUpload } = this.state;

    const fileTree = convertPathsToTree(files);
    const totalFileSize = files.reduce((totalSize, file) => totalSize + file.size, 0);

    return (
      <div className="DocumentUploadView">
        <div className="DocumentUploadView__content">
          {this.renderFolder(fileTree)}
        </div>
        <p>{intl.formatMessage(messages.summary, {
          numberOfFiles: filesToUpload.length,
          totalSize: <FileSize value={totalFileSize} />
        })}</p>
        <div className="bp3-dialog-footer-actions">
          <Button
            type="submit"
            intent={Intent.PRIMARY}
            text={intl.formatMessage(messages.save)}
            onClick={this.submit}
          />
        </div>
      </div>
    );
  }
}

export default injectIntl(DocumentUploadView);
{'fraction_non_alphanumeric': 0.13853948287910553, 'fraction_numerical': 0.0019217330538085255, 'mean_word_length': 2.547087980173482, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 51, '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': '4227788', 'n_tokens_mistral': 1704, 'n_tokens_neox': 1680, 'n_words': 312}