<commit_before>import { connect } from 'react-redux'
import { browserHistory } from 'react-router'
import { setupAction, updateAction } from 'rform'
import mapCollection from 'lodash/map'
import isEqual from 'lodash/isEqual'
import isArray from 'lodash/isArray'
import some from 'lodash/some'
import formObjectSelect from '../lib/formObjectSelect'
import generateFormId from '../lib/generateFormId'
import seedDataFromEntity from '../lib/seedDataFromEntity'
import  { setUi, setUiLoaded } from '../../../Backend/actions/setUi'
import addFlashMessage from '../../../Backend/actions/addFlashMessage'
import loadAjaxData from '../../../Backend/actions/loadAjaxData'
import addEntities from '../../../Backend/actions/addEntities'
import Form from '../components/Form'
import settings from '../../../lib/settings'
import { denormalizeStateEntity } from '../../../lib/denormalizeUtils'

const mapStateToProps = (state, ownProps) => {
  const {
    model, id, submodelKey, modifySeedData, formIdSpecification
  } = ownProps
  const submodelPath = ownProps.submodelPath || []
  const formId = generateFormId(
    model, submodelPath, submodelKey, id, formIdSpecification
  )
  const formSettings = state.settings[model]
  const formData = state.rform[formId] || {}
  const instance = denormalizeStateEntity(state.entities, model, id)
  const isAssignable =
    instance && instance['current-assignment-id'] !== undefined
  const afterSaveActiveKey = state.ui.afterSaveActiveKey
  const afterSaveActions =
    mapCollection(settings.AFTER_SAVE_ACTIONS, (value, key) => ({
      action: key, name: value, active: afterSaveActiveKey == key
    }))
  const formObjectClass = formObjectSelect(model, !!id)
  const seedData = {
    fields: seedDataFromEntity(instance, formObjectClass, modifySeedData)
  }

  let action = `/api/v1/${model}`
  let method = 'POST'
  const buttonData = buildActionButtonData(
    state, model, id, instance, formObjectClass, formData
  )
  const errorMessages = checkforErrors(state, model, editId)

  // Changes in case the form updates instead of creating
  if (id && !ownProps.forceCreate) {
    action += '/' + id
    method = 'PUT'
  }

  return {
    seedData,
    action,
    method,
    formId,
    formObjectClass,
    instance,
    isAssignable,
    buttonData,
    afterSaveActions,
    afterSaveActiveKey,
    editId,
    errorMessages
    id
  }
}

const mapDispatchToProps = (dispatch, ownProps) => ({
  dispatch,
})

const mergeProps = (stateProps, dispatchProps, ownProps) => {
  const { dispatch } = dispatchProps
  const { model, id } = ownProps // , onSuccessfulSubmit<commit_msg>hotfix<commit_after>import { connect } from 'react-redux'
import { browserHistory } from 'react-router'
import { setupAction, updateAction } from 'rform'
import mapCollection from 'lodash/map'
import isEqual from 'lodash/isEqual'
import isArray from 'lodash/isArray'
import some from 'lodash/some'
import formObjectSelect from '../lib/formObjectSelect'
import generateFormId from '../lib/generateFormId'
import seedDataFromEntity from '../lib/seedDataFromEntity'
import  { setUi, setUiLoaded } from '../../../Backend/actions/setUi'
import addFlashMessage from '../../../Backend/actions/addFlashMessage'
import loadAjaxData from '../../../Backend/actions/loadAjaxData'
import addEntities from '../../../Backend/actions/addEntities'
import Form from '../components/Form'
import settings from '../../../lib/settings'
import { denormalizeStateEntity } from '../../../lib/denormalizeUtils'

const mapStateToProps = (state, ownProps) => {
  const {
    model, id, submodelKey, modifySeedData, formIdSpecification
  } = ownProps
  const submodelPath = ownProps.submodelPath || []
  const formId = generateFormId(
    model, submodelPath, submodelKey, id, formIdSpecification
  )
  const formSettings = state.settings[model]
  const formData = state.rform[formId] || {}
  const instance = denormalizeStateEntity(state.entities, model, id)
  const isAssignable =
    instance && instance['current-assignment-id'] !== undefined
  const afterSaveActiveKey = state.ui.afterSaveActiveKey
  const afterSaveActions =
    mapCollection(settings.AFTER_SAVE_ACTIONS, (value, key) => ({
      action: key, name: value, active: afterSaveActiveKey == key
    }))
  const formObjectClass = formObjectSelect(model, !!id)
  const seedData = {
    fields: seedDataFromEntity(instance, formObjectClass, modifySeedData)
  }

  let action = `/api/v1/${model}`
  let method = 'POST'
  const buttonData = buildActionButtonData(
    state, model, id, instance, formObjectClass, formData
  )
  const errorMessages = checkforErrors(state, model, editId)

  // Changes in case the form updates instead of creating
  if (id && !ownProps.forceCreate) {
    action += '/' + id
    method = 'PUT'
  }

  return {
    seedData,
    action,
    method,
    formId,
    formObjectClass,
    instance,
    isAssignable,
    buttonData,
    afterSaveActions,
    afterSaveActiveKey,
    editId,
    errorMessages,
    id
  }
}

const mapDispatchToProps = (dispatch, ownProps) => ({
  dispatch,
})

const mergeProps = (stateProps, dispatchProps, ownProps) => {
  const { dispatch } = dispatchProps
  const { model, id } = ownProps // , onSuccessfulSubmit
{'fraction_non_alphanumeric': 0.1215078453884424, 'fraction_numerical': 0.0003827018752391887, 'mean_word_length': 3.935788479697828, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '2974142', 'n_tokens_mistral': 1547, 'n_tokens_neox': 1558, 'n_words': 401}