<commit_before>import React from 'react';
import _ from 'underscore';
import Radium from 'radium';
import Clipboard from 'clipboard';
import $ from 'jquery';
import 'foundation'; 

import DownloadButton from '../widgets/download_button.jsx';

const CopyToClipButton = React.createClass({
  propTypes: {
    copiedText: React.PropTypes.string.isRequired
  },

  getInitialState() {
    return { isCopied: false };
  },

  render () {
    let tooltipAttr = this.state.isCopied ? { 'data-tooltip': true } : {};
    let hoverText = this.state.isCopied ? 'Copied!' : '';
    return (
      <span {...tooltipAttr} ref='tooltip' aria-haspopup='true' title={hoverText}>
        <a ref='actionButton' data-clipboard-text={this.props.copiedText}><i className='fa fa-clipboard' /> Copy to Clipboard</a>
      </span>
    );
  },

  componentDidMount() {
    this._clip = new Clipboard(this.refs.actionButton);
    this._clip.on('success', e => {
      this.setState({ isCopied: true }, () => {
        $(document).foundation('tooltip', 'reflow');
        $(this.refs.tooltip).trigger('mouseenter');
      });
    })
  },

  componentWillUnmount() {
    this._clip.destroy();
  }
});

const SearchResult = React.createClass({
  propTypes: {
    category: React.PropTypes.string.isRequired,
    description: React.PropTypes.string,
    highlights: React.PropTypes.object,
    name: React.PropTypes.string.isRequired,
    href: React.PropTypes.string,
    loci: React.PropTypes.array, // i.e. ['rad54', ...]
    keyStr: React.PropTypes.string, // same as key to give a unique str
    readme_url: React.PropTypes.string,
    file_size: React.PropTypes.string,

  },

  getInitialState() {
    return {
      isLociVisible: false
    };
  },

  render () {
    let innerNode = this._getBasicResultNode();
    return (
      <div className='search-result' style={[style.wrapper]}>
        {innerNode}
       
      </div>
    );
  },

  _getBasicResultNode () {
    let name = this.props.name || '(no name available)';
    let downloadButtonNode = null;
    let readMeButtonNode= null;
    let fileSizeNode = null;
    let downloadNodes = null;
    let nameNode = <a href={this.props.href}>{name}</a>;
    if (this.props.category === 'download') {
      let temp = [];
      if (this.props.href){
        downloadButtonNode = <div className="columns medium-4" key="abv">
            <a className="button secondary small" download href={this.props.href} style={{ marginTop: "0.6rem" }}>
              <i className="fa fa-download" /> Download
            </a>
          </div>;
          temp.push(downloadButtonNode);
      }
      
      if (this.props.file_size) {
        readMeButtonNode = <div className="columns medium-4" key="abv2" style={{ marginTop: "1.0rem" }}>
            <span  style={{ marginTop: "0.6rem", fontSize: "large" }}>
              {this.props.file_size}
            </span>
          </div>;
        temp.push(readMeButtonNode);
      }
      if (this.props.readme_url) {
        fileSizeNode = <div className="columns medium-4 " key="abv3" style={{ marginTop: "1.0rem"}}>
              <a target="_blank" href={this.props.readme_url} style={{ marginTop: "0.6rem", color: "#2993FC" }}>
                <i className="fa fa-file-text-o" /> README
              </a>
          </div>;
        temp.push(fileSizeNode);
      }
      
      if (temp.length > 0){
        downloadNodes = <div className="row">{temp}</div>
      }
      nameNode = <span href={this.props.href}>{name}</span>;
    }
    return <div>
        <div className="search-result-title-container" style={[style.titleContainer]}>
          <h2 style={[style.title]}>{nameNode}</h2>
          <span>
            <span className={`search-cat ${this.props.category}`} /> {this.props.categoryName}
          </span>
        </div>
        {this._renderHighlightsNode()}<commit_msg>link security vulnerability fix<commit_after>import React from 'react';
import _ from 'underscore';
import Radium from 'radium';
import Clipboard from 'clipboard';
import $ from 'jquery';
import 'foundation'; 

import DownloadButton from '../widgets/download_button.jsx';

const CopyToClipButton = React.createClass({
  propTypes: {
    copiedText: React.PropTypes.string.isRequired
  },

  getInitialState() {
    return { isCopied: false };
  },

  render () {
    let tooltipAttr = this.state.isCopied ? { 'data-tooltip': true } : {};
    let hoverText = this.state.isCopied ? 'Copied!' : '';
    return (
      <span {...tooltipAttr} ref='tooltip' aria-haspopup='true' title={hoverText}>
        <a ref='actionButton' data-clipboard-text={this.props.copiedText}><i className='fa fa-clipboard' /> Copy to Clipboard</a>
      </span>
    );
  },

  componentDidMount() {
    this._clip = new Clipboard(this.refs.actionButton);
    this._clip.on('success', e => {
      this.setState({ isCopied: true }, () => {
        $(document).foundation('tooltip', 'reflow');
        $(this.refs.tooltip).trigger('mouseenter');
      });
    })
  },

  componentWillUnmount() {
    this._clip.destroy();
  }
});

const SearchResult = React.createClass({
  propTypes: {
    category: React.PropTypes.string.isRequired,
    description: React.PropTypes.string,
    highlights: React.PropTypes.object,
    name: React.PropTypes.string.isRequired,
    href: React.PropTypes.string,
    loci: React.PropTypes.array, // i.e. ['rad54', ...]
    keyStr: React.PropTypes.string, // same as key to give a unique str
    readme_url: React.PropTypes.string,
    file_size: React.PropTypes.string,

  },

  getInitialState() {
    return {
      isLociVisible: false
    };
  },

  render () {
    let innerNode = this._getBasicResultNode();
    return (
      <div className='search-result' style={[style.wrapper]}>
        {innerNode}
       
      </div>
    );
  },

  _getBasicResultNode () {
    let name = this.props.name || '(no name available)';
    let downloadButtonNode = null;
    let readMeButtonNode= null;
    let fileSizeNode = null;
    let downloadNodes = null;
    let nameNode = <a href={this.props.href}>{name}</a>;
    if (this.props.category === 'download') {
      let temp = [];
      if (this.props.href){
        downloadButtonNode = <div className="columns medium-4" key="abv">
            <a className="button secondary small" download href={this.props.href} style={{ marginTop: "0.6rem" }}>
              <i className="fa fa-download" /> Download
            </a>
          </div>;
          temp.push(downloadButtonNode);
      }
      
      if (this.props.file_size) {
        readMeButtonNode = <div className="columns medium-4" key="abv2" style={{ marginTop: "1.0rem" }}>
            <span  style={{ marginTop: "0.6rem", fontSize: "large" }}>
              {this.props.file_size}
            </span>
          </div>;
        temp.push(readMeButtonNode);
      }
      if (this.props.readme_url) {
        let mod_url = this.props.readme_url.replace(":443", "");
        fileSizeNode = <div className="columns medium-4 " key="abv3" style={{ marginTop: "1.0rem"}}>
              <a target="_blank" rel="noopener noreferrer" href={mod_url} style={{ marginTop: "0.6rem", color: "#2993FC" }}>
                <i className="fa fa-file-text-o" /> README <i className="fa fa-external-link"></i>
              </a>
          </div>;
        temp.push(fileSizeNode);
      }
      
      if (temp.length > 0){
        downloadNodes = <div className="row">{temp}</div>
      }
      nameNode = <span href={this.props.href}>{name}</span>;
    }
    return <div>
        <div className="search-result-title-container" style={[style.titleContainer]}>
          <h2 style={[style.title]}>{nameNode}</h2>
          <span>
            <span className={`search-cat ${this.props.category}`} /> {this.props.categoryName}
          </span>
        </div>
        {this._renderHighlightsNode()}
{'fraction_non_alphanumeric': 0.16001020798775042, 'fraction_numerical': 0.006507592190889371, 'mean_word_length': 2.6219963031423292, 'pattern_counts': {'":': 1, '<': 75, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3033', 'n_tokens_mistral': 2483, 'n_tokens_neox': 2464, 'n_words': 488}