Skip to content

Commit

Permalink
wiup
Browse files Browse the repository at this point in the history
  • Loading branch information
cquiroz committed Sep 19, 2024
1 parent 4bddf13 commit 74be049
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 21 deletions.
5 changes: 4 additions & 1 deletion common/src/main/scala/explore/model/ObsConfiguration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import lucuma.schemas.model.BasicConfiguration
import org.typelevel.cats.time.instances.duration.*

import java.time.Duration
import eu.timepit.refined.types.string.NonEmptyString
import eu.timepit.refined.cats.*

case class ObsConfiguration(
configuration: Option[BasicConfiguration],
Expand All @@ -29,7 +31,8 @@ case class ObsConfiguration(
acquisitionOffsets: Option[NonEmptyList[Offset]],
averagePA: Option[AveragePABasis],
obsDuration: Option[Duration],
needGuideStar: Boolean
needGuideStar: Boolean,
selectedGSName: Option[NonEmptyString]
) derives Eq:
// In case there is no guide star we still want to have a posAngle equivalent
// To draw visualization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ object ObservationSubquery extends GraphQLSubquery.Typed[ObservationDB, Observat
asterism {
id
}
guideTargetName
}
constraintSet $ConstraintSetSubquery
timingWindows $TimingWindowSubquery
Expand Down
33 changes: 19 additions & 14 deletions explore/src/clue/scala/queries/common/TargetQueriesGQL.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import lucuma.schemas.ObservationDB
import lucuma.schemas.odb.*
// gql: import lucuma.schemas.decoders.given

object TargetQueriesGQL {
object TargetQueriesGQL:

@GraphQL
trait TargetNameQuery extends GraphQLOperation[ObservationDB] {
trait TargetNameQuery extends GraphQLOperation[ObservationDB]:
// FIXME Change this to an actual name pattern query when it's available in the API
val document = s"""
query($$programId: ProgramId!) {
Expand All @@ -23,10 +23,9 @@ object TargetQueriesGQL {
}
}
"""
}

@GraphQL
trait CreateTargetMutation extends GraphQLOperation[ObservationDB] {
trait CreateTargetMutation extends GraphQLOperation[ObservationDB]:
val document = """
mutation($input: CreateTargetInput!) {
createTarget(input: $input) {
Expand All @@ -36,10 +35,9 @@ object TargetQueriesGQL {
}
}
"""
}

@GraphQL
trait UpdateTargetsMutation extends GraphQLOperation[ObservationDB] {
trait UpdateTargetsMutation extends GraphQLOperation[ObservationDB]:
val document = """
mutation($input: UpdateTargetsInput!) {
updateTargets(input: $input) {
Expand All @@ -49,32 +47,41 @@ object TargetQueriesGQL {
}
}
"""
}

@GraphQL
trait CloneTargetMutation extends GraphQLOperation[ObservationDB] {
trait CloneTargetMutation extends GraphQLOperation[ObservationDB]:
val document = s"""
mutation($$input: CloneTargetInput!) {
cloneTarget(input: $$input) {
newTarget $TargetWithIdSubquery
}
}
"""
}

@GraphQL
trait TargetEditSubscription extends GraphQLOperation[ObservationDB] {
trait SetGuideTargetName extends GraphQLOperation[ObservationDB]:
val document = s"""
mutation($$input: SetGuideTargetNameInput!) {
setGuideTargetName(input: $$input) {
observation {
id
}
}
}
"""

@GraphQL
trait TargetEditSubscription extends GraphQLOperation[ObservationDB]:
val document = """
subscription($targetId: TargetId!) {
targetEdit(input: {targetId: $targetId}) {
id
}
}
"""
}

@GraphQL
trait ProgramTargetsDelta extends GraphQLOperation[ObservationDB] {
trait ProgramTargetsDelta extends GraphQLOperation[ObservationDB]:
val document = s"""
subscription($$input: TargetEditInput!) {
targetEdit(input: $$input) {
Expand All @@ -85,5 +92,3 @@ object TargetQueriesGQL {
}
}
"""
}
}
6 changes: 5 additions & 1 deletion explore/src/main/scala/explore/tabs/ObsTabTiles.scala
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ object ObsTabTiles:
val vizDurationView: View[Option[TimeSpan]] =
props.observation.model.zoom(Observation.observationDuration)

