Skip to content

Commit

Permalink
renames and rearrangements
Browse files Browse the repository at this point in the history
  • Loading branch information
rpiaggio committed Oct 30, 2024
1 parent ad0faf4 commit 05985ad
Show file tree
Hide file tree
Showing 23 changed files with 367 additions and 383 deletions.
6 changes: 3 additions & 3 deletions common/src/main/scala/explore/model/reusability.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import explore.model.enums.AgsState
import explore.model.enums.SelectedPanel
import explore.model.itc.ItcExposureTime
import explore.model.itc.ItcTarget
import explore.modes.InstrumentConfig
import explore.modes.InstrumentOverrides
import explore.modes.InstrumentRow
import explore.undo.UndoStacks
import explore.utils.OdbRestClient
import japgolly.scalajs.react.ReactCats.*
Expand Down Expand Up @@ -101,7 +101,7 @@ object reusability:
given Reusability[AngularSize] = Reusability.byEq
given Reusability[CatalogTargetResult] = Reusability.byEq
given Reusability[BasicConfiguration] = Reusability.byEq
given Reusability[BasicConfigAndItc] = Reusability.byEq
given Reusability[InstrumentConfigAndItcResult] = Reusability.byEq
given Reusability[GuideStarCandidate] = Reusability.by(_.name.value)
given Reusability[AgsPosition] = Reusability.byEq
given Reusability[AgsParams] = Reusability.byEq
Expand All @@ -110,7 +110,7 @@ object reusability:
given Reusability[ObsConfiguration] = Reusability.byEq
given Reusability[Existence] = Reusability.byEq
given Reusability[ItcExposureTime] = Reusability.byEq
given Reusability[InstrumentRow] = Reusability.byEq
given Reusability[InstrumentConfig] = Reusability.byEq
given Reusability[CentralWavelength] = Reusability.byEq
given Reusability[ObjectTracking] = Reusability.byEq
given Reusability[Asterism] = Reusability.byEq[Asterism]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import cats.Order.given
import cats.syntax.all.*
import crystal.Pot
import eu.timepit.refined.auto.autoUnwrap
import explore.cats.given
import explore.givens.given
import explore.model.GroupTree
import explore.model.GroupUpdate
import explore.model.Observation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ import explore.model.ScienceRequirements
import explore.model.display.*
import explore.model.display.given
import explore.model.enums.WavelengthUnits
import explore.modes.GmosNorthSpectroscopyRow
import explore.modes.GmosSouthSpectroscopyRow
import explore.modes.InstrumentConfig
import explore.modes.ModeCommonWavelengths
import explore.modes.ModeSlitSize
import explore.modes.ModeWavelength
Expand Down Expand Up @@ -230,11 +229,11 @@ sealed abstract class AdvancedConfigurationPanelBuilder[
reqsWavelength.flatMap(cw =>
(mode, row.instrument) match
case (m: ObservingMode.GmosNorthLongSlit,
GmosNorthSpectroscopyRow(rGrating, rFpu, rFilter, _)
InstrumentConfig.GmosNorthSpectroscopy(rGrating, rFpu, rFilter, _)
) if m.grating === rGrating && m.filter === rFilter && m.fpu === rFpu =>
ModeData.build(row, reqsWavelength)
case (m: ObservingMode.GmosSouthLongSlit,
GmosSouthSpectroscopyRow(rGrating, rFpu, rFilter, _)
InstrumentConfig.GmosSouthSpectroscopy(rGrating, rFpu, rFilter, _)
) if m.grating === rGrating && m.filter === rFilter && m.fpu === rFpu =>
ModeData.build(row, reqsWavelength)
case _ => none
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import crystal.react.hooks.*
import explore.Icons
import explore.components.ui.ExploreStyles
import explore.model.AppContext
import explore.model.BasicConfigAndItc
import explore.model.ImagingConfigurationOptions
import explore.model.InstrumentConfigAndItcResult
import explore.model.Observation
import explore.model.ScienceRequirements
import explore.model.ScienceRequirements.Spectroscopy
Expand All @@ -38,7 +38,7 @@ case class BasicConfigurationPanel(
userId: Option[User.Id],
obsId: Observation.Id,
spectroscopyView: ViewOpt[Spectroscopy],
selectedConfig: View[Option[BasicConfigAndItc]],
selectedConfig: View[Option[InstrumentConfigAndItcResult]],
constraints: ConstraintSet,
itcTargets: List[ItcTarget],
baseCoordinates: Option[CoordinatesAtVizTime],
Expand Down Expand Up @@ -73,7 +73,7 @@ private object BasicConfigurationPanel:
.map(_.wavelength)
.fold("Wavelength is required for creating a configuration.".some)(_ =>
props.selectedConfig.get match {
case Some(BasicConfigAndItc(_, itc)) =>
case Some(InstrumentConfigAndItcResult(_, itc)) =>
itc match {
case Some(Right(r)) if r.isPending => "Waiting for ITC result...".some
case Some(Right(r)) if r.isSuccess => none
Expand Down
42 changes: 21 additions & 21 deletions explore/src/main/scala/explore/config/ConfigurationPanel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import explore.common.ScienceQueries.ScienceRequirementsUndoView
import explore.common.ScienceQueries.UpdateScienceRequirements
import explore.components.ui.ExploreStyles
import explore.model.AppContext
import explore.model.BasicConfigAndItc
import explore.model.InstrumentConfigAndItcResult
import explore.model.ObsConfiguration
import explore.model.Observation
import explore.model.ScienceRequirements
import explore.model.ScienceRequirements.Spectroscopy
import explore.model.enums.WavelengthUnits
import explore.model.itc.ItcTarget
import explore.modes.InstrumentRow
import explore.modes.InstrumentConfig
import explore.modes.SpectroscopyModesMatrix
import explore.undo.*
import japgolly.scalajs.react.*
Expand All @@ -45,21 +45,21 @@ import monocle.Iso
import queries.common.ObsQueriesGQL

case class ConfigurationPanel(
userId: Option[User.Id],
programId: Program.Id,
obsId: Observation.Id,
requirements: UndoSetter[ScienceRequirements],
mode: UndoSetter[Option[ObservingMode]],
posAngle: View[PosAngleConstraint],
obsConf: ObsConfiguration,
itcTargets: List[ItcTarget],
baseCoordinates: Option[CoordinatesAtVizTime],
selectedConfig: View[Option[BasicConfigAndItc]],
instrumentRow: Option[InstrumentRow], // configuration selected if reverted
modes: SpectroscopyModesMatrix,
sequenceChanged: Callback,
readonly: Boolean,
units: WavelengthUnits
userId: Option[User.Id],
programId: Program.Id,
obsId: Observation.Id,
requirements: UndoSetter[ScienceRequirements],
mode: UndoSetter[Option[ObservingMode]],
posAngle: View[PosAngleConstraint],
obsConf: ObsConfiguration,
itcTargets: List[ItcTarget],
baseCoordinates: Option[CoordinatesAtVizTime],
selectedConfig: View[Option[InstrumentConfigAndItcResult]],
revertedInstrumentConfig: Option[InstrumentConfig],
modes: SpectroscopyModesMatrix,
sequenceChanged: Callback,
readonly: Boolean,
units: WavelengthUnits
) extends ReactFnProps[ConfigurationPanel](ConfigurationPanel.component)

object ConfigurationPanel:
Expand Down Expand Up @@ -154,11 +154,11 @@ object ConfigurationPanel:
modeAligner.view(_.map(_.toInput).orUnassign)

val deleteConfiguration: Callback =
optModeView.set(none) >> // Select the reverted config
props.instrumentRow
.map: row =>
optModeView.set(none) >>
props.revertedInstrumentConfig
.map: row => // Select the reverted config
props.selectedConfig.mod(c =>
BasicConfigAndItc(
InstrumentConfigAndItcResult(
row,
c.flatMap(_.itcResult.flatMap(_.toOption.map(_.asRight)))
).some
Expand Down
77 changes: 23 additions & 54 deletions explore/src/main/scala/explore/config/SpectroscopyModesTable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import explore.components.HelpIcon
import explore.components.ui.ExploreStyles
import explore.events.*
import explore.model.AppContext
import explore.model.BasicConfigAndItc
import explore.model.InstrumentConfigAndItcResult
import explore.model.Progress
import explore.model.ScienceRequirements
import explore.model.WorkerClients.*
Expand Down Expand Up @@ -74,7 +74,7 @@ import scalajs.js.JSConverters.*

case class SpectroscopyModesTable(
userId: Option[User.Id],
selectedConfig: View[Option[BasicConfigAndItc]],
selectedConfig: View[Option[InstrumentConfigAndItcResult]],
spectroscopyRequirements: ScienceRequirements.Spectroscopy,
constraints: ConstraintSet,
targets: Option[List[ItcTarget]],
Expand Down Expand Up @@ -151,15 +151,15 @@ private object SpectroscopyModesTable:
private val formatSlitLength: ModeSlitSize => String = ss =>
f"${ModeSlitSize.milliarcseconds.get(ss.value).setScale(0, BigDecimal.RoundingMode.DOWN)}%1.0f"

private def formatGrating(grating: InstrumentRow#Grating): String = grating match
private def formatGrating(grating: InstrumentConfig#Grating): String = grating match
case f: GmosSouthGrating => f.shortName
case f: GmosNorthGrating => f.shortName
case f: F2Disperser => f.shortName
case f: GpiDisperser => f.shortName
case f: GnirsDisperser => f.shortName
case r => r.toString

private def formatFilter(filter: InstrumentRow#Filter): String = filter match
private def formatFilter(filter: InstrumentConfig#Filter): String = filter match
case Some(f: GmosSouthFilter) => f.shortName
case Some(f: GmosNorthFilter) => f.shortName
case f: F2Filter => f.shortName
Expand All @@ -169,9 +169,9 @@ private object SpectroscopyModesTable:

// I think these are valid Orderings because they should be consistent with ==
// They could probably be Orders, as well, but only Ordering is actually needed here.
private given Ordering[InstrumentRow#Grating] = Ordering.by(_.toString)
private given Ordering[InstrumentRow#Filter] = Ordering.by(_.toString)
private given Ordering[TimeSpan | Unit] = Ordering.by(_.toOption)
private given Ordering[InstrumentConfig#Grating] = Ordering.by(_.toString)
private given Ordering[InstrumentConfig#Filter] = Ordering.by(_.toString)
private given Ordering[TimeSpan | Unit] = Ordering.by(_.toOption)

private def formatInstrument(r: (Instrument, NonEmptyString)): String = r match
case (i @ Instrument.Gnirs, m) => s"${i.longName} $m"
Expand Down Expand Up @@ -293,40 +293,6 @@ private object SpectroscopyModesTable:
.sortable
)

// extension (row: SpectroscopyModeRow)
// private def rowToConf(cw: Option[Wavelength]): Option[BasicConfiguration] =
// cw.flatMap(row.intervalCenter)
// .flatMap: cc =>
// row.instrument match
// case GmosNorthSpectroscopyRow(grating, fpu, filter, modeOverrides)
// if row.focalPlane === FocalPlane.SingleSlit =>
// BasicConfiguration
// .GmosNorthLongSlit(
// grating = grating,
// filter = filter,
// fpu = fpu,
// centralWavelength = cc
// )
// .some
// case GmosSouthSpectroscopyRow(grating, fpu, filter, _)
// if row.focalPlane === FocalPlane.SingleSlit =>
// BasicConfiguration
// .GmosSouthLongSlit(
// grating = grating,
// filter = filter,
// fpu = fpu,
// centralWavelength = cc
// )
// .some
// case _ => none

// extension (row: SpectroscopyModeRowWithResult)
// private def rowToConfAndItc(cw: Option[Wavelength]): Option[BasicConfigAndItc] =
// row.entry.rowToConf(cw).map(c => BasicConfigAndItc(c, row.result.some))

// private def equalsConf(conf: BasicConfiguration, cw: Option[Wavelength]): Boolean =
// row.entry.rowToConf(cw).contains_(conf)

extension (row: SpectroscopyModeRow)
private def enabledRow: Boolean =
List(Instrument.GmosNorth, Instrument.GmosSouth).contains_(row.instrument.instrument) &&
Expand Down Expand Up @@ -458,7 +424,7 @@ private object SpectroscopyModesTable:
props.selectedConfig.get
.flatMap: c =>
rows.value.find: row =>
c.configuration === row.entry.instrument
c.instrumentConfig === row.entry.instrument
.map(_.entry)
// selectedIndex
// The selected index needs to be the index into the sorted data, because that is what
Expand All @@ -475,9 +441,9 @@ private object SpectroscopyModesTable:
_ =>
val optRow: Option[SpectroscopyModeRowWithResult] =
selectedIndex.value.flatMap(idx => sortedRows.lift(idx))
val conf: Option[BasicConfigAndItc] =
val conf: Option[InstrumentConfigAndItcResult] =
optRow.map: row =>
BasicConfigAndItc(row.entry.instrument, row.result.some)
InstrumentConfigAndItcResult(row.entry.instrument, row.result.some)
if (props.selectedConfig.get =!= conf)
props.selectedConfig.set(conf)
else Callback.empty
Expand Down Expand Up @@ -531,12 +497,13 @@ private object SpectroscopyModesTable:
row.entry.instrument.instrument match
case Instrument.GmosNorth | Instrument.GmosSouth =>
cache.contains:
ItcRequestParams(w,
sn,
snAt,
constraints,
asterism,
row.entry.instrument
ItcRequestParams(
w,
sn,
snAt,
constraints,
asterism,
row.entry.instrument
)
case _ => true

Expand Down Expand Up @@ -612,9 +579,11 @@ private object SpectroscopyModesTable:

def toggleRow(
row: SpectroscopyModeRowWithResult
): Option[BasicConfigAndItc] =
Option.when(props.selectedConfig.get.forall(_.configuration =!= row.entry.instrument)):
BasicConfigAndItc(row.entry.instrument, row.result.some)
): Option[InstrumentConfigAndItcResult] =
Option.when(
props.selectedConfig.get.forall(_.instrumentConfig =!= row.entry.instrument)
):
InstrumentConfigAndItcResult(row.entry.instrument, row.result.some)

def scrollButton(content: VdomNode, style: Css, indexCondition: Int => Boolean): TagMod =
selectedIndex.value.whenDefined(idx =>
Expand Down Expand Up @@ -688,7 +657,7 @@ private object SpectroscopyModesTable:
ExploreStyles.TableRowSelected
.when:
props.selectedConfig.get
.exists(_.configuration === row.original.entry.instrument)
.exists(_.instrumentConfig === row.original.entry.instrument)
,
(
^.onClick --> (
Expand Down
Loading

0 comments on commit 05985ad

Please sign in to comment.