Skip to content

Commit

Permalink
Merge pull request #614 from nfdi4plants/Feature_RefactorSelectedColumns
Browse files Browse the repository at this point in the history
Feature refactor selected columns
  • Loading branch information
Freymaurer authored Feb 5, 2025
2 parents a266a2f + 7caa9da commit 2576a92
Show file tree
Hide file tree
Showing 17 changed files with 121 additions and 185 deletions.
29 changes: 1 addition & 28 deletions src/Client/MainComponents/Cells.fs
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
module Spreadsheet.Cells

open Feliz
open Feliz.DaisyUI
open Fable.Core

open Spreadsheet
open MainComponents
open Messages
open Shared
open ARCtrl
open Components
open Model

module private CellAux =

let headerTSRSetter (columnIndex: int, s: string, header: CompositeHeader, dispatch) =
log (s, header)
match header.TryOA(), s with
Expand All @@ -24,25 +20,18 @@ module private CellAux =
|> Option.map header.UpdateWithOA
|> fun s -> log s; s
|> Option.iter (fun nextHeader -> Msg.UpdateHeader (columnIndex, nextHeader) |> SpreadsheetMsg |> dispatch)

let headerTANSetter (columnIndex: int, s: string, header: CompositeHeader, dispatch) =
match header.TryOA(), s with
| Some oa, "" -> oa.TermAccessionNumber <- None; Some oa
| Some oa, s1 -> oa.TermAccessionNumber <- Some s1; Some oa
| None, _ -> None
|> Option.map header.UpdateWithOA
|> Option.iter (fun nextHeader -> Msg.UpdateHeader (columnIndex, nextHeader) |> SpreadsheetMsg |> dispatch)

let oasetter (index, nextCell: CompositeCell, dispatch) = Msg.UpdateCell (index, nextCell) |> SpreadsheetMsg |> dispatch

let contextMenuController index model dispatch = if model.SpreadsheetModel.TableViewIsActive() then ContextMenu.Table.onContextMenu (index, dispatch) else ContextMenu.DataMap.onContextMenu (index, dispatch)

open CellAux

module private EventPresets =

open Shared

let onClickSelect (index: int*int, isIdle:bool, selectedCells: Set<int*int>, model:Model, dispatch)=
fun (e: Browser.Types.MouseEvent) ->
// don't select cell if active(editable)
Expand Down Expand Up @@ -124,7 +113,6 @@ type Cell =
Daisy.loading []
]
]

[<ReactComponent>]
static member HeaderBase(columnType: ColumnType, setter: string -> unit, cellValue: string, columnIndex: int, header: CompositeHeader, state_extend: Set<int>, setState_extend, model: Model, dispatch, ?readonly: bool) =
let readonly = defaultArg readonly false
Expand Down Expand Up @@ -170,7 +158,6 @@ type Cell =
]
]
]

static member Header(columnIndex: int, header: CompositeHeader, state_extend: Set<int>, setState_extend, model: Model, dispatch, ?readonly: bool) =
let cellValue = header.ToString()
let setter =
Expand All @@ -185,34 +172,28 @@ type Cell =
nextHeader <- nextHeader.UpdateWithOA updatedOA
Msg.UpdateHeader (columnIndex, nextHeader) |> SpreadsheetMsg |> dispatch
Cell.HeaderBase(Main, setter, cellValue, columnIndex, header, state_extend, setState_extend, model, dispatch, ?readonly=readonly)

static member HeaderUnit(columnIndex: int, header: CompositeHeader, state_extend: Set<int>, setState_extend, model: Model, dispatch, ?readonly) =
let cellValue = "Unit"
let setter = fun (s: string) -> ()
Cell.HeaderBase(Unit, setter, cellValue, columnIndex, header, state_extend, setState_extend, model, dispatch, ?readonly=readonly)

static member HeaderTSR(columnIndex: int, header: CompositeHeader, state_extend: Set<int>, setState_extend, model: Model, dispatch, ?readonly) =
let cellValue = header.TryOA() |> Option.map (fun oa -> oa.TermSourceREF) |> Option.flatten |> Option.defaultValue ""
let setter = fun (s: string) -> headerTSRSetter(columnIndex, s, header, dispatch)
Cell.HeaderBase(TSR, setter, cellValue, columnIndex, header, state_extend, setState_extend, model, dispatch, ?readonly=readonly)

