<commit_before>import _get from 'lodash/get'
import _join from 'lodash/join'
import {rest} from 'tocco-app-extensions'

import {call} from 'redux-saga/effects'

export function* getPreselectedValues(preselectedSearchFields, entityModel, loadRelationEntity, searchFormVisible) {
  const formValues = {}
  for (const preselectedSearchField of preselectedSearchFields) {
    const fieldName = preselectedSearchField.id
    const value = preselectedSearchField.value

    let transformedValue
    if (entityModel[fieldName] && entityModel[fieldName].type === 'relation') {
      let entities = []
      if (!preselectedSearchField.hidden && searchFormVisible) {
        const targetEntity = entityModel[fieldName].targetEntity
        const query = `IN(pk,${_join(value, ',')})`
        entities = yield call(rest.fetchEntities, targetEntity, {query, fields: ['pk']})
      }
      transformedValue = entities
    } else {
      transformedValue = value
    }

    formValues[fieldName] = transformedValue
  }<commit_msg>fix(entity-list): fix hidden search form values<commit_after>import _get from 'lodash/get'
import _join from 'lodash/join'
import {rest} from 'tocco-app-extensions'

import {call} from 'redux-saga/effects'

export function* getPreselectedValues(preselectedSearchFields, entityModel, loadRelationEntity, searchFormVisible) {
  const formValues = {}
  for (const preselectedSearchField of preselectedSearchFields) {
    const fieldName = preselectedSearchField.id
    const value = preselectedSearchField.value

    let transformedValue = value

    if (entityModel[fieldName] && entityModel[fieldName].type === 'relation') {
      if (!preselectedSearchField.hidden && searchFormVisible) {
        const targetEntity = entityModel[fieldName].targetEntity
        const query = `IN(pk,${_join(value, ',')})`
        transformedValue = yield call(rest.fetchEntities, targetEntity, {query, fields: ['pk']})
      } else {
        transformedValue = Array.isArray(value) ? value.map(v => ({key: v})) : {key: value}
      }
    }

    formValues[fieldName] = transformedValue
  }
{'fraction_non_alphanumeric': 0.11052631578947368, 'fraction_numerical': 0.0, 'mean_word_length': 4.320610687022901, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '6334717', 'n_tokens_mistral': 594, 'n_tokens_neox': 583, 'n_words': 139}