Skip to content

Commit

Permalink
Fix correct forwarding of values to search fields in table cells #380
Browse files Browse the repository at this point in the history
  • Loading branch information
Freymaurer committed Feb 21, 2024
1 parent 7be0dc7 commit 418fb2f
Showing 1 changed file with 15 additions and 28 deletions.
43 changes: 15 additions & 28 deletions src/Client/MainComponents/Cells.fs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ module private CellComponents =
[<ReactComponent>]
let CellInputElement (isHeader: bool, isReadOnly: bool, updateMainStateTable: string -> unit, setState_cell, state_cell, cell_value, columnType) =
let ref = React.useElementRef()

React.useLayoutEffectOnce(fun _ -> ClickOutsideHandler.AddListener (ref, fun _ -> updateMainStateTable state_cell.Value))
let input =
Bulma.control.div [
Expand Down Expand Up @@ -102,29 +103,11 @@ module private CellComponents =
]
]
]
let switchToSearchButton =
Bulma.control.div [
Bulma.button.button [
prop.className "is-ghost"
prop.style [style.borderWidth 0; style.borderRadius 0]
prop.onClick(fun e ->
e.stopPropagation()
//setState_cell {state_cell with CellMode = Search}
)
prop.children [
Bulma.icon [Html.i [prop.className "fa-solid fa-search"]]
]
]
]
Bulma.field.div [
Bulma.field.hasAddons
prop.ref ref
prop.className "is-flex-grow-1 m-0"
prop.children [
input
if not isHeader && columnType = Main then
switchToSearchButton
]
prop.children [ input ]
]

let basicValueDisplayCell (v: string) =
Expand Down Expand Up @@ -193,6 +176,15 @@ module private CellAux =
|> Option.map header.UpdateWithOA
|> Option.iter (fun nextHeader -> Msg.UpdateHeader (columnIndex, nextHeader) |> SpreadsheetMsg |> dispatch)

let oasetter (index, cell: CompositeCell, dispatch) = fun (oa:OntologyAnnotation) ->
let nextCell =
if oa.TermSourceREF.IsNone && oa.TermAccessionNumber.IsNone then // update only mainfield, if mainfield is the only field with value
cell.UpdateMainField oa.NameText
else
cell.UpdateWithOA oa
Msg.UpdateCell (index, nextCell) |> SpreadsheetMsg |> dispatch


open CellComponents
open CellAux

Expand Down Expand Up @@ -379,14 +371,8 @@ type Cell =
let setter = fun (s: string) ->
let nextCell = cell.UpdateMainField s
Msg.UpdateCell (index, nextCell) |> SpreadsheetMsg |> dispatch
let oaSetter = fun (oa:OntologyAnnotation) ->
let nextCell =
if oa.TermSourceREF.IsNone && oa.TermAccessionNumber.IsNone then // update only mainfield, if mainfield is the only field with value
cell.UpdateMainField oa.NameText
else
cell.UpdateWithOA oa
Msg.UpdateCell (index, nextCell) |> SpreadsheetMsg |> dispatch
Cell.BodyBase(Main, cellValue, setter, index, cell, model, dispatch, oaSetter)
let oasetter = if cell.isTerm then CellAux.oasetter(index, cell, dispatch) |> Some else None
Cell.BodyBase(Main, cellValue, setter, index, cell, model, dispatch, ?oasetter=oasetter)

static member BodyUnit(index: (int*int), cell: CompositeCell, model: Model, dispatch) =
let cellValue = cell.GetContent().[1]
Expand All @@ -396,7 +382,8 @@ type Cell =
let nextOA = {oa with Name = newName }
let nextCell = cell.UpdateWithOA nextOA
Msg.UpdateCell (index, nextCell) |> SpreadsheetMsg |> dispatch
Cell.BodyBase(Unit, cellValue, setter, index, cell, model, dispatch)
let oasetter = if cell.isUnitized then CellAux.oasetter(index, cell, dispatch) |> Some else None
Cell.BodyBase(Unit, cellValue, setter, index, cell, model, dispatch, ?oasetter=oasetter)

static member BodyTSR(index: (int*int), cell: CompositeCell, model: Model, dispatch) =
let contentIndex = if cell.isUnitized then 2 else 1
Expand Down

0 comments on commit 418fb2f

Please sign in to comment.