diff --git a/src/Client/MainComponents/Widgets.fs b/src/Client/MainComponents/Widgets.fs index 8769559e..1a5fa7d5 100644 --- a/src/Client/MainComponents/Widgets.fs +++ b/src/Client/MainComponents/Widgets.fs @@ -218,6 +218,7 @@ type Widget = let selectContent() = [ Protocol.Search.FileSortElement(model, config, setConfig, "@md/templateWidget:grid-cols-3") + ModalElements.Box("Selected Templates", "fa-solid fa-cog", Search.SelectedTemplatesElement model dispatch) Protocol.Search.Component (filteredTemplates, model, dispatch, length.px 350) ] let insertContent() = diff --git a/src/Client/Modals/SelectiveImportModal.fs b/src/Client/Modals/SelectiveImportModal.fs index e531c388..ee6600b4 100644 --- a/src/Client/Modals/SelectiveImportModal.fs +++ b/src/Client/Modals/SelectiveImportModal.fs @@ -121,10 +121,10 @@ type SelectiveImportModal = ) [] - static member TableImport(tableIndex: int, table0: ArcTable, state: SelectiveImportModalState, addTableImport: int -> bool -> unit, rmvTableImport: int -> unit, selectedColumns, setSelectedColumns, ?templateName, ?radioGroup) = + static member TableImport(tableIndex: int, table0: ArcTable, state: SelectiveImportModalState, addTableImport: int -> bool -> unit, rmvTableImport: int -> unit, selectedColumns, setSelectedColumns, ?templateName) = let name = defaultArg templateName table0.Name - let radioGroup = defaultArg radioGroup "" - let radioGroup = "radioGroup_" + radioGroup + let guid = React.useMemo(fun () -> System.Guid.NewGuid().ToString()) + let radioGroup = "radioGroup_" + guid let import = state.ImportTables |> List.tryFind (fun it -> it.Index = tableIndex) let isActive = import.IsSome let isDisabled = state.ImportMetadata diff --git a/src/Client/Pages/ProtocolTemplates/ProtocolSearch.fs b/src/Client/Pages/ProtocolTemplates/ProtocolSearch.fs index ce591411..0de05a37 100644 --- a/src/Client/Pages/ProtocolTemplates/ProtocolSearch.fs +++ b/src/Client/Pages/ProtocolTemplates/ProtocolSearch.fs @@ -6,6 +6,7 @@ open Model open Messages open Feliz open Feliz.DaisyUI +open Modals module private HelperProtocolSearch = @@ -58,6 +59,7 @@ type SearchContainer = prop.children [ Protocol.Search.InfoField() Protocol.Search.FileSortElement(model, config, setConfig) + ModalElements.Box("Selected Templates", "fa-solid fa-cog", Search.SelectedTemplatesElement model dispatch) Protocol.Search.Component (filteredTemplates, model, dispatch) ] ] diff --git a/src/Client/Pages/ProtocolTemplates/ProtocolSearchViewComponent.fs b/src/Client/Pages/ProtocolTemplates/ProtocolSearchViewComponent.fs index 5ccd593b..2b6ec09b 100644 --- a/src/Client/Pages/ProtocolTemplates/ProtocolSearchViewComponent.fs +++ b/src/Client/Pages/ProtocolTemplates/ProtocolSearchViewComponent.fs @@ -553,6 +553,46 @@ type Search = ] ] + static member private displayTemplateNames model = + Html.div [ + prop.className "flex gap-2" + prop.children [ + let names = List.rev model.ProtocolState.TemplatesSelected |> List.map (fun template -> template.Name) + for i in 0..names.Length-1 do + Html.div [ yield! [prop.text $"\"{names.[i]}\""]] + ] + ] + static member private selectTemplatesButton model dispatch = + Html.div [ + prop.className "flex justify-center gap-2" + prop.children [ + Daisy.button.a [ + button.sm + prop.onClick (fun _ -> + SelectProtocols model.ProtocolState.TemplatesSelected |> ProtocolMsg |> dispatch + ) + button.wide + if model.ProtocolState.TemplatesSelected.Length > 0 then + button.success + else + button.disabled + prop.text "Select templates" + ] + ] + ] + static member SelectedTemplatesElement model dispatch = + Html.div [ + prop.style [style.overflowX.auto; style.marginBottom (length.rem 1)] + prop.children [ + Html.div [ + prop.children [ + Search.displayTemplateNames model + ] + ] + Search.selectTemplatesButton model dispatch + ] + ] + [] static member Component (templates, model: Model, dispatch, ?maxheight: Styles.ICssUnit) = let maxheight = defaultArg maxheight (length.px 600) @@ -603,43 +643,5 @@ type Search = ] ] ] - let names = - Html.div [ - prop.className "flex gap-2" - prop.children [ - let names = List.rev model.ProtocolState.TemplatesSelected |> List.map (fun template -> template.Name) - for i in 0..names.Length-1 do - Html.div [ yield! [prop.text $"\"{names.[i]}\""]] - ] - ] - let button = - Html.div [ - prop.className "flex justify-center gap-2" - prop.children [ - Daisy.button.a [ - button.sm - prop.onClick (fun _ -> - SelectProtocols model.ProtocolState.TemplatesSelected |> ProtocolMsg |> dispatch - ) - button.wide - button.success - prop.text "Select templates" - ] - ] - ] - let element = - Html.div [ - prop.style [style.overflowX.auto; style.marginBottom (length.rem 1)] - prop.children [ - Html.div [ - prop.children [ - names - ] - ] - button - ] - ] - if model.ProtocolState.TemplatesSelected.Length > 0 then - ModalElements.Box("Selected Templates", "fa-solid fa-cog", element) ] ] diff --git a/src/Client/Pages/ProtocolTemplates/SelectiveTemplateFromDB.fs b/src/Client/Pages/ProtocolTemplates/SelectiveTemplateFromDB.fs index ad6ad012..19c26028 100644 --- a/src/Client/Pages/ProtocolTemplates/SelectiveTemplateFromDB.fs +++ b/src/Client/Pages/ProtocolTemplates/SelectiveTemplateFromDB.fs @@ -146,7 +146,7 @@ type SelectiveTemplateFromDB = let templates = model.ProtocolState.TemplatesSelected for templateIndex in 0..templates.Length-1 do let template = templates.[templateIndex] - SelectiveImportModal.TableImport(templateIndex, template.Table, importTypeState, addTableImport, rmvTableImport, importTypeState, setImportTypeState, template.Name, template.Name) + SelectiveImportModal.TableImport(templateIndex, template.Table, importTypeState, addTableImport, rmvTableImport, importTypeState, setImportTypeState, template.Name) Html.div [ SelectiveTemplateFromDB.AddTemplatesFromDBToTableButton "Add templates" model importTypeState dispatch ]