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

More context menu options #503

Merged
merged 6 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/Client/Client.fs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ let View (model : Model) (dispatch : Msg -> unit) =
let v = {colorstate with SetTheme = setColorstate}
React.contextProvider(LocalStorage.Darkmode.themeContext, v,
Html.div [
prop.className "flex grow"
prop.id "ClientView"
prop.className "flex w-full h-full overflow-auto"
prop.children [
match model.PersistentStorageState.Host with
| Some Swatehost.Excel ->
Expand Down
28 changes: 10 additions & 18 deletions src/Client/Helper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -148,21 +148,13 @@ type Navigator =
[<Emit("navigator")>]
let navigator : Navigator = jsNative

/// <summary>
/// take "count" many items from array if existing. if not enough items return as many as possible
/// </summary>
/// <param name="count"></param>
/// <param name="array"></param>
let takeFromArray (count: int) (array: 'a []) =
let exit (acc: 'a list) = List.rev acc |> Array.ofList
let rec takeRec (l2: 'a list) (acc: 'a list) index =
if index >= count then
exit acc
else
match l2 with
| [] -> exit acc
| item::tail ->
let newAcc = item::acc
takeRec tail newAcc (index+1)

takeRec (Array.toList array) [] 0
module Array =

/// <summary>
/// Take "count" many items from array if existing. if not enough items return as many as possible
/// </summary>
/// <param name="count"></param>
/// <param name="array"></param>
let takeSafe (count: int) (array: 'a []) =
let count = System.Math.Min(count, array.Length)
Array.take count array
19 changes: 13 additions & 6 deletions src/Client/MainComponents/ContextMenu.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ open Feliz.Bulma
open Spreadsheet
open ARCtrl
open Model
open Shared

module private Shared =

Expand Down Expand Up @@ -59,7 +60,8 @@ module Table =
Clear : (Browser.Types.MouseEvent -> unit) -> Browser.Types.MouseEvent -> unit
TransformCell : (Browser.Types.MouseEvent -> unit) -> Browser.Types.MouseEvent -> unit
UpdateAllCells : (Browser.Types.MouseEvent -> unit) -> Browser.Types.MouseEvent -> unit
//EditColumn : (Browser.Types.MouseEvent -> unit) -> Browser.Types.MouseEvent -> unit
GetTermDetails : OntologyAnnotation -> (Browser.Types.MouseEvent -> unit) -> Browser.Types.MouseEvent -> unit
EditColumn : (Browser.Types.MouseEvent -> unit) -> Browser.Types.MouseEvent -> unit
RowIndex : int
ColumnIndex : int
}
Expand All @@ -68,7 +70,11 @@ module Table =
/// This element will remove the contextmenu when clicking anywhere else
let isHeader = Shared.isHeader funcs.RowIndex
let buttonList = [
//button ("Edit Column", "fa-solid fa-table-columns", funcs.EditColumn rmv, [])
Shared.button ("Edit Column", "fa-solid fa-table-columns", funcs.EditColumn rmv, [])
if (isHeader && header.IsTermColumn) || Shared.isUnitOrTermCell contextCell then
let oa = if isHeader then header.ToTerm() else contextCell.Value.ToOA()
if oa.TermAccessionShort <> "" then
Shared.button ("Details", "fa-solid fa-magnifying-glass", funcs.GetTermDetails oa rmv, [])
if not isHeader then
Shared.button ("Fill Column", "fa-solid fa-pen", funcs.FillColumn rmv, [])
if Shared.isUnitOrTermCell contextCell then
Expand Down Expand Up @@ -106,8 +112,6 @@ module Table =
]
]

open Shared

let onContextMenu (index: int*int, model: Model, dispatch) = fun (e: Browser.Types.MouseEvent) ->
e.stopPropagation()
e.preventDefault()
Expand All @@ -124,12 +128,14 @@ module Table =
let cell = model.SpreadsheetModel.ActiveTable.TryGetCellAt(ci, ri)
let header = model.SpreadsheetModel.ActiveTable.Headers.[ci]
let isSelectedCell = model.SpreadsheetModel.SelectedCells.Contains index
//let editColumnEvent _ = Modals.Controller.renderModal("EditColumn_Modal", Modals.EditColumn.Main (fst index) model dispatch)
let editColumnEvent _ = Modals.Controller.renderModal("EditColumn_Modal", Modals.EditColumn.Main (fst index) model dispatch)
let triggerMoveColumnModal _ = Modals.Controller.renderModal("MoveColumn_Modal", Modals.MoveColumn.Main(ci, model, dispatch))
let triggerUpdateColumnModal _ =
let columnIndex = fst index
let column = model.SpreadsheetModel.ActiveTable.GetColumn columnIndex
Modals.Controller.renderModal("UpdateColumn_Modal", Modals.UpdateColumn.Main(ci, column, dispatch))
let triggerTermModal oa _ =
Modals.Controller.renderModal("TermDetails_Modal", Modals.TermModal.Main(oa, dispatch))
let funcs = {
DeleteRow = fun rmv e -> rmv e; deleteRowEvent e
DeleteColumn = fun rmv e -> rmv e; Spreadsheet.DeleteColumn (ci) |> Messages.SpreadsheetMsg |> dispatch
Expand Down Expand Up @@ -161,7 +167,8 @@ module Table =
rmv e; Spreadsheet.UpdateCell (index, nextCell) |> Messages.SpreadsheetMsg |> dispatch

UpdateAllCells = fun rmv e -> rmv e; triggerUpdateColumnModal e
//EditColumn = fun rmv e -> rmv e; editColumnEvent e
GetTermDetails = fun oa rmv e -> rmv e; triggerTermModal oa e
EditColumn = fun rmv e -> rmv e; editColumnEvent e
RowIndex = snd index
ColumnIndex = fst index
}
Expand Down
2 changes: 1 addition & 1 deletion src/Client/MainComponents/MainViewContainer.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module MainComponents.MainViewContainer
module MainComponents.MainViewContainer


open Feliz
Expand Down
Loading