Skip to content

Commit

Permalink
Merge pull request #706 from gemini-hlsw/login
Browse files Browse the repository at this point in the history
Login
  • Loading branch information
rpiaggio authored Jul 25, 2023
2 parents d4228ca + b0b3657 commit 42c1932
Show file tree
Hide file tree
Showing 18 changed files with 341 additions and 218 deletions.
35 changes: 1 addition & 34 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,37 +73,4 @@ jobs:
run: sbt -v -J-Xmx6g 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' coverageReport coverageAggregate

- name: Upload code coverage data
run: 'bash <(curl -s https://codecov.io/bash)'

dependency-submission:
name: Submit Dependencies
if: github.event_name != 'pull_request'
strategy:
matrix:
os: [ubuntu-latest]
java: [temurin@17]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Java (temurin@17)
id: setup-java-temurin-17
if: matrix.java == 'temurin@17'
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 17
cache: sbt

- name: sbt update
if: matrix.java == 'temurin@17' && steps.setup-java-temurin-17.outputs.cache-hit == 'false'
run: sbt -v -J-Xmx6g '++ ${{ matrix.scala }}' reload +update

- name: Submit Dependencies
uses: scalacenter/sbt-dependency-submission@v2
with:
modules-ignore: root rootJS app_observe_server app_observe_server_gs app_observe_server_gs_test rootJVM rootNative app_observe_server_gn app_observe_server_gn_test
configs-ignore: test scala-tool scala-doc-tool
uses: codecov/codecov-action@v3
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,7 @@ package-lock.json
modules/edu.gemini.observe.web/edu.gemini.observe.web.server/log/

# Nix
.direnv/
.direnv/

# Web development runtime files
modules/web/src/main/publicdev/
2 changes: 1 addition & 1 deletion .scalafmt-common.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# this file by hand! Instead, if you wish to make changes, you should
# make a PR to sbt-lucuma.

version = "3.7.4"
version = "3.7.7"
style = default

runner.dialect = scala3
Expand Down
2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ ThisBuild / Test / bspEnabled := false

ThisBuild / githubWorkflowSbtCommand := "sbt -v -J-Xmx6g"

ThisBuild / lucumaCssExts += "svg"

ThisBuild / tlFatalWarnings := false // TODO: Remove this when we are ready to have linting checks

inThisBuild(
Expand Down
35 changes: 1 addition & 34 deletions modules/web/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,37 +73,4 @@ jobs:
run: sbt -v -J-Xmx6g 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' coverageReport coverageAggregate

- name: Upload code coverage data
run: 'bash <(curl -s https://codecov.io/bash)'

dependency-submission:
name: Submit Dependencies
if: github.event_name != 'pull_request'
strategy:
matrix:
os: [ubuntu-latest]
java: [temurin@17]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Java (temurin@17)
id: setup-java-temurin-17
if: matrix.java == 'temurin@17'
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 17
cache: sbt

- name: sbt update
if: matrix.java == 'temurin@17' && steps.setup-java-temurin-17.outputs.cache-hit == 'false'
run: sbt -v -J-Xmx6g '++ ${{ matrix.scala }}' reload +update

- name: Submit Dependencies
uses: scalacenter/sbt-dependency-submission@v2
with:
modules-ignore: root rootJS app_observe_server app_observe_server_gs app_observe_server_gs_test rootJVM rootNative app_observe_server_gn app_observe_server_gn_test
configs-ignore: test scala-tool scala-doc-tool
uses: codecov/codecov-action@v3
13 changes: 13 additions & 0 deletions modules/web/src/main/public/environments.conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"hostName": "*",
"environment": "DEVELOPMENT",
"odbURI": "wss://lucuma-postgres-odb-dev.herokuapp.com/ws",
"sso": {
"uri": "https://sso-dev.gpp.lucuma.xyz",
"readTimeoutSeconds": 10,
"refreshTimeoutDeltaSeconds": 10,
"refreshIntervalFactor": 1
}
}
]
20 changes: 20 additions & 0 deletions modules/web/src/main/scala/observe/ui/AppConfig.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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 observe.ui

