Skip to content

Commit

Permalink
correct list of sources for BasedOn
Browse files Browse the repository at this point in the history
Used in loops and variable :
- add dynamic arrays and pairing labels
From referenced questionnaires :
- remove linked loops
- add dynamic arrays and pariring
  • Loading branch information
BulotF committed Oct 12, 2023
1 parent f4cf8c6 commit 1e62748
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 30 deletions.
53 changes: 52 additions & 1 deletion src/actions/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,17 @@ export const loadExternalQuestionnairesVariables =

// Metadata : loops from external elements

const isQuestionLoop = component => {
return (
component.type === 'QuestionType' &&
((component.questionType === 'TABLE' &&
component.ResponseStructure.Dimension.some(
dim => dim.dimensionType === 'PRIMARY' && dim.dynamic !== '0',
)) ||
component.questionType === 'PAIRING')
);
};

export const loadExternalQuestionnairesLoops =
(idExternalQuestionnaire, token) => async dispatch => {
dispatch({
Expand All @@ -219,7 +230,47 @@ export const loadExternalQuestionnairesLoops =
const externalQuestionnairesMetadata = [
{
id: idExternalQuestionnaire,
loops: externalQuestionnaire.Iterations?.Iteration || [],
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() || [],
},
];
return dispatch(
Expand Down
27 changes: 7 additions & 20 deletions src/widgets/component-new-edit/components/component-new-edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -425,26 +425,13 @@ const ComponentNewEdit = props => {
};

const scopes = [
getQuestionnaireScope(componentsStore).map(questionnaireIteration => {
return (
<GenericOption
key={`scope-${questionnaireIteration.id}`}
value={questionnaireIteration.id}
>
{questionnaireIteration.nameLoop}
getQuestionnaireScope(componentsStore, externalLoopsStore).map(
iteration => (
<GenericOption key={`scope-${iteration.id}`} value={iteration.id}>
{iteration.name}
</GenericOption>
);
}),
externalLoopsStore.map(externalIteration => {
return (
<GenericOption
key={`scope-${externalIteration.id}`}
value={externalIteration.id}
>
{externalIteration.Name}
</GenericOption>
);
}),
),
),
];

const associatedFieldsProps = {
Expand Down Expand Up @@ -540,7 +527,7 @@ const ComponentNewEdit = props => {
<GenericOption key="selectFinalMember" value="">
{Dictionary.selectFinalMembre}
</GenericOption>
{getFinalOptions(componentsStore)}
{InitialMember && getFinalOptions(componentsStore)}
</Field>
</>
)}
Expand Down
27 changes: 18 additions & 9 deletions src/widgets/component-new-edit/components/variables/utils-loops.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,22 @@ const { LIST } = DIMENSION_FORMATS;
* @param {object} components List of components
* @return {array} list components for loop
*/
export function getQuestionnaireScope(components) {
return Object.values(components).filter(
component =>
(component.type === LOOP && !component.basedOn) ||
(component.type === QUESTION &&
(component.responseFormat.type === PAIRING ||
(component.responseFormat.type === TABLE &&
component.responseFormat.TABLE.PRIMARY.type === LIST))),
);
export function getQuestionnaireScope(components, externalLoops) {
return [
Object.values(components)
.filter(component => component.type === LOOP && !component.basedOn)
.map(loop => {
return { id: loop.id, name: loop.nameLoop };
}),
Object.values(components)
.filter(
component =>
component.type === QUESTION &&
(component.responseFormat.type === PAIRING ||
(component.responseFormat.type === TABLE &&
component.responseFormat.TABLE.PRIMARY.type === LIST)),
)
.map(question => ({ id: question.id, name: question.name })),
externalLoops,
].flat();
}

0 comments on commit 1e62748

Please sign in to comment.