Skip to content

Commit

Permalink
Fix replies in KM preview
Browse files Browse the repository at this point in the history
  • Loading branch information
janslifka committed Jan 27, 2025
1 parent 55a5377 commit b352578
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 10 additions & 36 deletions engine-wizard/elm/Wizard/KMEditor/Editor/Update.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b352578

Please sign in to comment.