Skip to content

Commit

Permalink
allow accessing menu when selecting program
Browse files Browse the repository at this point in the history
  • Loading branch information
rpiaggio committed Dec 22, 2024
1 parent dc4f512 commit 2afed0c
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 69 deletions.
98 changes: 52 additions & 46 deletions explore/src/main/scala/explore/ExploreLayout.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import clue.data.syntax.*
import crystal.Pot
import crystal.react.*
import crystal.react.hooks.*
import crystal.syntax.*
import eu.timepit.refined.types.string.NonEmptyString
import explore.cache.CfpCacheController
import explore.cache.ModesCacheController
Expand Down Expand Up @@ -47,6 +48,7 @@ import lucuma.ui.enums.Theme
import lucuma.ui.hooks.*
import lucuma.ui.layout.LayoutStyles
import lucuma.ui.sso.UserVault
import lucuma.ui.syntax.all.*
import lucuma.ui.syntax.all.given
import org.scalajs.dom.document
import queries.common.UserPreferencesQueriesGQL.*
Expand Down Expand Up @@ -200,22 +202,24 @@ object ExploreLayout:

given Display[AppTab] = _.title

val (showProgsPopup, msg, isSubmitted, proposalReference)
: (Boolean, Option[String], Boolean, Option[ProposalReference]) =
props.model.programSummariesValue.toOption.fold((false, none, false, none)):
pss =>
routingInfo.optProgramId.fold((true, none, false, none)): id =>
if (pss.programs.get(id).exists(!_.deleted))
(false, none, pss.proposalIsSubmitted, pss.proposalId)
else
(true,
s"The program id in the url, '$id', either does not exist, is deleted, or you do not have authorization to view it.".some,
false,
none
)
val programSummaries: Pot[ProgramSummaries] =
props.model.programSummariesValue

val (showProgsPopupPot, msg, isSubmitted, proposalReference)
: (Pot[Boolean], Option[String], Boolean, Option[ProposalReference]) =
programSummaries.toOption.fold((pending, none, false, none)): pss =>
routingInfo.optProgramId.fold((true.ready, none, false, none)): id =>
if (pss.programs.get(id).exists(!_.deleted))
(false.ready, none, pss.proposalIsSubmitted, pss.proposalId)
else
(true.ready,
s"The program id in the url, '$id', either does not exist, is deleted, or you do not have authorization to view it.".some,
false,
none
)

val deadline: Option[Timestamp] =
props.model.programSummariesValue.toOption
programSummaries.toOption
.flatMap: programSummaries =>
(ProgramSummaries.proposal.getOption(programSummaries).flatten,
RootModel.cfps.get(view.get).toOption
Expand Down Expand Up @@ -272,7 +276,7 @@ object ExploreLayout:
TopBar(
vault,
routingInfo.optProgramId,
props.model.programSummariesValue.toOption
programSummaries.toOption
.flatMap(_.programOrProposalReference),
view.zoom(RootModel.localPreferences).get,
view.zoom(RootModel.undoStacks),
Expand All @@ -285,37 +289,39 @@ object ExploreLayout:
)
)
),
SideTabs(
"side-tabs".refined,
routingInfoView.zoom(RoutingInfo.appTab),
tab => ctx.pageUrl((tab, routingInfo.programId, routingInfo.focused).some),
_.separatorAfter,
tab =>
props.model.programSummariesValue.toOption
.flatMap(_.optProgramDetails)
.forall: program =>
// Only show Program and Proposal tabs for Science proposals, and Program only for Accepted ones
(tab =!= AppTab.Proposal && tab =!= AppTab.Program) ||
program.programType === ProgramType.Science &&
(tab === AppTab.Proposal || program.proposalStatus === ProposalStatus.Accepted)
),
if (showProgsPopup)
ProgramsPopup(
currentProgramId = none,
props.model.programSummaries.throttlerView
.zoom(Pot.readyPrism)
.zoom(ProgramSummaries.programs),
undoStacks = view.zoom(RootModel.undoStacks),
onLogout = (onLogout >>
view.zoom(RootModel.vault).set(none).toAsync).some,
message = msg
): VdomElement
else
<.div(LayoutStyles.MainBody, LayoutStyles.WithMessage.when(isSubmitted))(
props.resolution.renderP(props.model),
TagMod
.when(isSubmitted)(SubmittedProposalMessage(proposalReference, deadline))
)
showProgsPopupPot.renderPot: showProgsPopup =>
if (showProgsPopup)
ProgramsPopup(
currentProgramId = none,
props.model.programSummaries.throttlerView
.zoom(Pot.readyPrism)
.zoom(ProgramSummaries.programs),
undoStacks = view.zoom(RootModel.undoStacks),
message = msg
): VdomElement
else
React.Fragment(
SideTabs(
"side-tabs".refined,
routingInfoView.zoom(RoutingInfo.appTab),
tab =>
ctx.pageUrl((tab, routingInfo.programId, routingInfo.focused).some),
_.separatorAfter,
tab =>
programSummaries.toOption
.flatMap(_.optProgramDetails)
.forall: program =>
// Only show Program and Proposal tabs for Science proposals, and Program only for Accepted ones
(tab =!= AppTab.Proposal && tab =!= AppTab.Program) ||
program.programType === ProgramType.Science &&
(tab === AppTab.Proposal || program.proposalStatus === ProposalStatus.Accepted)
),
<.div(LayoutStyles.MainBody, LayoutStyles.WithMessage.when(isSubmitted))(
props.resolution.renderP(props.model),
TagMod:
SubmittedProposalMessage(proposalReference, deadline)
)
)
)
)
}
Expand Down
19 changes: 11 additions & 8 deletions explore/src/main/scala/explore/TopBar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,21 @@ object TopBar:
props.preferences.copy(level = l)
) *> IO(window.location.reload())).runAsync

