Skip to content

Commit

Permalink
Use contextual navigation components
Browse files Browse the repository at this point in the history
This PR uses the contextual navigation sidebar and breadcrumbs from the
publishing components gem. It removes all the logic for what to display
where and replaces it with calls to the components.

The intention is that this PR doesn't change the layout, but there are
a few changes:

- Contacts have the new sidebar, but the data has stayed the same. I'm
unsure why universal layout hadn't been implemented for contacts in the
first place, and Ganesh wasn't sure either. This might have been an
oversight.
- On topical event pages about pages, there's no more "(archived)" in
the title when the topical event is archived. I think this is an
acceptable trade-off given the complexity it would mean moving this
special functionality to the components.
- We no longer override the header navigation type for things tagged
tagged to the taxonomy. I don't think there was very much reason behind
showing it and not showing it, so I'm okay with this change (this is
the content_for :simple_header stuff that's removed)
- Even though there's a related_items method in the travel advice
presenter, it was unused and the travel advice pages are unchanged
after this PR.

https://trello.com/c/1LEofaHC
  • Loading branch information
tijmenb committed Mar 26, 2018
1 parent bb0255d commit d5b5e93
Show file tree
Hide file tree
Showing 55 changed files with 26 additions and 729 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ gem 'gds-api-adapters', '~> 52.2'
gem 'govuk_ab_testing', '~> 2.4'
gem 'govuk_app_config', '~> 1.3'
gem 'govuk_frontend_toolkit', '~> 7.4'
gem 'govuk_navigation_helpers', '~> 9.2.1'
gem 'govuk_publishing_components', '~> 5.7.0'
gem 'plek', '~> 2.1'
gem 'slimmer', '~> 12.0'
Expand Down
1 change: 0 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ DEPENDENCIES
govuk_ab_testing (~> 2.4)
govuk_app_config (~> 1.3)
govuk_frontend_toolkit (~> 7.4)
govuk_navigation_helpers (~> 9.2.1)
govuk_publishing_components (~> 5.7.0)
govuk_schemas (~> 3.1)
htmlentities (~> 4.3)
Expand Down
1 change: 0 additions & 1 deletion app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
@import 'helpers/organisation-links';
@import 'helpers/parts';
@import 'helpers/add-title-margin';
@import "helpers/step-by-step-nav-title";
@import "helpers/content-bottom-margin";
@import "helpers/publisher-metadata-with-logo";

Expand Down
7 changes: 0 additions & 7 deletions app/assets/stylesheets/helpers/_step-by-step-nav-title.scss

This file was deleted.

5 changes: 0 additions & 5 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ class ApplicationController < ActionController::Base

private

def step_nav_helper
@step_nav_helpers ||= GovukPublishingComponents::StepNavHelper.new(content_item.content_item, request.path)
end
helper_method :step_nav_helper

def content_item_path
path_and_optional_locale = params
.values_at(:path, :locale)
Expand Down
5 changes: 0 additions & 5 deletions app/controllers/content_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class ContentItemsController < ApplicationController
def show
load_content_item

set_up_navigation
set_expiry
set_access_control_allow_origin_header if request.format.atom?
set_guide_draft_access_token if @content_item.is_a?(GuidePresenter)
Expand Down Expand Up @@ -89,10 +88,6 @@ def set_expiry
expires_in(max_age, public: !cache_private)
end

def set_up_navigation
@navigation = NavigationType.new(@content_item.content_item)
end

def with_locale
I18n.with_locale(@content_item.locale || I18n.default_locale) { yield }
end
Expand Down
28 changes: 0 additions & 28 deletions app/models/navigation_type.rb

This file was deleted.

45 changes: 0 additions & 45 deletions app/presenters/contact_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,6 @@ def title_and_context
end
end

def related_items
sections = []
if quick_links.any?
sections << {
title: "Elsewhere on GOV.UK",
items: quick_links
}
end

if related_contacts_links.any?
sections << {
title: "Other contacts",
items: related_contacts_links
}
end

{
sections: sections
}
end

