From a0a4b2ea4b42ae1e62127184290e060af6bd9412 Mon Sep 17 00:00:00 2001 From: Harriet H-W Date: Tue, 5 Nov 2024 11:26:21 +0000 Subject: [PATCH 1/2] Link to draft host document for content block preview We would like to link to the draft store so that users can see the changes they've just made to the block in host documents. As this table component is also used on the 'view' page I am passing in a boolean to determine whether to show draft or live frontend. --- .../show/host_editions_table_component.rb | 13 +++++++++++-- .../editions/workflow/review_links.html.erb | 1 + .../features/edit_object.feature | 5 +++++ .../content_block_manager_steps.rb | 11 +++++++++++ .../show/host_editions_table_component_test.rb | 15 +++++++++++++++ 5 files changed, 43 insertions(+), 2 deletions(-) diff --git a/lib/engines/content_block_manager/app/components/content_block_manager/content_block/document/show/host_editions_table_component.rb b/lib/engines/content_block_manager/app/components/content_block_manager/content_block/document/show/host_editions_table_component.rb index 5abb8c8ede6..daad0e09de4 100644 --- a/lib/engines/content_block_manager/app/components/content_block_manager/content_block/document/show/host_editions_table_component.rb +++ b/lib/engines/content_block_manager/app/components/content_block_manager/content_block/document/show/host_editions_table_component.rb @@ -1,9 +1,10 @@ # frozen_string_literal: true class ContentBlockManager::ContentBlock::Document::Show::HostEditionsTableComponent < ViewComponent::Base - def initialize(caption:, host_content_items:) + def initialize(caption:, host_content_items:, is_preview: false) @caption = caption @host_content_items = host_content_items + @is_preview = is_preview end private @@ -43,8 +44,16 @@ def users @users ||= User.where(uid: host_content_items.map(&:last_edited_by_editor_id)) end + def frontend_path(content_item) + if @is_preview + Plek.external_url_for("draft-origin") + content_item.base_path + else + Plek.external_url_for("government-frontend") + content_item.base_path + end + end + def content_link(content_item) - link_to(content_item.title, Plek.website_root + content_item.base_path, class: "govuk-link") + link_to(content_item.title, frontend_path(content_item), class: "govuk-link") end def organisation_link(content_item) diff --git a/lib/engines/content_block_manager/app/views/content_block_manager/content_block/editions/workflow/review_links.html.erb b/lib/engines/content_block_manager/app/views/content_block_manager/content_block/editions/workflow/review_links.html.erb index c911b266e48..34aae6cb260 100644 --- a/lib/engines/content_block_manager/app/views/content_block_manager/content_block/editions/workflow/review_links.html.erb +++ b/lib/engines/content_block_manager/app/views/content_block_manager/content_block/editions/workflow/review_links.html.erb @@ -13,6 +13,7 @@
<%= render( ContentBlockManager::ContentBlock::Document::Show::HostEditionsTableComponent.new( + is_preview: true, caption: "Content it appears in", host_content_items: @host_content_items, ), diff --git a/lib/engines/content_block_manager/features/edit_object.feature b/lib/engines/content_block_manager/features/edit_object.feature index 33a982f81a4..65ee825f0f5 100644 --- a/lib/engines/content_block_manager/features/edit_object.feature +++ b/lib/engines/content_block_manager/features/edit_object.feature @@ -97,3 +97,8 @@ Feature: Edit a content object And I visit the Content Block Manager home page Then I should still see the live edition on the homepage + Scenario: GDS editor can preview a host document + When I revisit the edit page + And I fill out the form + Then I am shown where the changes will take place + And the host documents link to the draft content store diff --git a/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb b/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb index ba90596a8fe..72dbb315cb8 100644 --- a/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb +++ b/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb @@ -420,6 +420,7 @@ def should_show_edit_form_for_email_address_content_block(document_title, email_ "content_id" => SecureRandom.uuid, "last_edited_by_editor_id" => SecureRandom.uuid, "last_edited_at" => 2.days.ago.to_s, + "host_content_id" => "abc12345", "primary_publishing_organisation" => { "content_id" => SecureRandom.uuid, "title" => "Organisation #{i}", @@ -453,6 +454,16 @@ def should_show_edit_form_for_email_address_content_block(document_title, email_ end end +And("the host documents link to the draft content store") do + @dependent_content.each do |item| + expect(page).to have_selector("a.govuk-link[href='#{Plek.external_url_for('draft-origin') + item['base_path']}']", text: item["title"]) + end +end + +When("I click on the first host document") do + click_on @dependent_content.first["title"] +end + When(/^I save and continue$/) do click_save_and_continue end diff --git a/lib/engines/content_block_manager/test/components/content_block/document/show/host_editions_table_component_test.rb b/lib/engines/content_block_manager/test/components/content_block/document/show/host_editions_table_component_test.rb index 102ad703d4a..b884ce66539 100644 --- a/lib/engines/content_block_manager/test/components/content_block/document/show/host_editions_table_component_test.rb +++ b/lib/engines/content_block_manager/test/components/content_block/document/show/host_editions_table_component_test.rb @@ -59,6 +59,7 @@ def self.it_returns_unknown_user assert_selector "tbody .govuk-table__row", count: 1 assert_selector "tbody .govuk-table__cell", text: host_content_item.title + assert_selector "a[href='#{Plek.external_url_for('government-frontend') + host_content_item.base_path}']", text: host_content_item.title assert_selector "tbody .govuk-table__cell", text: host_content_item.document_type.humanize assert_selector "tbody .govuk-table__cell", text: "1.2m" assert_selector "tbody .govuk-table__cell", text: host_content_item.publishing_organisation["title"] @@ -152,5 +153,19 @@ def self.it_returns_unknown_user assert_selector "tbody .govuk-table__cell", text: "Not set" end end + + context "when previewing" do + it "returns the draft content store link" do + render_inline( + described_class.new( + is_preview: true, + caption:, + host_content_items:, + ), + ) + + assert_selector "a[href='#{Plek.external_url_for('draft-origin') + host_content_item.base_path}']", text: host_content_item.title + end + end end end From b04d8b6a33b8b5d923719c3e4a2405745c628d37 Mon Sep 17 00:00:00 2001 From: Harriet H-W Date: Tue, 5 Nov 2024 12:17:25 +0000 Subject: [PATCH 2/2] open host document links in new tab Although opening a new tab is not ideal for accessibility, in this case we think it is the preferred behaviour - opening a new tab can be recommended if a user is in the middle of a for or would lose context of what they are working on if not taken to a new tab. In the case of these host documents, if the user is previewing changes they will be in the middle of the form, if they are just viewing the content block it could be confusing to be taken to gov.uk and out of Content Block Manager. There is precedent across Whitehall GDS for opening in new tabs when needed, and the mitigation is to include a message for screen readers declaring that the link opens in a new tab. We can test how this approach works for our users and change if needed. --- .../document/show/host_editions_table_component.rb | 10 +++++++++- .../show/host_editions_table_component_test.rb | 8 ++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/engines/content_block_manager/app/components/content_block_manager/content_block/document/show/host_editions_table_component.rb b/lib/engines/content_block_manager/app/components/content_block_manager/content_block/document/show/host_editions_table_component.rb index daad0e09de4..1c3f6ed93d4 100644 --- a/lib/engines/content_block_manager/app/components/content_block_manager/content_block/document/show/host_editions_table_component.rb +++ b/lib/engines/content_block_manager/app/components/content_block_manager/content_block/document/show/host_editions_table_component.rb @@ -52,8 +52,16 @@ def frontend_path(content_item) end end + def content_link_text(content_item) + sanitize [ + content_item.title, + tag.span("(opens in new tab)", class: "govuk-visually-hidden"), + ].join(" ") + end + def content_link(content_item) - link_to(content_item.title, frontend_path(content_item), class: "govuk-link") + link_to(content_link_text(content_item), + frontend_path(content_item), class: "govuk-link", target: "_blank", rel: "noopener") end def organisation_link(content_item) diff --git a/lib/engines/content_block_manager/test/components/content_block/document/show/host_editions_table_component_test.rb b/lib/engines/content_block_manager/test/components/content_block/document/show/host_editions_table_component_test.rb index b884ce66539..fb5431d925e 100644 --- a/lib/engines/content_block_manager/test/components/content_block/document/show/host_editions_table_component_test.rb +++ b/lib/engines/content_block_manager/test/components/content_block/document/show/host_editions_table_component_test.rb @@ -58,8 +58,12 @@ def self.it_returns_unknown_user assert_selector "tbody .govuk-table__row", count: 1 - assert_selector "tbody .govuk-table__cell", text: host_content_item.title - assert_selector "a[href='#{Plek.external_url_for('government-frontend') + host_content_item.base_path}']", text: host_content_item.title + assert_selector ".govuk-link" do |link| + assert_equal "#{host_content_item.title} (opens in new tab)", link.text + assert_equal Plek.external_url_for("government-frontend") + host_content_item.base_path, link[:href] + assert_equal "noopener", link[:rel] + assert_equal "_blank", link[:target] + end assert_selector "tbody .govuk-table__cell", text: host_content_item.document_type.humanize assert_selector "tbody .govuk-table__cell", text: "1.2m" assert_selector "tbody .govuk-table__cell", text: host_content_item.publishing_organisation["title"]