<commit_before>import React from 'react'

import GenericField from './genericfield'
import {object_is_equal, map_drop} from 'app/utils'
import PropTypes from 'prop-types'
import uuid4 from 'uuid/v4'

class GenericForm extends React.Component{
  constructor(props){
    super(props)
    this.state = this.getInitialState(props)
    this.state.form_id = uuid4()

    this.updateForm = _.debounce(this.updateForm, 100)
  }
  getInitialState(props){
    props = props || this.props
    let state={};
    (props.fields || []).map((f) => { if (f.name){ state[f.name]=(f.value || f.default || '') } } )
    if (props.data){
      Object.keys(props.data).map( (k) => { if (k){ state[k]=props.data[k] }})
    }
    return state
  }
  setValue(k, v){
    let update = {[k]: v }
    this.setState( update )
    let nstate=Object.assign({}, this.state, update ) // looks like react delays state change, I need it now
    //console.log(nstate, this.props)
    this.updateForm()
  }
  componentWillReceiveProps(newprops){
    if (!object_is_equal(newprops.fields, this.props.fields) || !object_is_equal(newprops.data, this.props.data)){
      this.setState( this.getInitialState(newprops) )
    }
  }
  componentDidMount(){<commit_msg>Fix checkbox false at generic form transforms to true<commit_after>import React from 'react'

import GenericField from './genericfield'
import {object_is_equal, map_drop} from 'app/utils'
import PropTypes from 'prop-types'
import uuid4 from 'uuid/v4'

class GenericForm extends React.Component{
  constructor(props){
    super(props)
    this.state = this.getInitialState(props)
    this.state.form_id = uuid4()

    this.updateForm = _.debounce(this.updateForm, 100)
  }
  getInitialState(props){
    props = props || this.props
    let state={};
    (props.fields || []).map((f) => {
      if (f.name){
        let v = f.value
        if (v == undefined){
          if (f.default == undefined)
            v = ""
          else
            v = f.default
        }
        state[f.name]=v
      } 
    })
    if (props.data){
      Object.keys(props.data).map( (k) => { if (k){ state[k]=props.data[k] }})
    }
    return state
  }
  setValue(k, v){
    let update = {[k]: v }
    this.setState( update )
    let nstate=Object.assign({}, this.state, update ) // looks like react delays state change, I need it now
    //console.log(nstate, this.props)
    this.updateForm()
  }
  componentWillReceiveProps(newprops){
    if (!object_is_equal(newprops.fields, this.props.fields) || !object_is_equal(newprops.data, this.props.data)){
      this.setState( this.getInitialState(newprops) )
    }
  }
  componentDidMount(){
{'fraction_non_alphanumeric': 0.14696969696969697, 'fraction_numerical': 0.004545454545454545, 'mean_word_length': 3.1137071651090342, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4815775', 'n_tokens_mistral': 880, 'n_tokens_neox': 872, 'n_words': 197}