static member HeaderTAN(columnIndex: int, header: CompositeHeader, state_extend: Set<int>, setState_extend, model: Model, dispatch, ?readonly) =
let cellValue = header.TryOA() |> Option.map (fun oa -> oa.TermAccessionShort) |> Option.defaultValue ""
let setter = fun (s: string) -> headerTANSetter(columnIndex, s, header, dispatch)
Cell.HeaderBase(TAN, setter, cellValue, columnIndex, header, state_extend, setState_extend, model, dispatch, ?readonly=readonly)

static member HeaderDataSelector(columnIndex: int, header: CompositeHeader, state_extend: Set<int>, setState_extend, model: Model, dispatch) =
let ct = ColumnType.DataSelector
let cellValue = ct.ToColumnHeader()
let setter = fun _ -> ()
Cell.HeaderBase(ct, setter, cellValue, columnIndex, header, state_extend, setState_extend, model, dispatch, true)

static member HeaderDataFormat(columnIndex: int, header: CompositeHeader, state_extend: Set<int>, setState_extend, model: Model, dispatch) =
let ct = ColumnType.DataFormat
let cellValue = ct.ToColumnHeader()
let setter = fun _ -> ()
Cell.HeaderBase(ct, setter, cellValue, columnIndex, header, state_extend, setState_extend, model, dispatch, true)

static member HeaderDataSelectorFormat(columnIndex: int, header: CompositeHeader, state_extend: Set<int>, setState_extend, model: Model, dispatch) =
let ct = ColumnType.DataSelectorFormat
let cellValue = ct.ToColumnHeader()
Expand All @@ -229,7 +210,6 @@ type Cell =
]
]
]]

[<ReactComponent>]
static member BodyBase(columnType: ColumnType, cellValue: string, setter: string -> unit, index: (int*int), model: Model, dispatch, ?oasetter: {|oa: OntologyAnnotation; setter: OntologyAnnotation -> unit|}, ?displayValue, ?readonly: bool, ?tooltip: string) =
let readonly = defaultArg readonly false
Expand Down Expand Up @@ -349,7 +329,6 @@ type Cell =
]
]
]

static member Body(index: (int*int), cell: CompositeCell, model: Model, dispatch) =
let cellValue = cell.GetContentSwate().[0]
let setter = fun (s: string) ->
Expand All @@ -369,7 +348,6 @@ type Cell =
None
let displayValue = cell.ToString()
Cell.BodyBase(Main, cellValue, setter, index, model, dispatch, ?oasetter=oasetter, displayValue=displayValue)

static member BodyUnit(index: (int*int), cell: CompositeCell, model: Model, dispatch) =
let cellValue = cell.ToOA().NameText
let setter = fun (s: string) ->
Expand All @@ -392,7 +370,6 @@ type Cell =
None
let displayValue = cell.ToString()
Cell.BodyBase(Unit, cellValue, setter, index, model, dispatch, ?oasetter=oasetter, displayValue=displayValue)

static member BodyTSR(index: (int*int), cell: CompositeCell, model: Model, dispatch) =
let cellValue = cell.ToOA().TermSourceREF |> Option.defaultValue ""
let setter = fun (s: string) ->
Expand All @@ -402,7 +379,6 @@ type Cell =
let nextCell = cell.UpdateWithOA oa
Msg.UpdateCell (index, nextCell) |> SpreadsheetMsg |> dispatch
Cell.BodyBase(TSR, cellValue, setter, index, model, dispatch)

static member BodyTAN(index: (int*int), cell: CompositeCell, model: Model, dispatch) =
let cellValue = cell.ToOA().TermAccessionNumber |> Option.defaultValue ""
let setter = fun (s: string) ->
Expand All @@ -412,7 +388,6 @@ type Cell =
let nextCell = cell.UpdateWithOA oa
Msg.UpdateCell (index, nextCell) |> SpreadsheetMsg |> dispatch
Cell.BodyBase(TAN, cellValue, setter, index, model, dispatch)

