Skip to content

Commit b352578

Browse files
committed
Fix replies in KM preview
1 parent 55a5377 commit b352578

File tree

2 files changed

+11
-37
lines changed

2 files changed

+11
-37
lines changed

engine-shared/elm/Shared/Data/QuestionnaireQuestionnaire.elm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ generateReplies currentTime seed questionUuid km questionnaireDetail =
803803
foldReplies currentTime km parentMap seed questionUuid Dict.empty
804804

805805
reply =
806-
findReplyBySuffix questionUuid replies
806+
findReplyBySuffix questionUuid questionnaireDetail.replies
807807

808808
newReplies =
809809
if Maybe.isJust reply then

engine-wizard/elm/Wizard/KMEditor/Editor/Update.elm

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import Shared.Api.Branches as BranchesApi
1414
import Shared.Api.Prefabs as PrefabsApi
1515
import Shared.Data.Branch.BranchState as BranchState
1616
import Shared.Data.Event as Event
17-
import Shared.Data.QuestionnaireDetail.Reply.ReplyValue exposing (ReplyValue(..))
1817
import Shared.Data.WebSockets.BranchAction.SetContentBranchAction as SetContentBranchAction exposing (SetContentBranchAction)
1918
import Shared.Data.WebSockets.ClientBranchAction as ClientBranchAction
2019
import Shared.Data.WebSockets.ServerBranchAction as ServerBranchAction
@@ -75,47 +74,22 @@ fetchSubrouteData appState model =
7574

7675
KMEditorRoute (EditorRoute _ KMEditorRoute.Preview) ->
7776
let
78-
mbScrollPath =
79-
Dict.keys model.previewModel.questionnaireModel.questionnaire.replies
80-
|> List.sortBy String.length
81-
|> List.reverse
82-
|> List.head
83-
8477
mbActiveQuestionUuid =
8578
ActionResult.toMaybe model.branchModel
8679
|> Maybe.map EditorBranch.getActiveQuestionUuid
87-
88-
scrollIntoView parts =
89-
Ports.scrollIntoView ("[data-path=\"" ++ String.join "." parts ++ "\"]")
9080
in
91-
case ( mbScrollPath, mbActiveQuestionUuid ) of
92-
-- Somewhere deep in the questionnaire
93-
( Just scrollPath, Just activeQuestionUuid ) ->
94-
let
95-
value =
96-
Dict.get scrollPath model.previewModel.questionnaireModel.questionnaire.replies
97-
98-
answerPathUuid =
99-
Maybe.withDefault "" <|
100-
case Maybe.map .value value of
101-
Just (AnswerReply answerUuid) ->
102-
Just answerUuid
103-
104-
Just (ItemListReply itemUuids) ->
105-
List.head itemUuids
106-
107-
_ ->
108-
Nothing
109-
in
110-
scrollIntoView [ scrollPath, answerPathUuid, activeQuestionUuid ]
111-
112-
-- Top level question in a chapter
113-
( Nothing, Just activeQuestionUuid ) ->
81+
case mbActiveQuestionUuid of
82+
Just activeQuestionUuid ->
11483
let
115-
chapterUuid =
116-
ActionResult.unwrap "" (EditorBranch.getChapterUuid activeQuestionUuid) model.branchModel
84+
scrollIntoView path =
85+
Ports.scrollIntoView ("[data-path=\"" ++ path ++ "\"]")
11786
in
118-
scrollIntoView [ chapterUuid, activeQuestionUuid ]
87+
-- 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
88+
model.previewModel.questionnaireModel.questionnaire.replies
89+
|> Dict.filter (\key _ -> String.endsWith activeQuestionUuid key)
90+
|> Dict.toList
91+
|> List.map (scrollIntoView << Tuple.first)
92+
|> Cmd.batch
11993

12094
_ ->
12195
Cmd.none

0 commit comments

Comments
 (0)