From 77d14d760f80ef3c6ac11dae91a86abca8efdcc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atte=20Per=C3=A4m=C3=A4ki?= Date: Mon, 16 Dec 2024 10:34:35 +0200 Subject: [PATCH 1/7] Answer limits no longer checked for conditional questions --- server/src/application/submission.ts | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/server/src/application/submission.ts b/server/src/application/submission.ts index 82fa7f69..233d4393 100644 --- a/server/src/application/submission.ts +++ b/server/src/application/submission.ts @@ -4,7 +4,7 @@ import { MapQuestionAnswer, Submission, SurveyMapSubQuestionAnswer, - SurveyPageSection + SurveyPageSection, } from '@interfaces/survey'; import { getColumnSet, @@ -91,7 +91,8 @@ async function validateEntriesByAnswerLimits(answerEntries: AnswerEntry[]) { FROM data.page_section WHERE id = ANY ($1) AND - details->'answerLimits' IS NOT NULL`, + details->'answerLimits' IS NOT NULL AND + predecessor_section = NULL`, [answerEntries.map((entry) => entry.sectionId)], ); // Validate each entry against the question answer limits @@ -834,17 +835,28 @@ export async function getSubmissionsForSurvey(surveyId: number) { { surveyId }, ); const result = []; - let currentSubmission: {id: number, timestamp: Date, entries: DBAnswerEntry[]} | null = null; + let currentSubmission: { + id: number; + timestamp: Date; + entries: DBAnswerEntry[]; + } | null = null; for (const row of rows) { if (currentSubmission?.id !== row.submission_id) { currentSubmission = { id: row.submission_id, timestamp: row.updated_at, - entries: [] - } + entries: [], + }; result.push(currentSubmission); } currentSubmission.entries.push(row); } - return result.map(x => ({id: x.id, timestamp: x.timestamp, answerEntries: dbAnswerEntriesToAnswerEntries(x.entries)} as Submission)); + return result.map( + (x) => + ({ + id: x.id, + timestamp: x.timestamp, + answerEntries: dbAnswerEntriesToAnswerEntries(x.entries), + }) as Submission, + ); } From 166cb72092178aa20d2496ee2313e969e2ea7489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atte=20Per=C3=A4m=C3=A4ki?= Date: Mon, 16 Dec 2024 11:17:03 +0200 Subject: [PATCH 2/7] Deleting a question now removes subquestions linked to it. --- server/src/application/survey.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/application/survey.ts b/server/src/application/survey.ts index 38c226ef..ac8e44a2 100644 --- a/server/src/application/survey.ts +++ b/server/src/application/survey.ts @@ -1010,7 +1010,7 @@ async function deleteRemovedSections( ); if (removedSectionIds.length) { await getDb().none( - `DELETE FROM data.page_section WHERE id = ANY ($1) OR parent_section = ANY ($1)`, + `DELETE FROM data.page_section WHERE id = ANY ($1) OR parent_section = ANY ($1) OR predecessor_section = ANY($1)`, [removedSectionIds], ); } From e5b7e4a4d4a15a3d8065f901c8aafc09b86cbdfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atte=20Per=C3=A4m=C3=A4ki?= Date: Mon, 16 Dec 2024 11:46:34 +0200 Subject: [PATCH 3/7] Deleting a question now removes subquestions linked to it. --- server/src/application/survey.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/application/survey.ts b/server/src/application/survey.ts index ac8e44a2..5fcca28b 100644 --- a/server/src/application/survey.ts +++ b/server/src/application/survey.ts @@ -987,7 +987,7 @@ async function getSectionConditions(sectionIds: number[]) { } /** - * When updating a survey, deletes all sections that should be removed from DB. + * When updating a survey, deletes all sections (and subsections linked to them) that should be removed from DB. * @param surveyId Survey ID * @param newSections New sections */ From ae6920ba65118109313649b3208a13a74aa79fd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atte=20Per=C3=A4m=C3=A4ki?= Date: Mon, 23 Dec 2024 13:04:08 +0200 Subject: [PATCH 4/7] follow up section conditions removed on copy --- client/src/components/admin/ConditionRow.tsx | 1 + .../components/admin/EditSurveySideBar.tsx | 70 ++++++++++++------- .../SurveySectionAccordion.tsx | 21 +++++- 3 files changed, 64 insertions(+), 28 deletions(-) diff --git a/client/src/components/admin/ConditionRow.tsx b/client/src/components/admin/ConditionRow.tsx index 7adb6665..f111d719 100644 --- a/client/src/components/admin/ConditionRow.tsx +++ b/client/src/components/admin/ConditionRow.tsx @@ -128,6 +128,7 @@ export function ConditionRow({ /> ) : ( option?.id > 0)} + disabled={options.every((option) => option.id < 0)} multiple sx={{ flex: 1, From cdf62f221a3b8805f3c27b1f0416ea6da1c61662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atte=20Per=C3=A4m=C3=A4ki?= Date: Fri, 27 Dec 2024 14:04:56 +0200 Subject: [PATCH 7/7] Allow 0 as condition for conditional page/section --- server/src/application/survey.ts | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/server/src/application/survey.ts b/server/src/application/survey.ts index 5fcca28b..37ec8809 100644 --- a/server/src/application/survey.ts +++ b/server/src/application/survey.ts @@ -1213,9 +1213,9 @@ export async function updateSurvey(survey: Survey) { Object.entries(page.conditions).map(async ([sectionId, conditions]) => { // Filter out null values from conditions caused by trying to save "-" as numeric condition const validConditions = { - equals: conditions.equals.filter(Boolean), - lessThan: conditions.lessThan.filter(Boolean), - greaterThan: conditions.greaterThan.filter(Boolean), + equals: conditions.equals.filter((value) => value != null), + lessThan: conditions.lessThan.filter((value) => value != null), + greaterThan: conditions.greaterThan.filter((value) => value != null), }; await upsertSectionConditions( Number(sectionId), @@ -1314,10 +1314,15 @@ export async function updateSurvey(survey: Survey) { await deleteSectionConditions(null, [sectionRow.id]); // Filter out null values from conditions caused by trying to save "-" as numeric condition const validConditions = { - equals: linkedSection.conditions.equals.filter(Boolean), - lessThan: linkedSection.conditions.lessThan.filter(Boolean), - greaterThan: - linkedSection.conditions.greaterThan.filter(Boolean), + equals: linkedSection.conditions.equals.filter( + (value) => value != null, + ), + lessThan: linkedSection.conditions.lessThan.filter( + (value) => value != null, + ), + greaterThan: linkedSection.conditions.greaterThan.filter( + (value) => value != null, + ), }; await upsertSectionConditions( sectionRow.id, @@ -1557,17 +1562,17 @@ function dbSectionConditionsToConditions( ): Conditions { return dbSectionConditions.reduce( (conditions, condition) => { - if (condition.equals) { + if (condition.equals != null) { return { ...conditions, equals: [...conditions.equals, condition.equals], }; - } else if (condition.less_than) { + } else if (condition.less_than != null) { return { ...conditions, lessThan: [...conditions.lessThan, condition.less_than], }; - } else if (condition.greater_than) { + } else if (condition.greater_than != null) { return { ...conditions, greaterThan: [...conditions.greaterThan, condition.greater_than],