From b352578427127ab7157b0a7894df2fb801398320 Mon Sep 17 00:00:00 2001 From: Jan Slifka Date: Mon, 27 Jan 2025 17:32:17 +0100 Subject: [PATCH] Fix replies in KM preview --- .../Data/QuestionnaireQuestionnaire.elm | 2 +- .../elm/Wizard/KMEditor/Editor/Update.elm | 46 ++++--------------- 2 files changed, 11 insertions(+), 37 deletions(-) diff --git a/engine-shared/elm/Shared/Data/QuestionnaireQuestionnaire.elm b/engine-shared/elm/Shared/Data/QuestionnaireQuestionnaire.elm index 5bcf1b8a3..5da2a1103 100644 --- a/engine-shared/elm/Shared/Data/QuestionnaireQuestionnaire.elm +++ b/engine-shared/elm/Shared/Data/QuestionnaireQuestionnaire.elm @@ -803,7 +803,7 @@ generateReplies currentTime seed questionUuid km questionnaireDetail = foldReplies currentTime km parentMap seed questionUuid Dict.empty reply = - findReplyBySuffix questionUuid replies + findReplyBySuffix questionUuid questionnaireDetail.replies newReplies = if Maybe.isJust reply then diff --git a/engine-wizard/elm/Wizard/KMEditor/Editor/Update.elm b/engine-wizard/elm/Wizard/KMEditor/Editor/Update.elm index a6b0f430d..c5f1a867f 100644 --- a/engine-wizard/elm/Wizard/KMEditor/Editor/Update.elm +++ b/engine-wizard/elm/Wizard/KMEditor/Editor/Update.elm @@ -14,7 +14,6 @@ import Shared.Api.Branches as BranchesApi import Shared.Api.Prefabs as PrefabsApi import Shared.Data.Branch.BranchState as BranchState import Shared.Data.Event as Event -import Shared.Data.QuestionnaireDetail.Reply.ReplyValue exposing (ReplyValue(..)) import Shared.Data.WebSockets.BranchAction.SetContentBranchAction as SetContentBranchAction exposing (SetContentBranchAction) import Shared.Data.WebSockets.ClientBranchAction as ClientBranchAction import Shared.Data.WebSockets.ServerBranchAction as ServerBranchAction @@ -75,47 +74,22 @@ fetchSubrouteData appState model = KMEditorRoute (EditorRoute _ KMEditorRoute.Preview) -> let - mbScrollPath = - Dict.keys model.previewModel.questionnaireModel.questionnaire.replies - |> List.sortBy String.length - |> List.reverse - |> List.head - mbActiveQuestionUuid = ActionResult.toMaybe model.branchModel |> Maybe.map EditorBranch.getActiveQuestionUuid - - scrollIntoView parts = - Ports.scrollIntoView ("[data-path=\"" ++ String.join "." parts ++ "\"]") in - case ( mbScrollPath, mbActiveQuestionUuid ) of - -- Somewhere deep in the questionnaire - ( Just scrollPath, Just activeQuestionUuid ) -> - let - value = - Dict.get scrollPath model.previewModel.questionnaireModel.questionnaire.replies - - answerPathUuid = - Maybe.withDefault "" <| - case Maybe.map .value value of - Just (AnswerReply answerUuid) -> - Just answerUuid - - Just (ItemListReply itemUuids) -> - List.head itemUuids - - _ -> - Nothing - in - scrollIntoView [ scrollPath, answerPathUuid, activeQuestionUuid ] - - -- Top level question in a chapter - ( Nothing, Just activeQuestionUuid ) -> + case mbActiveQuestionUuid of + Just activeQuestionUuid -> let - chapterUuid = - ActionResult.unwrap "" (EditorBranch.getChapterUuid activeQuestionUuid) model.branchModel + scrollIntoView path = + Ports.scrollIntoView ("[data-path=\"" ++ path ++ "\"]") in - scrollIntoView [ chapterUuid, activeQuestionUuid ] + -- TODO: There might be replies that are no longer accessible but there is no cleaning of replies in preview values now, so we just try to scroll them all + model.previewModel.questionnaireModel.questionnaire.replies + |> Dict.filter (\key _ -> String.endsWith activeQuestionUuid key) + |> Dict.toList + |> List.map (scrollIntoView << Tuple.first) + |> Cmd.batch _ -> Cmd.none