Skip to content

Commit

Permalink
Merge pull request #4449 from gemini-hlsw/improve-config-request-dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
toddburnside authored Dec 31, 2024
2 parents 524ec76 + 2002033 commit e44abbd
Showing 1 changed file with 65 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import explore.model.AppContext
import japgolly.scalajs.react.*
import japgolly.scalajs.react.vdom.html_<^.*
import lucuma.core.util.NewType
import lucuma.react.common.ReactFnComponent
import lucuma.react.common.ReactFnProps
import lucuma.react.primereact.Button
import lucuma.react.primereact.Dialog
Expand All @@ -23,72 +24,77 @@ import lucuma.ui.primereact.given
case class ConfigurationRequestEditorPopup(
trigger: Button,
onSubmit: String => Callback
) extends ReactFnProps(ConfigurationRequestEditorPopup.component)
) extends ReactFnProps(ConfigurationRequestEditorPopup)

object ConfigurationRequestEditorPopup:
private type Props = ConfigurationRequestEditorPopup
object ConfigurationRequestEditorPopup
extends ReactFnComponent[ConfigurationRequestEditorPopup](props =>
for {
ctx <- useContext(AppContext.ctx)
popupState <- useStateView(PopupState.Closed)
message <- useStateView("")
isEmpty <- useStateView(true)
isBlank <- useStateView(true)
_ <- useEffectWithDeps(message.get): msg =>
isEmpty.set(msg.isEmpty) >> isBlank.set(msg.isBlank)
} yield
val close = popupState.set(PopupState.Closed)

private object PopupState extends NewType[Boolean]:
inline def Open: PopupState = PopupState(true)
inline def Closed: PopupState = PopupState(false)

private type PopupState = PopupState.Type

val component = ScalaFnComponent
.withHooks[Props]
.useContext(AppContext.ctx)
.useStateView(PopupState.Closed)
.useStateView("") // message
.render: (props, ctx, popupState, message) =>
val close = popupState.set(PopupState.Closed)

val notice =
"""Please briefly describe and justify the requested changes to the approved
val notice =
"""Please briefly describe and justify the requested changes to the approved
|coordinates + instrument configurations + constraints. These changes will
|be reviewed by the Head of Science Operations at the site of the observations.
""".stripMargin.linesIterator.mkString(" ")

val footer = React.Fragment(
Button(
label = "Clear Text",
icon = Icons.Eraser,
disabled = message.get.isEmpty,
onClick = message.set("")
).small,
Button(
label = "Cancel",
icon = Icons.Close,
severity = Button.Severity.Danger,
onClick = close
).small,
Button(
label = "Submit",
icon = Icons.PaperPlaneTop,
disabled = message.get.isBlank,
onClick = close >> props.onSubmit(message.get)
).small
)
val footer = React.Fragment(
Button(
label = "Clear Text",
icon = Icons.Eraser,
disabled = isEmpty.get,
onClick = message.set("")
).small,
Button(
label = "Cancel",
icon = Icons.Close,
severity = Button.Severity.Danger,
onClick = close
).small,
Button(
label = "Submit",
icon = Icons.PaperPlaneTop,
disabled = isBlank.get,
onClick = close >> props.onSubmit(message.get)
).small
)

React.Fragment(
props.trigger.copy(onClick = props.trigger.onClick >> popupState.set(PopupState.Open)),
Dialog(
visible = popupState.get.value,
onHide = close,
closable = true,
closeOnEscape = true,
dismissableMask = true,
resizable = true,
clazz = LucumaPrimeStyles.Dialog.Small |+| ExploreStyles.ConfigurationRequestEditorPopup,
header = "Request Editor",
footer = footer
)(
<.div(
notice,
Divider(),
FormInputTextAreaView(
id = "message_text_area".refined,
value = message
React.Fragment(
props.trigger.copy(onClick = props.trigger.onClick >> popupState.set(PopupState.Open)),
Dialog(
visible = popupState.get.value,
onHide = close,
closable = true,
closeOnEscape = true,
dismissableMask = true,
resizable = true,
clazz =
LucumaPrimeStyles.Dialog.Small |+| ExploreStyles.ConfigurationRequestEditorPopup,
header = "Request Editor",
footer = footer
)(
<.div(
notice,
Divider(),
FormInputTextAreaView(
id = "message_text_area".refined,
value = message,
onTextChange = s => isBlank.set(s.isBlank) >> isEmpty.set(s.isEmpty)
)
)
)
)
)
)

private object PopupState extends NewType[Boolean]:
inline def Open: PopupState = PopupState(true)
inline def Closed: PopupState = PopupState(false)

private type PopupState = PopupState.Type

0 comments on commit e44abbd

Please sign in to comment.