Skip to content

Commit

Permalink
Merge pull request #611 from nfdi4plants/Bug_Swate_ImportJsonError
Browse files Browse the repository at this point in the history
Enable import of json tables
  • Loading branch information
Freymaurer authored Jan 29, 2025
2 parents 9f3e2f1 + a40b698 commit ff21890
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
8 changes: 2 additions & 6 deletions src/Client/Modals/SelectiveImportModal.fs
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,7 @@ type SelectiveImportModal =
| Study (s,_) -> s.Tables, ArcFilesDiscriminate.Study
| Template t -> ResizeArray([t.Table]), ArcFilesDiscriminate.Template
| Investigation _ -> ResizeArray(), ArcFilesDiscriminate.Investigation
let columns =
tables
|> Array.ofSeq
|> Array.map (fun t -> Array.init t.Columns.Length (fun _ -> true))
let importDataState, setImportDataState = React.useState(SelectiveImportModalState.init())
let importDataState, setImportDataState = React.useState(SelectiveImportModalState.init(tables))
let setMetadataImport = fun b ->
if b then
{
Expand All @@ -186,7 +182,7 @@ type SelectiveImportModal =
ImportTables = [for ti in 0 .. tables.Count-1 do {ImportTable.Index = ti; ImportTable.FullImport = true}]
} |> setImportDataState
else
SelectiveImportModalState.init() |> setImportDataState
SelectiveImportModalState.init(tables) |> setImportDataState
let addTableImport = fun (i: int) (fullImport: bool) ->
let newImportTable: ImportTable = {Index = i; FullImport = fullImport}
let newImportTables = newImportTable::importDataState.ImportTables |> List.distinct
Expand Down
4 changes: 2 additions & 2 deletions src/Client/Pages/ProtocolTemplates/ProtocolView.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ open JsonImport
type Templates =

[<ReactComponent>]
static member Main (model:Model, dispatch) =
static member Main (model: Model, dispatch) =
let isProtocolSearch, setProtocolSearch = React.useState(false)
let importTypeStateData = React.useState(SelectiveImportModalState.init())
let importTypeStateData = React.useState(SelectiveImportModalState.init([]))
if model.ProtocolState.TemplatesSelected.Length > 0 && (fst importTypeStateData).SelectedColumns.Length = 0 then
let columns =
model.ProtocolState.TemplatesSelected
Expand Down
10 changes: 8 additions & 2 deletions src/Client/Types.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[<AutoOpen>]
module Types

open ARCtrl

module JsonImport =

[<RequireQualifiedAccess>]
Expand All @@ -17,12 +19,16 @@ module JsonImport =
SelectedColumns: bool [] []
TemplateName: string option
} with
static member init() =
static member init(tables: seq<ArcTable>) =
let selectedColumns =
tables
|> Array.ofSeq
|> Array.map (fun t -> Array.init t.Columns.Length (fun _ -> true))
{
ImportType = ARCtrl.TableJoinOptions.Headers
ImportMetadata = false
ImportTables = []
SelectedColumns = Array.empty
SelectedColumns = selectedColumns
TemplateName = None
}

Expand Down
2 changes: 1 addition & 1 deletion src/Client/Views/SpreadsheetView.fs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ open JsonImport
[<ReactComponent>]
let Main (model: Model, dispatch) =
let widgets, setWidgets = React.useState([])
let importTypeStateData = React.useState(SelectiveImportModalState.init())
let importTypeStateData = React.useState(SelectiveImportModalState.init([]))
let rmvWidget (widget: Widget) = widgets |> List.except [widget] |> setWidgets
let bringWidgetToFront (widget: Widget) =
let newList = widgets |> List.except [widget] |> fun x -> widget::x |> List.rev
Expand Down

0 comments on commit ff21890

Please sign in to comment.