<commit_before>"use strict";

EC.ExportCsv = React.createClass({
  propTypes: {
    exportType: React.PropTypes.string.isRequired,
    filters: React.PropTypes.object.isRequired,
    teacher: React.PropTypes.object.isRequired
  },

  getDefaultProps: function() {
    return {
      requestUrl: '/teachers/progress_reports/csv_exports'
    };
  },

  createExport: function() {
    $.ajax({
      url: this.props.requestUrl,
      data: {
        csv_export: {
          export_type: this.props.exportType,
          filters: this.props.filters
        }
      },
      context: this,
      dataType: 'json',
      type: 'POST',
      success: function onSuccess(data) {
        this.openModal();
      }
    });
  },

  openModal: function() {
    $(this.refs.exportModal.getDOMNode()).modal();
  },

  render: function() {
    return (
      <div className="export-csv">
        <EC.ExportCsvModal email={this.props.teacher.email} ref="exportModal" />
        <button className="button-green" onClick={this.createExport}>Download Report</button>
      </div>
    );
  }
});<commit_msg>Display error when csv export fails<commit_after>"use strict";

EC.ExportCsv = React.createClass({
  propTypes: {
    exportType: React.PropTypes.string.isRequired,
    filters: React.PropTypes.object.isRequired,
    teacher: React.PropTypes.object.isRequired
  },

  getDefaultProps: function() {
    return {
      requestUrl: '/teachers/progress_reports/csv_exports'
    };
  },

  createExport: function() {
    $.ajax({
      url: this.props.requestUrl,
      data: {
        csv_export: {
          export_type: this.props.exportType,
          filters: this.props.filters
        }
      },
      context: this,
      dataType: 'json',
      type: 'POST',
      success: function onSuccess(data) {
        this.openModal();
      },
      error: function(xhr) {
        alert('Something went wrong with your CSV export. Most likely it is not implemented yet.');
      }
    });
  },

  openModal: function() {
    $(this.refs.exportModal.getDOMNode()).modal();
  },

  render: function() {
    return (
      <div className="export-csv">
        <EC.ExportCsvModal email={this.props.teacher.email} ref="exportModal" />
        <button className="button-green" onClick={this.createExport}>Download Report</button>
      </div>
    );
  }
});
{'fraction_non_alphanumeric': 0.14095972579263066, 'fraction_numerical': 0.0, 'mean_word_length': 2.581288343558282, 'pattern_counts': {'":': 0, '<': 13, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2014234', 'n_tokens_mistral': 719, 'n_tokens_neox': 705, 'n_words': 127}