From fdca568583c531d30fa204a64e5a7e92be3fb770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bulot=20Fran=C3=A7ois?= Date: Mon, 27 Nov 2023 17:40:04 +0100 Subject: [PATCH] update external questionnaire loops --- src/actions/metadata.js | 74 +++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 40 deletions(-) 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(