diff --git a/src/actions/metadata.js b/src/actions/metadata.js index d48170ceb..9b0df839d 100644 --- a/src/actions/metadata.js +++ b/src/actions/metadata.js @@ -227,50 +227,44 @@ export const loadExternalQuestionnairesLoops = idExternalQuestionnaire, token, ); + const externalQuestionnaireLoopsMetadata = + externalQuestionnaire.Iterations?.Iteration.filter( + loop => !loop.IterableReference, + ).map(loop => ({ id: loop.id, name: loop.Name })); const externalQuestionnairesMetadata = [ { id: idExternalQuestionnaire, loops: - externalQuestionnaire.Child.reduce( - (accQuest, sequence) => { - const sequenceContent = Object.values(sequence.Child).reduce( - (acc, component) => { - if (isQuestionLoop(component)) - return [ - ...acc, - { id: component.id, name: component.Name }, - ]; - if ( - component.type === 'sequenceType' && - component.genericName === 'SUBMODULE' - ) { - Object.values(component.Child).reduce( - (subacc, subcomponent) => { - if (isQuestionLoop(subcomponent)) - return [ - ...subacc, - { - id: subcomponent.id, - name: subcomponent.Name, - }, - ]; - return subacc; - }, - [], - ); - } - return acc; - }, - [], - ); - return [...accQuest, ...sequenceContent]; - }, - [ - externalQuestionnaire.Iterations?.Iteration.filter( - loop => !loop.IterableReference, - ).map(loop => ({ id: loop.id, Name: loop.Name })), - ], - ).flat() || [], + externalQuestionnaire.Child.reduce((accQuest, sequence) => { + const sequenceContent = Object.values(sequence.Child).reduce( + (acc, component) => { + if (isQuestionLoop(component)) + return [...acc, { id: component.id, name: component.Name }]; + if ( + component.type === 'sequenceType' && + component.genericName === 'SUBMODULE' + ) { + Object.values(component.Child).reduce( + (subacc, subcomponent) => { + if (isQuestionLoop(subcomponent)) + return [ + ...subacc, + { + id: subcomponent.id, + name: subcomponent.Name, + }, + ]; + return subacc; + }, + [], + ); + } + return acc; + }, + [], + ); + return [...accQuest, ...sequenceContent]; + }, externalQuestionnaireLoopsMetadata || []).flat() || [], }, ]; return dispatch(