Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cquiroz committed Aug 17, 2024
1 parent d08d6e8 commit 841108d
Show file tree
Hide file tree
Showing 23 changed files with 158 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import japgolly.scalajs.react.vdom.html_<^.*
import lucuma.core.model.ObsAttachment as ObsAtt
import lucuma.core.model.Program
import lucuma.core.util.Enumerated
import lucuma.core.util.NewType
import lucuma.core.util.Timestamp
import lucuma.react.common.ReactFnProps
import lucuma.react.common.style.Css
Expand All @@ -58,7 +59,6 @@ import org.scalajs.dom.File as DomFile
import org.typelevel.log4cats.Logger

import scala.collection.immutable.SortedSet
import lucuma.core.util.NewType

object ObsAttachmentsTableTileState extends NewType[Action]:
def apply(): ObsAttachmentsTableTileState = ObsAttachmentsTableTileState(Action.None)
Expand All @@ -69,10 +69,10 @@ case class ObsAttachmentsTableBody(
authToken: NonEmptyString,
obsAttachmentAssignments: ObsAttachmentAssignmentMap,
obsAttachments: View[ObsAttachmentList],
readOnly: Boolean
)(
val state: View[ObsAttachmentsTableTileState]
) extends ReactFnProps(ObsAttachmentsTableBody.component)
readOnly: Boolean,
tileState: View[ObsAttachmentsTableTileState]
) extends ReactFnProps(ObsAttachmentsTableBody.component):
val action = tileState.zoom(ObsAttachmentsTableTileState.value.asLens)

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

def column[V](id: ColumnId, accessor: ObsAttachment => V)
: ColumnDef.Single.WithTableMeta[View[ObsAttachment], V, TableMeta] =
Expand All @@ -206,7 +205,7 @@ object ObsAttachmentsTableBody extends ObsAttachmentUtils:
val files = e.target.files.toList
(Callback(e.target.value = null) *>
updateAttachment(props, meta.client, thisOa, files)
.switching(action.async, Action.Replace, Action.None)
.switching(props.action.async, Action.Replace, Action.None)
.runAsync)
.when_(files.nonEmpty)

Expand Down Expand Up @@ -337,9 +336,7 @@ object ObsAttachmentsTableBody extends ObsAttachmentUtils:
getRowId = (row, _, _) => RowId(row.get.id.toString),
meta = TableMeta(client, props.obsAttachmentAssignments, urlMap.get, props.readOnly)
)
.render: (props, ctx, client, _, _, _, table) =>
val action = props.state.zoom(ObsAttachmentsTableTileState.value.asLens)

