Skip to content

Commit

Permalink
Create new Design System layout
Browse files Browse the repository at this point in the history
Create design_system.html.erb layout. Make the ReportsController use the
new layout. Create a helper to build the navigation link structure for
the navbar. Write tests for the NavigationItems helper.
  • Loading branch information
patrickpatrickpatrick committed Jan 24, 2024
1 parent 1506373 commit 6a4830e
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class ReportsController < ApplicationController
layout "design_system"

include ActionView::Helpers::TagHelper

before_action :authenticate_user!
Expand Down
16 changes: 16 additions & 0 deletions app/helpers/navigation_items_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module NavigationItemsHelper
def navigation_items(is_editor)
list = [
{ text: "Publications", href: root_path },
]

if is_editor
list << { text: "Add artefact", href: new_artefact_path }
list << { text: "Downtime", href: downtimes_path }
end

list << { text: "Reports", href: reports_path }
list << { text: "Search by user", href: user_search_path }
list << { text: "Sign out", href: "/auth/gds/sign_out" }
end
end

Check failure on line 16 in app/helpers/navigation_items_helper.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Layout/TrailingEmptyLines: Final newline missing. (https://rubystyle.guide#newline-eof)
43 changes: 43 additions & 0 deletions app/views/layouts/design_system.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<% environment = GovukPublishingComponents::AppHelpers::Environment.current_acceptance_environment %>
<%= render "govuk_publishing_components/components/layout_for_admin", product_title: "Publisher", browser_title: yield(:page_title), environment: environment do %>
<% render "layouts/google_tag_manager" %>
<%= render "govuk_publishing_components/components/skip_link" %>
<% user = current_user %>
<%= render "govuk_publishing_components/components/layout_header", {
product_name: "Publisher",
environment: environment,
navigation_items: navigation_items(current_user.govuk_editor?)
} %>

<div class="govuk-width-container">
<% [:success, :info, :warning, :danger, :notice, :alert].select { |k| flash[k].present? }.each do |k| %>
<%
case k
when :notice
alert_class = "success"
when :alert
alert_class = "danger"
else
alert_class = k
end
%>
<div class="alert alert-<%= alert_class %>"
data-module="auto-track-event"
data-track-action="alert-<%= alert_class %>"
data-track-label="<%= strip_tags(flash[k]) %>">
<%= flash[k] %>
</div>
<% end %>
<%= yield %>
</div>

<%= render "govuk_publishing_components/components/layout_footer", {
navigation: [],
} %>
<% end %>
25 changes: 25 additions & 0 deletions test/unit/helpers/naviation_items_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require "test_helper"

class NavigationItemsHelperTest < ActionView::TestCase
context "NavigationItemsHelper" do
should "include editor only links when user is an editor" do
assert_equal [
{ text: "Publications", href: root_path },
{ text: "Add artefact", href: new_artefact_path },
{ text: "Downtime", href: downtimes_path },
{ text: "Reports", href: reports_path },
{ text: "Search by user", href: user_search_path },
{ text: "Sign out", href: "/auth/gds/sign_out" },
], navigation_items(true)
end

should "include not include editor only links when user is not an editor" do
assert_equal [
{ text: "Publications", href: root_path },
{ text: "Reports", href: reports_path },
{ text: "Search by user", href: user_search_path },
{ text: "Sign out", href: "/auth/gds/sign_out" },
], navigation_items(false)
end
end
end

0 comments on commit 6a4830e

Please sign in to comment.