<commit_before>import React, { Component } from 'react'

export default class TextBase extends Component {
  constructor(props){
    super(props);
    this.newId = 1;

    const inputs = [];
    this.props.values.forEach((target) => {
      inputs.push(this.createFormTag(target))
    });
    this.state = {
      inputs: inputs
    }

    this.$wrapper = null;
  }

  getCount(){
    return this.props.data.count === undefined ? 1 : this.props.data.count;
  }

  onValueChange(e){
    const values = [];
    this.$wrapper.find('.text-form').each((key, elem) => {
      const $elem = $(elem)
      values.push({
        id: $elem.attr("data-id"),
        value: $elem.val(),
      });
    });

    this.props.onValueChange({
      values: values,
      code: this.props.data.code
    });
  }

  createFormTag(){
    throw new Error("Imprements createFormTag");
  }

  componentDidMount(){
    this.$wrapper = $(this.refs.wrapper);
    if(this.props.data.count == 1){
      if(this.props.values.length == 0){
        this.onClickAdd();
      }
    } else {
      this.$wrapper
        .sortable({
  			  opacity: 0.8,
          handle: '.handle',
          stop: (ev, ui) => {
          }
        })
    }
  }

  onClickAdd(){
    const values = [...this.props.values];
    values.push({id: 'new_' + this.newId++, value: ""})
    this.props.onValueChange({
      values: values,
      code: this.props.data.code
    });
  }

  render() {
    let addButton = null;
    if(this.props.data.count > 1){
      addButton = (
        <button className="btn btn-primary" type="button" onClick={() => this.onClickAdd()}>
          <i className="fa fa-plus" aria-hidden="true"></i>&nbsp; 追加
        </button>
      )
    }
    return (
      <div>
        {addButton}
        <ul ref="wrapper" className="list-unstyled">
          {this.props.values.map(target => {
            return this.createFormTag(target)
          })}
        </ul>
      </div>
    )
  }
}<commit_msg>削除を実装。<commit_after>import React, { Component } from 'react'

export default class TextBase extends Component {
  constructor(props){
    super(props);
    this.newId = 1;

    const inputs = [];
    this.props.values.forEach((target) => {
      inputs.push(this.createFormTag(target))
    });
    this.state = {
      inputs: inputs
    }

    this.$wrapper = null;
  }

  getCount(){
    return this.props.data.count === undefined ? 1 : this.props.data.count;
  }

  onValueChange(e){
    const values = [];
    this.$wrapper.find('.text-form').each((key, elem) => {
      const $elem = $(elem)
      values.push({
        id: $elem.attr("data-id"),
        value: $elem.val(),
      });
    });

    this.props.onValueChange({
      values: values,
      code: this.props.data.code
    });
  }

  createFormTag(){
    throw new Error("Imprements createFormTag");
  }

  componentDidMount(){
    this.$wrapper = $(this.refs.wrapper);
    if(this.props.data.count == 1){
      if(this.props.values.length == 0){
        this.onClickAdd();
      }
    } else {
      this.$wrapper
        .sortable({
  			  opacity: 0.8,
          handle: '.handle',
          stop: (ev, ui) => {
            this.onValueChange();
          }
        })
    }
  }

  onClickAdd(){
    const values = [...this.props.values];
    values.push({id: 'new_' + this.newId++, value: ""})
    this.props.onValueChange({
      values: values,
      code: this.props.data.code
    });
  }

  onClickDelete(e){
    const id = e.currentTarget.getAttribute("data-id");
    this.props.onValueChange({
      values: this.props.values.filter(target => target.id != id),
      code: this.props.data.code
    });
  }

  render() {
    let addButton = null;
    if(this.props.data.count > 1){
      addButton = (
        <button className="btn btn-primary" type="button" onClick={() => this.onClickAdd()}>
          <i className="fa fa-plus" aria-hidden="true"></i>&nbsp; 追加
        </button>
      )
    }
    return (
      <div>
        {addButton}
        <ul ref="wrapper" className="list-unstyled">
          {this.props.values.map(target => {
            return (
              <div key={target.id} className="clearfix">
                <div className="handle">
                  <i className="fa fa-bars" aria-hidden="true"></i>
                </div>
                <div className="body">
                  {this.createFormTag(target)}
                </div>
                <div className="delete">
                  <button data-id={target.id} className="btn btn-danger" type="button" onClick={(e) => this.onClickDelete(e)}>
                    <i className="fa fa-times" aria-hidden="true"></i>
                  </button>
                </div>
              </div>
            )
          })}
        </ul>
      </div>
    )
  }
}
{'fraction_non_alphanumeric': 0.16795811518324608, 'fraction_numerical': 0.002931937172774869, 'mean_word_length': 1.905109489051095, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 47, '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': '3134256', 'n_tokens_mistral': 1546, 'n_tokens_neox': 1503, 'n_words': 269}