def online_form_links
contact_form_links = content_item["details"]["contact_form_links"] || []
contact_form_links.map do |link|
Expand Down Expand Up @@ -112,30 +91,6 @@ def webchat_open_url
"https://www.tax.service.gov.uk/csp-partials/open/#{webchat_id}"
end

def breadcrumbs
return [] if content_item["links"]['organisations'].try(:length) != 1

org = content_item["links"]['organisations'].first
title = org['title']
base = org['base_path']
contact_url = "#{base}/contact"

[
{
title: "Home",
url: "/",
},
{
title: title,
url: base,
},
{
title: "Contact #{title}",
url: contact_url,
}
]
end

private

def phone_numbers_in_group(group)
Expand Down
21 changes: 0 additions & 21 deletions app/presenters/content_item_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def initialize(content_item, requested_content_item_path = nil)
@locale = content_item["locale"] || "en"
@phase = content_item["phase"]
@document_type = content_item["document_type"]
@nav_helper = GovukNavigationHelpers::NavigationHelper.new(content_item)
@part_slug = requesting_a_part? ? requested_content_item_path.split('/').last : nil
end

Expand Down Expand Up @@ -50,26 +49,6 @@ def content_id
content_item["content_id"]
end

def breadcrumbs
@nav_helper.breadcrumbs[:breadcrumbs]
end

def taxon_breadcrumbs
@nav_helper.taxon_breadcrumbs[:breadcrumbs]
end

def taxonomy_sidebar
@nav_helper.taxonomy_sidebar
end

def related_items
@nav_helper.related_items
end

def tagged_to_a_taxon?
content_item.dig("links", "taxons").present?
end

private

def display_date(timestamp, format = "%-d %B %Y")
Expand Down
4 changes: 0 additions & 4 deletions app/presenters/guide_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ def print_link
"#{base_path}/print"
end

def related_items
@nav_helper.related_items
end

# Append token parameters to part paths to allow fact-checkers to fact-check all pages
def parts
if draft_access_token
Expand Down
15 changes: 0 additions & 15 deletions app/presenters/specialist_document_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,6 @@ def important_metadata
end
end

def breadcrumbs
return [] unless finder

[
{
title: "Home",
url: "/",
},
{
title: finder['title'],
url: finder['base_path'],
}
]
end

def continuation_link
content_item
.dig("details", "metadata", "continuation_link")
Expand Down
22 changes: 0 additions & 22 deletions app/presenters/topical_event_about_page_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,10 @@ class TopicalEventAboutPagePresenter < ContentItemPresenter
include ContentItem::ContentsList
include ContentItem::TitleAndContext

# Old topical event pages have a "archived" string appended to their title
# which we also include in the breadcrumbs of topical event about pages
# for example: https://www.gov.uk/government/topical-events/ebola-virus-government-response/about
def breadcrumbs
result = super
result.last[:title] = parent['title'] if parent
result
end

def title_and_context
super.tap do |t|
t.delete(:average_title_length)
t.delete(:context)
end
end

private

def parent
return nil unless super
topical_event_end_date = super.dig("details", "end_date")

if topical_event_end_date && Time.zone.parse(topical_event_end_date) <= Time.zone.today
super.merge("title" => "#{super['title']} (Archived)")
else
super
end
end
end
22 changes: 0 additions & 22 deletions app/presenters/travel_advice_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,6 @@ def country_name
content_item["details"]["country"]["name"]
end

def related_items
items = ordered_related_items.map do |link|
{
title: link["title"],
url: link["base_path"]
}
end

{
sections: [
{
title: 'Elsewhere on GOV.UK',
items: items
}
]
}
end

def is_summary?
@part_slug.nil?
end
Expand Down Expand Up @@ -127,10 +109,6 @@ def summary_part
}
end

def ordered_related_items
content_item["links"]["ordered_related_items"] || []
end

