Skip to content

Commit

Permalink
Add the isAncestorOfFoundField function to expand the ancestors of th…
Browse files Browse the repository at this point in the history
…e found field.

This expands sometimes, but not always when expected. So maybe we need to find a way to update the SearchFoundId field in the model instead of in the unmodifiedModel. Maybe we need to use an inOutMsg.
  • Loading branch information
ScottHutchinson committed Sep 27, 2023
1 parent eb1b356 commit 37f3ff4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions NG-DART.StructFilters/Domain.fs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Model = {
MaxLevel: int
Search_Text: string
SearchEnterText: string
SearchFoundId: FieldId option
}
with
member this.ParentStruct = this.DummyRoot.Fields.Head
Expand Down
27 changes: 23 additions & 4 deletions NG-DART.StructFilters/StructFilters.fs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module App =
MaxLevel = 2
Search_Text = ""
SearchEnterText = ""
SearchFoundId = None
}

let mutable configFolderPath = ""
Expand Down Expand Up @@ -117,7 +118,8 @@ module App =
ExpandLevel = unmodifiedModel.ExpandLevel
MaxLevel = unmodifiedModel.MaxLevel
Search_Text = unmodifiedModel.Search_Text
SearchEnterText = ""
SearchEnterText = unmodifiedModel.SearchEnterText
SearchFoundId = unmodifiedModel.SearchFoundId
}
unmodifiedModel

Expand Down Expand Up @@ -151,8 +153,8 @@ module App =
| SetFilteringEnabled of isEnabled: bool
| SearchText of searchText: string
| SearchEnter
| SearchFoundMsg of foundFieldId: FieldId

let selectAncestorMsg fieldId msg = SelectAncestorMsg (fieldId, msg)
let outSelectChild isGmlSelected msg = OutSelectChild (isGmlSelected, msg)
let selectMsg isGmlSelected msg = SelectMsg (isGmlSelected, msg)

Expand Down Expand Up @@ -314,6 +316,8 @@ module App =
{ m with Search_Text = searchText }
| SearchEnter ->
{ m with SearchEnterText = m.Search_Text }
| SearchFoundMsg fldId ->
{ m with SearchFoundId = Some fldId }

let mapOutMsg = function
| OutSelectChild (isGmlSelected, msg) ->
Expand All @@ -339,6 +343,18 @@ module App =
else
caseInsensitiveContains fd.Type searchText || caseInsensitiveContains fd.Name searchText

let isAncestorOfFoundField (s: RoseTree<FieldData>) =
let rec loop (s: RoseTree<FieldData>) =
(false, s.Fields)
||> List.fold (fun isFldAncestor fld ->
match unmodifiedModel.SearchFoundId with
| Some foundId ->
fld.Data.Id = foundId
| None ->
loop fld
)
loop s

let rec fieldBindings level () =
if level > unmodifiedModel.MaxLevel then
unmodifiedModel <- { unmodifiedModel with MaxLevel = level }
Expand Down Expand Up @@ -376,13 +392,16 @@ module App =
getMenuItemHeader $"Clear all fields of {s.Data.Type} for GML")
"ContextCancel" |> Binding.cmd (LeafMsg ContextCancel)
"IsEnabled" |> Binding.oneWay(fun ((m: Model), _) -> not m.IsEmpty)
"IsExpanded" |> Binding.oneWay(fun ((m: Model), _) ->
level < m.ExpandLevel // TODO: || is an ancestor of the selected item found in a search
"IsExpanded" |> Binding.oneWay(fun ((m: Model), { Self = (s: RoseTree<FieldData>) }) ->
level < m.ExpandLevel || isAncestorOfFoundField s
)
"IsSelected" |> Binding.oneWay(fun ((m: Model), { Self = (s: RoseTree<FieldData>) }) ->
let isSelected = isFoundInSearch m.SearchEnterText s.Data
if isSelected then
// TODO: Send a SearchFoundMsg to update the model instead of the unmodifiedModel.
unmodifiedModel <- { unmodifiedModel with SearchFoundId = Some s.Data.Id }
Debug.WriteLine($"****** Name: {s.Data.Name}, Type: {s.Data.Type} selected")

isSelected
)

Expand Down

0 comments on commit 37f3ff4

Please sign in to comment.