.render: (props, _, _, _, _, _, table) =>
React.Fragment(
PrimeTable(
table,
Expand All @@ -351,8 +348,8 @@ object ObsAttachmentsTableBody extends ObsAttachmentUtils:
ConfirmPopup(),
Dialog(
onHide = Callback.empty,
visible = action.get != Action.None,
header = action.get.msg,
visible = props.action.get != Action.None,
header = props.action.get.msg,
blockScroll = true,
modal = true,
dismissableMask = false,
Expand All @@ -366,10 +363,10 @@ case class ObsAttachmentsTableTitle(
pid: Program.Id,
authToken: NonEmptyString,
obsAttachments: View[ObsAttachmentList],
readOnly: Boolean
)(
val state: View[ObsAttachmentsTableTileState]
) extends ReactFnProps(ObsAttachmentsTableTitle.component)
readOnly: Boolean,
tileState: View[ObsAttachmentsTableTileState]
) extends ReactFnProps(ObsAttachmentsTableTitle.component):
val action = tileState.zoom(ObsAttachmentsTableTileState.value.asLens)

object ObsAttachmentsTableTitle extends ObsAttachmentUtils:
private type Props = ObsAttachmentsTableTitle
Expand Down Expand Up @@ -409,7 +406,7 @@ object ObsAttachmentsTableTitle extends ObsAttachmentUtils:
props.obsAttachments,
newAttType.get,
client,
props.state.zoom(ObsAttachmentsTableTileState.value.asLens)
props.action
),
^.id := "attachment-upload",
^.name := "file",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

package explore.components

import crystal.react.View
import cats.syntax.all.*
import crystal.react.View
import explore.components.ui.ExploreStyles
import japgolly.scalajs.react.*
import japgolly.scalajs.react.vdom.html_<^.*
import lucuma.react.common.ReactFnProps
import lucuma.react.table.ColumnId
import lucuma.react.table.Table
import lucuma.ui.table.ColumnSelector
import lucuma.react.table.ColumnId

case class ColumnSelectorState[A, B](
table: Option[Table[A, B]] = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,33 @@ import crystal.react.*
import crystal.react.given
import crystal.react.hooks.*
import explore.*
import explore.components.HelpIcon
import explore.components.ui.ExploreStyles
import explore.model.AppContext
import explore.model.Execution
import explore.model.Observation
import explore.model.reusability.given
import explore.syntax.ui.*
import japgolly.scalajs.react.*
import japgolly.scalajs.react.vdom.html_<^.*
import lucuma.core.enums.ObserveClass
import lucuma.core.math.SignalToNoise
import lucuma.core.model.Program
import lucuma.core.model.Target
import lucuma.core.model.sequence.InstrumentExecutionConfig
import lucuma.core.util.TimeSpan
import lucuma.react.common.ReactFnProps
import lucuma.react.primereact.Message
import lucuma.refined.*
import lucuma.schemas.model.ExecutionVisits
import lucuma.schemas.odb.SequenceQueriesGQL.*
import lucuma.schemas.odb.input.*
import lucuma.ui.components.TimeSpanView
import lucuma.ui.syntax.all.*
import lucuma.ui.syntax.all.given
import queries.common.ObsQueriesGQL
import queries.common.TargetQueriesGQL
import queries.common.VisitQueriesGQL.*
import explore.model.Execution
import explore.syntax.ui.*
import lucuma.core.util.TimeSpan

import explore.components.HelpIcon
import lucuma.ui.components.TimeSpanView
import lucuma.refined.*

case class GeneratedSequenceBody(
programId: Program.Id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import crystal.react.*
import explore.Icons
import explore.common.UserPreferencesQueries
import explore.common.UserPreferencesQueries.TableStore
import explore.components.ui.ExploreStyles
import explore.components.ColumnSelectorState
import explore.components.ui.ExploreStyles
import explore.model.AppContext
import explore.model.ConstraintGroup
import explore.model.ConstraintGroupList
Expand Down Expand Up @@ -40,9 +40,9 @@ case class ConstraintsSummaryTableBody(
userId: Option[User.Id],
programId: Program.Id,
constraintList: ConstraintGroupList,
expandedIds: View[SortedSet[ObsIdSet]]
)(val state: View[ColumnSelectorState[ConstraintGroup, Nothing]])
extends ReactFnProps(ConstraintsSummaryTableBody.component)
expandedIds: View[SortedSet[ObsIdSet]],
tileState: View[ColumnSelectorState[ConstraintGroup, Nothing]]
) extends ReactFnProps(ConstraintsSummaryTableBody.component)

object ConstraintsSummaryTableBody:
private type Props = ConstraintsSummaryTableBody
Expand Down Expand Up @@ -231,7 +231,7 @@ object ConstraintsSummaryTableBody:
TableStore(props.userId, TableId.ConstraintsSummary, cols)
)
)
.useEffectOnMountBy((p, _, _, _, table) => p.state.set(ColumnSelectorState(table.some)))
.useEffectOnMountBy((p, _, _, _, table) => p.tileState.set(ColumnSelectorState(table.some)))
.render { (props, _, _, _, table) =>
<.div(
PrimeTable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import lucuma.ui.components.SolarProgress
import lucuma.ui.reusability.given
import lucuma.ui.syntax.all.given
import lucuma.ui.syntax.pot.*
import monocle.Focus

import scala.collection.immutable.SortedSet
import monocle.Focus

case class FinderChartsTileState(chartSelector: ChartSelector, selected: Option[ObsAtt.Id])

Expand Down
20 changes: 8 additions & 12 deletions explore/src/main/scala/explore/itc/ItcPanelTile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,14 @@ import explore.model.itc.*
import japgolly.scalajs.react.*
import japgolly.scalajs.react.vdom.html_<^.*
import lucuma.core.model.User
import lucuma.core.util.NewType
import lucuma.react.common.ReactFnProps
import lucuma.ui.syntax.all.given
import monocle.Lens
import monocle.Focus

case class ItcPanelTileState(
selectedTarget: Option[ItcTarget] = None
)
object ItcPanelTileState extends NewType[Option[ItcTarget]]:
def apply(): ItcPanelTileState = ItcPanelTileState(None)

object ItcPanelTileState:
val selectedTarget: Lens[ItcPanelTileState, Option[ItcTarget]] =
Focus[ItcPanelTileState](_.selectedTarget)
type ItcPanelTileState = ItcPanelTileState.Type

case class ItcPanelBody(
uid: User.Id,
Expand All @@ -39,9 +35,9 @@ case class ItcPanelBody(
itcChartResults: Map[ItcTarget, Pot[ItcChartResult]],
itcLoading: LoadingState,
globalPreferences: View[GlobalPreferences],
state: View[ItcPanelTileState]
tileState: View[ItcPanelTileState]
) extends ReactFnProps(ItcPanelBody.component) {
val selectedTarget = state.zoom(ItcPanelTileState.selectedTarget)
val selectedTarget = tileState.zoom(ItcPanelTileState.value.asLens)
}

object ItcPanelBody:
Expand Down Expand Up @@ -69,7 +65,7 @@ object ItcPanelBody:
val detailsView =
globalPreferences.zoom(GlobalPreferences.itcDetailsOpen)

val selectedTarget = props.state.get.selectedTarget
val selectedTarget = props.selectedTarget.get

val isModeSelected = props.itcProps.finalConfig.isDefined
val selectMode = "Select a mode to plot".some.filterNot(_ => isModeSelected)
Expand Down Expand Up @@ -108,7 +104,7 @@ object ItcPanelBody:
selectedResult.map(_.charts),
error,
chartTypeView.get,
props.state.get.selectedTarget.map(_.name.value),
selectedTarget.map(_.name.value),
props.itcProps.signalToNoiseAt,
props.itcLoading,
detailsView.get
Expand Down
4 changes: 2 additions & 2 deletions explore/src/main/scala/explore/itc/ItcPanelTitle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ case class ItcPanelTitle(
itcPanelProps: ItcProps,
itcChartResults: Map[ItcTarget, Pot[ItcChartResult]],
itcLoading: LoadingState,
state: View[ItcPanelTileState]
tileState: View[ItcPanelTileState]
) extends ReactFnProps(ItcPanelTitle.component) {
val selectedTarget = state.zoom(ItcPanelTileState.selectedTarget)
val selectedTarget = tileState.zoom(ItcPanelTileState.value.asLens)
}

object ItcPanelTitle:
Expand Down
19 changes: 10 additions & 9 deletions explore/src/main/scala/explore/notes/NotesTile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import explore.components.Tile
import explore.components.ui.ExploreStyles
import explore.model.ObsTabTilesIds
import explore.model.Observation
import explore.model.enums.TileSizeState
import japgolly.scalajs.react.*
import japgolly.scalajs.react.vdom.html_<^.*
import lucuma.core.util.NewType
Expand All @@ -27,7 +28,6 @@ import lucuma.ui.primereact.*
import lucuma.ui.primereact.given
import monocle.Focus
import monocle.Lens
import explore.model.enums.TileSizeState

object NotesTile:

Expand All @@ -38,7 +38,7 @@ object NotesTile:
s"Note for Observer",
canMinimize = true,
bodyClass = ExploreStyles.NotesTile
)(NotesTileBody(obsId, notes), NotesTileTitle(obsId, notes))
)(NotesTileBody(obsId, notes, _), NotesTileTitle(obsId, notes, _, _))

case class NotesTileState(notes: String, editing: Editing)

Expand All @@ -48,9 +48,9 @@ object NotesTileState:

case class NotesTileBody(
obsId: Observation.Id,
notes: View[Option[NonEmptyString]]
)(val state: View[NotesTileState])
extends ReactFnProps(NotesTileBody.component)
notes: View[Option[NonEmptyString]],
state: View[NotesTileState]
) extends ReactFnProps(NotesTileBody.component)

