<commit_before>/* eslint no-console: 0 */

import React, { Component, PropTypes } from 'react';
import Modal from 'react-modal';
// import classSet from 'classnames';
import Const from '../Const';
// import editor from '../Editor';
import Notifier from '../Notification.js';
import InsertModal from './InsertModal';
import InsertButton from './InsertButton';
import DeleteButton from './DeleteButton';
import ExportCSVButton from './ExportCSVButton';
import ShowSelectedOnlyButton from './ShowSelectedOnlyButton';
import SearchField from './SearchField';
import ClearSearchButton from './ClearSearchButton';

class ToolBar extends Component {

  static modalSeq = 0;

  constructor(props) {
    super(props);
    this.timeouteClear = 0;
    this.modalClassName;
    this.state = {
      isInsertModalOpen: false,
      validateState: null,
      shakeEditor: false,
      showSelected: false
    };
  }

  componentWillMount() {
    const delay = this.props.searchDelayTime ? this.props.searchDelayTime : 0;
    this.debounceCallback = this.handleDebounce(() => {
      const { seachInput } = this.refs;
      seachInput && this.props.onSearch(seachInput.getValue());
    },
      delay
    );
  }

  componentWillReceiveProps(nextProps) {
    if (nextProps.reset) {
      this.setSearchInput('');
    }
  }

  componentWillUnmount() {
    this.clearTimeout();
  }

  setSearchInput(text) {
    const { seachInput } = this.refs;
    if (seachInput && seachInput.value !== text) {
      seachInput.value = text;
    }
  }

  clearTimeout() {
    if (this.timeouteClear) {
      clearTimeout(this.timeouteClear);
      this.timeouteClear = 0;
    }
  }

  displayCommonMessage = () => {
    this.refs.notifier.notice(
      'error',
      'Form validate errors, please checking!',
      'Pressed ESC can cancel');
  }

  validateNewRow(newRow) {
    const validateState = {};
    let isValid = true;
    let tempMsg;
    let responseType;

    this.props.columns.forEach(column => {
      if (column.isKey && column.keyValidator) { // key validator for checking exist key
        tempMsg = this.props.isValidKey(newRow[column.field]);
        if (tempMsg) {
          this.displayCommonMessage();
          isValid = false;
          validateState[column.field] = tempMsg;
        }
      } else if (column.editable && column.editable.validator) { // process validate
        tempMsg = column.editable.validator(newRow[column.field]);
        responseType = typeof tempMsg;
        if (responseType !== 'object' && tempMsg !== true) {
          this.displayCommonMessage();
          isValid = false;
          validateState[column.field] = tempMsg;
        } else if (responseType === 'object' && tempMsg.isValid !== true) {
          this.refs.notifier.notice(
              tempMsg.notification.type,
              tempMsg.notification.msg,
              tempMsg.notification.title);
          isValid = false;
          validateState[column.field] = tempMsg.notification.msg;<commit_msg>fix #1455<commit_after>/* eslint no-console: 0 */

import React, { Component, PropTypes } from 'react';
import Modal from 'react-modal';
// import classSet from 'classnames';
import Const from '../Const';
// import editor from '../Editor';
import Notifier from '../Notification.js';
import InsertModal from './InsertModal';
import InsertButton from './InsertButton';
import DeleteButton from './DeleteButton';
import ExportCSVButton from './ExportCSVButton';
import ShowSelectedOnlyButton from './ShowSelectedOnlyButton';
import SearchField from './SearchField';
import ClearSearchButton from './ClearSearchButton';

class ToolBar extends Component {

  static modalSeq = 0;

  constructor(props) {
    super(props);
    this.timeouteClear = 0;
    this.modalClassName;
    this.state = {
      isInsertModalOpen: false,
      validateState: null,
      shakeEditor: false,
      showSelected: false
    };
  }

  componentWillMount() {
    const delay = this.props.searchDelayTime ? this.props.searchDelayTime : 0;
    this.debounceCallback = this.handleDebounce(() => {
      const { seachInput } = this.refs;
      seachInput && this.props.onSearch(seachInput.getValue());
    },
      delay
    );
  }

  componentWillReceiveProps(nextProps) {
    if (nextProps.reset) {
      this.setSearchInput('');
    }
  }

  componentWillUnmount() {
    this.clearTimeout();
  }

  setSearchInput(text) {
    const { seachInput } = this.refs;
    if (seachInput && seachInput.value !== text) {
      seachInput.value = text;
    }
  }

  clearTimeout() {
    if (this.timeouteClear) {
      clearTimeout(this.timeouteClear);
      this.timeouteClear = 0;
    }
  }

  displayCommonMessage = () => {
    this.refs.notifier.notice(
      'error',
      'Form validate errors, please checking!',
      'Pressed ESC can cancel');
  }

  validateNewRow(newRow) {
    const validateState = {};
    let isValid = true;
    let tempMsg;
    let responseType;

    this.props.columns.forEach(column => {
      if (column.isKey && column.keyValidator) { // key validator for checking exist key
        tempMsg = this.props.isValidKey(newRow[column.field]);
        if (tempMsg) {
          this.displayCommonMessage();
          isValid = false;
          validateState[column.field] = tempMsg;
        }
      } else if (column.editable && column.editable.validator) { // process validate
        tempMsg = column.editable.validator(newRow[column.field], newRow);
        responseType = typeof tempMsg;
        if (responseType !== 'object' && tempMsg !== true) {
          this.displayCommonMessage();
          isValid = false;
          validateState[column.field] = tempMsg;
        } else if (responseType === 'object' && tempMsg.isValid !== true) {
          this.refs.notifier.notice(
              tempMsg.notification.type,
              tempMsg.notification.msg,
              tempMsg.notification.title);
          isValid = false;
          validateState[column.field] = tempMsg.notification.msg;
{'fraction_non_alphanumeric': 0.12303577398863257, 'fraction_numerical': 0.002340354396522902, 'mean_word_length': 2.7891070297656744, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '5487848', 'n_tokens_mistral': 1731, 'n_tokens_neox': 1689, 'n_words': 383}