Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cquiroz committed Aug 15, 2024
1 parent 171c2c4 commit 8f14bb2
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 35 deletions.
10 changes: 5 additions & 5 deletions common/src/main/scala/explore/components/Tile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ case class Tile[A](
initialState: A,
title: String,
back: Option[VdomNode] = None,
// control: TileSizeState => Option[VdomNode] = _ => None,
canMinimize: Boolean = true,
canMaximize: Boolean = true,
hidden: Boolean = false,
Expand All @@ -34,8 +33,10 @@ case class Tile[A](
bodyClass: Css = Css.Empty, // applied to tile body
tileClass: Css = Css.Empty, // applied to the tile
tileTitleClass: Css = Css.Empty // applied to the title
)(val tileBody: View[A] => VdomNode, val tileTitle: View[A] => VdomNode = (_: View[A]) => EmptyVdom)
extends ReactFnProps(Tile.component) {
)(
val tileBody: View[A] => VdomNode,
val tileTitle: (View[A], TileSizeState) => VdomNode = (_: View[A], _: TileSizeState) => EmptyVdom
) extends ReactFnProps(Tile.component) {
def showMaximize: Boolean =
sizeState === TileSizeState.Minimized || (canMaximize && sizeState === TileSizeState.Minimized)

Expand Down Expand Up @@ -107,9 +108,8 @@ object Tile:
<.div(
ExploreStyles.TileTitleControlArea,
<.div(ExploreStyles.TileTitleStrip |+| ExploreStyles.TileControl,
p.tileTitle(sharedState)
p.tileTitle(sharedState, p.sizeState)
),
// .map(b => <.div(ExploreStyles.TileTitleStrip |+| ExploreStyles.TileControl, b)),
<.div(^.key := s"tileTitle-${p.id.value}",
^.untypedRef(setInfoRef).when(infoRef.value.isEmpty)
)(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import org.typelevel.log4cats.Logger

import scala.collection.immutable.SortedSet
import lucuma.core.util.NewType
import explore.model.enums.TileSizeState

object ObsAttachmentsTableTileState extends NewType[Action]:
def apply(): ObsAttachmentsTableTileState = ObsAttachmentsTableTileState(Action.None)
Expand Down Expand Up @@ -368,7 +369,8 @@ case class ObsAttachmentsTableTitle(
obsAttachments: View[ObsAttachmentList],
readOnly: Boolean
)(
val state: View[ObsAttachmentsTableTileState]
val state: View[ObsAttachmentsTableTileState],
tileSize: TileSizeState
) extends ReactFnProps(ObsAttachmentsTableTitle.component)

object ObsAttachmentsTableTitle extends ObsAttachmentUtils:
Expand Down
7 changes: 5 additions & 2 deletions explore/src/main/scala/explore/proposal/ProgramUsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ case class ProgramUsers(

object ProgramUsers:

def inviteControl(readOnly: Boolean, ref: OverlayPanelRef)(state: View[ProgramUsersState]) =
def inviteControl(readOnly: Boolean, ref: OverlayPanelRef)(
state: View[ProgramUsersState],
s: TileSizeState
) =
Button(
severity = Button.Severity.Secondary,
size = Button.Size.Small,
Expand All @@ -73,7 +76,7 @@ object ProgramUsers:
ProposalTabTileIds.UsersId.id,
ProgramUsersState(CreateInviteProcess.Idle),
"Investigators"
)(ProgramUsers(pid, readOnly, users, invitations)(_), inviteControl(readOnly, ref)(_))
)(ProgramUsers(pid, readOnly, users, invitations), inviteControl(readOnly, ref))

private type Props = ProgramUsers

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import lucuma.ui.syntax.all.given
import lucuma.ui.syntax.pot.*
import org.typelevel.log4cats.Logger
import spire.std.any.*
import explore.model.enums.TileSizeState

case class ProposalDetailsTileState()

Expand Down Expand Up @@ -519,12 +520,14 @@ object ProposalDetailsBody:
)(using ctx.logger)

case class ProposalDetailsTitle(undoCtx: UndoContext[Proposal])(
state: View[ProposalDetailsTileState]
state: View[ProposalDetailsTileState],
val tileSize: TileSizeState
) extends ReactFnProps(ProposalDetailsTitle.component)

object ProposalDetailsTitle:
private type Props = ProposalDetailsTitle

private val component =
ScalaFnComponent[Props]: props =>
<.div(ExploreStyles.TitleUndoButtons)(UndoButtons(props.undoCtx))
if (props.tileSize === TileSizeState.Minimized) EmptyVdom
else <.div(ExploreStyles.TitleUndoButtons)(UndoButtons(props.undoCtx))
3 changes: 2 additions & 1 deletion explore/src/main/scala/explore/proposal/ProposalEditor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ object ProposalEditor:
props.timeEstimateRange,
props.cfps,
props.readonly
)(_), ProposalDetailsTitle(undoCtx)(_)
),
ProposalDetailsTitle(undoCtx)
)

