From 3f2ef3e776e86bc6ec5c344b1435501363c3998a Mon Sep 17 00:00:00 2001 From: Dhruwang Jariwala <67850763+Dhruwang@users.noreply.github.com> Date: Tue, 11 Jul 2023 22:15:54 +0530 Subject: [PATCH] Fix Logic Jumps are not updated properly when questions are updated or deleted (#530) * modified updateQuestion functio * added type defs * pnpm format * fix LogicEditor fields not updating properly --------- Co-authored-by: Matthias Nannt --- .../surveys/[surveyId]/edit/LogicEditor.tsx | 18 ++++---- .../surveys/[surveyId]/edit/QuestionCard.tsx | 9 ++-- .../surveys/[surveyId]/edit/QuestionsView.tsx | 41 +++++++++++-------- 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/apps/web/app/environments/[environmentId]/surveys/[surveyId]/edit/LogicEditor.tsx b/apps/web/app/environments/[environmentId]/surveys/[surveyId]/edit/LogicEditor.tsx index 47949ae64e..97365481be 100644 --- a/apps/web/app/environments/[environmentId]/surveys/[surveyId]/edit/LogicEditor.tsx +++ b/apps/web/app/environments/[environmentId]/surveys/[surveyId]/edit/LogicEditor.tsx @@ -82,6 +82,7 @@ export default function LogicEditor({ cta: ["clicked", "skipped"], consent: ["skipped", "accepted"], }; + const logicConditions: LogicConditions = { submitted: { label: "is submitted", @@ -201,10 +202,9 @@ export default function LogicEditor({ }; const deleteLogic = (logicIdx: number) => { - const newLogic = !question.logic - ? [] - : (question.logic as Logic[]).filter((_: any, idx: number) => idx !== logicIdx); - updateQuestion(questionIdx, { logic: newLogic }); + const updatedLogic = !question.logic ? [] : JSON.parse(JSON.stringify(question.logic)); + updatedLogic.splice(logicIdx, 1); + updateQuestion(questionIdx, { logic: updatedLogic }); }; const truncate = (str: string, n: number) => @@ -225,9 +225,7 @@ export default function LogicEditor({

If this answer

- updateLogic(logicIdx, { condition: e })}> @@ -246,9 +244,7 @@ export default function LogicEditor({ {logic.condition && logicConditions[logic.condition].values != null && (
{!logicConditions[logic.condition].multiSelect ? ( - updateLogic(logicIdx, { value: e })}> @@ -294,7 +290,7 @@ export default function LogicEditor({

skip to