Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug excel restore building block details #560

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 48 additions & 5 deletions src/Client/OfficeInterop/OfficeInterop.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ let tryGetSelectedTableIndex (table: Table) (context: RequestContext) =
/// </summary>
/// <param name="columns"></param>
/// <param name="selectedIndex"></param>
let getSelectedBuildingBlock (table: Table) (context: RequestContext) =
let getSelectedCompositeColumn (table: Table) (context: RequestContext) =
promise {
let selectedRange = context.workbook.getSelectedRange().load(U2.Case2 (ResizeArray[|"columnIndex"|]))
let headerRange = table.getHeaderRowRange()
Expand Down Expand Up @@ -1154,7 +1154,7 @@ let getSelectedBuildingBlockCell (table: Table) (context: RequestContext) =
/// </summary>
let getArcMainColumn (excelTable: Table) (arcTable: ArcTable) (context: RequestContext) =
promise {
let! selectedBlock = getSelectedBuildingBlock excelTable context
let! selectedBlock = getSelectedCompositeColumn excelTable context

let protoHeaders = excelTable.getHeaderRowRange()
let _ = protoHeaders.load(U2.Case2 (ResizeArray(["values"])))
Expand Down Expand Up @@ -1288,7 +1288,7 @@ let removeSelectedAnnotationBlock () =

match excelTableRes with
| Some excelTable ->
let! selectedBuildingBlock = getSelectedBuildingBlock excelTable context
let! selectedBuildingBlock = getSelectedCompositeColumn excelTable context

// iterate DESCENDING to avoid index shift
for i, _ in Seq.sortByDescending fst selectedBuildingBlock do
Expand Down Expand Up @@ -1547,7 +1547,7 @@ let validateBuildingBlock (excelTable: Table, context: RequestContext) =
let mutable errors:list<exn*string> = []

if isMainColumn then
let! selectedBuildingBlock = getSelectedBuildingBlock excelTable context
let! selectedBuildingBlock = getSelectedCompositeColumn excelTable context
let targetIndex = fst (selectedBuildingBlock.Item (selectedBuildingBlock.Count - 1))
let! result = validateSelectedColumns(headerRange, bodyRowRange, int columnIndex, targetIndex, context)

Expand Down Expand Up @@ -2111,7 +2111,7 @@ let fillSelectedWithOntologyAnnotation (ontologyAnnotation: OntologyAnnotation)
if firstRow = 0. then 1.
else firstRow

let! selectedBuildingBlock = getSelectedBuildingBlock excelTable context
let! selectedBuildingBlock = getSelectedCompositeColumn excelTable context

let columnIndices = selectedBuildingBlock |> Array.ofSeq |> Array.map (fun (index, _) -> index)
let columnHeaders = ARCtrl.Spreadsheet.ArcTable.helperColumnStrings |> Array.ofSeq
Expand Down Expand Up @@ -2163,6 +2163,49 @@ let fillSelectedWithOntologyAnnotation (ontologyAnnotation: OntologyAnnotation)
}
)

let getCompositeColumnDetails () =
Excel.run(fun context ->
promise {
let! excelTableRes = AnnotationTable.tryGetActive context
match excelTableRes with
| Some excelTable ->

let! selectedCompositeColumn = getSelectedCompositeColumn excelTable context
let selectedRange = context.workbook.getSelectedRange()
let tableRange = excelTable.getRange()
let _ =
tableRange.load(U2.Case2 (ResizeArray[|"values";|])) |> ignore
selectedRange.load(U2.Case2 (ResizeArray[|"rowIndex";|]))

do! context.sync().``then``(fun _ -> ())

let mainColumnIndex = fst (selectedCompositeColumn.Item 0)
let rowIndex = int selectedRange.rowIndex

let values =
tableRange.values
|> Array.ofSeq
|> Array.map (fun item ->
item |> Array.ofSeq
|> Array.map (fun itemi ->
Option.map string itemi
|> Option.defaultValue ""))

let value = values.[rowIndex].[mainColumnIndex]

let! termsRes = searchTermsInDatabase [value]

let terms =
termsRes
|> Array.choose (fun term -> term)

let name = terms |> Array.map (fun item -> item.Name)

return [InteropLogging.Msg.create InteropLogging.Info "Some Info"]
| None ->
return [InteropLogging.NoActiveTableMsg]
}
)

