Skip to content

Commit

Permalink
repeating answers and empty list collectors (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
martyncolmer authored Feb 14, 2024
1 parent cd01341 commit f8e3d0d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 23 deletions.
46 changes: 24 additions & 22 deletions src/eq_schema/schema/Question/index.js
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 13 additions & 1 deletion src/utils/functions/pageGetters.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -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 };

0 comments on commit f8e3d0d

Please sign in to comment.