Skip to content

Commit

Permalink
Merge pull request #1318 from gemini-hlsw/id-getter-table-row-selection
Browse files Browse the repository at this point in the history
Allow optional custom RowId in multirow selector handler
  • Loading branch information
rpiaggio authored Oct 23, 2024
2 parents cd807f7 + 75e463d commit 3860835
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import org.scalajs.linker.interface.ModuleSplitStyle

ThisBuild / tlBaseVersion := "0.118"
ThisBuild / tlBaseVersion := "0.119"
ThisBuild / tlCiReleaseBranches := Seq("master")

val Versions = new {
Expand Down
12 changes: 7 additions & 5 deletions modules/ui/src/main/scala/lucuma/ui/syntax/table.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import japgolly.scalajs.react.ReactMouseEvent
import lucuma.react.table.*

trait table:
extension [T, TM](row: Row[T, TM])
def getMultiRowSelectedHandler(table: Table[T, TM]): ReactMouseEvent => Callback =
extension [T, TM](table: Table[T, TM])
def getMultiRowSelectedHandler(rowId: RowId): ReactMouseEvent => Callback =
(e: ReactMouseEvent) =>
val isShiftPressed: Boolean = e.shiftKey
val isCmdCtrlPressed: Boolean = e.metaKey || e.ctrlKey
Expand All @@ -22,11 +22,10 @@ trait table:
if (isShiftPressed && selectedRows.nonEmpty) {
// If shift is pressed extend
val allRows: List[(Row[T, TM], Int)] = table.getRowModel().rows.zipWithIndex
val currentId: RowId = row.id
// selectedRow is not empty, these won't fail
val firstId: RowId = selectedRows.head.id
val lastId: RowId = selectedRows.last.id
val indexOfCurrent: Int = allRows.indexWhere(_._1.id == currentId)
val indexOfCurrent: Int = allRows.indexWhere(_._1.id == rowId)
val indexOfFirst: Int = allRows.indexWhere(_._1.id == firstId)
val indexOfLast: Int = allRows.indexWhere(_._1.id == lastId)
if (indexOfCurrent =!= -1 && indexOfFirst =!= -1 && indexOfLast =!= -1)
Expand All @@ -44,7 +43,10 @@ trait table:
.map { case (row, _) => row.id -> true }*
)
else Callback.empty
} else row.toggleSelected()
} else
table.modRowSelection: rowSelection =>
RowSelection:
rowSelection.value + (rowId -> rowSelection.value.get(rowId).fold(true)(!_))
)

object table extends table

0 comments on commit 3860835

Please sign in to comment.