Skip to content

Commit

Permalink
Add an Information banner
Browse files Browse the repository at this point in the history
We've used this banner before for scheduled maintenance so it makes
sense to make it even more generic and quicker to use.

Here we add it to every page when the appropriate environment variable
is set to true and add the content to the locales to make identifying
and update quick and painless.
  • Loading branch information
mec committed Mar 27, 2024
1 parent f9f3041 commit 1270333
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 15 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Clear any radio button values in the Sponsored support grant type task if the
task is later saved as "Not applicable"

### Changed

- the maintenance banner has been repurposed as a more generic information
banner that can be switched on and off.

## [Release-61][release-61]

### Added
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<div class="govuk-width-container ">
<%= yield :pre_content_nav %>
<main class="govuk-main-wrapper app-content" id="main-content" role="main">
<%= render partial: "/shared/information_banner" if ENV["SHOW_INFORMATION_BANNER"].eql?("true") %>
<%= render(NotificationBanner.new(flashes: flash)) %>
<%= yield %>
Expand Down
13 changes: 13 additions & 0 deletions app/views/shared/_information_banner.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="govuk-notification-banner" id="information-banner" role="region" aria-labelledby="govuk-notification-banner-title" data-module="govuk-notification-banner">
<div class="govuk-notification-banner__header">
<h2 class="govuk-notification-banner__title" id="govuk-notification-banner-title">
Important
</h2>
</div>
<div class="govuk-notification-banner__content">
<h3 class="govuk-notification-banner__heading">
<%= t("information_banner.title") %>
</h3>
<%= t("information_banner.body.html") %>
</div>
</div>
15 changes: 0 additions & 15 deletions app/views/shared/_maintenance_banner.html.erb

This file was deleted.

8 changes: 8 additions & 0 deletions config/locales/information_banner.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
en:
information_banner:
title: Upcoming scheduled maintenance
body:
html:
<p>We will carry out maintenance on Complete from 5pm to 6pm on Friday 5 April 2024.</p>
<p>Project changes will not be saved during the maintenance.</p>
<p>Make sure you save your changes before the work starts.</p>
5 changes: 5 additions & 0 deletions doc/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ the `/healthcheck` endpoint to confirm the app is up & running.
`APPLICATION_INSIGHTS_KEY`

The instrumentation key for Microsoft Application Insights.

`SHOW_INFORMATION_BANNER`

Turns the [information banner](./information_banner.md) on across the
application.
18 changes: 18 additions & 0 deletions doc/information_banner.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Information Banner

We sometimes want to inform all users of something important, scheduled downtime
for example.

To do so we have an Information banner that can be enabled and is then shown
across the application.

To set the content of the banner:

- locate the `config/locales/information_banner.yml` locale file
- update the `title`
- update the HTML used for the `body`
- commit, merge and deploy this change

Then:

- set the `SHOW_INFORMATION_BANNER` environment variable to `true`
52 changes: 52 additions & 0 deletions spec/features/information_banner_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
require "rails_helper"

RSpec.feature "Users can see an information banner" do
let(:user) { create(:user, :regional_delivery_officer) }

before do
sign_in_with_user(user)
end

context "with the environment variable present and set to true" do
it "shows the banner on all pages" do
ClimateControl.modify SHOW_INFORMATION_BANNER: "true" do
visit in_progress_your_projects_path

expect(page).to have_selector("#information-banner")

visit all_in_progress_projects_path

expect(page).to have_selector("#information-banner")
end
end

it "shows the title and body" do
ClimateControl.modify SHOW_INFORMATION_BANNER: "true" do
visit in_progress_your_projects_path

within("#information-banner") do
expect(page).to have_content(I18n.t("information_banner.title"))
expect(page.html).to include(I18n.t("information_banner.body.html"))
end
end
end
end

context "with the environment variable present and set to false" do
it "does not show the banner" do
ClimateControl.modify SHOW_INFORMATION_BANNER: "false" do
visit in_progress_your_projects_path

expect(page).not_to have_selector("#information-banner")
end
end
end

context "without the environment variable set" do
it "does not show the banner" do
visit in_progress_your_projects_path

expect(page).not_to have_selector("#information-banner")
end
end
end

0 comments on commit 1270333

Please sign in to comment.