Skip to content

Commit

Permalink
Finish building block search logic ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
Freymaurer committed Jan 24, 2024
1 parent a94e870 commit 16e62ac
Show file tree
Hide file tree
Showing 13 changed files with 420 additions and 708 deletions.
1 change: 0 additions & 1 deletion src/Client/Init.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ let initializeModel () =
PersistentStorageState = PersistentStorageState .init ()
DevState = DevState .init ()
TermSearchState = TermSearch.Model .init ()
AdvancedSearchState = AdvancedSearch.Model .init ()
ExcelState = OfficeInterop.Model .init ()
ApiState = ApiState .init ()
FilePickerState = FilePicker.Model .init ()
Expand Down
17 changes: 13 additions & 4 deletions src/Client/Messages.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ open OfficeInteropTypes
open Model
open Routing
open ARCtrl.ISA
open Fable.Core

type System.Exception with
member this.GetPropagatedError() =
Expand All @@ -36,6 +37,12 @@ module TermSearch =
| UpdateSelectedTerm of OntologyAnnotation option
| UpdateParentTerm of OntologyAnnotation option


module AdvancedSearch =

type Msg =
| GetSearchResults of {| config:AdvancedSearchTypes.AdvancedSearchOptions; responseSetter: Term [] -> unit |}

type DevMsg =
| LogTableMetadata
| GenericLog of Cmd<Messages.Msg> * (string*string)
Expand Down Expand Up @@ -81,9 +88,10 @@ module BuildingBlock =
open TermSearch

type Msg =
| SelectHeader of CompositeHeader
/// Returns all child terms
| SelectBodyCell of CompositeCell option
| UpdateHeaderCellType of BuildingBlock.HeaderCellType
| UpdateHeaderArg of U2<OntologyAnnotation,IOType> option
| UpdateBodyCellType of BuildingBlock.BodyCellType
| UpdateBodyArg of U2<string, OntologyAnnotation> option
// Below everything is more or less deprecated
// Is still used for unit update in office
| SearchUnitTermTextChange of searchString:string
Expand Down Expand Up @@ -131,7 +139,6 @@ type Model = {
DevState : DevState
///States regarding term search
TermSearchState : TermSearch.Model
AdvancedSearchState : AdvancedSearch.Model
///Use this in the future to model excel stuff like table data
ExcelState : OfficeInterop.Model
/// This should be removed. Overhead making maintainance more difficult
Expand Down Expand Up @@ -171,6 +178,7 @@ type Msg =
| Api of ApiMsg
| DevMsg of DevMsg
| TermSearchMsg of TermSearch.Msg
| AdvancedSearchMsg of AdvancedSearch.Msg
| OfficeInteropMsg of OfficeInterop.Msg
| PersistentStorage of PersistentStorageMsg
| FilePickerMsg of FilePicker.Msg
Expand All @@ -189,6 +197,7 @@ type Msg =
| UpdatePageState of Routing.Route option
| UpdateIsExpert of bool
| Batch of seq<Messages.Msg>
| Run of (unit -> unit)
| UpdateHistory of LocalHistory.Model
/// Top level msg to test specific api interactions, only for dev.
| TestMyAPI
Expand Down
103 changes: 77 additions & 26 deletions src/Client/Model.fs
Original file line number Diff line number Diff line change
Expand Up @@ -195,57 +195,90 @@ module FilePicker =
}

open OfficeInteropTypes
open Fable.Core

module BuildingBlock =

open ARCtrl.ISA

type [<RequireQualifiedAccess>] HeaderCellType =
| Component
| Characteristic
| Factor
| Parameter
| ProtocolType
| ProtocolDescription
| ProtocolUri
| ProtocolVersion
| ProtocolREF
| Performer
| Date
| Input
| Output
with
/// <summary>
/// Returns true if the Building Block is a term column
/// </summary>
member this.IsTermColumn() =
match this with
| Component
| Characteristic
| Factor
| Parameter
| ProtocolType -> true
| _ -> false
member this.HasOA() =
match this with
| Component
| Characteristic
| Factor
| Parameter -> true
| _ -> false

member this.HasIOType() =
match this with
| Input
| Output -> true
| _ -> false

type [<RequireQualifiedAccess>] BodyCellType =
| Term
| Unitized
| Text

