<commit_before>import React from 'react';

import { readenergystring } from '../energycalculations.js';

export default class ActionsPanel extends React.Component {

  handleFiles(e, onLoadHandler) {
    let file;
    if (e.dataTransfer) {
      file = e.dataTransfer.files[0];
    } else if (e.target) {
      file = e.target.files[0];
    }

    let getData = str => {
      let { components, meta } = readenergystring(str);
      components = components.map(dd => { return {...dd, active: true }; });
      return { components, meta };
    };

    const reader = new FileReader();
    reader.onload = e => onLoadHandler(getData(e.target.result));
    reader.readAsText(file);
  }

  downloadFile(e, getEnergyString) {
    const energystring = getEnergyString();
    const data = new Blob([energystring],
                          { type: 'text/plain;charset=utf8;' });
    // create hidden link
    const element = document.createElement('a');
    document.body.appendChild(element);
    element.setAttribute('href', window.URL.createObjectURL(data));
    element.setAttribute('download', 'csvEPBDpanel.csv');
    element.style.display = '';
    element.click();
    document.body.removeChild(element);
  }

  render() {
    return (
      <div className="btn-group pull-right btn-group-xs" role="group" aria-label="acciones">
        <button className="btn" id="add" type="button"
                onClick={this.props.onAdd}><commit_msg>ActionsPanel: guardar archivo con último nombre de archivo abierto o con nombre por defecto<commit_after>import React from 'react';

import { readenergystring } from '../energycalculations.js';

export default class ActionsPanel extends React.Component {

  constructor(props) {
    super(props);
    this.currentFileName = false;
  }

  handleFiles(e, onLoadHandler) {
    let file;
    if (e.dataTransfer) {
      file = e.dataTransfer.files[0];
    } else if (e.target) {
      file = e.target.files[0];
    }
    this.currentFileName = file.name;

    let getData = str => {
      let { components, meta } = readenergystring(str);
      components = components.map(dd => { return {...dd, active: true }; });
      return { components, meta };
    };

    const reader = new FileReader();
    reader.onload = e => onLoadHandler(getData(e.target.result));
    reader.readAsText(file);
  }

  downloadFile(e, getEnergyString) {
    const energystring = getEnergyString();
    const data = new Blob([energystring],
                          { type: 'text/plain;charset=utf8;' });
    // create hidden link
    const element = document.createElement('a');
    document.body.appendChild(element);
    element.setAttribute('href', window.URL.createObjectURL(data));
    element.setAttribute('download', this.currentFileName || 'csvEPBDpanel.csv');
    element.style.display = '';
    element.click();
    document.body.removeChild(element);
  }

  render() {
    return (
      <div className="btn-group pull-right btn-group-xs" role="group" aria-label="acciones">
        <button className="btn" id="add" type="button"
                onClick={this.props.onAdd}>
{'fraction_non_alphanumeric': 0.1406451612903226, 'fraction_numerical': 0.001935483870967742, 'mean_word_length': 3.1181938911022575, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '339145', 'n_tokens_mistral': 928, 'n_tokens_neox': 901, 'n_words': 197}