Skip to content

Commit

Permalink
Merge pull request #574 from nfdi4plants/Feature_AddColumnParentInfoT…
Browse files Browse the repository at this point in the history
…oOntologySearch

Add parent information for ontology search on click in search field
  • Loading branch information
Freymaurer authored Nov 19, 2024
2 parents 14c0447 + 61a7364 commit 1a63b90
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
28 changes: 28 additions & 0 deletions src/Client/OfficeInterop/OfficeInterop.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2385,6 +2385,34 @@ type Main =
}
)

static member getParentTerm (?table: Excel.Table, ?context: RequestContext) =
excelRunWith context <| fun context ->
promise {

let! excelTable =
match table with
| Some table -> promise {return Some table}
| None -> AnnotationTable.tryGetActive context

if excelTable.IsNone then failwith "Error. No active table found!"

let excelTable = excelTable.Value

let! arcTableRes = ArcTable.fromExcelTable(excelTable, context)

match arcTableRes with
| Ok arcTable ->
let selectedRange = context.workbook.getSelectedRange().load(U2.Case2 (ResizeArray[|"rowIndex"|]))
let! (_, arcIndex) = getArcMainColumn excelTable arcTable context
let rowIndex = selectedRange.rowIndex

let parent = arcTable.GetColumn(arcIndex).Header.TryOA()

return parent

| Result.Error exn -> return None
}

/// <summary>
/// Handle any diverging functionality here. This function is also used to make sure any new building blocks comply to the swate annotation-table definition
/// </summary>
Expand Down
14 changes: 13 additions & 1 deletion src/Client/Pages/TermSearch/TermSearchView.fs
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,25 @@ let private addButton (model: Model, dispatch) =
[<ReactComponent>]
let Main (model:Model, dispatch) =
let setTerm = fun (term: OntologyAnnotation option) -> TermSearch.UpdateSelectedTerm term |> TermSearchMsg |> dispatch

let excelGetParentTerm =
match model.PersistentStorageState.Host with
| Some Swatehost.Excel ->
fun _ ->
promise {
let! parent = OfficeInterop.Core.Main.getParentTerm()
TermSearch.UpdateParentTerm parent |> TermSearchMsg |> dispatch
}
|> Some
| _ -> None

SidebarComponents.SidebarLayout.Container [
SidebarComponents.SidebarLayout.Header "Ontology term search"

SidebarComponents.SidebarLayout.Description "Search for an ontology term to fill into the selected field(s)"

SidebarComponents.SidebarLayout.LogicContainer [
Components.TermSearch.Input(setTerm, fullwidth=true, ?parent=model.TermSearchState.ParentTerm, advancedSearchDispatch=dispatch)
Components.TermSearch.Input(setTerm, fullwidth=true, ?parent=model.TermSearchState.ParentTerm, advancedSearchDispatch=dispatch, ?onFocus=excelGetParentTerm, autofocus=true)
addButton(model, dispatch)
]
]
19 changes: 17 additions & 2 deletions src/Client/SharedComponents/TermSearchInput.fs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ type TermSearch =
?isSearchable: bool,
?advancedSearchDispatch: Messages.Msg -> unit,
?portalTermSelectArea: HTMLElement,
?onBlur: Event -> unit, ?onEscape: KeyboardEvent -> unit, ?onEnter: KeyboardEvent -> unit,
?onBlur: Event -> unit, ?onEscape: KeyboardEvent -> unit, ?onEnter: KeyboardEvent -> unit, ?onFocus: FocusEvent -> Fable.Core.JS.Promise<unit>,
?autofocus: bool, ?fullwidth: bool, ?isjoin: bool, ?displayParent: bool, ?classes: string)
=
let isjoin = defaultArg isjoin false
Expand Down Expand Up @@ -324,6 +324,11 @@ type TermSearch =
let registerChange(searchTest: string option) =
let oa = searchTest |> Option.map (fun x -> OntologyAnnotation x)
debouncel debounceStorage.current "SetterDebounce" 500 setLoading setter oa
React.useLayoutEffect((
fun _ ->
if autofocus && inputRef.current.IsSome then
inputRef.current.Value.focus()
), [|box parent|])
Daisy.formControl [
prop.className "w-full"
prop.children [
Expand All @@ -344,7 +349,17 @@ type TermSearch =
prop.autoFocus autofocus
if input.IsSome then prop.valueOrDefault input.Value.NameText
prop.ref inputRef
prop.onMouseDown(fun e -> e.stopPropagation())
prop.onMouseDown(fun e ->
e.stopPropagation()
)
if onFocus.IsSome then
prop.onFocus(fun fe ->
promise {
do! onFocus.Value fe
inputRef.current.Value.focus()
}
|> Promise.start
)
prop.onDoubleClick(fun e ->
let s : string = e.target?value
if s.Trim() = "" && parent.IsSome && parent.Value.TermAccessionShort <> "" then // trigger get all by parent search
Expand Down
2 changes: 1 addition & 1 deletion src/Client/SidebarComponents/Navbar.fs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ let SelectModalDialog (closeModal: unit -> unit) model (dispatch: Messages.Msg -
setExcelMetadataType (ExcelMetadataState.init())
let! result = OfficeInterop.Core.Main.tryParseToArcFile(getTables=false)
match result with
| Result.Ok (arcFile) ->
| Result.Ok arcFile ->
setExcelMetadataType {
excelMetadataType with
Loading = false
Expand Down

0 comments on commit 1a63b90

Please sign in to comment.