[<RequireQualifiedAccess>]
type DropdownPage =
| Main
| More
| IOTypes of ((IOType -> CompositeHeader)*string)
| IOTypes of HeaderCellType

member this.toString =
match this with
| Main -> "Main Page"
| More -> "More"
| IOTypes (_,name) -> name
| IOTypes (t) -> t.ToString()

member this.toTooltip =
match this with
| More -> "More"
| IOTypes (_,name) -> $"Per table only one {name} is allowed. The value of this column must be a unique identifier."
| IOTypes (t) -> $"Per table only one {t} is allowed. The value of this column must be a unique identifier."
| _ -> ""

type [<RequireQualifiedAccess>] BodyCellType =
| Term
| Unitized
| Text

type BuildingBlockUIState = {
DropdownIsActive : bool
DropdownPage : DropdownPage
BodyCellType : BodyCellType
} with
static member init() = {
DropdownIsActive = false
DropdownPage = DropdownPage.Main
BodyCellType = BodyCellType.Term
}

type Model = {

Header : CompositeHeader
BodyCell : CompositeCell option
/// This can refer to directly inserted terms as values for the body or to unit terms applied to all body cells.
HeaderSearchText : string
/// This always referrs to any term applied to the header.
HeaderSearchResults : Term []
/// This always referrs to any term applied to the header.
BodySearchText : string
/// This can refer to directly inserted terms as values for the body or to unit terms applied to all body cells.
BodySearchResults : Term []
HeaderCellType : HeaderCellType
HeaderArg : U2<OntologyAnnotation,IOType> option
BodyCellType : BodyCellType
BodyArg : U2<string, OntologyAnnotation> option

// Below everything is more or less deprecated
// This section is used to add a unit directly to an already existing building block
Expand All @@ -258,12 +291,10 @@ module BuildingBlock =
} with
static member init () = {

HeaderSearchText = ""
HeaderSearchResults = [||]
Header = CompositeHeader.ParameterEmpty
BodySearchText = ""
BodySearchResults = [||]
BodyCell = None
HeaderCellType = HeaderCellType.Parameter
HeaderArg = None
BodyCellType = BodyCellType.Term
BodyArg = None

// Below everything is more or less deprecated
// This section is used to add a unit directly to an already existing building block
Expand All @@ -274,6 +305,26 @@ module BuildingBlock =
HasUnit2TermSuggestionsLoading = false
}

member this.TryHeaderOA() =
match this.HeaderArg with
| Some (U2.Case1 oa) -> Some oa
| _ -> None

member this.TryHeaderIO() =
match this.HeaderArg with
| Some (U2.Case2 io) -> Some io
| _ -> None

member this.TryBodyOA() =
match this.BodyArg with
| Some (U2.Case2 oa) -> Some oa
| _ -> None

member this.TryBodyString() =
match this.BodyArg with
| Some (U2.Case1 s) -> Some s
| _ -> None

/// Validation scheme for Table
module Validation =
type Model = {
Expand Down
26 changes: 22 additions & 4 deletions src/Client/Pages/BuildingBlock/BuildingBlockView.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,29 @@ open Elmish

let update (addBuildingBlockMsg:BuildingBlock.Msg) (state: BuildingBlock.Model) : BuildingBlock.Model * Cmd<Messages.Msg> =
match addBuildingBlockMsg with
| SelectHeader header ->
let nextState = { state with Header = header }
| UpdateBodyArg next ->
let nextState = { state with BodyArg = next }
nextState, Cmd.none
| SelectBodyCell (cell) ->
let nextState = { state with BodyCell = cell}
| UpdateHeaderArg next ->
let nextState = { state with HeaderArg = next}
nextState, Cmd.none
| UpdateHeaderCellType next ->
let nextState =
if Helper.isSameMajorHeaderCellType state.HeaderCellType next then
{ state with
HeaderCellType = next
}
else
let nextBodyCellType = if next.IsTermColumn() then BuildingBlock.BodyCellType.Term else BuildingBlock.BodyCellType.Text
{ state with
HeaderCellType = next
BodyCellType = nextBodyCellType
HeaderArg = None
BodyArg = None
}
nextState, Cmd.none
| UpdateBodyCellType next ->
let nextState = { state with BodyCellType = next }
nextState, Cmd.none

| SearchUnitTermTextChange (newTerm) ->
Expand Down
Loading

0 comments on commit 16e62ac

Please sign in to comment.