Skip to content

Commit

Permalink
Merge branch 'main' into publish_bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Freymaurer authored Feb 7, 2025
2 parents f534afb + d13421e commit 68c07f1
Show file tree
Hide file tree
Showing 19 changed files with 185 additions and 272 deletions.
28 changes: 11 additions & 17 deletions src/Client/MainComponents/Widgets.fs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ type Widget =
static member Base(content: ReactElement, prefix: string, rmv: MouseEvent -> unit, ?help: ReactElement) =
let position, setPosition = React.useState(fun _ -> Rect.initPositionFromPrefix prefix)
let size, setSize = React.useState(fun _ -> Rect.initSizeFromPrefix prefix)
let helpIsActive, setHelpIsActive = React.useState(false)
let element = React.useElementRef()
React.useLayoutEffectOnce(fun _ -> position |> Option.iter (fun position -> MoveEventListener.ensurePositionInsideWindow element position |> Some |> setPosition)) // Reposition widget inside window
let resizeElement (content: ReactElement) =
Expand Down Expand Up @@ -145,7 +144,7 @@ type Widget =
]
resizeElement <| Html.div [
prop.onMouseDown(fun e -> e.stopPropagation())
prop.className "border-b border-black cursor-default flex flex-col grow"
prop.className "cursor-default flex flex-col grow"
prop.children [
Html.div [
prop.onMouseDown(fun e -> // move
Expand All @@ -172,6 +171,7 @@ type Widget =
content
]
]
//It is not used anymore
if help.IsSome then
Html.div [
prop.tabIndex 0
Expand Down Expand Up @@ -200,27 +200,22 @@ type Widget =
static member BuildingBlock (model, dispatch, rmv: MouseEvent -> unit) =
let content = BuildingBlock.SearchComponent.Main model dispatch
let help = React.fragment [
Html.p "Add a new Building Block."
Html.ul [
Html.li "If a cell is selected, a new Building Block is added to the right of the selected cell."
Html.li "If no cell is selected, a new Building Block is appended at the right end of the table."
]
]
Html.p "Add a new Building Block."
Html.ul [
Html.li "If a cell is selected, a new Building Block is added to the right of the selected cell."
Html.li "If no cell is selected, a new Building Block is appended at the right end of the table."
]
]
let prefix = WidgetLiterals.BuildingBlock
Widget.Base(content, prefix, rmv, help)

[<ReactComponent>]
static member Templates (model: Model, importTypeStateData, dispatch, rmv: MouseEvent -> unit) =
let templates = model.ProtocolState.Templates
let config, setConfig = React.useState(TemplateFilterConfig.init)
let isProtocolSearch, setProtocolSearch = React.useState(true)
let filteredTemplates = Protocol.Search.filterTemplates (templates, config)
React.useEffectOnce(fun _ -> Messages.Protocol.GetAllProtocolsRequest |> Messages.ProtocolMsg |> dispatch)
let selectContent() =
[
Protocol.Search.FileSortElement(model, config, setConfig, "@md/templateWidget:grid-cols-3")
ModalElements.Box("Selected Templates", "fa-solid fa-cog", Search.SelectedTemplatesElement model setProtocolSearch importTypeStateData dispatch)
Protocol.Search.Component (filteredTemplates, model, setProtocolSearch, importTypeStateData, dispatch, length.px 350)
Protocol.SearchContainer.Main(model, setProtocolSearch, importTypeStateData, dispatch)
]
let insertContent() =
[
Expand All @@ -238,13 +233,12 @@ type Widget =
else
insertContent ()
Html.div [
prop.className "flex flex-col gap-4 @container/templateWidget"
prop.className "prose-sm prose-p:m-1 prose-ul:mt-1 max-w-none"
prop.children switchContent
]

let help = Protocol.Search.InfoField()
let prefix = WidgetLiterals.Templates
Widget.Base(content, prefix, rmv, help)
Widget.Base(content, prefix, rmv)

static member FilePicker (model, dispatch, rmv) =
let content = Html.div [
Expand Down
3 changes: 1 addition & 2 deletions src/Client/Modals/ModalElements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ type ModalElements =
static member Button(text: string, onClickAction, buttonInput, ?isDisabled: bool) =
let isDisabled = defaultArg isDisabled false
Daisy.button.a [
button.success
button.primary
button.wide
if isDisabled then
button.error
prop.disabled isDisabled
prop.onClick (fun _ -> onClickAction buttonInput)

prop.text text
]

Expand Down
23 changes: 10 additions & 13 deletions src/Client/Modals/SelectiveImportModal.fs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type SelectiveImportModal =
prop.style [
style.height(length.perc 100)
]
prop.isChecked (not (Set.contains (columnIndex, tableIndex) selectionInformation.DeselectedColumns))
prop.isChecked (not (Set.contains (tableIndex, columnIndex) selectionInformation.DeselectedColumns))
prop.onChange (fun (b: bool) ->
if columns.Length > 0 then
let selectedData = selectionInformation.toggleDeselectedColumns(tableIndex, columnIndex)
Expand All @@ -45,12 +45,12 @@ type SelectiveImportModal =
]
]

static member TableWithImportColumnCheckboxes(table: ArcTable, ?tableIndex, ?selectionInformation: SelectiveImportModalState, ?setSelectedColumns: SelectiveImportModalState -> unit) =
static member TableWithImportColumnCheckboxes(table: ArcTable, ?tableIndex, ?selectionInformation: SelectiveImportModalState, ?setDeselectedColumns: SelectiveImportModalState -> unit) =
let columns = table.Columns
let tableIndex = defaultArg tableIndex 0
let displayCheckBox =
//Determine whether to display checkboxes or not
selectionInformation.IsSome && setSelectedColumns.IsSome
selectionInformation.IsSome && setDeselectedColumns.IsSome
Daisy.table [
prop.children [
Html.thead [
Expand All @@ -61,20 +61,13 @@ type SelectiveImportModal =
prop.className "join flex flex-row centered gap-2"
prop.children [
if displayCheckBox then
SelectiveImportModal.CheckBoxForTableColumnSelection(columns, tableIndex, columnIndex, selectionInformation.Value, setSelectedColumns.Value)
SelectiveImportModal.CheckBoxForTableColumnSelection(columns, tableIndex, columnIndex, selectionInformation.Value, setDeselectedColumns.Value)
Html.text (columns.[columnIndex].Header.ToString())
Html.div [
prop.onClick (fun _ ->
if columns.Length > 0 && selectionInformation.IsSome then
let selectedData = selectionInformation.Value.toggleDeselectedColumns(tableIndex, columnIndex)
{selectionInformation.Value with DeselectedColumns = selectedData} |> setSelectedColumns.Value)
]
]
]
]
]
]

Html.tbody [
for ri in 0 .. (table.RowCount-1) do
let row = table.GetRow(ri, true)
Expand Down Expand Up @@ -143,9 +136,13 @@ type SelectiveImportModal =
]
Daisy.collapse [
Html.input [prop.type'.checkbox; prop.className "min-h-0 h-5"]

Daisy.collapseTitle [
prop.className "p-1 min-h-0 h-5 text-sm"
prop.text (if isActive then "Select Columns" else "Preview Table")
prop.className "p-1 min-h-0 h-5 text-success text-sm font-bold space-x-2"
prop.children [
Html.span (if isActive then "Select Columns" else "Preview Table")
Html.i [prop.className "fa-solid fa-magnifying-glass"]
]
]
Daisy.collapseContent [
prop.className "overflow-x-auto"
Expand Down
30 changes: 14 additions & 16 deletions src/Client/OfficeInterop/OfficeInterop.fs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ module GetHandler =
/// </summary>
/// <param name="deselectedColumns"></param>
/// <param name="tableIndex"></param>
let getDeSelectedTableColumns (deselectedColumns: Set<int*int>) (tableIndex: int) =
let getDeselectedTableColumnIndices (deselectedColumns: Set<int*int>) (tableIndex: int) =
deselectedColumns
|> List.ofSeq
|> List.choose (fun item -> if (fst item) = tableIndex then Some (snd item) else None)
Expand All @@ -211,8 +211,7 @@ module GetHandler =
importTables
|> List.map (fun importTable -> tablesToAdd.[importTable.Index], importTable.FullImport)

let mutable tablesToAdd, selectedColumnsCollectionToAdd, tablesToJoin, selectedColumnsCollectionToJoin =
list.Empty, list.Empty, list.Empty, list.Empty
let mutable tablesToAdd, tablesToJoin = list.Empty, list.Empty

importData
|> List.iter (fun (table, importType) ->
Expand All @@ -223,7 +222,6 @@ module GetHandler =
)

tablesToAdd |> Array.ofList,
selectedColumnsCollectionToAdd |> Array.ofList,
tablesToJoin |> Array.ofList

/// <summary>
Expand Down Expand Up @@ -466,22 +464,22 @@ module UpdateHandler =
/// <param name="selectedColumnsCollection"></param>
/// <param name="options"></param>
/// <param name="context"></param>
let addTemplates (tablesToAdd: ArcTable[]) (selectedColumnsCollection: Set<int>[]) (options: TableJoinOptions option) (context: RequestContext) =
let addTemplates (tablesToAdd: ArcTable[]) (deselectedColumnsCollection: Set<int*int>) (options: TableJoinOptions option) (context: RequestContext) =
promise {
let! result = tryGetActiveExcelTable context

for i in 0..tablesToAdd.Length - 1 do
let tableToAdd = tablesToAdd.[i]
let selectedColumnCollection = selectedColumnsCollection.[i] |> List.ofSeq
for tableIndex in 0..tablesToAdd.Length - 1 do
let tableToAdd = tablesToAdd.[tableIndex]
let deselectedColumnIndices = getDeselectedTableColumnIndices deselectedColumnsCollection tableIndex
let newName = createNewTableName()
let originTable = ArcTable.init(newName)
let finalTable =
let endTable = Table.selectiveTablePrepare originTable tableToAdd selectedColumnCollection
let endTable = Table.selectiveTablePrepare originTable tableToAdd deselectedColumnIndices
originTable.Join(endTable, ?joinOptions = options)
originTable

let! activeWorksheet =
if i = 0 && result.IsNone then
if tableIndex = 0 && result.IsNone then
promise { return context.workbook.worksheets.getActiveWorksheet() }
else
promise {
Expand Down Expand Up @@ -949,7 +947,7 @@ module UpdateHandler =
//Loop over all tables to be added and add them to the origin table
let rec loop (originTable: ArcTable) (tablesToAdd: ArcTable []) (deselectedColumns: Set<int*int>) (options: TableJoinOptions option) i =
let tableToAdd = tablesToAdd.[i]
let deselectedColumnIndices = getDeSelectedTableColumns deselectedColumns i
let deselectedColumnIndices = getDeselectedTableColumnIndices deselectedColumns i
let refinedTableToAdd = Table.selectiveTablePrepare originTable tableToAdd deselectedColumnIndices

let newTable =
Expand Down Expand Up @@ -1180,12 +1178,12 @@ type Main =
/// <param name="tableToAdd"></param>
/// <param name="index"></param>
/// <param name="options"></param>
static member joinTables (tablesToAdd: ArcTable [], selectedColumnsCollection: Set<int*int>, options: TableJoinOptions option, importTables: JsonImport.ImportTable list, ?context0) =
static member joinTables (tablesToAdd: ArcTable [], deselectedColumnsCollection: Set<int*int>, options: TableJoinOptions option, importTables: JsonImport.ImportTable list, ?context0) =
excelRunWith context0 <| fun context ->
promise {
//When a name is available get the annotation and arctable for easy access of indices and value adaption
//Annotation table enables a easy way to adapt the table, updating existing and adding new columns
let tablesToAdd, selectedColumnsCollectionToAdd, tablesToJoin =
let tablesToAdd, tablesToJoin =
selectTablesToAdd tablesToAdd importTables
let! result = tryGetActiveExcelTable context
match result with
Expand All @@ -1197,12 +1195,12 @@ type Main =
| Result.Ok originTable ->
let! msgJoin =
if tablesToJoin.Length > 0 then
joinTemplatesToTable originTable excelTable tablesToJoin selectedColumnsCollection options context
joinTemplatesToTable originTable excelTable tablesToJoin deselectedColumnsCollection options context
else
promise {return []}

let! msgAdd =
addTemplates tablesToAdd selectedColumnsCollectionToAdd options context
addTemplates tablesToAdd deselectedColumnsCollection options context

if msgAdd.IsEmpty then
return msgJoin
Expand All @@ -1214,7 +1212,7 @@ type Main =
if tablesToJoin.Length > 0 then
return [InteropLogging.NoActiveTableMsg]
else
let! msgAdd = addTemplates tablesToAdd selectedColumnsCollectionToAdd options context
let! msgAdd = addTemplates tablesToAdd deselectedColumnsCollection options context
return msgAdd
}

Expand Down
Loading

0 comments on commit 68c07f1

Please sign in to comment.