Skip to content

Commit

Permalink
Fix edit column default issue #521
Browse files Browse the repository at this point in the history
  • Loading branch information
Freymaurer committed Oct 28, 2024
1 parent d05b563 commit cfe983e
Show file tree
Hide file tree
Showing 10 changed files with 190 additions and 165 deletions.
6 changes: 3 additions & 3 deletions src/Client/Messages.fs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ module BuildingBlock =
open TermSearch

type Msg =
| UpdateHeaderWithIO of BuildingBlock.HeaderCellType * IOType
| UpdateHeaderCellType of BuildingBlock.HeaderCellType
| UpdateHeaderWithIO of CompositeHeaderDiscriminate * IOType
| UpdateHeaderCellType of CompositeHeaderDiscriminate
| UpdateHeaderArg of U2<OntologyAnnotation,IOType> option
| UpdateBodyCellType of BuildingBlock.BodyCellType
| UpdateBodyCellType of CompositeCellDiscriminate
| UpdateBodyArg of U2<string, OntologyAnnotation> option

module Protocol =
Expand Down
74 changes: 38 additions & 36 deletions src/Client/Modals/EditColumn.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ open ARCtrl

type private State =
{
NextHeaderType: BuildingBlock.HeaderCellType option
NextHeaderType: CompositeHeaderDiscriminate option
NextIOType: IOType option
} with
static member init() = {
Expand All @@ -37,33 +37,34 @@ module private EditColumnComponents =
prop.onClick submit
]

let SelectHeaderTypeOption(headerType: BuildingBlock.HeaderCellType) =
let SelectHeaderTypeOption(headerType: CompositeHeaderDiscriminate) =
let txt = headerType.ToString()
Html.option [
prop.value txt
prop.text txt
]

let SelectHeaderType(state, setState) =
let SelectHeaderType(header, state, setState) =
Bulma.select [
prop.onChange (fun (e: string) -> {state with NextHeaderType = Some (BuildingBlock.HeaderCellType.fromString e)} |> setState )
prop.value (header.ToString())
prop.onChange (fun (e: string) -> {state with NextHeaderType = Some (CompositeHeaderDiscriminate.fromString e)} |> setState )
prop.children [
// -- term columns --
SelectHeaderTypeOption BuildingBlock.HeaderCellType.Characteristic
SelectHeaderTypeOption BuildingBlock.HeaderCellType.Component
SelectHeaderTypeOption BuildingBlock.HeaderCellType.Factor
SelectHeaderTypeOption BuildingBlock.HeaderCellType.Parameter
SelectHeaderTypeOption CompositeHeaderDiscriminate.Characteristic
SelectHeaderTypeOption CompositeHeaderDiscriminate.Component
SelectHeaderTypeOption CompositeHeaderDiscriminate.Factor
SelectHeaderTypeOption CompositeHeaderDiscriminate.Parameter
// -- io columns --
SelectHeaderTypeOption BuildingBlock.HeaderCellType.Input
SelectHeaderTypeOption BuildingBlock.HeaderCellType.Output
SelectHeaderTypeOption CompositeHeaderDiscriminate.Input
SelectHeaderTypeOption CompositeHeaderDiscriminate.Output
// -- single columns --
SelectHeaderTypeOption BuildingBlock.HeaderCellType.Date
SelectHeaderTypeOption BuildingBlock.HeaderCellType.Performer
SelectHeaderTypeOption BuildingBlock.HeaderCellType.ProtocolDescription
SelectHeaderTypeOption BuildingBlock.HeaderCellType.ProtocolREF
SelectHeaderTypeOption BuildingBlock.HeaderCellType.ProtocolType
SelectHeaderTypeOption BuildingBlock.HeaderCellType.ProtocolUri
SelectHeaderTypeOption BuildingBlock.HeaderCellType.ProtocolVersion
SelectHeaderTypeOption CompositeHeaderDiscriminate.Date
SelectHeaderTypeOption CompositeHeaderDiscriminate.Performer
SelectHeaderTypeOption CompositeHeaderDiscriminate.ProtocolDescription
SelectHeaderTypeOption CompositeHeaderDiscriminate.ProtocolREF
SelectHeaderTypeOption CompositeHeaderDiscriminate.ProtocolType
SelectHeaderTypeOption CompositeHeaderDiscriminate.ProtocolUri
SelectHeaderTypeOption CompositeHeaderDiscriminate.ProtocolVersion
]
]

