<commit_before>import {receiveEntities} from '../modules/mergeMatrix/entities/actions'
import {retrieveEditOptions} from '../modules/mergeStrategy/editOptions/actions'
import {retrieveModel} from '../modules/mergeMatrix/model/actions'
import {changeTargetEntity} from '../modules/mergeMatrix/actions'
import {toggleRelationMany, clearRelationMany} from '../modules/mergeMatrix/selections/actions'

export const getDispatchActions = input => (
  [
    receiveEntities(input.entities),
    retrieveModel(input.model),
    changeTargetEntity(input.entities[0].pk),
    clearRelationMany(),
    retrieveEditOptions(input.sourceEntitiesEditOptions),
    ...dispatchToManySelections(input)
  ]
)

const dispatchToManySelections = input => {
  const result = []
  input.model.relations
    .filter(relation => relation.toMany)
    .map(relation => {
      input.entities.map(entity => {
        const userRelation = entity.relations[relation.name]
        userRelation.values.map(userRelationValue => {
          if (userRelationValue.checked) {
            return toggleRelationMany(relation.name, userRelationValue.pk, entity.pk)<commit_msg>refactor(merge): rewrite input toMany dispatching<commit_after>import {receiveEntities} from '../modules/mergeMatrix/entities/actions'
import {retrieveEditOptions} from '../modules/mergeStrategy/editOptions/actions'
import {retrieveModel} from '../modules/mergeMatrix/model/actions'
import {changeTargetEntity} from '../modules/mergeMatrix/actions'
import {toggleRelationMany, clearRelationMany} from '../modules/mergeMatrix/selections/actions'

export const getDispatchActions = input => (
  [
    receiveEntities(input.entities),
    retrieveModel(input.model),
    changeTargetEntity(input.entities[0].pk),
    clearRelationMany(),
    retrieveEditOptions(input.sourceEntitiesEditOptions),
    ...getToManySelectDispatchActions(input)
  ]
)

const getToManySelectDispatchActions = ({model, entities}) => {
  const result = []
  model.relations
    .filter(relation => relation.toMany)
    .forEach(relation => {
      entities.forEach(entity => {
        const userRelation = entity.relations[relation.name]
        userRelation.values.forEach(userRelationValue => {
          if (userRelationValue.checked) {
            result.push(toggleRelationMany(relation.name, userRelationValue.pk, entity.pk))
{'fraction_non_alphanumeric': 0.11923076923076924, 'fraction_numerical': 0.0008547008547008547, 'mean_word_length': 4.5738095238095235, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '3497662', 'n_tokens_mistral': 639, 'n_tokens_neox': 646, 'n_words': 105}