<commit_before>import {channel} from 'redux-saga'
import _join from 'lodash/join'
import uuid from 'uuid/v4'
import {all, call, fork, put, takeEvery, take, spawn, select} from 'redux-saga/effects'
import {api} from 'tocco-util'

import notifier from './../../notifier'
import rest from '../../rest'
import * as advancedSearchActions from './actions'
import * as valueActions from '../values/actions'
import {getSelection, getValue, getAdvancedSearchComponent} from './utils'

export const textResourceSelector = (state, key) => state.intl.messages[key] || key

export default function* sagas(config) {
  yield all([
    fork(takeEvery, advancedSearchActions.OPEN_ADVANCED_SEARCH, openAdvancedSearch, config)
  ])
}

export function* openAdvancedSearch(config, {payload}) {
  const {listApp} = config
  const {formName, formField, modelField, value} = payload

  const {multi, targetEntity: entity} = modelField
  const {id: fieldId, label, formBase: fieldFormBase} = formField
  const formBase = fieldFormBase || entity
  const listFormDefinition = yield call(rest.fetchForm, `${formBase}_remotefield`)
  const answerChannel = yield call(channel)
  const modalId = yield call(uuid)
  const advancedSearchTitle = yield select(textResourceSelector, 'client.common.advancedSearch')
  const selection = yield call(getSelection, value, multi)

  const advancedSearchComponent = getAdvancedSearchComponent(
    listApp,
    entity,
    formBase,
    listFormDefinition,
    selection,
    ids => { answerChannel.put(advancedSearchActions.advancedSearchUpdate(ids)) },
    () => { answerChannel.put(advancedSearchActions.advancedSearchClose()) },
    fieldId,
    multi)

  yield put(notifier.modalComponent(modalId, `${label}: ${advancedSearchTitle}`, null, advancedSearchComponent, true))
  yield spawn(closeAdvancedSearch, answerChannel, modalId, fieldId, formName, entity, multi)
}<commit_msg>refactor(app-extension): fetch remote field form with scope<commit_after>import {channel} from 'redux-saga'
import _join from 'lodash/join'
import uuid from 'uuid/v4'
import {all, call, fork, put, takeEvery, take, spawn, select} from 'redux-saga/effects'
import {api} from 'tocco-util'

import notifier from './../../notifier'
import rest from '../../rest'
import * as advancedSearchActions from './actions'
import * as valueActions from '../values/actions'
import {getSelection, getValue, getAdvancedSearchComponent} from './utils'

export const textResourceSelector = (state, key) => state.intl.messages[key] || key

export default function* sagas(config) {
  yield all([
    fork(takeEvery, advancedSearchActions.OPEN_ADVANCED_SEARCH, openAdvancedSearch, config)
  ])
}

export function* openAdvancedSearch(config, {payload}) {
  const {listApp} = config
  const {formName, formField, modelField, value} = payload

  const {multi, targetEntity: entity} = modelField
  const {id: fieldId, label, formBase: fieldFormBase} = formField
  const remoteFieldFormName = fieldFormBase || entity
  const listFormDefinition = yield call(rest.fetchForm, remoteFieldFormName, 'remotefield')
  const answerChannel = yield call(channel)
  const modalId = yield call(uuid)
  const advancedSearchTitle = yield select(textResourceSelector, 'client.common.advancedSearch')
  const selection = yield call(getSelection, value, multi)

  const advancedSearchComponent = getAdvancedSearchComponent(
    listApp,
    entity,
    remoteFieldFormName,
    listFormDefinition,
    selection,
    ids => { answerChannel.put(advancedSearchActions.advancedSearchUpdate(ids)) },
    () => { answerChannel.put(advancedSearchActions.advancedSearchClose()) },
    fieldId,
    multi)

  yield put(notifier.modalComponent(modalId, `${label}: ${advancedSearchTitle}`, null, advancedSearchComponent, true))
  yield spawn(closeAdvancedSearch, answerChannel, modalId, fieldId, formName, entity, multi)
}
{'fraction_non_alphanumeric': 0.11304122374902774, 'fraction_numerical': 0.0005185377236193933, 'mean_word_length': 5.484033613445378, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '255390', 'n_tokens_mistral': 1113, 'n_tokens_neox': 1082, 'n_words': 305}