Skip to content

Commit

Permalink
Merge pull request #4485 from alphagov/consolidate-document-list-and-…
Browse files Browse the repository at this point in the history
…press-notices

Consolidate document list and press notice blocks
  • Loading branch information
leenagupte authored Nov 29, 2024
2 parents a044a3d + 4c72237 commit 9817cee
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 98 deletions.
3 changes: 2 additions & 1 deletion app/models/landing_page/block/document_list.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module LandingPage::Block
class DocumentList < Base
attr_reader :taxon_base_path
attr_reader :taxon_base_path, :heading

TAXON_SEARCH_FIELDS = %w[title
link
Expand All @@ -12,6 +12,7 @@ def initialize(block_hash, landing_page)
super

@taxon_base_path = data["taxon_base_path"]
@heading = data["heading"]
end

def full_width?
Expand Down
4 changes: 0 additions & 4 deletions app/models/landing_page/block/press_notices.rb

This file was deleted.

19 changes: 15 additions & 4 deletions app/views/landing_page/blocks/_document_list.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
<%= render "govuk_publishing_components/components/document_list", {
margin_bottom: 4,
items: block.items,
} %>
<% heading = block.heading || "Latest Updates" %>

<% if block.items.any? %>
<%= render "govuk_publishing_components/components/heading", {
text: heading,
padding: true,
border_top: 5,
margin_bottom: 3
} %>

<%= render "govuk_publishing_components/components/document_list", {
margin_bottom: 0,
items: block.items,
} %>
<% end %>
13 changes: 0 additions & 13 deletions app/views/landing_page/blocks/_press_notices.html.erb

This file was deleted.

34 changes: 4 additions & 30 deletions docs/building_blocks_for_flexible_content.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ Simple blocks generally render one component or "thing". They can either be rend
- [Heading](#heading)
- [Image](#image)
- [Main Navigation](#main-navigation)
- [Press notices](#press-notices)
- [Quote](#quote)
- [Share links](#share-links)
- [Side Navigation](#side-navigation)
Expand Down Expand Up @@ -64,14 +63,17 @@ A wrapper around the [Big number component](https://components.publishing.servic

#### Document list

A wrapper around the [Document list component](https://components.publishing.service.gov.uk/component-guide/document_list)
A wrapper around the [Document list component](https://components.publishing.service.gov.uk/component-guide/document_list) with a title that will only appear if there are any items in the list (if the list is entirely empty the heading will not appear either)

The document list can either be populated with the most recent content tagged to a taxon or from a hard-coded list.

If the `taxon_base_path` is provided and the taxon exists and it has content tagged to it, the document list will be populated with that content. If not, it will default to the hard-coded list.

If the `heading` is provided that will be used, otherwise it will default to the hard-coded heading.

```yaml
- type: document_list
heading: My Favourite Things
taxon_base_path: /government/government-efficiency-transparency-and-accountability
items:
- text: An example link
Expand Down Expand Up @@ -159,34 +161,6 @@ The top-level navigation. It supports multiple headings, each with a row of link
navigation_group_id: Top Menu
```

#### Press notices

A wrapper around the [Document list component](https://components.publishing.service.gov.uk/component-guide/document_list) with a hardcoded title that will only appear if there are any items in the list (if the list is entirely empty the heading will not appear either)

The document list can either be populate with the most recent content tagged to a taxon, or from a hard-coded list.

If the `taxon_base_path` is provided, the taxon exists and it has content tagged to it, the document list will be populated with that content, otherwise it will default to the hard-coded list.

##### Example

```yaml
- type: press_notices
taxon_base_path: /government/government-efficiency-transparency-and-accountability
items:
- text: An example link
path: https://www.gov.uk
document_type: Press release
public_updated_at: "2016-06-27 10:29:44 +0000"
- text: Another example link
path: https://www.gov.uk
document_type: News article
public_updated_at: "2021-01-16 11:34:12 +0000"
- text: A third example link
path: https://www.gov.uk
document_type: Consultation
public_updated_at: "2024-02-01 09:00:11 +0000"
#### Quote

A blockquote.
Expand Down
3 changes: 2 additions & 1 deletion lib/data/landing_page_content_items/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ blocks:
- type: two_column_layout
theme: two_thirds_one_third
blocks:
- type: press_notices
- type: document_list
heading: "Latest things"
items:
- text: An example title for this press notice 1
path: "https://www.gov.uk"
Expand Down
24 changes: 1 addition & 23 deletions spec/models/landing_page/block/document_list_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
require "gds_api/test_helpers/search"

RSpec.describe LandingPage::Block::DocumentList do
include GdsApi::TestHelpers::Search
include ContentStoreHelpers
include SearchHelpers

describe "#items" do
context "when the list is hard-coded" do
Expand Down Expand Up @@ -133,24 +131,4 @@
end
end
end

def stub_taxon_search_results
results = [
{
"title" => "Doc one",
"link" => "/doc-one",
"description" => "Doc one description",
"format" => "press_release",
"public_timestamp" => Time.zone.local(2024, 1, 1, 10, 24, 0),
},
]

body = {
"results" => results,
"start" => "0",
"total" => results.size,
}

stub_any_search.to_return("body" => body.to_json)
end
end
18 changes: 0 additions & 18 deletions spec/models/landing_page/block/press_notices_spec.rb

This file was deleted.

28 changes: 28 additions & 0 deletions spec/support/search_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require "govuk_schemas"
require "gds_api/test_helpers/search"

module SearchHelpers
include GdsApi::TestHelpers::Search

def stub_taxon_search_results(slug = "doc-one")
title = slug.tr("-", " ").capitalize

results = [
{
"title" => title,
"link" => "/#{slug}",
"description" => "#{title} description",
"format" => "press_release",
"public_timestamp" => Time.zone.local(2024, 1, 1, 10, 24, 0),
},
]

body = {
"results" => results,
"start" => "0",
"total" => results.size,
}

stub_any_search.to_return("body" => body.to_json)
end
end
13 changes: 9 additions & 4 deletions spec/system/landing_page_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
require "gds_api/test_helpers/search"

RSpec.describe "LandingPage" do
include GdsApi::TestHelpers::Search
include SearchHelpers

context "show" do
let(:content_item) do
Expand Down Expand Up @@ -46,7 +44,7 @@
stub_content_store_has_item(base_path, content_item)
stub_request(:get, %r{/media/000000000000000000000001/data_one.csv}).to_return(status: 200, body: File.read("spec/fixtures/landing_page_statistics_data/data_one.csv"), headers: {})
stub_content_store_has_item(basic_taxon["base_path"], basic_taxon)
stub_any_search_to_return_no_results
stub_taxon_search_results
end

it "displays the page" do
Expand Down Expand Up @@ -95,5 +93,12 @@

assert_selector ".govuk-breadcrumbs"
end

it "renders a document list" do
visit base_path

assert_selector ".gem-c-heading"
assert_selector ".gem-c-document-list"
end
end
end

0 comments on commit 9817cee

Please sign in to comment.