Skip to content

Commit

Permalink
Change forms pages to use different data
Browse files Browse the repository at this point in the history
- rework the list of documents on the forms pages to use the content item data in `details->attachments` to render the required content, in place of the data in `details->documents`, which is pre-rendered
- will make putting tracking onto these elements easier
  • Loading branch information
andysellick committed Jan 15, 2024
1 parent eff11be commit c8f879d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions app/presenters/publication_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def details
content_item["details"]["body"]
end

def documents
content_item["details"]["documents"].to_a.join("")
def documents_attachments
content_item["details"]["attachments"]
end

def featured_attachments
Expand Down
19 changes: 11 additions & 8 deletions app/views/content_items/_attachments.html.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<% attachments ||= [] %>
<% attachment_details = attachments.filter_map { |id| @content_item&.attachment_details(id) } %>
<% featured_attachments ||= [] %>
<% attachment_details = featured_attachments.filter_map { |id| @content_item&.attachment_details(id) } %>
<% if legacy_pre_rendered_documents.present? || attachment_details.any? %>
<section id="<%= title.parameterize %>">
<%= render 'govuk_publishing_components/components/heading',
text: title,
mobile_top_margin: true %>

<% if legacy_pre_rendered_documents.present? %>
<%= render 'govuk_publishing_components/components/govspeak', {
direction: page_text_direction,
} do %>
<% add_gem_component_stylesheet("details") if legacy_pre_rendered_documents.include? "govuk\-details" %>
<%= raw(legacy_pre_rendered_documents) %>
<% add_gem_component_stylesheet("details") %>
<% if attachments.present? %>
<% attachments.each do |details| %>
<div class="govuk-!-static-margin-bottom-6">
<%= render 'govuk_publishing_components/components/attachment', {
heading_level: 3,
attachment: details
} %>
</div>
<% end %>
<% else %>
<% attachment_details.each do |details| %>
Expand Down
3 changes: 2 additions & 1 deletion app/views/content_items/publication.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
<%= render "attachments",
title: t("publication.documents", count: 5), # This should always be pluralised.
legacy_pre_rendered_documents: @content_item.documents,
attachments: @content_item.featured_attachments
attachments: @content_item.documents_attachments,
featured_attachments: @content_item.featured_attachments
%>

<section id="details">
Expand Down
2 changes: 1 addition & 1 deletion test/presenters/publication_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def schema_name
assert_equal schema_item["schema_name"], presented_item.schema_name
assert_equal schema_item["title"], presented_item.title
assert_equal schema_item["details"]["body"], presented_item.details
assert_equal schema_item["details"]["documents"].join(""), presented_item.documents
assert_equal schema_item["details"]["documents"], presented_item.documents_attachments
end

test "#published returns a formatted date of the day the content item became public" do
Expand Down

0 comments on commit c8f879d

Please sign in to comment.