Skip to content

Commit

Permalink
Enable naming of radioGroup to enable usage in swate alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
Etschbeijer committed Dec 4, 2024
1 parent 9cf7d21 commit 95dcf24
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
39 changes: 36 additions & 3 deletions src/Client/MainComponents/Widgets.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ open Browser.Types
open LocalStorage.Widgets
open Modals
open Types.TableImport
open Types.JsonImport

module private InitExtensions =

Expand Down Expand Up @@ -213,9 +214,13 @@ type Widget =
[<ReactComponent>]
static member Templates (model: Model, dispatch, rmv: MouseEvent -> unit) =
let templates, setTemplates = React.useState(model.ProtocolState.Templates)
let selectedColumnsLength = if model.ProtocolState.TemplateSelected.IsSome then model.ProtocolState.TemplateSelected.Value.Table.Columns.Length else 0
let selectedColumns, setSelectedColumns = React.useState(SelectedColumns.init selectedColumnsLength)
let config, setConfig = React.useState(TemplateFilterConfig.init)
let selectedColumnsLength =
if model.ProtocolState.TemplateSelected.IsSome then
model.ProtocolState.TemplateSelected.Value.Table.Columns.Length
else 0
let selectedColumns, setSelectedColumns = React.useState(SelectedColumns.init selectedColumnsLength)
let importTypeState, setImportTypeState = React.useState(SelectiveImportModalState.init)
let filteredTemplates = Protocol.Search.filterTemplates (templates, config)
React.useEffectOnce(fun _ -> Messages.Protocol.GetAllProtocolsRequest |> Messages.ProtocolMsg |> dispatch)
React.useEffect((fun _ -> setTemplates model.ProtocolState.Templates), [|box model.ProtocolState.Templates|])
Expand All @@ -229,7 +234,35 @@ type Widget =
Html.div [
prop.style [style.maxHeight (length.px 350); style.overflow.auto]
prop.children [
SelectiveTemplateFromDBModal.Main(model, dispatch)
SidebarComponents.SidebarLayout.LogicContainer [
Html.div [
SelectiveTemplateFromDBModal.ToProtocolSearchElement model dispatch
]
if model.ProtocolState.TemplateSelected.IsSome then
Html.div [
SelectiveImportModal.RadioPluginsBox(
"Import Type",
"fa-solid fa-cog",
importTypeState.ImportType,
"importType ",
[|
ARCtrl.TableJoinOptions.Headers, " Column Headers";
ARCtrl.TableJoinOptions.WithUnit, " ..With Units";
ARCtrl.TableJoinOptions.WithValues, " ..With Values";
|],
fun importType -> {importTypeState with ImportType = importType} |> setImportTypeState
)
]
Html.div [
ModalElements.Box(
model.ProtocolState.TemplateSelected.Value.Name,
"",
SelectiveTemplateFromDBModal.displaySelectedProtocolElements(model, selectedColumns, setSelectedColumns, dispatch, false))
]
Html.div [
SelectiveTemplateFromDBModal.AddFromDBToTableButton model selectedColumns importTypeState dispatch
]
]
]
]
]
Expand Down
2 changes: 1 addition & 1 deletion src/Client/Modals/ModalElements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type ModalElements =
prop.text text
]

static member RadioPlugin(radioGroup: string, txt:string, isChecked, onChange: bool -> unit, ?isDisabled: bool) =
static member RadioPlugin(radioGroup: string, txt: string, isChecked, onChange: bool -> unit, ?isDisabled: bool) =
let isDisabled = defaultArg isDisabled false
Daisy.formControl [
Daisy.label [
Expand Down
5 changes: 3 additions & 2 deletions src/Client/Modals/SelectiveImportModal.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ open Components

type SelectiveImportModal =

static member RadioPluginsBox(boxName, icon, importType: TableJoinOptions, radioData: (TableJoinOptions * string)[], setImportType: TableJoinOptions -> unit) =
static member RadioPluginsBox(boxName, icon, importType: TableJoinOptions, radioGroupName, radioData: (TableJoinOptions * string)[], setImportType: TableJoinOptions -> unit) =
let myradio(target: TableJoinOptions, txt: string) =
let isChecked = importType = target
ModalElements.RadioPlugin("importType", txt, isChecked, fun (b: bool) -> if b then setImportType target)
ModalElements.RadioPlugin(radioGroupName, txt, isChecked, fun (b: bool) -> if b then setImportType target)
ModalElements.Box (boxName, icon, React.fragment [
Html.div [
for i in 0..radioData.Length-1 do
Expand Down Expand Up @@ -206,6 +206,7 @@ type SelectiveImportModal =
"Import Type",
"fa-solid fa-cog",
state.ImportType,
"importType",
[|
ARCtrl.TableJoinOptions.Headers, " Column Headers";
ARCtrl.TableJoinOptions.WithUnit, " ..With Units";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type SelectiveTemplateFromDBModal =
"Import Type",
"fa-solid fa-cog",
importTypeState.ImportType,
"importType",
[|
ARCtrl.TableJoinOptions.Headers, " Column Headers";
ARCtrl.TableJoinOptions.WithUnit, " ..With Units";
Expand Down

0 comments on commit 95dcf24

Please sign in to comment.