Skip to content

Commit

Permalink
Merge pull request #4282 from gemini-hlsw/sc-3931-hide-inactive-obser…
Browse files Browse the repository at this point in the history
…vations-in-overview-warnings
  • Loading branch information
toddburnside authored Nov 4, 2024
2 parents 5cae632 + eecbeac commit 6448242
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package explore.validations
import cats.effect.IO
import cats.syntax.all.*
import crystal.react.View
import crystal.react.syntax.effect.*
import explore.Icons
import explore.components.ui.ExploreStyles
import explore.model.AppContext
Expand Down Expand Up @@ -34,7 +33,6 @@ import lucuma.react.table.ColumnDef
import lucuma.react.table.ColumnId
import lucuma.ui.primereact.*
import lucuma.ui.table.*
import queries.schemas.odb.ObsQueries

import scala.scalajs.js

Expand All @@ -59,7 +57,6 @@ object ObservationValidationsTableBody {
private val ObservationStateColumnId = ColumnId("observation_state")
private val ValidationCodeColumnId = ColumnId("validation_code")
private val ValidationMessageColumnId = ColumnId("validation_message")
private val ActionsColumnId = ColumnId("actions")

private val columnNames: Map[ColumnId, String] = Map(
ObservationIdColumnId -> "Observation Id",
Expand All @@ -86,8 +83,6 @@ object ObservationValidationsTableBody {
.useContext(AppContext.ctx)
// columns
.useMemoBy((_, _) => ()) { (props, ctx) => _ =>
import ctx.given

def obsUrl(obsId: Observation.Id): String =
ctx.pageUrl(AppTab.Observations, props.programId, Focused.singleObs(obsId))
def goToObs(obsId: Observation.Id): Callback =
Expand All @@ -96,24 +91,6 @@ object ObservationValidationsTableBody {
def toggleAll(row: Row[Expandable[ValidationsTableRow], Nothing]): Callback =
row.toggleExpanded() *> row.subRows.traverse(r => toggleAll(r)).void

def requestApprovalButton(row: ValidationsTableRow): Option[Button] =
row
.forObsOption(row =>
val obs = row.obs
if (obs.hasNotRequestedCode)
obs.configuration.flatMap(config =>
Button(
"Request Approval",
onClick = props.observations.mod(
// this also gets rid of any buttons on "affected" observations
_.mapValues(_.id, _.updateToPendingIfConfigurationApplies(config))
) >>
ObsQueries.createConfigurationRequest[IO](row.id).void.runAsync
).tiny.compact.some
)
else none
)

List(
ColDef(
ColumnId("expander"),
Expand Down Expand Up @@ -148,16 +125,15 @@ object ObservationValidationsTableBody {
ValidationMessageColumnId,
cell = cell => cell.row.original.value.message(cell.row.getIsExpanded()),
header = columnNames(ValidationMessageColumnId)
),
ColDef(
ActionsColumnId,
cell = cell => requestApprovalButton(cell.row.original.value)
).setMaxSize(111.toPx)
)
)
}
// Rows
.useMemoBy((props, _, _) => props.observations.get.toList)((_, _, _) =>
_.filterNot(_.workflow.validationErrors.isEmpty)
// We don't want to show inactive observations here, nor ones related to configuration requests
_.filter(obs =>
!obs.isInactive && obs.hasValidationErrors && !obs.hasConfigurationRequestError
)
.map(obs =>
Expandable(
ObsRow(obs),
Expand Down
12 changes: 12 additions & 0 deletions model/shared/src/main/scala/explore/model/Observation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ case class Observation(
ObservationWorkflowState
].all.toSet -- workflow.validTransitions.toSet - workflow.state

val isInactive = workflow.state === ObservationWorkflowState.Inactive

inline def isCalibration: Boolean = calibrationRole.isDefined
inline def isExecuted: Boolean =
ExecutedStates.contains(workflow.state) ||
Expand All @@ -275,16 +277,26 @@ case class Observation(
(hasNotRequestedCode || hasDeniedValidationCode) &&
configuration.fold(false)(config.subsumes)

inline def hasValidationErrors: Boolean =
!workflow.validationErrors.isEmpty

inline def hasValidationCode(code: ObservationValidationCode): Boolean =
workflow.validationErrors.exists(_.code === code)

// If an observation has a ConfigurationRequest* error, it is the only error they will have
inline def hasPendingRequestCode: Boolean =
hasValidationCode(ObservationValidationCode.ConfigurationRequestPending)

inline def hasNotRequestedCode: Boolean =
hasValidationCode(ObservationValidationCode.ConfigurationRequestNotRequested)

inline def hasDeniedValidationCode: Boolean =
hasValidationCode(ObservationValidationCode.ConfigurationRequestDenied)

// if it has any of the ConfigurationRequest* errors. We filter these out of the validations table.
inline def hasConfigurationRequestError: Boolean =
hasPendingRequestCode || hasNotRequestedCode || hasDeniedValidationCode

inline def updateToPending: Observation =
Observation.validationErrors.replace(List(ObservationValidation.configurationRequestPending))(
this
Expand Down

0 comments on commit 6448242

Please sign in to comment.