Expand Down Expand Up @@ -136,43 +137,44 @@ let Main (columnIndex: int) (model: Model) (dispatch) (rmv: _ -> unit) =
match state.NextHeaderType, state.NextIOType with
| None, _ -> column
// -- term columns --
| Some BuildingBlock.HeaderCellType.Characteristic, _ ->
| Some CompositeHeaderDiscriminate.Characteristic, _ ->
CompositeColumn.create(CompositeHeader.Characteristic (header.ToTerm()), cellsToTermCells(column))
| Some BuildingBlock.HeaderCellType.Parameter, _ ->
| Some CompositeHeaderDiscriminate.Parameter, _ ->
CompositeColumn.create(CompositeHeader.Parameter (header.ToTerm()), cellsToTermCells(column))
| Some BuildingBlock.HeaderCellType.Component, _ ->
| Some CompositeHeaderDiscriminate.Component, _ ->
CompositeColumn.create(CompositeHeader.Component (header.ToTerm()), cellsToTermCells(column))
| Some BuildingBlock.HeaderCellType.Factor, _ ->
| Some CompositeHeaderDiscriminate.Factor, _ ->
CompositeColumn.create(CompositeHeader.Factor (header.ToTerm()), cellsToTermCells(column))
// -- input columns --
| Some BuildingBlock.HeaderCellType.Input, Some IOType.Data ->
| Some CompositeHeaderDiscriminate.Input, Some IOType.Data ->
CompositeColumn.create(CompositeHeader.Input IOType.Data, cellsToDataOrFreeText(column))
| Some BuildingBlock.HeaderCellType.Input, Some io ->
| Some CompositeHeaderDiscriminate.Input, Some io ->
CompositeColumn.create(CompositeHeader.Input io, cellsToFreeText(column))
| Some BuildingBlock.HeaderCellType.Input, None ->
| Some CompositeHeaderDiscriminate.Input, None ->
CompositeColumn.create(CompositeHeader.Input IOType.Sample, cellsToFreeText(column))
// -- output columns --
| Some BuildingBlock.HeaderCellType.Output, Some IOType.Data ->
| Some CompositeHeaderDiscriminate.Output, Some IOType.Data ->
CompositeColumn.create(CompositeHeader.Output IOType.Data, cellsToDataOrFreeText(column))
| Some BuildingBlock.HeaderCellType.Output, Some io ->
| Some CompositeHeaderDiscriminate.Output, Some io ->
CompositeColumn.create(CompositeHeader.Output io, cellsToFreeText(column))
| Some BuildingBlock.HeaderCellType.Output, None ->
| Some CompositeHeaderDiscriminate.Output, None ->
CompositeColumn.create(CompositeHeader.Output IOType.Sample, cellsToFreeText(column))
// -- single columns --
| Some BuildingBlock.HeaderCellType.ProtocolREF, _ ->
| Some CompositeHeaderDiscriminate.ProtocolREF, _ ->
CompositeColumn.create(CompositeHeader.ProtocolREF, cellsToFreeText(column))
| Some BuildingBlock.HeaderCellType.Date, _ ->
| Some CompositeHeaderDiscriminate.Date, _ ->
CompositeColumn.create(CompositeHeader.Date, cellsToFreeText(column))
| Some BuildingBlock.HeaderCellType.Performer, _ ->
| Some CompositeHeaderDiscriminate.Performer, _ ->
CompositeColumn.create(CompositeHeader.Performer, cellsToFreeText(column))
| Some BuildingBlock.HeaderCellType.ProtocolDescription, _ ->
| Some CompositeHeaderDiscriminate.ProtocolDescription, _ ->
CompositeColumn.create(CompositeHeader.ProtocolDescription, cellsToFreeText(column))
| Some BuildingBlock.HeaderCellType.ProtocolType, _ ->
| Some CompositeHeaderDiscriminate.ProtocolType, _ ->
CompositeColumn.create(CompositeHeader.ProtocolType, cellsToTermCells(column))
| Some BuildingBlock.HeaderCellType.ProtocolUri, _ ->
| Some CompositeHeaderDiscriminate.ProtocolUri, _ ->
CompositeColumn.create(CompositeHeader.ProtocolUri, cellsToFreeText(column))
| Some BuildingBlock.HeaderCellType.ProtocolVersion, _ ->
| Some CompositeHeaderDiscriminate.ProtocolVersion, _ ->
CompositeColumn.create(CompositeHeader.ProtocolVersion, cellsToFreeText(column))
| Some CompositeHeaderDiscriminate.Comment, _ -> failwith "Comment header type is not yet implemented"
let submit (e) =
let nxtCol = updateColumn column0
Spreadsheet.SetColumn (columnIndex, nxtCol) |> SpreadsheetMsg |> dispatch
Expand All @@ -196,9 +198,9 @@ let Main (columnIndex: int) (model: Model) (dispatch) (rmv: _ -> unit) =
Bulma.field.div [
Bulma.buttons [
prop.children [
SelectHeaderType(state, setState)
SelectHeaderType(column0.Header.AsDiscriminate, state, setState)
match state.NextHeaderType with
| Some BuildingBlock.HeaderCellType.Output | Some BuildingBlock.HeaderCellType.Input ->
| Some CompositeHeaderDiscriminate.Output | Some CompositeHeaderDiscriminate.Input ->
SelectIOType(state, setState)
| _ -> Html.none
]
Expand Down
77 changes: 6 additions & 71 deletions src/Client/Model.fs
Original file line number Diff line number Diff line change
Expand Up @@ -181,78 +181,13 @@ open Fable.Core
module BuildingBlock =

open ARCtrl

[<RequireQualifiedAccess>]
type 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

static member fromString(str: string) =
match str with
| "Component" -> Component
| "Characteristic" -> Characteristic
| "Factor" -> Factor
| "Parameter" -> Parameter
| "ProtocolType" -> ProtocolType
| "ProtocolDescription" -> ProtocolDescription
| "ProtocolUri" -> ProtocolUri
| "ProtocolVersion" -> ProtocolVersion
| "ProtocolREF" -> ProtocolREF
| "Performer" -> Performer
| "Date" -> Date
| "Input" -> Input
| "Output" -> Output
| anyElse -> failwithf "BuildingBlock.HeaderCellType.fromString: '%s' is not a valid HeaderCellType" anyElse


[<RequireQualifiedAccess>]
type BodyCellType =
| Term
| Unitized
| Text
| Data
open ARCtrl.Helper

[<RequireQualifiedAccess>]
type DropdownPage =
| Main
| More
| IOTypes of HeaderCellType
| IOTypes of CompositeHeaderDiscriminate

member this.toString =
match this with
Expand All @@ -277,17 +212,17 @@ module BuildingBlock =

type Model = {

HeaderCellType : HeaderCellType
HeaderCellType : CompositeHeaderDiscriminate
HeaderArg : U2<OntologyAnnotation,IOType> option
BodyCellType : BodyCellType
BodyCellType : CompositeCellDiscriminate
BodyArg : U2<string, OntologyAnnotation> option

} with
static member init () = {

HeaderCellType = HeaderCellType.Parameter
HeaderCellType = CompositeHeaderDiscriminate.Parameter
HeaderArg = None
BodyCellType = BodyCellType.Term
BodyCellType = CompositeCellDiscriminate.Term
BodyArg = None
}

Expand Down
7 changes: 4 additions & 3 deletions src/Client/Pages/BuildingBlock/BuildingBlockView.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module BuildingBlock.Core
open Model
open Messages
open Messages.BuildingBlock
open Shared

open Elmish

Expand All @@ -16,12 +17,12 @@ let update (addBuildingBlockMsg:BuildingBlock.Msg) (state: BuildingBlock.Model)
nextState, Cmd.none
| UpdateHeaderCellType next ->
let nextState =
if Helper.isSameMajorHeaderCellType state.HeaderCellType next then
if Helper.isSameMajorCompositeHeaderDiscriminate state.HeaderCellType next then
{ state with
HeaderCellType = next
}
else
let nextBodyCellType = if next.IsTermColumn() then BuildingBlock.BodyCellType.Term else BuildingBlock.BodyCellType.Text
let nextBodyCellType = if next.IsTermColumn() then CompositeCellDiscriminate.Term else CompositeCellDiscriminate.Text
{ state with
HeaderCellType = next
BodyCellType = nextBodyCellType
Expand All @@ -35,7 +36,7 @@ let update (addBuildingBlockMsg:BuildingBlock.Msg) (state: BuildingBlock.Model)
HeaderCellType = hct
HeaderArg = Some (Fable.Core.U2.Case2 iotype)
BodyArg = None
BodyCellType = BuildingBlock.BodyCellType.Text
BodyCellType = CompositeCellDiscriminate.Text
}
nextState, Cmd.none
| UpdateBodyCellType next ->
Expand Down
24 changes: 13 additions & 11 deletions src/Client/Pages/BuildingBlock/CellConvertComponent.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ open Feliz
open Feliz.Bulma

open OfficeInterop.Core
open Shared
open ARCtrl.Helper

module private CellConvertComponentHelpers =

let getSelectedCellType (setState: Model.BuildingBlock.BodyCellType option -> unit) =
let getSelectedCellType (setState: CompositeCellDiscriminate option -> unit) =
promise {
//Write function to access current header state of excel

Expand All @@ -17,30 +19,30 @@ module private CellConvertComponentHelpers =
match mainColumn with
| Some column when column.Header.isInput -> None
| Some column when column.Header.isOutput -> None
| Some column when column.Cells.[0].isUnitized -> Model.BuildingBlock.BodyCellType.Unitized |> Some
| Some column when column.Cells.[0].isTerm -> Model.BuildingBlock.BodyCellType.Term |> Some
| Some column when column.Cells.[0].isFreeText -> Model.BuildingBlock.BodyCellType.Text |> Some
| Some column when column.Cells.[0].isData -> Model.BuildingBlock.BodyCellType.Data |> Some
| Some column when column.Cells.[0].isUnitized -> CompositeCellDiscriminate.Unitized |> Some
| Some column when column.Cells.[0].isTerm -> CompositeCellDiscriminate.Term |> Some
| Some column when column.Cells.[0].isFreeText -> CompositeCellDiscriminate.Text |> Some
| Some column when column.Cells.[0].isData -> CompositeCellDiscriminate.Data |> Some
| _ -> None

setState result
}

let getTargetConversionType (cellType: Model.BuildingBlock.BodyCellType option) =
let getTargetConversionType (cellType: CompositeCellDiscriminate option) =
if cellType.IsSome then
match cellType.Value with
| Model.BuildingBlock.BodyCellType.Unitized -> Model.BuildingBlock.BodyCellType.Term |> Some
| Model.BuildingBlock.BodyCellType.Term -> Model.BuildingBlock.BodyCellType.Unitized |> Some
| Model.BuildingBlock.BodyCellType.Text -> Model.BuildingBlock.BodyCellType.Data |> Some
| Model.BuildingBlock.BodyCellType.Data -> Model.BuildingBlock.BodyCellType.Text |> Some
| CompositeCellDiscriminate.Unitized -> CompositeCellDiscriminate.Term |> Some
| CompositeCellDiscriminate.Term -> CompositeCellDiscriminate.Unitized |> Some
| CompositeCellDiscriminate.Text -> CompositeCellDiscriminate.Data |> Some
| CompositeCellDiscriminate.Data -> CompositeCellDiscriminate.Text |> Some
else None

type CellConvertComponent =

[<ReactComponent>]
static member Main () =

let (state: Model.BuildingBlock.BodyCellType option), setState = React.useState(None)
let (state: CompositeCellDiscriminate option), setState = React.useState(None)

React.useEffectOnce(fun () ->
CellConvertComponentHelpers.getSelectedCellType setState
Expand Down
Loading

0 comments on commit cfe983e

Please sign in to comment.