Skip to content

Commit

Permalink
Prevent proposal submission with undefined observations
Browse files Browse the repository at this point in the history
  • Loading branch information
toddburnside committed Feb 6, 2025
1 parent 72c4c22 commit 713cd96
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 32 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 @@ -181,7 +181,7 @@ object Routing:
model.rootModel.zoom(RootModel.otherUndoStacks).zoom(ModelUndoStacks.forProposal),
userPreferences(model.rootModel).proposalTabLayout,
model.userIsReadonlyCoi,
programSummaries.get.hasProposalObsErrors
programSummaries.get.hasUndefinedObservations
)
.orEmpty

Expand Down
30 changes: 16 additions & 14 deletions explore/src/main/scala/explore/proposal/ProposalSubmissionBar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ import queries.common.ProposalQueriesGQL.SetProposalStatus
import scala.concurrent.duration.*

case class ProposalSubmissionBar(
programId: Program.Id,
proposalStatus: View[ProposalStatus],
deadline: Option[Timestamp],
callId: Option[CallForProposals.Id],
canSubmit: Boolean,
hasObsErrors: Boolean
programId: Program.Id,
proposalStatus: View[ProposalStatus],
deadline: Option[Timestamp],
callId: Option[CallForProposals.Id],
canSubmit: Boolean,
hasUndefinedObservations: Boolean
) extends ReactFnProps(ProposalSubmissionBar.component)

object ProposalSubmissionBar:
Expand Down Expand Up @@ -79,13 +79,15 @@ object ProposalSubmissionBar:
ctx <- useContext(AppContext.ctx)
isUpdatingStatus <- useStateView(IsUpdatingStatus(false))
errorMessage <- useStateView(none[String]) // Submission error message
_ <- useLayoutEffectWithDeps((props.proposalStatus.get, props.callId, props.hasObsErrors)):
(ps, _, he) =>
if (he && ps === ProposalStatus.NotSubmitted)
errorMessage.set(
"One or more observations has an error. See Overview tab for details.".some
)
else errorMessage.set(none) // Reset error message on CfP change
_ <-
useLayoutEffectWithDeps(
(props.proposalStatus.get, props.callId, props.hasUndefinedObservations)
): (ps, _, he) =>
if (he && ps === ProposalStatus.NotSubmitted)
errorMessage.set(
"Proposal cannot be submitted with undefined observations. Define them or mark them as inactive.".some
)
else errorMessage.set(none) // Reset error message on CfP change
nowPot <- useStreamOnMount:
Stream
.fixedRateStartImmediately[IO](1.second)
Expand Down Expand Up @@ -122,7 +124,7 @@ object ProposalSubmissionBar:
label = "Submit Proposal",
onClick = updateStatus(ProposalStatus.Submitted),
disabled =
isUpdatingStatus.get.value || props.callId.isEmpty || isDueDeadline || props.hasObsErrors
isUpdatingStatus.get.value || props.callId.isEmpty || isDueDeadline || props.hasUndefinedObservations
).compact.tiny,
props.deadline.map: deadline =>
val (deadlineStr, left): (String, Option[String]) =
Expand Down
22 changes: 11 additions & 11 deletions explore/src/main/scala/explore/proposal/ProposalTabContents.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ import org.typelevel.log4cats.Logger
import queries.common.ProposalQueriesGQL.*

case class ProposalTabContents(
programId: Program.Id,
userVault: Option[UserVault],
programDetails: View[ProgramDetails],
cfps: List[CallForProposal],
timeEstimateRange: Pot[Option[ProgramTimeRange]],
attachments: View[AttachmentList],
undoStacks: View[UndoStacks[IO, ProgramDetails]],
layout: LayoutsMap,
userIsReadonlyCoi: Boolean,
hasProposalObsErrors: Boolean
programId: Program.Id,
userVault: Option[UserVault],
programDetails: View[ProgramDetails],
cfps: List[CallForProposal],
timeEstimateRange: Pot[Option[ProgramTimeRange]],
attachments: View[AttachmentList],
undoStacks: View[UndoStacks[IO, ProgramDetails]],
layout: LayoutsMap,
userIsReadonlyCoi: Boolean,
hasUndefinedObservations: Boolean
) extends ReactFnProps(ProposalTabContents.component)

object ProposalTabContents:
Expand Down Expand Up @@ -135,7 +135,7 @@ object ProposalTabContents:
deadline,
proposal.get.callId,
isStdUser && !props.userIsReadonlyCoi,
props.hasProposalObsErrors
props.hasUndefinedObservations
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,8 @@ case class ProgramSummaries(
.flattenOption
.toMap

lazy val hasProposalObsErrors: Boolean =
observations.values.exists: obs =>
obs.workflow.state =!= ObservationWorkflowState.Inactive &&
obs.workflow.validationErrors.exists(
_.code === ObservationValidationCode.CallForProposalsError
)
lazy val hasUndefinedObservations: Boolean =
observations.values.exists(_.workflow.state === ObservationWorkflowState.Undefined)

lazy val obsAttachmentAssignments: ObsAttachmentAssignmentMap =
observations.toList
Expand Down

0 comments on commit 713cd96

Please sign in to comment.