static member BodyDataSelector(index: (int*int), cell: CompositeCell, model: Model, dispatch) =
let data = cell.AsData
let cellValue = data.Selector |> Option.defaultValue ""
Expand All @@ -422,7 +397,6 @@ type Cell =
let nextCell = cell.UpdateWithData data
Msg.UpdateCell (index, nextCell) |> SpreadsheetMsg |> dispatch
Cell.BodyBase(ColumnType.DataSelector, cellValue, setter, index, model, dispatch)

static member BodyDataFormat(index: (int*int), cell: CompositeCell, model: Model, dispatch) =
let data = cell.AsData
let cellValue = data.Format |> Option.defaultValue ""
Expand All @@ -432,7 +406,6 @@ type Cell =
let nextCell = cell.UpdateWithData data
Msg.UpdateCell (index, nextCell) |> SpreadsheetMsg |> dispatch
Cell.BodyBase(ColumnType.DataFormat, cellValue, setter, index, model, dispatch)

static member BodyDataSelectorFormat(index: (int*int), cell: CompositeCell, model: Model, dispatch) =
let data = cell.AsData
let cellValue = data.SelectorFormat |> Option.defaultValue ""
Expand All @@ -441,4 +414,4 @@ type Cell =
data.SelectorFormat <- next
let nextCell = cell.UpdateWithData data
Msg.UpdateCell (index, nextCell) |> SpreadsheetMsg |> dispatch
Cell.BodyBase(ColumnType.DataSelectorFormat, cellValue, setter, index, model, dispatch)
Cell.BodyBase(ColumnType.DataSelectorFormat, cellValue, setter, index, model, dispatch)
6 changes: 0 additions & 6 deletions src/Client/MainComponents/Widgets.fs
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,6 @@ type Widget =
let config, setConfig = React.useState(TemplateFilterConfig.init)
let isProtocolSearch, setProtocolSearch = React.useState(true)
let filteredTemplates = Protocol.Search.filterTemplates (templates, config)
if model.ProtocolState.TemplatesSelected.Length > 0 && (fst importTypeStateData).SelectedColumns.Length = 0 then
let columns =
model.ProtocolState.TemplatesSelected
|> List.map (fun template -> Array.init template.Table.Columns.Length (fun _ -> true))
|> Array.ofList
{fst importTypeStateData with SelectedColumns = columns} |> snd importTypeStateData
React.useEffectOnce(fun _ -> Messages.Protocol.GetAllProtocolsRequest |> Messages.ProtocolMsg |> dispatch)
let selectContent() =
[
Expand Down
25 changes: 10 additions & 15 deletions src/Client/Modals/SelectiveImportModal.fs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,11 @@ type SelectiveImportModal =
prop.style [
style.height(length.perc 100)
]
prop.isChecked
(if selectionInformation.SelectedColumns.Length > 0 then
selectionInformation.SelectedColumns.[tableIndex].[columnIndex]
else true)
prop.isChecked (not (Set.contains (columnIndex, tableIndex) selectionInformation.DeselectedColumns))
prop.onChange (fun (b: bool) ->
if columns.Length > 0 then
let selectedData = selectionInformation.SelectedColumns
selectedData.[tableIndex].[columnIndex] <- b
{selectionInformation with SelectedColumns = selectedData} |> setSelectedColumns)
let selectedData = selectionInformation.toggleDeselectedColumns(tableIndex, columnIndex)
{selectionInformation with DeselectedColumns = selectedData} |> setSelectedColumns)
]
]
]
Expand All @@ -70,9 +66,8 @@ type SelectiveImportModal =
Html.div [
prop.onClick (fun _ ->
if columns.Length > 0 && selectionInformation.IsSome then
let selectedData = selectionInformation.Value.SelectedColumns
selectedData.[tableIndex].[columnIndex] <- not selectedData.[tableIndex].[columnIndex]
{selectionInformation.Value with SelectedColumns = selectedData} |> setSelectedColumns.Value)
let selectedData = selectionInformation.Value.toggleDeselectedColumns(tableIndex, columnIndex)
{selectionInformation.Value with DeselectedColumns = selectedData} |> setSelectedColumns.Value)
]
]
]
Expand Down Expand Up @@ -121,7 +116,7 @@ type SelectiveImportModal =
)