import cats.Eq
import cats.derived.*
import io.circe.Decoder
import lucuma.ui.enums.ExecutionEnvironment
import lucuma.ui.sso.SSOConfig
import org.http4s.Uri
import org.http4s.circe.*

final case class AppConfig(
hostName: String,
environment: ExecutionEnvironment,
odbURI: Uri,
sso: SSOConfig
) derives Eq,
Decoder
18 changes: 13 additions & 5 deletions modules/web/src/main/scala/observe/ui/AppContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,27 @@

package observe.ui

import cats.FlatMap
import cats.effect.IO
import cats.syntax.all.*
import clue.js.WebSocketJSClient
import clue.websocket.CloseParams
import io.circe.Json
import japgolly.scalajs.react.React
import japgolly.scalajs.react.feature.Context
import lucuma.schemas.ObservationDB
import lucuma.ui.sso.SSOClient
import org.typelevel.log4cats.Logger

final case class AppContext[F[_]](
logger: Logger[F],
odbClient: WebSocketJSClient[F, ObservationDB]
case class AppContext[F[_]: FlatMap](ssoClient: SSOClient[F])(using
val logger: Logger[F],
val odbClient: WebSocketJSClient[F, ObservationDB]
):
given Logger[F] = logger
given WebSocketJSClient[F, ObservationDB] = odbClient
def initODBClient(payload: Map[String, Json]): F[Unit] =
odbClient.connect() >> odbClient.initialize(payload)

val closeODBClient: F[Unit] =
odbClient.terminate() >> odbClient.disconnect(CloseParams(code = 1000))

object AppContext:
val ctx: Context[AppContext[IO]] = React.createContext(null) // No default value
20 changes: 20 additions & 0 deletions modules/web/src/main/scala/observe/ui/BroadcastEvent.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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 observe.ui

import scala.scalajs.js

// These are messages sent across tabs thus they need to be JS compatible
// We don't need yet more than just an index to differentiate
sealed trait BroadcastEvent extends js.Object {
def event: Int
def value: js.Any // encode whatever value as a String. it can be e.g. json
}

object BroadcastEvent:
val LogoutEventId = 1

class LogoutEvent(val nonce: String) extends BroadcastEvent:
val event = LogoutEventId
val value = nonce
35 changes: 30 additions & 5 deletions modules/web/src/main/scala/observe/ui/Layout.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,45 @@

package observe.ui

import cats.effect.IO
import cats.syntax.all.*
import crystal.react.View
import japgolly.scalajs.react._
import japgolly.scalajs.react.extra.router._
import japgolly.scalajs.react.vdom.html_<^._
import lucuma.refined.*
import lucuma.ui.components.state.IfLogged
import lucuma.ui.sso.UserVault
import observe.ui.model.RootModel
import react.common.Css
import react.common.ReactFnProps
import react.common.given

case class Layout(c: RouterCtl[Page], resolution: ResolutionWithProps[Page, View[RootModel]])(
val rootModel: View[RootModel]
) extends ReactFnProps[Layout](Layout.component)

object Layout:
protected type Props = Layout
private type Props = Layout

protected val component = ScalaFnComponent[Props] { props =>
props.resolution.renderP(props.rootModel)
}
private val component =
ScalaFnComponent
.withHooks[Props]
.useContext(AppContext.ctx)
.render: (props, ctx) =>
import ctx.given

IfLogged[BroadcastEvent](
"Observe".refined,
Css.Empty,
allowGuest = false,
ctx.ssoClient,
props.rootModel.zoom(RootModel.userVault),
props.rootModel.zoom(RootModel.userSelectionMessage),
ctx.initODBClient(_),
ctx.closeODBClient,
IO.unit,
"observe".refined,
_.event === BroadcastEvent.LogoutEventId,
_.value.toString,
BroadcastEvent.LogoutEvent(_)
)((vault: UserVault, onLogout: IO[Unit]) => props.resolution.renderP(props.rootModel))
Loading

0 comments on commit 42c1932

Please sign in to comment.