<commit_before>import { default as React, Component } from 'react';
import { render } from 'react-dom';
import { dataOperation } from '../../service/DataOperation';
import { ErrorModal } from '../../others/ErrorModal';
var Codemirror = require('react-codemirror');
require('codemirror/mode/javascript/javascript');
require('codemirror/addon/search/searchcursor.js');
require('codemirror/addon/search/search.js');
require('codemirror/addon/dialog/dialog.js');
require('codemirror/addon/edit/matchbrackets.js');
require('codemirror/addon/edit/closebrackets.js');
require('codemirror/addon/comment/comment.js');
require('codemirror/addon/comment/comment.js');
require('codemirror/addon/fold/foldcode.js');
require('codemirror/addon/fold/foldgutter.js');
require('codemirror/addon/fold/brace-fold.js');
require('codemirror/addon/fold/xml-fold.js');
require('codemirror/addon/fold/markdown-fold.js');
require('codemirror/addon/fold/comment-fold.js');
require('codemirror/mode/javascript/javascript.js');
require('codemirror/keymap/sublime.js');

export class JsonImport extends Component {
  constructor(props) {
    super(props);
    this.sample = {
      "name": "Foo",
      "id": 1234,
      "flag": true,
      "location": {
        "lat": 1234,
        "lon": 1234
      },
      "place": {
        "country": "india",
        "city": "ahmedabad",
        "pincode": 380055
      }
    };
  	this.state = {
  		code: JSON.stringify(this.sample, null, 4),
      error: {
        title: null,
        message: null
      }
  	};
  	this.updateCode = this.updateCode.bind(this);
    this.closeError = this.closeError.bind(this);
  }
  updateCode(newCode) {
  	this.setState({
  	    code: newCode
  	});
  }
  submit() {
    if(this.props.selectedType.length === 1) {
      let isJson = this.isJson(this.state.code);
      if(isJson.validFlag) {
        let parsedJson = isJson.jsonInput;
        this.props.detectMapping(parsedJson);
      } else {
        this.setState({
          error: {
            title: 'Invalid json',
            message: 'Json is invalid, provide valid json to proceed further.'
          }
        });
      }
    } else {
      this.setState({
        error: {
          title: 'Type selection',
          message: 'Please select only 1 type from the left side.'
        }
      });<commit_msg>Apply ui blocks changes on change of json<commit_after>import { default as React, Component } from 'react';
import { render } from 'react-dom';
import { dataOperation } from '../../service/DataOperation';
import { ErrorModal } from '../../others/ErrorModal';
var Codemirror = require('react-codemirror');
require('codemirror/mode/javascript/javascript');
require('codemirror/addon/search/searchcursor.js');
require('codemirror/addon/search/search.js');
require('codemirror/addon/dialog/dialog.js');
require('codemirror/addon/edit/matchbrackets.js');
require('codemirror/addon/edit/closebrackets.js');
require('codemirror/addon/comment/comment.js');
require('codemirror/addon/comment/comment.js');
require('codemirror/addon/fold/foldcode.js');
require('codemirror/addon/fold/foldgutter.js');
require('codemirror/addon/fold/brace-fold.js');
require('codemirror/addon/fold/xml-fold.js');
require('codemirror/addon/fold/markdown-fold.js');
require('codemirror/addon/fold/comment-fold.js');
require('codemirror/mode/javascript/javascript.js');
require('codemirror/keymap/sublime.js');

export class JsonImport extends Component {
  constructor(props) {
    super(props);
    this.sample = {
      "name": "Foo",
      "id": 1234,
      "flag": true,
      "location": {
        "lat": 1234,
        "lon": 1234
      },
      "place": {
        "country": "india",
        "city": "ahmedabad",
        "pincode": 380055
      }
    };
  	this.state = {
  		code: JSON.stringify(this.sample, null, 4),
      error: {
        title: null,
        message: null
      }
  	};
  	this.updateCode = this.updateCode.bind(this);
    this.closeError = this.closeError.bind(this);
  }
  componentWillMount() {
    this.submit.call(this);
  }
  updateCode(newCode) {
  	this.setState({
  	    code: newCode
  	}, this.submit.bind(this));
  }
  submit() {
    if(this.props.selectedType.length === 1) {
      let isJson = this.isJson(this.state.code);
      if(isJson.validFlag) {
        let parsedJson = isJson.jsonInput;
        this.props.detectMapping(parsedJson);
      } 
{'fraction_non_alphanumeric': 0.16172445255474452, 'fraction_numerical': 0.009352189781021899, 'mean_word_length': 3.1603415559772294, 'pattern_counts': {'":': 20, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '6598', 'n_tokens_mistral': 1501, 'n_tokens_neox': 1469, 'n_words': 228}