[<ReactComponent>]
static member TableImport(tableIndex: int, table0: ArcTable, state: SelectiveImportModalState, addTableImport: int -> bool -> unit, rmvTableImport: int -> unit, selectedColumns, setSelectedColumns, ?templateName) =
static member TableImport(tableIndex: int, table0: ArcTable, state: SelectiveImportModalState, addTableImport: int -> bool -> unit, rmvTableImport: int -> unit, deselectedColumns, setSelectedColumns, ?templateName) =
let name = defaultArg templateName table0.Name
let guid = React.useMemo(fun () -> System.Guid.NewGuid().ToString())
let radioGroup = "radioGroup_" + guid
Expand Down Expand Up @@ -156,7 +151,7 @@ type SelectiveImportModal =
prop.className "overflow-x-auto"
prop.children [
if isActive then
SelectiveImportModal.TableWithImportColumnCheckboxes(table0, tableIndex, selectedColumns, setSelectedColumns)
SelectiveImportModal.TableWithImportColumnCheckboxes(table0, tableIndex, deselectedColumns, setSelectedColumns)
else
SelectiveImportModal.TableWithImportColumnCheckboxes(table0)
]
Expand All @@ -173,7 +168,7 @@ type SelectiveImportModal =
| Study (s,_) -> s.Tables, ArcFilesDiscriminate.Study
| Template t -> ResizeArray([t.Table]), ArcFilesDiscriminate.Template
| Investigation _ -> ResizeArray(), ArcFilesDiscriminate.Investigation
let importDataState, setImportDataState = React.useState(SelectiveImportModalState.init(tables))
let importDataState, setImportDataState = React.useState(SelectiveImportModalState.init())
let setMetadataImport = fun b ->
if b then
{
Expand All @@ -182,7 +177,7 @@ type SelectiveImportModal =
ImportTables = [for ti in 0 .. tables.Count-1 do {ImportTable.Index = ti; ImportTable.FullImport = true}]
} |> setImportDataState
else
SelectiveImportModalState.init(tables) |> setImportDataState
SelectiveImportModalState.init() |> setImportDataState
let addTableImport = fun (i: int) (fullImport: bool) ->
let newImportTable: ImportTable = {Index = i; FullImport = fullImport}
let newImportTables = newImportTable::importDataState.ImportTables |> List.distinct
Expand Down Expand Up @@ -224,7 +219,7 @@ type SelectiveImportModal =
prop.style [style.marginLeft length.auto]
prop.text "Submit"
prop.onClick(fun e ->
{| importState = importDataState; importedFile = import; selectedColumns = importDataState.SelectedColumns |} |> SpreadsheetInterface.ImportJson |> InterfaceMsg |> dispatch
{| importState = importDataState; importedFile = import; deselectedColumns = importDataState.DeselectedColumns |} |> SpreadsheetInterface.ImportJson |> InterfaceMsg |> dispatch
rmv e
)
]
Expand Down
15 changes: 0 additions & 15 deletions src/Client/OfficeInterop/ARCtrlHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -197,21 +197,6 @@ let tryGetPrevTableOutput (prevArcTable: ArcTable option) =
return None
}

/// <summary>
/// Prepare the given table to be joined with the currently active annotation table
/// </summary>
/// <param name="tableToAdd"></param>
let prepareTemplateInMemory (originTable: ArcTable) (tableToAdd: ArcTable) (selectedColumns:bool []) =
let selectedColumnIndices =
selectedColumns
|> Array.mapi (fun i item -> if item = false then Some i else None)
|> Array.choose (fun x -> x)
|> List.ofArray

let finalTable = Table.selectiveTablePrepare originTable tableToAdd selectedColumnIndices

finalTable

[<AutoOpen>]
module ARCtrlExtensions =

Expand Down
Loading

0 comments on commit 2576a92

Please sign in to comment.