<commit_before>import React from 'react';
import PropTypes from 'prop-types';
import { WhiteTheme, Sidebar, Osmose } from 'osm-ui-react';

import EditorModal from './EditorModal';
import { osmose, osm } from 'helpers/requests';

class OsmoseSidebar extends React.Component {
  state = {
    error: null,
    original: null,
    fix: null
  };

  displayEditor = (fix, original) =>
    this.setState({
      original,
      fix
    });

  closeEditor = () =>
    this.setState({
      original: null,
      fix: null
    });

  submitCorrection = fix => {
    const errorId = this.state.error.error_id;
    const original = this.state.error.elems[0];
    const elemId = `${original.type}/${original.id}`;

    const changesetIdP = osm.createChangeset('ourson', 'This is a test');
    const elemP = osm.fetchElement(elemId);

    Promise.all([changesetIdP, elemP])
    .then(([id, element]) => {
      element = osm.setProperties(element, fix);

      return osm.isChangesetStillOpen(id)
      .then(id => {
        console.log('This should send edited Element to OSM', element);
         /* Uncomment this to send */
        // return osm.sendElement(element, id);
      });
    })
    .then(() => {
      console.log('All is good, closing');
      /* Uncomment this to send */
      // osmose.closeError(errorId);
      this.closeEditor();
    })
    .catch(err => console.log('Error in sending Element', err));
  };

  componentWillReceiveProps(nextProps) {
    if (nextProps.match !== null) {
      osmose
        .fetchError(nextProps.match.params.id)
        .then(error => this.setState({ error }));
    }
  }

  render() {
    const { error, original, fix } = this.state;
    const { history, match, themePath } = this.props;

    console.log('ERROR', error);

    return (
      <WhiteTheme>
        <Sidebar
          opened={!!match}
          loading={error ? false : true}
          position="right"<commit_msg>fix: fixed small lint error<commit_after>import React from 'react';
import PropTypes from 'prop-types';
import { WhiteTheme, Sidebar, Osmose } from 'osm-ui-react';

import EditorModal from './EditorModal';
import { osmose, osm } from 'helpers/requests';

class OsmoseSidebar extends React.Component {
  state = {
    error: null,
    original: null,
    fix: null
  };

  displayEditor = (fix, original) =>
    this.setState({
      original,
      fix
    });

  closeEditor = () =>
    this.setState({
      original: null,
      fix: null
    });

  submitCorrection = fix => {
    const errorId = this.state.error.error_id;
    const original = this.state.error.elems[0];
    const elemId = `${original.type}/${original.id}`;

    const changesetIdP = osm.createChangeset('ourson', 'This is a test');
    const elemP = osm.fetchElement(elemId);

    Promise.all([changesetIdP, elemP])
      .then(([id, element]) => {
        element = osm.setProperties(element, fix);

        return osm.isChangesetStillOpen(id).then(id => {
          console.log('This should send edited Element to OSM', element);
          /* Uncomment this to send */
          // return osm.sendElement(element, id);
        });
      })
      .then(() => {
        console.log('This should close Osmose error', errorId);
        /* Uncomment this to send */
        // osmose.closeError(errorId);
        this.closeEditor();
      })
      .catch(err => console.log('Error in sending Element', err));
  };

  componentWillReceiveProps(nextProps) {
    if (nextProps.match !== null) {
      osmose
        .fetchError(nextProps.match.params.id)
        .then(error => this.setState({ error }));
    }
  }

  render() {
    const { error, original, fix } = this.state;
    const { history, match, themePath } = this.props;

    console.log('ERROR', error);

    return (
      <WhiteTheme>
        <Sidebar
          opened={!!match}
          loading={error ? false : true}
          position="right"
{'fraction_non_alphanumeric': 0.14388304693511156, 'fraction_numerical': 0.0005129520389843549, 'mean_word_length': 2.542234332425068, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, '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': '919570', 'n_tokens_mistral': 1205, 'n_tokens_neox': 1180, 'n_words': 282}