/// <summary>This function is used to insert file names into the selected range.</summary>
let insertFileNamesFromFilePicker (fileNameList: string list) =
Expand Down
18 changes: 9 additions & 9 deletions src/Client/SidebarComponents/Navbar.fs
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,15 @@ let private ShortCutIconList toggleMetdadataModal model (dispatch: Messages.Msg
],
(fun _ -> SpreadsheetInterface.RemoveBuildingBlock |> InterfaceMsg |> dispatch)
)
//QuickAccessButton.create(
// "Get Building Block Information",
// [
// Html.i [prop.className "fa-solid fa-question pr-1"]
// Html.span model.BuildingBlockDetailsState.CurrentRequestState.toStringMsg
// Html.i [prop.className "fa-solid fa-table-columns"]
// ],
// (fun _ -> SpreadsheetInterface.EditBuildingBlock |> InterfaceMsg |> dispatch)
//)
QuickAccessButton.create(
"Get Building Block Information",
[
Html.i [prop.className "fa-solid fa-question pr-1"]
//Html.span model.BuildingBlockDetailsState.CurrentRequestState.toStringMsg
Html.i [prop.className "fa-solid fa-table-columns"]
],
(fun _ -> SpreadsheetInterface.GetBuildingBlockDetails |> InterfaceMsg |> dispatch)
)
]
|> List.map (fun x -> x.toReactElement())
|> React.fragment
Expand Down
1 change: 1 addition & 0 deletions src/Client/States/OfficeInteropState.fs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Msg =
| AddTemplate of ArcTable
| JoinTable of ArcTable * options: TableJoinOptions option
| RemoveBuildingBlock
| GetBuildingBlockDetails
| UpdateUnitForCells
| AutoFitTable of hideRefCols:bool
// Term search functions
Expand Down
1 change: 1 addition & 0 deletions src/Client/States/SpreadsheetInterface.fs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Msg =
| UpdateArcFile of ArcFiles
/// Inserts TermMinimal to selected fields of one column
| InsertOntologyAnnotation of OntologyAnnotation
| GetBuildingBlockDetails
| InsertFileNames of string list
| ImportXlsx of byte []
| ImportJson of {|importState: SelectiveImportModalState; importedFile: ArcFiles|}
Expand Down
17 changes: 17 additions & 0 deletions src/Client/Update/InterfaceUpdate.fs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,23 @@ module Interface =
Spreadsheet.DeleteColumn (distinct.[0]) |> SpreadsheetMsg |> Cmd.ofMsg
model, cmd
| _ -> failwith "not implemented"
| GetBuildingBlockDetails ->
match host with
| Some Swatehost.Excel ->
let cmd = OfficeInterop.GetBuildingBlockDetails |> OfficeInteropMsg |> Cmd.ofMsg
model, cmd
//| Some Swatehost.Browser | Some Swatehost.ARCitect ->
// if Set.isEmpty model.SpreadsheetModel.SelectedCells then failwith "No column selected"
// let selectedColumns, _ = model.SpreadsheetModel.SelectedCells |> Set.toArray |> Array.unzip
// let distinct = selectedColumns |> Array.distinct
// let cmd =
// if distinct.Length <> 1 then
// let msg = Failure("Please select one column only if you want to use `Remove Building Block`.")
// GenericError (Cmd.none,msg) |> DevMsg |> Cmd.ofMsg
// else
// Spreadsheet.DeleteColumn (distinct.[0]) |> SpreadsheetMsg |> Cmd.ofMsg
// model, cmd
| _ -> failwith "not implemented"
| AddDataAnnotation data ->
match host with
| Some Swatehost.Excel ->
Expand Down
9 changes: 9 additions & 0 deletions src/Client/Update/OfficeInteropUpdate.fs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ module OfficeInterop =
(curry GenericError Cmd.none >> DevMsg)
state, model, cmd

| GetBuildingBlockDetails ->
let cmd =
Cmd.OfPromise.either
OfficeInterop.Core.getCompositeColumnDetails
()
(curry GenericInteropLogs Cmd.none >> DevMsg)
(curry GenericError Cmd.none >> DevMsg)
state, model, cmd

| UpdateUnitForCells ->
let cmd =
Cmd.OfPromise.either
Expand Down