Skip to content

Commit

Permalink
Do not allow proposal submission with zero defined observations.
Browse files Browse the repository at this point in the history
  • Loading branch information
toddburnside committed Feb 24, 2025
1 parent 50cdf4b commit cf1762e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions explore/src/main/scala/explore/Routing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ object Routing:
model.rootModel.zoom(RootModel.otherUndoStacks).zoom(ModelUndoStacks.forProposal),
userPreferences(model.rootModel).proposalTabLayout,
model.userIsReadonlyCoi,
programSummaries.get.hasDefinedObservations,
programSummaries.get.hasUndefinedObservations
)
.orEmpty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ case class ProposalSubmissionBar(
deadline: Option[Timestamp],
callId: Option[CallForProposals.Id],
canSubmit: Boolean,
hasDefinedObservations: Boolean,
hasUndefinedObservations: Boolean
) extends ReactFnProps(ProposalSubmissionBar.component)
) extends ReactFnProps(ProposalSubmissionBar.component):
val hasObsError = !hasDefinedObservations || hasUndefinedObservations

object ProposalSubmissionBar:
private object IsUpdatingStatus extends NewType[Boolean]
Expand Down Expand Up @@ -81,9 +83,17 @@ object ProposalSubmissionBar:
errorMessage <- useStateView(none[String]) // Submission error message
_ <-
useLayoutEffectWithDeps(
(props.proposalStatus.get, props.callId, props.hasUndefinedObservations)
): (ps, _, he) =>
if (he && ps === ProposalStatus.NotSubmitted)
(props.proposalStatus.get,
props.callId,
props.hasDefinedObservations,
props.hasUndefinedObservations
)
): (ps, _, hasDef, hasUndef) =>
if (!hasDef && ps === ProposalStatus.NotSubmitted)
errorMessage.set(
"Proposal cannot be submitted without at least one defined observation.".some
)
else if (hasUndef && ps === ProposalStatus.NotSubmitted)
errorMessage.set(
"Proposal cannot be submitted with undefined observations. Define them or mark them as inactive.".some
)
Expand Down Expand Up @@ -124,7 +134,7 @@ object ProposalSubmissionBar:
label = "Submit Proposal",
onClick = updateStatus(ProposalStatus.Submitted),
disabled =
isUpdatingStatus.get.value || props.callId.isEmpty || isDueDeadline || props.hasUndefinedObservations
isUpdatingStatus.get.value || props.callId.isEmpty || isDueDeadline || props.hasObsError
).compact.tiny,
props.deadline.map: deadline =>
val (deadlineStr, left): (String, Option[String]) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ case class ProposalTabContents(
undoStacks: View[UndoStacks[IO, ProgramDetails]],
layout: LayoutsMap,
userIsReadonlyCoi: Boolean,
hasDefinedObservations: Boolean,
hasUndefinedObservations: Boolean
) extends ReactFnProps(ProposalTabContents.component)

Expand Down Expand Up @@ -135,6 +136,7 @@ object ProposalTabContents:
deadline,
proposal.get.call.map(_.id),
isStdUser && !props.userIsReadonlyCoi,
props.hasDefinedObservations,
props.hasUndefinedObservations
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ case class ProgramSummaries(
lazy val hasUndefinedObservations: Boolean =
observations.values.exists(_.workflow.state === ObservationWorkflowState.Undefined)

lazy val hasDefinedObservations: Boolean =
observations.values.exists(_.workflow.state === ObservationWorkflowState.Defined)

lazy val obsAttachmentAssignments: ObsAttachmentAssignmentMap =
observations.toList
.flatMap((obsId, obs) => obs.attachmentIds.map(_ -> obsId))
Expand Down

0 comments on commit cf1762e

Please sign in to comment.