Skip to content

Commit

Permalink
Add phase banner to the app
Browse files Browse the repository at this point in the history
We want to add a phase banner that will indicate to our users that this
app is in Beta. The banner title is dynamic based on the environment we
are in and both claims and placements can control the content of it.
  • Loading branch information
CatalinVoineag committed Dec 19, 2023
1 parent 7a23257 commit 6bb16dd
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/assets/stylesheets/application.sass.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ $govuk-new-link-styles: true;
$govuk-assets-path: "";

@import "govuk-frontend/dist/govuk/all";

@import "components/all";
1 change: 1 addition & 0 deletions app/assets/stylesheets/components/_all.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "page_banner";
22 changes: 22 additions & 0 deletions app/assets/stylesheets/components/_page_banner.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.app-phase-banner .govuk-tag {
color: govuk-colour("white");
text-transform: uppercase;
letter-spacing: 1px;
font-weight: 700;
}

.app-phase-banner__env--development .govuk-tag {
background: govuk-colour("dark-grey");
}

.app-phase-banner__env--qa .govuk-tag {
background-color: govuk-colour("orange");
}

.app-phase-banner__env--staging .govuk-tag {
background-color: govuk-colour("red");
}

.app-phase-banner__env--beta .govuk-tag {
background: govuk-colour("blue");
}
13 changes: 13 additions & 0 deletions app/models/hosting_environment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module HostingEnvironment
def self.name(current_service)
if Rails.env.production?
I18n.t(".models.hosting_environment.#{current_service}.name")
else
Rails.env
end
end

def self.banner_description(current_service)
I18n.t(".models.hosting_environment.#{current_service}.banner.description")
end
end
8 changes: 8 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@

<%= govuk_header(homepage_url: "https://www.gov.uk", service_name: t(".#{current_service}.header.service_name"), service_url: "/") %>

<div class="app-phase-banner app-phase-banner__env--<%= HostingEnvironment.name(current_service) %>">
<div class="govuk-width-container">
<%= govuk_phase_banner(tag: { text: HostingEnvironment.name(current_service) }) do %>
<%= govuk_link_to HostingEnvironment.banner_description(current_service), request.env["PATH_INFO"], class: "govuk-link--no-visited-state" %>
<% end %>
</div>
</div>

<div class="govuk-width-container">
<main class="govuk-main-wrapper" id="main-content" role="main">
<%= yield %>
Expand Down
7 changes: 7 additions & 0 deletions config/locales/claims/en/models/hosting_environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
en:
models:
hosting_environment:
claims:
name: beta
banner:
description: Make a complaint or give feedback
7 changes: 7 additions & 0 deletions config/locales/placements/en/models/hosting_environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
en:
models:
hosting_environment:
placements:
name: beta
banner:
description: Make a complaint or give feedback
40 changes: 40 additions & 0 deletions spec/models/hosting_environment_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require "rails_helper"

RSpec.describe HostingEnvironment do
describe ".name" do
it "returns the name of the hosting environment" do
current_service = "claims"
expect(described_class.name(current_service)).to eq("test")
end

context "when environment is production" do
it "returns the name of the hosting environment for claims" do
allow(Rails.env).to receive(:production?).and_return(true)
current_service = "claims"
expect(described_class.name(current_service)).to eq("beta")
end

it "returns the name of the hosting environment for placements" do
allow(Rails.env).to receive(:production?).and_return(true)
current_service = "placements"
expect(described_class.name(current_service)).to eq("beta")
end
end
end

describe ".banner_description" do
it "returns the banner description of the hosting environment for claims" do
current_service = "claims"
expect(described_class.banner_description(current_service)).to eq(
"Make a complaint or give feedback"
)
end

it "returns the banner description of the hosting environment for placements" do
current_service = "placements"
expect(described_class.banner_description(current_service)).to eq(
"Make a complaint or give feedback"
)
end
end
end

0 comments on commit 6bb16dd

Please sign in to comment.