<commit_before>import React from 'react';
import { connect } from 'react-redux';
import { FormattedMessage } from 'react-intl';
import { Popover, PopoverInteractionKind, Position } from "@blueprintjs/core";

import './DocumentToolbar.css';

class DocumentToolbar extends React.Component {
  render() {
    return (
      <div className="document-content-toolbar">
        <DownloadButton download={this.props.download} session={this.props.session}/>
        <div className="pt-input-group" style={{maxWidth: 200, float: 'right'}}>
          <span className="pt-icon pt-icon-search"></span>
          <input className="pt-input" disabled type="search" placeholder="Search in document" dir="auto"/>
        </div>
      </div>
    );
  }
}

const mapStateToProps = state => ({
  session: state.session,
});

export default connect(mapStateToProps)(DocumentToolbar);

/*
 * Expects a 'download' prop with the values {name: '', url: ''}
 * 
 * May also be passed an array of similar objects if there are multiple download
 * options, the first item in the array will be the default download action.
 */
export class DownloadButton extends React.Component {
  render() {
      
    if (this.props.session && this.props.download) {
      if (Array.isArray(this.props.download)) {
        // If passed an array, rrender Download button with multiple options
        let popoverContent = (
            <ul className="pt-menu">
              {this.props.download.map((item,i) => {
                return <li key={i}><a className="pt-menu-item" href={item.url}>{item.name}</a></li>
              })}
            </ul>
          )
        return (
          <div className="pt-button-group">
            <a href={this.props.session.token ? `${this.props.download[0].url}?api_key=${this.props.session.token}` : this.props.download[0].url} className="pt-button">
              <span className="pt-icon-standard pt-icon-download"></span>
              <span><FormattedMessage id="document.download" defaultMessage="Download"/></span>
            </a>
           <Popover
            content={popoverContent}
            interactionKind={PopoverInteractionKind.CLICK}
            position={Position.BOTTOM_RIGHT}
            modifiers={{
              arrow: { enabled: false },
              preventOverflow: { enabled: false, boundariesElement: "scrollParent" }
            }}
            >
              <a type="button" className="pt-button pt-icon-caret-down"></a>
            </Popover>
          </div>
        );
      } else {
        // Render Download button with single button
        return (
          <a href={this.props.session.token ? `${this.props.download.url}?api_key=${this.props.session.token}` : this.props.download.url} type="button" className="pt-button">
            <span className="pt-icon-standard pt-icon-download"></span>
            <span><FormattedMessage id="document.download" defaultMessage="Download"/></span>
          </a>
        );
      }
    } else {
      // Render disabled control
      return (
        <button type="button" className="pt-button" disabled>
          <span className="pt-icon-standard pt-icon-download"></span>
          <span><FormattedMessage id="document.download" defaultMessage="Download"/></span>
        </button>
      );
    }
  }
}<commit_msg>Minor markup change to remove build warning<commit_after>import React from 'react';
import { connect } from 'react-redux';
import { FormattedMessage } from 'react-intl';
import { Popover, PopoverInteractionKind, Position } from "@blueprintjs/core";

import './DocumentToolbar.css';

class DocumentToolbar extends React.Component {
  render() {
    return (
      <div className="document-content-toolbar">
        <DownloadButton download={this.props.download} session={this.props.session}/>
        <div className="pt-input-group" style={{maxWidth: 200, float: 'right'}}>
          <span className="pt-icon pt-icon-search"></span>
          <input className="pt-input" disabled type="search" placeholder="Search in document" dir="auto"/>
        </div>
      </div>
    );
  }
}

const mapStateToProps = state => ({
  session: state.session,
});

export default connect(mapStateToProps)(DocumentToolbar);

/*
 * Expects a 'download' prop with the values {name: '', url: ''}
 * 
 * May also be passed an array of similar objects if there are multiple download
 * options, the first item in the array will be the default download action.
 */
export class DownloadButton extends React.Component {
  render() {
    if (this.props.session && this.props.download) {
      if (Array.isArray(this.props.download)) {
        // If passed an array, rrender Download button with multiple options
        let popoverContent = (
            <ul className="pt-menu">
              {this.props.download.map((item,i) => {
                return <li key={i}><a className="pt-menu-item" href={item.url}>{item.name}</a></li>
              })}
            </ul>
          )
        return (
          <div className="pt-button-group">
            <a href={this.props.session.token ? `${this.props.download[0].url}?api_key=${this.props.session.token}` : this.props.download[0].url} className="pt-button">
              <span className="pt-icon-standard pt-icon-download"></span>
              <span><FormattedMessage id="document.download" defaultMessage="Download"/></span>
            </a>
           <Popover
            content={popoverContent}
            interactionKind={PopoverInteractionKind.CLICK}
            position={Position.BOTTOM_RIGHT}
            modifiers={{
              arrow: { enabled: false },
              preventOverflow: { enabled: false, boundariesElement: "scrollParent" }
            }}
            >
              <div className="pt-button pt-icon-caret-down"/>
            </Popover>
          </div>
        );
      } else {
        // Render Download button with single button
        return (
          <a href={this.props.session.token ? `${this.props.download.url}?api_key=${this.props.session.token}` : this.props.download.url} type="button" className="pt-button">
            <span className="pt-icon-standard pt-icon-download"></span>
            <span><FormattedMessage id="document.download" defaultMessage="Download"/></span>
          </a>
        );
      }
    } else {
      // Render disabled control
      return (
        <button type="button" className="pt-button" disabled>
          <span className="pt-icon-standard pt-icon-download"></span>
          <span><FormattedMessage id="document.download" defaultMessage="Download"/></span>
        </button>
      );
    }
  }
}
{'fraction_non_alphanumeric': 0.14387291981845687, 'fraction_numerical': 0.0015128593040847202, 'mean_word_length': 2.522109749600426, 'pattern_counts': {'":': 0, '<': 84, '<?xml version=': 0, '>': 88, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 50, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '671975', 'n_tokens_mistral': 1801, 'n_tokens_neox': 1808, 'n_words': 399}