def change_description
content_item['details']['change_description']
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/content_items/_body_with_related_links.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
<% end %>
</div>
<%= render 'shared/sidebar_navigation', local_assigns %>
<%= render 'shared/sidebar_navigation' %>
</div>
7 changes: 6 additions & 1 deletion app/views/content_items/contact.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
<div class="grid-row">
<div class="column-two-thirds">
<%= render 'govuk_component/title', @content_item.title_and_context %>
</div>
</div>

<div class="grid-row">
<div class="column-two-thirds">

<% body = capture do %>
<% if @content_item.online_form_links.any? %>
Expand Down Expand Up @@ -92,5 +97,5 @@

<%= render 'govuk_component/govspeak', content: body, rich_govspeak: true %>
</div>
<%= render 'shared/related_items', content_item: @content_item %>
<%= render 'shared/sidebar_navigation' %>
</div>
2 changes: 1 addition & 1 deletion app/views/content_items/detailed_guide.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
</div>
<% end %>
</div>
<%= render "shared/sidebar_navigation" %>
<%= render 'shared/sidebar_navigation' %>
</div>
4 changes: 1 addition & 3 deletions app/views/content_items/document_collection.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<%= content_for :simple_header, @navigation.should_present_taxonomy_navigation? %>

<div class="grid-row">
<div class="column-two-thirds">
<%= render 'govuk_component/title',
Expand Down Expand Up @@ -35,5 +33,5 @@
</div>
<% end %>
</div>
<%= render "shared/sidebar_navigation" %>
<%= render 'shared/sidebar_navigation' %>
</div>
2 changes: 1 addition & 1 deletion app/views/content_items/guide.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
<% end %>
<% end %>
</div>
<%= render 'shared/sidebar_navigation', local_assigns %>
<%= render 'shared/sidebar_navigation' %>
</div>
5 changes: 1 addition & 4 deletions app/views/content_items/publication.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
<%= content_for :no_breadcrumbs, step_nav_helper.show_header? %>
<%= content_for :simple_header, @navigation.should_present_taxonomy_navigation? %>

<div class="grid-row">
<div class="column-two-thirds">
<%= render 'govuk_component/title',
Expand Down Expand Up @@ -32,5 +29,5 @@
history: @content_item.history
} %>
</div>
<%= render 'shared/sidebar_navigation', local_assigns %>
<%= render 'shared/sidebar_navigation' %>
</div>
2 changes: 1 addition & 1 deletion app/views/content_items/specialist_document.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@
</div>
<% end %>
</div>
<%= render "shared/sidebar_navigation" %>
<%= render 'shared/sidebar_navigation' %>
</div>
2 changes: 1 addition & 1 deletion app/views/content_items/statistical_data_set.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
</div>
<% end %>
</div>
<%= render "shared/sidebar_navigation" %>
<%= render 'shared/sidebar_navigation' %>
</div>
2 changes: 1 addition & 1 deletion app/views/content_items/topical_event_about_page.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
direction: page_text_direction %>
<% end %>
</div>
<%= render "shared/sidebar_navigation" %>
<%= render 'shared/sidebar_navigation' %>
</div>
2 changes: 1 addition & 1 deletion app/views/content_items/travel_advice.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@

<%= render 'components/print-link', href: @content_item.print_link, link_text: t("multi_page.print_entire_guide") %>
</div>
<%= render "shared/sidebar_navigation" %>
<%= render 'shared/sidebar_navigation' %>
</div>
8 changes: 1 addition & 7 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,7 @@

<div id="wrapper" class="<%= wrapper_class %>">
<%= render_phase_label @content_item, content_for(:phase_message) %>
<% if step_nav_helper.show_header? %>
<%= render 'shared/step_nav_header' %>
<% else %>
<% if !content_for(:no_breadcrumbs) %>
<%= render 'shared/breadcrumbs' %>
<% end %>
<% end %>
<%= render 'govuk_publishing_components/components/contextual_breadcrumbs', content_item: @content_item.content_item.parsed_content %>
<main role="main" id="content" class="<%= @content_item.schema_name.dasherize %>" lang="<%= I18n.locale %>">
<%= yield %>
</main>
Expand Down
Loading

0 comments on commit d5b5e93

Please sign in to comment.