Skip to content

Commit

Permalink
feat: Add a banner on the admin pages indicating what environment you…
Browse files Browse the repository at this point in the history
…'re in (#2594)

Co-authored-by: Hannah Purcell <[email protected]>
  • Loading branch information
joshlarson and hannahpurcell authored May 14, 2024
1 parent 3c425ed commit 0d1e0cb
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 1 deletion.
3 changes: 2 additions & 1 deletion config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ config :skate,
restrict_environment_access?: System.get_env("RESTRICT_ENVIRONMENT_ACCESS") == "true",
base_tileset_url: System.get_env("BASE_TILESET_URL"),
satellite_tileset_url: System.get_env("SATELLITE_TILESET_URL"),
aws_place_index: System.get_env("AWS_PLACE_INDEX")
aws_place_index: System.get_env("AWS_PLACE_INDEX"),
environment_name: System.get_env("ENVIRONMENT_NAME", "missing-env")

if System.get_env("SECRET_KEY_BASE") do
config :skate, SkateWeb.Endpoint, secret_key_base: System.get_env("SECRET_KEY_BASE")
Expand Down
35 changes: 35 additions & 0 deletions lib/skate_web/components/core_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,39 @@ defmodule SkateWeb.CoreComponents do
<% end %>
"""
end

defp banner_background_color("skate-local"), do: "var(--color-mbta-silver)"
defp banner_background_color("skate-dev"), do: "var(--color-mbta-cr)"
defp banner_background_color("skate-dev-blue"), do: "var(--color-mbta-blue)"
defp banner_background_color("skate-dev-green"), do: "var(--color-mbta-green)"
defp banner_background_color("skate-prod"), do: "var(--color-mbta-red)"
defp banner_background_color(_), do: "var(--color-mbta-bus)"

@envs ["skate-local", "skate-dev", "skate-dev-blue", "skate-dev-green", "skate-prod"]

defp banner_font_color(env) when env in @envs, do: "white"
defp banner_font_color(_), do: "black"

@doc """
Generates a banner for the top of the admin page
"""
def admin_banner(assigns) do
env = Application.get_env(:skate, :environment_name)

attributes = %{
class: "banner",
style: "background-color: #{banner_background_color(env)}; color: #{banner_font_color(env)}"
}

assigns =
assigns
|> assign(:env, env)
|> assign(:attributes, attributes)

~H"""
<div {@attributes}>
Environment: <%= @env %>
</div>
"""
end
end
26 changes: 26 additions & 0 deletions lib/skate_web/components/layouts/barebones.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,40 @@
/>

<style>
:root {
--color-mbta-bus: #ffc72c;
--color-mbta-silver: #7c878e;
--color-mbta-green: #00843d;
--color-mbta-red: #da291c;
--color-mbta-orange: #ed8b00;
--color-mbta-blue: #003da5;
--color-mbta-cr: #80276c;
}
body {
margin: 0;
}
.container {
margin: 8px;
}
.error-tag {
color: red;
font-style: italic;
}
.banner {
text-align: center;
line-height: 4;
}
</style>
</head>

<body>
<.admin_banner />
<main role="main" class="container">
<%= @inner_content %>
</main>
Expand Down
10 changes: 10 additions & 0 deletions test/skate_web/controllers/admin_controller_test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule SkateWeb.AdminControllerTest do
import Test.Support.Helpers
use SkateWeb.ConnCase

describe "index/2" do
Expand All @@ -17,5 +18,14 @@ defmodule SkateWeb.AdminControllerTest do
assert html_response(conn, 200) =~ "Test Groups"
assert html_response(conn, 200) =~ "Reports"
end

@tag :authenticated_admin
test "returns page with a banner indicating the environment", %{conn: conn} do
reassign_env(:skate, :environment_name, "dev")

conn = get(conn, ~p"/admin")

assert html_response(conn, 200) =~ "Environment: dev"
end
end
end

0 comments on commit 0d1e0cb

Please sign in to comment.