val selectedGSNameView: View[Option[NonEmptyString]] =
props.observation.model.zoom(Observation.selectedGSName)

val asterismAsNel: Option[NonEmptyList[TargetWithId]] =
NonEmptyList.fromList:
props.observation.get.scienceTargetIds.toList
Expand Down Expand Up @@ -389,7 +392,8 @@ object ObsTabTiles:
sequenceOffsets.toOption.flatMap(_.acquisition),
averagePA,
obsDuration.map(_.toDuration),
props.observation.get.needsAGS
props.observation.get.needsAGS,
selectedGSNameView.get
)

def getObsInfo(obsId: Observation.Id)(targetId: Target.Id): TargetEditObsInfo =
Expand Down
4 changes: 3 additions & 1 deletion explore/src/main/scala/explore/tabs/TargetTabContents.scala
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ object TargetTabContents extends TwoPanels:
_,
_,
_,
_,
const,
_,
_,
Expand Down Expand Up @@ -522,7 +523,8 @@ object TargetTabContents extends TwoPanels:
none,
none,
none,
needsAGS
needsAGS,
none
),
none,
props.focused.target,
Expand Down
34 changes: 30 additions & 4 deletions explore/src/main/scala/explore/targeteditor/AladinCell.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,17 @@ import lucuma.ui.syntax.all.given
import monocle.Lens
import org.typelevel.log4cats.Logger
import queries.schemas.UserPreferencesDB
import queries.schemas.odb.ObsQueries

import java.time.Duration
import java.time.Instant
import scala.concurrent.duration.*
import eu.timepit.refined.types.string.NonEmptyString
import eu.timepit.refined.cats.*

case class AladinCell(
uid: User.Id,
obsId: Option[Observation.Id],
asterism: Asterism,
vizTime: Instant,
obsConf: Option[ObsConfiguration],
Expand Down Expand Up @@ -106,6 +110,9 @@ case class AladinCell(
def modeSelected: Boolean =
obsConf.exists(_.configuration.isDefined)

def selectedGSName: Option[NonEmptyString] =
obsConf.flatMap(_.selectedGSName)

def sciencePositionsAt(vizTime: Instant): List[Coordinates] =
asterism.asList
.flatMap(_.toSidereal)
Expand Down Expand Up @@ -286,6 +293,20 @@ object AladinCell extends ModelOptics with AladinCommon:
} yield ()
)
.useStateView(ManualAgsOverride(false))
// Reset offset and gs if asterism change
.useEffectWithDepsBy((p, _, _, gsc, _, _, index, _, _) =>
(p.selectedGSName, gsc, index.reuseByValue)
)((p, _, _, gsc, _, _, _, _, _) =>
_ =>
val f = gsc.value.value.flatMap(_.find(a => p.selectedGSName.exists(_ === a.name)))
Callback.log(s"From odb ${p.selectedGSName}") *>
Callback.log(gsc.value.value.foldMap(_.size)) *>
Callback.log(p.selectedGSName.map(_.value).toString) *> Callback.log(
s"Found $f"
// gsc.value.value.foldMap(_.map(_.name.value).toString)
// gsc.value.map(_.map(_.map(_.name.value)).toString)
)
)
// Reset selection if pos angle changes except for manual selection changes
.useEffectWithDepsBy((p, _, _, _, _, _, _, _, _) => p.obsConf.flatMap(_.posAngleConstraint))(
(_, _, _, _, _, _, selectedIndex, _, agsOverride) =>
Expand Down Expand Up @@ -316,6 +337,7 @@ object AladinCell extends ModelOptics with AladinCommon:
candidates
) if props.needsAGS =>
import ctx.given
println(s"GS odb ${props.selectedGSName}")

