From d55289be9db9d3fba937b2cc63b0b5c4bb28204b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Piaggio?= Date: Wed, 23 Oct 2024 17:06:13 -0300 Subject: [PATCH 1/2] allow optional custom RowId in multirow selector handler --- build.sbt | 2 +- .../ui/src/main/scala/lucuma/ui/syntax/table.scala | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/build.sbt b/build.sbt index 7143e2dd2..4c1f0a0c2 100644 --- a/build.sbt +++ b/build.sbt @@ -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 { diff --git a/modules/ui/src/main/scala/lucuma/ui/syntax/table.scala b/modules/ui/src/main/scala/lucuma/ui/syntax/table.scala index cf01e180b..561958ca2 100644 --- a/modules/ui/src/main/scala/lucuma/ui/syntax/table.scala +++ b/modules/ui/src/main/scala/lucuma/ui/syntax/table.scala @@ -10,7 +10,10 @@ import lucuma.react.table.* trait table: extension [T, TM](row: Row[T, TM]) - def getMultiRowSelectedHandler(table: Table[T, TM]): ReactMouseEvent => Callback = + def getMultiRowSelectedHandler( + table: Table[T, TM], + rowId: RowId = row.id + ): ReactMouseEvent => Callback = (e: ReactMouseEvent) => val isShiftPressed: Boolean = e.shiftKey val isCmdCtrlPressed: Boolean = e.metaKey || e.ctrlKey @@ -22,11 +25,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) @@ -44,7 +46,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 From 75e463deb9d07e3ada447f4449772f2cdc3a8b7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Piaggio?= Date: Wed, 23 Oct 2024 17:33:11 -0300 Subject: [PATCH 2/2] better idiom for multirow selection handler --- modules/ui/src/main/scala/lucuma/ui/syntax/table.scala | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/modules/ui/src/main/scala/lucuma/ui/syntax/table.scala b/modules/ui/src/main/scala/lucuma/ui/syntax/table.scala index 561958ca2..fd722d6d1 100644 --- a/modules/ui/src/main/scala/lucuma/ui/syntax/table.scala +++ b/modules/ui/src/main/scala/lucuma/ui/syntax/table.scala @@ -9,11 +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], - rowId: RowId = row.id - ): 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