val firstItems = List(
val firstItems =
MenuItem.Item(
label = "About Explore",
icon = Icons.Info,
command = isAboutOpen.set(IsAboutOpen(true))
),
MenuItem.Item(
label = "Manage Programs",
icon = Icons.ListCheck,
command = isProgramsOpen.setState(IsProgramOpen(true))
)
)
) +:
(if (props.programId.isDefined)
List(
MenuItem.Item(
label = "Manage Programs",
icon = Icons.ListCheck,
command = isProgramsOpen.setState(IsProgramOpen(true))
)
)
else List.empty)

val lastItems = List(
MenuItem.Separator.some,
Expand Down
1 change: 0 additions & 1 deletion explore/src/main/scala/explore/programs/ProgramTable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ case class ProgramTable(
selectProgram: Program.Id => Callback,
isRequired: Boolean,
onClose: Option[Callback],
onLogout: Option[IO[Unit]],
virtualizerRef: UseRef[Option[HTMLTableVirtualizer]]
) extends ReactFnProps(ProgramTable.component)

Expand Down
16 changes: 2 additions & 14 deletions explore/src/main/scala/explore/programs/ProgramsPopup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ case class ProgramsPopup(
programInfos: ViewOpt[ProgramInfoList],
undoStacks: View[UndoStacks[IO, ProgramSummaries]],
onClose: Option[Callback] = none,
onLogout: Option[IO[Unit]] = none,
message: Option[String] = none
) extends ReactFnProps(ProgramsPopup.component)

Expand Down Expand Up @@ -112,16 +111,6 @@ object ProgramsPopup:
).small.compact.some
)

val logoutButton =
props.onLogout.fold(none)(io =>
Button(
label = "Logout",
icon = Icons.Logout,
severity = Button.Severity.Danger,
onClick = (ctx.sso.logout >> io).runAsync
).small.compact.some
)

val programInfosViewOpt: Option[View[ProgramInfoList]] =
props.programInfos.toOptionView

Expand All @@ -148,6 +137,7 @@ object ProgramsPopup:
position = DialogPosition.Top,
closeOnEscape = props.onClose.isDefined,
closable = props.onClose.isDefined,
modal = props.onClose.isDefined,
dismissableMask = props.onClose.isDefined,
resizable = false,
clazz = LucumaPrimeStyles.Dialog.Small |+| ExploreStyles.ProgramsPopup,
Expand All @@ -167,8 +157,7 @@ object ProgramsPopup:
value = showDeleted.zoom(ShowDeleted.value.asLens),
label = "Show deleted"
),
closeButton,
logoutButton
closeButton
)
)(
programInfoViewListOpt.toPot
Expand All @@ -179,7 +168,6 @@ object ProgramsPopup:
selectProgram = selectProgram(props.onClose, props.undoStacks, ctx),
props.onClose.isEmpty,
onHide,
props.onLogout,
virtualizerRef
),
props.message.map(msg =>
Expand Down

0 comments on commit 2afed0c

Please sign in to comment.