From f8e3d0d444303bdd93b42217533bad21c92a6afd Mon Sep 17 00:00:00 2001 From: Martyn Colmer <46242834+martyncolmer@users.noreply.github.com> Date: Wed, 14 Feb 2024 11:57:40 +0000 Subject: [PATCH] repeating answers and empty list collectors (#210) --- src/eq_schema/schema/Question/index.js | 46 ++++++++++++++------------ src/utils/functions/pageGetters.js | 14 +++++++- 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/src/eq_schema/schema/Question/index.js b/src/eq_schema/schema/Question/index.js index 53e634bc..ad20d748 100644 --- a/src/eq_schema/schema/Question/index.js +++ b/src/eq_schema/schema/Question/index.js @@ -1,5 +1,5 @@ const { find, get, flow, concat, last } = require("lodash/fp"); -const { set, remove, cloneDeep } = require("lodash"); +const { set, remove, cloneDeep, filter } = require("lodash"); const { getInnerHTMLWithPiping } = require("../../../utils/HTMLUtils"); const convertPipes = require("../../../utils/convertPipes"); @@ -8,6 +8,7 @@ const { reversePipeContent, } = require("../../../utils/compoundFunctions"); const { getList, getSupplementaryList } = require("../../../utils/functions/listGetters"); +const { getPagesByListId } = require("../../../utils/functions/pageGetters") const Answer = require("../Answer"); const { getValueSource } = require("../../builders/valueSource"); @@ -79,30 +80,31 @@ class Question { answers: this.buildAnswers(question.answers, ctx), }; - const newSkip = { - expressions: [ - { - secondaryCondition: "Equal", - right: { - customValue: { - number: 0 - }, - type: "Custom", - }, - condition: "CountOf", + const ListCollectorPages = filter(getPagesByListId(ctx, question.answers[0].repeatingLabelAndInputListId), { pageType: "ListCollectorConfirmationPage" }) + + if (ListCollectorPages.length) { + const expressions = ListCollectorPages.map((page) => ({ + condition: "Unanswered", left: { - listId: question.answers[0].repeatingLabelAndInputListId, - type: "List", + answerId: page.answers[0].id, + type: "Answer" }, - } - ], - operator: "And" - } + right: { + optionIds: [ + ] + } + }) + ) + const newSkip = { + expressions: expressions, + operator: "And" + } - if(question.skipConditions) { - question.skipConditions = [newSkip, ...question.skipConditions] - } else { - question.skipConditions = [newSkip] + if(question.skipConditions) { + question.skipConditions = [newSkip, ...question.skipConditions] + } else { + question.skipConditions = [newSkip] + } } if (question.totalValidation && question.totalValidation.enabled) { diff --git a/src/utils/functions/pageGetters.js b/src/utils/functions/pageGetters.js index 509ae17b..8099102f 100644 --- a/src/utils/functions/pageGetters.js +++ b/src/utils/functions/pageGetters.js @@ -1,3 +1,10 @@ +const { flatMap, filter } = require("lodash"); + +const getPages = (ctx) => + flatMap(ctx.questionnaireJson.sections, (section) => + flatMap(section.folders, ({ pages }) => pages) + ); + const getPageById = (ctx, pageId) => { let result; ctx.questionnaireJson.sections.forEach((section) => { @@ -13,4 +20,9 @@ const getPageById = (ctx, pageId) => { return result; }; -module.exports = { getPageById }; +const getPagesByListId = (ctx, listId) => + flatMap(ctx.questionnaireJson.sections, (section) => + flatMap(filter(section.folders, { listId:listId }), ({ pages }) => pages) + ); + +module.exports = { getPageById, getPagesByListId, getPages };