Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Now button to obs time #4035

Merged
merged 2 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ object ExploreStyles:
val PAConfigurationAngle: Css = Css("explore-pa-configuration-angle")
val AveragePA: Css = Css("explore-average-pa")
val ObsInstantTileTitle: Css = Css("explore-obs-instant-tile-title")
val DatePickerWithNowButton: Css = Css("explore-datepicker-with-now-button")
val ConfigurationGrid: Css = Css("explore-configuration-grid")
val BasicConfigurationGrid: Css = Css("explore-basic-configuration-grid")
val BasicConfigurationForm: Css = Css("explore-basic-configuration-form")
Expand Down
17 changes: 17 additions & 0 deletions common/src/main/webapp/sass/explore.scss
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,23 @@ thead tr th.sticky-header {
}
}

.explore-datepicker-with-now-button {
/* stylelint-disable-next-line selector-class-pattern */
.react-datepicker__children-container {
position: absolute;
bottom: 0;
text-align: right;
pointer-events: none; // Let clicks pass through to the time selector.

.p-button {
padding-top: 5px;
padding-bottom: 6px;
margin-bottom: 3px;
pointer-events: all; // Capture clicks again.
}
}
}

.explore-obs-instant-tile-title {
@include small-tile-title;
@include react-datepicker-input;
Expand Down
60 changes: 60 additions & 0 deletions explore/src/main/scala/explore/config/ObsTimeEditor.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) 2016-2023 Association of Universities for Research in Astronomy, Inc. (AURA)
// For license information see LICENSE or https://opensource.org/licenses/BSD-3-Clause

package explore.config

import cats.syntax.all.*
import crystal.react.View
import explore.components.HelpIcon
import explore.components.ui.ExploreStyles
import explore.utils.*
import japgolly.scalajs.react.*
import japgolly.scalajs.react.vdom.html_<^.*
import lucuma.react.common.ReactFnProps
import lucuma.react.datepicker.*
import lucuma.react.primereact.Button
import lucuma.refined.*
import lucuma.typed.reactDatepicker.mod.ReactDatePicker
import lucuma.ui.syntax.all.given

import java.time.Instant

import scalajs.js

case class ObsTimeEditor(vizTimeView: View[Option[Instant]])
extends ReactFnProps(ObsTimeEditor.component)

object ObsTimeEditor {
private type Props = ObsTimeEditor

private val component =
ScalaFnComponent
.withHooks[Props]
.useRef[Option[ReactDatePicker[Any, Any]]](none)
.render: (props, ref) =>
<.div(ExploreStyles.ObsInstantTileTitle)(
React.Fragment(
<.label(
dataAbbrv := "Time",
<.span("Observation time"),
HelpIcon("configuration/obstime.md".refined)
),
Datepicker(onChange =
(newValue, _) =>
newValue.fromDatePickerToInstantOpt.foldMap: i =>
props.vizTimeView.set(i.some)
)
.calendarClassName(ExploreStyles.DatePickerWithNowButton.htmlClass)
.showTimeInput(true)
.selected(props.vizTimeView.get.getOrElse(Instant.now).toDatePickerJsDate)
.dateFormat("yyyy-MM-dd HH:mm")(
Button(onClick =
props.vizTimeView.set(Instant.now.some) >>
ref.value.map(r => Callback(r.setOpen(false))).orEmpty
)("Now")
)
.withRef(r => ref.set(r.some).runNow()),
<.label("UTC")
)
)
}
51 changes: 0 additions & 51 deletions explore/src/main/scala/explore/config/VizTimeEditor.scala

This file was deleted.

4 changes: 2 additions & 2 deletions explore/src/main/scala/explore/tabs/AsterismEditorTile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import crystal.*
import crystal.react.*
import explore.components.Tile
import explore.components.ui.ExploreStyles
import explore.config.VizTimeEditor
import explore.config.ObsTimeEditor
import explore.model.AsterismIds
import explore.model.GlobalPreferences
import explore.model.ObsConfiguration
Expand Down Expand Up @@ -63,7 +63,7 @@ object AsterismEditorTile:
vizTime.withOnMod(t => ObsQueries.updateVisualizationTime[IO](obsIds.toList, t).runAsync)

val control: VdomNode =
<.div(ExploreStyles.JustifiedEndTileControl, VizTimeEditor(vizTimeView))
<.div(ExploreStyles.JustifiedEndTileControl, ObsTimeEditor(vizTimeView))

Tile(
ObsTabTilesIds.TargetId.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import crystal.react.*
import crystal.react.hooks.*
import explore.components.Tile
import explore.components.ui.ExploreStyles
import explore.config.VizTimeEditor
import explore.config.ObsTimeEditor
import explore.model.AladinFullScreen
import explore.model.AppContext
import explore.model.Asterism
Expand Down Expand Up @@ -114,7 +114,7 @@ object AsterismEditor extends AsterismModifier:
ExploreStyles.AddTargetButton
)
),
props.renderInTitle(VizTimeEditor(vizTimeView)),
props.renderInTitle(ObsTimeEditor(vizTimeView)),
TargetTable(
props.userId.some,
props.programId,
Expand Down
Loading