Skip to content

Commit

Permalink
Port scheduling tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
cquiroz committed Aug 15, 2024
1 parent 1424b82 commit 171c2c4
Show file tree
Hide file tree
Showing 9 changed files with 540 additions and 521 deletions.
2 changes: 1 addition & 1 deletion explore/src/main/scala/explore/Routing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ object Routing:
withProgramSummaries(model)(programSummaries =>
val routingInfo = RoutingInfo.from(page)
SchedulingTabContents(
model.zoom(RootModel.userId).get,
routingInfo.programId,
model.zoom(RootModel.userId).get,
programSummaries,
userPreferences(model),
routingInfo.focused.obsSet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ import org.typelevel.log4cats.Logger
import scala.collection.immutable.SortedSet
import lucuma.core.util.NewType

object ObsAttachmentsTableState extends NewType[Action]:
def apply(): ObsAttachmentsTableState = ObsAttachmentsTableState(Action.None)
type ObsAttachmentsTableState = ObsAttachmentsTableState.Type
object ObsAttachmentsTableTileState extends NewType[Action]:
def apply(): ObsAttachmentsTableTileState = ObsAttachmentsTableTileState(Action.None)
type ObsAttachmentsTableTileState = ObsAttachmentsTableTileState.Type

case class ObsAttachmentsTableBody(
pid: Program.Id,
Expand All @@ -71,7 +71,7 @@ case class ObsAttachmentsTableBody(
obsAttachments: View[ObsAttachmentList],
readOnly: Boolean
)(
val state: View[ObsAttachmentsTableState]
val state: View[ObsAttachmentsTableTileState]
) extends ReactFnProps(ObsAttachmentsTableBody.component)

object ObsAttachmentsTableBody extends ObsAttachmentUtils:
Expand Down Expand Up @@ -183,7 +183,7 @@ object ObsAttachmentsTableBody extends ObsAttachmentUtils:
.useMemoBy((_, _, _, _) => ()): (props, ctx, _, _) =>
_ =>
import ctx.given
val action = props.state.zoom(ObsAttachmentsTableState.value.asLens)
val action = props.state.zoom(ObsAttachmentsTableTileState.value.asLens)

def column[V](id: ColumnId, accessor: ObsAttachment => V)
: ColumnDef.Single.WithTableMeta[View[ObsAttachment], V, TableMeta] =
Expand Down Expand Up @@ -338,7 +338,7 @@ object ObsAttachmentsTableBody extends ObsAttachmentUtils:
meta = TableMeta(client, props.obsAttachmentAssignments, urlMap.get, props.readOnly)
)
.render: (props, ctx, client, _, _, _, table) =>
val action = props.state.zoom(ObsAttachmentsTableState.value.asLens)
val action = props.state.zoom(ObsAttachmentsTableTileState.value.asLens)

React.Fragment(
PrimeTable(
Expand Down Expand Up @@ -368,7 +368,7 @@ case class ObsAttachmentsTableTitle(
obsAttachments: View[ObsAttachmentList],
readOnly: Boolean
)(
val state: View[ObsAttachmentsTableState]
val state: View[ObsAttachmentsTableTileState]
) extends ReactFnProps(ObsAttachmentsTableTitle.component)

object ObsAttachmentsTableTitle extends ObsAttachmentUtils:
Expand Down Expand Up @@ -409,7 +409,7 @@ object ObsAttachmentsTableTitle extends ObsAttachmentUtils:
props.obsAttachments,
newAttType.get,
client,
props.state.zoom(ObsAttachmentsTableState.value.asLens)
props.state.zoom(ObsAttachmentsTableTileState.value.asLens)
),
^.id := "attachment-upload",
^.name := "file",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import explore.model.reusability.given
import explore.observationtree.ConstraintGroupObsList
import explore.shortcuts.*
import explore.shortcuts.given
import explore.timingwindows.TimingWindowsPanel
import explore.timingwindows.TimingWindowsTile
import explore.undo.*
import japgolly.scalajs.react.*
import japgolly.scalajs.react.callback.CallbackCatsEffect.*
Expand Down
2 changes: 1 addition & 1 deletion explore/src/main/scala/explore/tabs/ObsTabTiles.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import explore.model.layout.*
import explore.modes.SpectroscopyModesMatrix
import explore.observationtree.obsEditAttachments
import explore.syntax.ui.*
import explore.timingwindows.TimingWindowsPanel
import explore.timingwindows.TimingWindowsTile
import explore.undo.UndoSetter
import japgolly.scalajs.react.*
import japgolly.scalajs.react.extra.router.SetRouteVia
Expand Down
4 changes: 2 additions & 2 deletions explore/src/main/scala/explore/tabs/OverviewTabContents.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import cats.syntax.all.*
import crystal.react.*
import explore.attachments.ObsAttachmentsTableBody
import explore.attachments.ObsAttachmentsTableTitle
import explore.attachments.ObsAttachmentsTableState
import explore.attachments.ObsAttachmentsTableTileState
import explore.components.Tile
import explore.components.TileController
import explore.model.AppContext
Expand Down Expand Up @@ -66,7 +66,7 @@ object OverviewTabContents {
.map(vault =>
Tile(
ObsTabTilesIds.ObsAttachmentsId.id,
ObsAttachmentsTableState(),
ObsAttachmentsTableTileState(),
"Observation Attachments",
none,
canMinimize = true
Expand Down
149 changes: 74 additions & 75 deletions explore/src/main/scala/explore/tabs/SchedulingTabContents.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import explore.model.reusability.given
import explore.observationtree.SchedulingGroupObsList
import explore.shortcuts.*
import explore.shortcuts.given
import explore.timingwindows.TimingWindowsPanel
import explore.timingwindows.TimingWindowsTile
import explore.undo.*
import japgolly.scalajs.react.*
import japgolly.scalajs.react.callback.CallbackCatsEffect.*
Expand All @@ -48,8 +48,8 @@ import scala.collection.immutable.SortedSet
import scala.scalajs.LinkingInfo

case class SchedulingTabContents(
userId: Option[User.Id],
programId: Program.Id,
userId: Option[User.Id],
programSummaries: UndoContext[ProgramSummaries],
userPreferences: UserPreferences,
focusedObsSet: Option[ObsIdSet],
Expand Down Expand Up @@ -83,76 +83,75 @@ object SchedulingTabContents extends TwoPanels:
}
// Measure its size
.useResizeDetector()
.render((props, ctx, state, resize) => <.div("SchedulingTabContents"))
// import ctx.given
//
// def findSchedulingGroup(
// obsIds: ObsIdSet,
// cgl: SchedulingGroupList
// ): Option[SchedulingGroup] =
// cgl.find(_._1.intersect(obsIds).nonEmpty).map(SchedulingGroup.fromTuple)
//
// val observations: UndoSetter[ObservationList] =
// props.programSummaries.zoom(ProgramSummaries.observations)
//
// val rightSide = (_: UseResizeDetectorReturn) =>
// props.focusedObsSet
// .flatMap(ids =>
// findSchedulingGroup(ids, props.programSummaries.get.schedulingGroups)
// .map(cg => (ids, cg))
// )
// .fold[VdomNode] {
// <.div("Nothing selected - Will we have a summary table?")
// } { case (idsToEdit, schedulingGroup) =>
// val obsTraversal = Iso
// .id[ObservationList]
// .filterIndex((id: Observation.Id) => idsToEdit.contains(id))
// .andThen(KeyedIndexedList.value)
//
// val twTraversal = obsTraversal.andThen(Observation.timingWindows)
//
// val timingWindows: View[List[TimingWindow]] =
// TimingWindowsQueries.viewWithRemoteMod(
// idsToEdit,
// observations
// .undoableView[List[TimingWindow]](
// twTraversal.getAll.andThen(_.head),
// twTraversal.modify
// )
// )
//
// val timingWindowsTile =
// TimingWindowsPanel.timingWindowsPanel(timingWindows, props.readonly)
//
// TileController(
// props.userId,
// resize.width.getOrElse(1),
// ExploreGridLayouts.sectionLayout(GridLayoutSection.SchedulingLayout),
// props.userPreferences.schedulingTabLayout,
// List(timingWindowsTile),
// GridLayoutSection.SchedulingLayout,
// None
// )
// }
//
// val schedulingTree =
// SchedulingGroupObsList(
// props.programId,
// observations,
// props.programSummaries,
// props.programSummaries.get.schedulingGroups,
// props.programSummaries.get.calibrationObservations,
// props.programSummaries.get.obsExecutionPots,
// props.focusedObsSet,
// state.set(SelectedPanel.Summary),
// props.expandedIds,
// props.readonly
// )
//
// React.Fragment(
// if (LinkingInfo.developmentMode)
// FocusedStatus(AppTab.Scheduling, props.programId, Focused(props.focusedObsSet))
// else EmptyVdom,
// makeOneOrTwoPanels(state, schedulingTree, rightSide, RightSideCardinality.Multi, resize)
// )
// }
.render: (props, ctx, state, resize) =>
import ctx.given

def findSchedulingGroup(
obsIds: ObsIdSet,
cgl: SchedulingGroupList
): Option[SchedulingGroup] =
cgl.find(_._1.intersect(obsIds).nonEmpty).map(SchedulingGroup.fromTuple)

val observations: UndoSetter[ObservationList] =
props.programSummaries.zoom(ProgramSummaries.observations)

val rightSide = (_: UseResizeDetectorReturn) =>
props.focusedObsSet
.flatMap(ids =>
findSchedulingGroup(ids, props.programSummaries.get.schedulingGroups)
.map(cg => (ids, cg))
)
.fold[VdomNode] {
<.div("Nothing selected - Will we have a summary table?")
} { case (idsToEdit, schedulingGroup) =>
val obsTraversal = Iso
.id[ObservationList]
.filterIndex((id: Observation.Id) => idsToEdit.contains(id))
.andThen(KeyedIndexedList.value)

val twTraversal = obsTraversal.andThen(Observation.timingWindows)

val timingWindows: View[List[TimingWindow]] =
TimingWindowsQueries.viewWithRemoteMod(
idsToEdit,
observations
.undoableView[List[TimingWindow]](
twTraversal.getAll.andThen(_.head),
twTraversal.modify
)
)

val timingWindowsTile =
TimingWindowsTile.timingWindowsPanel(timingWindows, props.readonly)

TileController(
props.userId,
resize.width.getOrElse(1),
ExploreGridLayouts.sectionLayout(GridLayoutSection.SchedulingLayout),
props.userPreferences.schedulingTabLayout,
List(timingWindowsTile),
GridLayoutSection.SchedulingLayout,
None
)
}

val schedulingTree =
SchedulingGroupObsList(
props.programId,
observations,
props.programSummaries,
props.programSummaries.get.schedulingGroups,
props.programSummaries.get.calibrationObservations,
props.programSummaries.get.obsExecutionPots,
props.focusedObsSet,
state.set(SelectedPanel.Summary),
props.expandedIds,
props.readonly
)

React.Fragment(
if (LinkingInfo.developmentMode)
FocusedStatus(AppTab.Scheduling, props.programId, Focused(props.focusedObsSet))
else EmptyVdom,
makeOneOrTwoPanels(state, schedulingTree, rightSide, RightSideCardinality.Multi, resize)
)
Loading

0 comments on commit 171c2c4

Please sign in to comment.