Skip to content

Commit

Permalink
update external questionnaire loops
Browse files Browse the repository at this point in the history
  • Loading branch information
BulotF committed Nov 27, 2023
1 parent 0b589a1 commit fdca568
Showing 1 changed file with 34 additions and 40 deletions.
74 changes: 34 additions & 40 deletions src/actions/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit fdca568

Please sign in to comment.