Flexible Page Basic Structure - #4718
Conversation
a7433a6 to
3ee0962
Compare
8b7df2a to
76709a7
Compare
76709a7 to
aef2b63
Compare
35b697c to
61645c0
Compare
61645c0 to
f9e2cdf
Compare
f9e2cdf to
8c9a631
Compare
8c9a631 to
ba7d783
Compare
a06069d to
34eed93
Compare
34eed93 to
32661d8
Compare
32661d8 to
73ae6db
Compare
leenagupte
left a comment
There was a problem hiding this comment.
This is looking good. I've added a few inline comments, mainly where there's a missing test.
| attr_reader :data, :flexible_page, :type | ||
|
|
||
| def initialize(flexible_section_hash, flexible_page) | ||
| @data = flexible_section_hash |
There was a problem hiding this comment.
Calling this data has tripped me up in a later commit as I forgot it was assigned to flexible_section_hash. Perhaps instead it should be renamed to flexible_section_hash as that is what it is. Having two names is confusing.
There was a problem hiding this comment.
Hmm, this is tricky. The parameter name is "what the calling method thinks it's sending you", and the attribute is "what the object thinks of this", so I think it's legit to have them have two names (it's one name for each domain). That said, @data could be something like source_hash, maybe?
There was a problem hiding this comment.
Yeah, I think source_hash works. Although to be fair, in the ContentItem model we did keep content_store_response: https://github.com/alphagov/frontend/blob/main/app/models/content_item.rb#L11
There was a problem hiding this comment.
I'm going to change data to flexible_section_hash, as per our discussion.
andysellick
left a comment
There was a problem hiding this comment.
I won't approve for now as there's some comments still to address from other reviewers, but I'm happy with this code, good job 👏
0cd00af to
00bd3b2
Compare
00bd3b2 to
3faaca5
Compare
3faaca5 to
16d3be6
Compare
16d3be6 to
ad426c2
Compare
leenagupte
left a comment
There was a problem hiding this comment.
Thank for adding the tests.
I have a few inline questions about some of the naming. Otherwise it looks good. 🎉
| attr_reader :data, :flexible_page, :type | ||
|
|
||
| def initialize(flexible_section_hash, flexible_page) | ||
| @data = flexible_section_hash |
There was a problem hiding this comment.
Yeah, I think source_hash works. Although to be fair, in the ContentItem model we did keep content_store_response: https://github.com/alphagov/frontend/blob/main/app/models/content_item.rb#L11
| include described_class | ||
|
|
||
| describe "#render_flexible_section" do | ||
| it "contains error items" do |
There was a problem hiding this comment.
Minor: I think you could rename this to it "renders the correct partial for the flexible section" rather than talking about errors.
There was a problem hiding this comment.
Solving this problem by removing the whole helper.
| class Base | ||
| attr_reader :data, :flexible_page, :type | ||
|
|
||
| def initialize(flexible_section_hash, flexible_page) |
There was a problem hiding this comment.
I was getting very confused about what flexible_page is here. But it's the content item, right? Perhaps then it should be called content_item?
There was a problem hiding this comment.
I'm assuming the whole content item is being passed in here so that the links hash among others, can still be accessed?
| @@ -0,0 +1,11 @@ | |||
| class FlexiblePage::FlexibleSectionFactory | |||
| def self.build(flexible_section_hash, flexible_page) | |||
There was a problem hiding this comment.
Also here, flexible_page the full content_item right?
There was a problem hiding this comment.
Changing this to content_item.
| <% end %> | ||
|
|
||
| <div class="govuk-width-container"> | ||
| <% @content_item.flexible_sections.each do |flexible_section| %> |
There was a problem hiding this comment.
Nitpick: You should be able to use content_item here.
| def initialize(flexible_section_hash, flexible_page) | ||
| super | ||
|
|
||
| @context = data["context"] |
There was a problem hiding this comment.
This is where the @data naming tripped me up. I'd forgotten that @data == flexible_section_hash so then I had to go looking to see where it came from. I think I had the same name association issues in the landing page models.
| <div class="govuk-width-container"> | ||
| <% @content_item.flexible_sections.each do |flexible_section| %> | ||
| <div class="govuk-grid-row"> | ||
| <%= render_flexible_section(flexible_section) %> |
There was a problem hiding this comment.
Not a blocker: Is this helper method only used here? If so, I'd ask whether it's actually needed.
There was a problem hiding this comment.
Solving by removing helper.
| @govspeak = data["govspeak"] | ||
|
|
||
| if data["image"].present? | ||
| alt, src = data.fetch("image").values_at("alt", "src") |
There was a problem hiding this comment.
I forgot to mention in the previous review, this is a nice use of fetch with values_at.
|
|
||
| <% content_for :before_content do %> | ||
| <div class="govuk-width-container"> | ||
| <%= render "govuk_publishing_components/components/contextual_breadcrumbs", content_item: content_item.to_h %> |
There was a problem hiding this comment.
This is much nicer than having to hard-code the breadcrumb 🎉
- This fixture is over-detailed at this point, but matches the local content item for development that will be added later. It's necessary to have a file to run the request test (it doesn't have to be this detailed, but it doesn't hurt). It's modelled after the No 10 history page: https://www.gov.uk/government/history/10-downing-street
- At this point we have a controller, a route, and a view, so we can add the basic tests we're currently doing as review tests (basic 200, and correct template rendered)
- all flexible sections will have a type, the data they were initialised with, and a link to the content item (ie flexible page) that contains them. - factory works similar to the exist landing page block factory: https://github.com/alphagov/frontend/blob/7ae68c66b9308f1c45dab8cc2b56ee1814b9b11e/app/models/landing_page/block_factory.rb ...but with the simplification that we don't need to provide as much error handling, and we don't need a build_all method because there are not going to be any nested sections.
- We add a loop in the view to find renderable views for the sections and render them in place.
- This flexible section renders a page title with an optional context, using the heading component. Co-authored-by: Andy Sellick <andy.sellick@digital.cabinet-office.gov.uk>
- This flexible section renders a 1/3rd 2/3rd section of page, in which the left (1/3) side is a contents list for the right (2/3) section, which is govspeak. - Also add a contents list presenter that will return the content list in a format required by the contents list component. Co-authored-by: Andy Sellick <andy.sellick@digital.cabinet-office.gov.uk>
- This page modelled on the Number 10 history page https://www.gov.uk/government/history/10-downing-street
- System tests for all flexible page sections to be added here (it may be that we make those effectively individual view tests later, similar to components, but for the moment it's simplest to add here)
- Here we're relying on the contextual breadcrumb component to make a breadcrumb using the links/parent elements in the content item, but because of the full-width layout we have to opt out of the breadcrumb code in the layout and explicitly render it inside a govuk-width container.
ad426c2 to
48f8c96
Compare
leenagupte
left a comment
There was a problem hiding this comment.
Thanks for updating the naming 🥇
, Jira issue PNP-6387⚠️ This repo is Continuously Deployed: make sure you follow the guidance ⚠️
What
Adds basic support for Flexible Pages, and two section types (page_title and rich_content), suitable for making a basic version of the existing history pages. Also adds an example history page loaded from local content at test/flexible-page
(Note you will need ALLOW_LOCAL_CONTENT_ITEM_OVERRIDE=true set to see this item - I have set it on the preview app).
Example on preview app:
https://govuk-frontend-app-pr-4718.herokuapp.com/test/flexible-page
Why
alphagov/govuk-rfcs#182
Trello card: https://trello.com/c/Bwy1WiJW