val usersTile =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,12 @@ object OverviewTabContents {
props.obsAttachmentAssignments,
props.obsAttachments,
props.readonly
)(
_
),
ObsAttachmentsTableTitle(props.programId,
vault.token,
props.obsAttachments,
props.readonly
)(_)
)
)
)
.filterNot(_ => props.userVault.isGuest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import java.time.Duration
import java.time.Instant
import java.time.ZoneOffset
import java.time.ZonedDateTime
import explore.model.enums.TileSizeState

case class TimingWindowsTileState(
setRowSelection: RowSelection => Callback = _ => Callback.empty
Expand All @@ -73,8 +74,8 @@ object TimingWindowsTile:
val title =
if (timingWindows.get.isEmpty) base else s"$base (${timingWindows.get.length})"
Tile(ObsTabTilesIds.TimingWindowsId.id, TimingWindowsTileState(), title)(
TimingWindowsBody(timingWindows, readOnly)(_),
TimingWindowsTitle(timingWindows, readOnly)(_)
TimingWindowsBody(timingWindows, readOnly),
TimingWindowsTitle(timingWindows, readOnly)
)

object TimingWindowsBody:
Expand Down Expand Up @@ -425,15 +426,15 @@ object TimingWindowsBody:
case class TimingWindowsTitle(
windows: View[List[TimingWindow]],
readOnly: Boolean
)(val state: View[TimingWindowsTileState])
)(val state: View[TimingWindowsTileState], val tileSize: TileSizeState)
extends ReactFnProps(TimingWindowsTitle.component)

object TimingWindowsTitle:
private type Props = TimingWindowsTitle

private val component =
ScalaFnComponent[Props]: props =>
if (props.readOnly) EmptyVdom
if (props.readOnly || props.tileSize === TileSizeState.Minimized) EmptyVdom
else
Button(
severity = Button.Severity.Success,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import lucuma.ui.table.*

import scala.scalajs.js
import lucuma.core.util.NewType
import explore.model.enums.TileSizeState

object ObservationValidationsTableTileState extends NewType[Boolean => Callback]
type ObservationValidationsTableTileState = ObservationValidationsTableTileState.Type
Expand Down Expand Up @@ -233,25 +234,30 @@ object ObservationValidationsTableBody {
}
}

case class ObservationValidationsTableTitle(state: View[ObservationValidationsTableTileState])
extends ReactFnProps(ObservationValidationsTableTitle.component)
case class ObservationValidationsTableTitle(
state: View[ObservationValidationsTableTileState],
tileSize: TileSizeState
) extends ReactFnProps(ObservationValidationsTableTitle.component)

object ObservationValidationsTableTitle:
private type Props = ObservationValidationsTableTitle

private val component = ScalaFnComponent[Props]: p =>
<.div(
ExploreStyles.TableSelectionToolbar,
Button(
size = Button.Size.Small,
icon = Icons.SquarePlus,
tooltip = "Expand All",
onClick = p.state.get.value(true)
).compact,
Button(
size = Button.Size.Small,
icon = Icons.SquareMinus,
tooltip = "Collapse All",
onClick = p.state.get.value(false)
).compact
)
if (p.tileSize === TileSizeState.Minimized)
EmptyVdom
else
<.div(
ExploreStyles.TableSelectionToolbar,
Button(
size = Button.Size.Small,
icon = Icons.SquarePlus,
tooltip = "Expand All",
onClick = p.state.get.value(true)
).compact,
Button(
size = Button.Size.Small,
icon = Icons.SquareMinus,
tooltip = "Collapse All",
onClick = p.state.get.value(false)
).compact
)

0 comments on commit 8f14bb2

Please sign in to comment.