val runAgs = (positions,
tracking.at(vizTime),
Expand Down Expand Up @@ -403,10 +425,14 @@ object AladinCell extends ModelOptics with AladinCommon:
idx
.map(agsResults.value.lift)
.map(a =>
flipAngle(props, agsManualOverride)(a) *> props.obsConf
.flatMap(_.selectedGS)
.map(_.set(a))
.getOrEmpty
flipAngle(props, agsManualOverride)(a) *>
props.obsConf
.flatMap(_.selectedGS)
.map(_.set(a))
.getOrEmpty *>
(props.obsId, a.map(_.target.name))
.mapN((id, n) => ObsQueries.setGuideTargetName[IO](id, n).runAsyncAndForget)
.getOrEmpty
)
.getOrEmpty
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,14 @@ object SiderealTargetEditor:
_ === props.asterism.focus.id
) || cloning.get || props.readonly || props.obsInfo.isReadonly

val oid = props.obsInfo.current.map(_.head)
React.Fragment(
TargetCloneSelector(props.obsInfo, obsToCloneTo),
<.div(ExploreStyles.TargetGrid)(
vizTime.renderPot(vt =>
AladinCell(
props.userId,
oid,
props.asterism,
vt,
props.obsConf,
Expand Down
11 changes: 11 additions & 0 deletions explore/src/main/scala/queries/schemas/odb/ObsQueries.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import lucuma.schemas.ObservationDB.Enums.*
import lucuma.schemas.ObservationDB.Types.*
import lucuma.schemas.odb.input.*
import queries.common.ObsQueriesGQL.*
import queries.common.TargetQueriesGQL.SetGuideTargetName

import java.time.Instant
import scala.collection.immutable.SortedMap
Expand Down Expand Up @@ -269,3 +270,13 @@ object ObsQueries:
)
)
UpdateObservationMutation[F].execute(input).void

def setGuideTargetName[F[_]: Async](
obsId: Observation.Id,
targetName: NonEmptyString
)(using FetchClient[F, ObservationDB]) =
val input = SetGuideTargetNameInput(
observationId = obsId.assign,
targetName = targetName.assign
)
SetGuideTargetName[F].execute(input).void
6 changes: 6 additions & 0 deletions model/shared/src/main/scala/explore/model/Observation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ case class Observation(
status: ObsStatus,
activeStatus: ObsActiveStatus,
scienceTargetIds: AsterismIds,
selectedGSName: Option[NonEmptyString],
constraints: ConstraintSet,
timingWindows: List[TimingWindow],
attachmentIds: SortedSet[ObsAttachment.Id],
Expand Down Expand Up @@ -204,6 +205,7 @@ object Observation:
val validations = Focus[Observation](_.validations)
val observerNotes = Focus[Observation](_.observerNotes)
val calibrationRole = Focus[Observation](_.calibrationRole)
val selectedGSName = Focus[Observation](_.selectedGSName)

private case class TargetIdWrapper(id: Target.Id)
private object TargetIdWrapper:
Expand All @@ -221,6 +223,9 @@ object Observation:
status <- c.get[ObsStatus]("status")
activeStatus <- c.get[ObsActiveStatus]("activeStatus")
scienceTargetIds <- c.downField("targetEnvironment").get[List[TargetIdWrapper]]("asterism")
selectedGSName <- c.downField("targetEnvironment")
.downField("guideTargetName")
.as[Option[NonEmptyString]]
constraints <- c.get[ConstraintSet]("constraintSet")
timingWindows <- c.get[List[TimingWindow]]("timingWindows")
attachmentIds <- c.get[List[AttachmentIdWrapper]]("obsAttachments")
Expand All @@ -244,6 +249,7 @@ object Observation:
status,
activeStatus,
SortedSet.from(scienceTargetIds.map(_.id)),
selectedGSName,
constraints,
timingWindows,
SortedSet.from(attachmentIds.map(_.id)),
Expand Down

0 comments on commit 74be049

Please sign in to comment.