type Editing = Editing.Type
object Editing extends NewType[Boolean]:
Expand Down Expand Up @@ -96,10 +96,11 @@ object NotesTileBody:
}

case class NotesTileTitle(
obsId: Observation.Id,
notes: View[Option[NonEmptyString]]
)(val state: View[NotesTileState], val tileSize: TileSizeState)
extends ReactFnProps(NotesTileTitle.component)
obsId: Observation.Id,
notes: View[Option[NonEmptyString]],
state: View[NotesTileState],
tileSize: TileSizeState
) extends ReactFnProps(NotesTileTitle.component)

object NotesTileTitle:
private type Props = NotesTileTitle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import crystal.react.syntax.pot.given
import explore.Icons
import explore.common.UserPreferencesQueries
import explore.common.UserPreferencesQueries.TableStore
import explore.components.ColumnSelectorState
import explore.components.ui.ExploreStyles
import explore.model.AppContext
import explore.model.Asterism
Expand Down Expand Up @@ -58,16 +59,15 @@ import queries.schemas.odb.ObsQueries.ObservationList

import java.time.Instant
import java.util.UUID
import explore.components.ColumnSelectorState

final case class ObsSummaryTable(
userId: Option[User.Id],
programId: Program.Id,
observations: UndoSetter[ObservationList],
obsExecutions: ObservationExecutionMap,
allTargets: TargetList
)(val state: View[ColumnSelectorState[Expandable[ObsSummaryTable.ObsSummaryRow], Nothing]])
extends ReactFnProps(ObsSummaryTable.component)
allTargets: TargetList,
tileState: View[ColumnSelectorState[Expandable[ObsSummaryTable.ObsSummaryRow], Nothing]]
) extends ReactFnProps(ObsSummaryTable.component)

object ObsSummaryTable:
import ObsSummaryRow.*
Expand Down Expand Up @@ -317,7 +317,7 @@ object ObsSummaryTable:
),
TableStore(props.userId, TableId.ObservationsSummary, cols)
)
.useEffectOnMountBy((p, _, _, _, table) => p.state.set(ColumnSelectorState(table.some)))
.useEffectOnMountBy((p, _, _, _, table) => p.tileState.set(ColumnSelectorState(table.some)))
.useResizeDetector()
// adding new observation
.useStateView(AddingObservation(false))
Expand Down
Loading

0 comments on commit 841108d

Please sign in to comment.