Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add travel advice pages #4225

Draft
wants to merge 34 commits into
base: main
Choose a base branch
from
Draft

Conversation

leenagupte
Copy link
Contributor

⚠️ This repo is Continuously Deployed: make sure you follow the guidance ⚠️

What

Why

Trello card

How

Screenshots?

@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4225 September 10, 2024 11:53 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4225 September 10, 2024 12:03 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4225 September 10, 2024 12:06 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4225 September 10, 2024 15:46 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4225 September 11, 2024 15:05 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4225 September 11, 2024 15:46 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4225 September 11, 2024 15:51 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4225 September 11, 2024 16:38 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4225 September 11, 2024 16:41 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4225 September 11, 2024 16:41 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4225 September 12, 2024 13:40 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4225 September 12, 2024 17:12 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4225 September 13, 2024 14:52 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4225 September 13, 2024 16:58 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4225 September 13, 2024 17:21 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4225 September 16, 2024 16:29 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4225 September 17, 2024 13:30 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4225 September 17, 2024 16:34 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4225 September 19, 2024 14:56 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4225 September 19, 2024 16:42 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4225 September 20, 2024 13:36 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4225 September 20, 2024 13:44 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4225 September 20, 2024 16:04 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4225 September 24, 2024 15:34 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4225 September 24, 2024 17:05 Inactive
The print variant is only available on the first page i.e.
/foreign-travel-advice/{country}/print. It's only available on "part"
pages, so the route needs to be split to catch requests for the print
variant.

Audit trail:
content_items_controller.rb: https://github.com/alphagov/government-frontend/blob/3cd7f33a5de36271c837137be0137d2458f306e7/app/controllers/content_items_controller.rb#L190
travel_advice.html+print.erb: https://github.com/alphagov/government-frontend/blob/3cd7f33a5de36271c837137be0137d2458f306e7/app/views/content_items/travel_advice.html%2Bprint.erb
Moves the relevant model methods from the presenter in
government-frontend.

Audit_trail:
travel_advice_presenter.rb: https://github.com/alphagov/government-frontend/blob/c4bea9e232e929995c4fb5539951cadae8c740c8/app/presenters/travel_advice_presenter.rb
Moves the alert_status method from the travel_advice_presenter in
goverment-frontend.

The method has been slightly refactored and also removes the
presentation elements, specifically the translation lookup.

Audit_trail:
travel_advice_presenter.rb: https://github.com/alphagov/government-frontend/blob/c4bea9e232e929995c4fb5539951cadae8c740c8/app/presenters/travel_advice_presenter.rb#L77-L90
travel_advice_presenter_test.rb: https://github.com/alphagov/government-frontend/blob/c4bea9e232e929995c4fb5539951cadae8c740c8/test/presenters/travel_advice_presenter_test.rb#L189-L197
This calls the presentation code from the original presenter directly
in the view rather than adding a new method.

Audit_trail:
travel_advice_presenter.rb: https://github.com/alphagov/government-frontend/blob/a938e4bee78b794e4e5303a1bde1dfd05e94b287/app/presenters/travel_advice_presenter.rb#L87
The other document types call the metadata component directly. It seems
to add an unnecessary layer of abstraction to recreate a helper method
whose only extra purpose is to pass in the content item, and that can
done directly in each view.

Audit trail:
machine_readable_metadata_helper.rb: https://github.com/alphagov/government-frontend/blob/84047412f6f42eaf380a9092aadfe15037de0d35/app/helpers/machine_readable_metadata_helper.rb
This is rather than porting across the `title_and_context` presenter
method from the original travel_advice_presenter in government-frontend.

Audit trail:
travel_advice_presenter: https://github.com/alphagov/government-frontend/blob/16a0e99c52f482f54875eaecf537b31e6e2b75b4/app/presenters/travel_advice_presenter.rb#L34-L39
This ensures that the open graph meta tags are added to the page source
correctly.
This helper creates links to generic things rather than recreating
bespoke methods in a travel advice presenter.

Audit trail:
travel_advice_presenter.rb: https://github.com/alphagov/government-frontend/blob/main/app/presenters/travel_advice_presenter.rb#L65-L71
Parts are added as concern as the code will be shared by travel advice
and guide pages.

Updates current_part_body to return an empty string if nil so that
the `body_for_metadata` method does not need to be recreated.
`body_for_metadata` was created as a bug fix:
alphagov/government-frontend@74f6e4e

Makes `current_part` a public method so that it can be used in the call
to PartsNavigationHelper which will be created in a later commit.

Audit trail:
parts.rb: https://github.com/alphagov/government-frontend/blob/c4bea9e232e929995c4fb5539951cadae8c740c8/app/presenters/content_item/parts.rb
parts_test.rb: https://github.com/alphagov/government-frontend/blob/c4bea9e232e929995c4fb5539951cadae8c740c8/test/presenters/content_item/parts_test.rb
Adds the presentation logic in the government-frontend presenter that it
wasn't appropriate to include in the TravelAdvice model.

Some methods have not been included as they are no longer being used in
government-frontend:

- parts_navigation
- parts_navigation_second_list_start
- part_links
- part_navigation_group_size

The render_guide_as_single_page? check has been removed from
part_link_elements as it is out of date. The election it refers to
was in 2021

Though this helper was taken from the travel advice code in
government-frontend, the helper name has been kept generic so that it
can be reused when guide pages are moved to frontend.

Audit trail:
content_item_presenter.rb:
1. https://github.com/alphagov/government-frontend/blob/16a0e99c52f482f54875eaecf537b31e6e2b75b4/app/presenters/content_item_presenter.rb#L106
2. https://github.com/alphagov/government-frontend/blob/16a0e99c52f482f54875eaecf537b31e6e2b75b4/app/presenters/content_item_presenter.rb#L123-L126
It replicates the logic from government-frontend:
https://github.com/alphagov/government-frontend/blob/cbbbf70e5f2fd5a41b0208e9c01f9083bb6363d3/app/presenters/content_item_presenter.rb#L74-L80

It's only used in the show template, and passed to the
machine_readable_metadata component.

The travel advice index template calls
`Frontend.govuk_website_root + root_path` directly in the template.
Considered using this pattern, but having `Frontend.govuk_website_root`
defined seems unnecessary, and calling `Plek.new.website_root` directly
in the view feels wrong.
The tests also check that the print variant renders, they don't test that
the correct variant is being printed because that would be testing that
setting `request.variant` does the right thing.
Travel Advice pages need to known the withdrawn status in able to
construct the page title.

However, some of the methods from the original presenters feel like
model concerns rather than presentation concerns, so they have been
added the to model concern.

There is only one example of the content item with a withdrawn notice
in content schemas, so the shared example is being tested on the
generic content item model rather than travel advice.

The travel advice page title is a presentation concern and will be
added in a later commit.

Audit trail:
withdrawable.rb: https://github.com/alphagov/government-frontend/blob/main/app/presenters/content_item/withdrawable.rb#L8
travel_advice_presenter.rb: https://github.com/alphagov/government-frontend/blob/main/app/presenters/travel_advice_presenter.rb#L6-L12
This presenter is badly named ContentItemModelPresenter because
ContentItemPresenter already exists. ContentItemPresenter takes a
hash of the results from content store and models them. That work is
already being done by the ContentItem model, and shouldn't be repeated
in the presenter.

Some extra work needs to be done to evaluate the existing routes to see
how they can be unstitched from the existing ContentItemPresenter and
then this class can be removed.

The page_title has been added to a generic presenter because other
document types from government-frontend use it as the basis for their
own page title methods.

Audit trail:
withdrawable.rb: https://github.com/alphagov/government-frontend/blob/3cd7f33a5de36271c837137be0137d2458f306e7/app/presenters/content_item/withdrawable.rb#L7-L9
And use it in the views

It's not possible to use `@presenter` as that is being used by the
ApplicationHelper to define the wrapper classes. If you do, and you
don't have a "publication" defined, you get the following error:

NoMethodError:
     #   private method `format' called for #<TravelAdvicePresenter

./app/helpers/application_helper.rb:15:in `wrapper_class'

Solving the issue of needing a "publication" is outside the scope of the
PR. Instead a different variable name is being used.

Audit trail:
travel_advice_presenter.rb: https://github.com/alphagov/government-frontend/blob/3cd7f33a5de36271c837137be0137d2458f306e7/app/presenters/travel_advice_presenter.rb#L6-L12
This was in the travel advice presenter in government-frontend. However
as it is a purely presentation concern, it did not feel appropriate to
add it to the model.

It'll be needed by some new presenter methods.

Add change_description to TravelAdvice model to support this change.

travel_advice_presenter: https://github.com/alphagov/government-frontend/blob/c4bea9e232e929995c4fb5539951cadae8c740c8/app/presenters/travel_advice_presenter.rb#L108-L110
Adds methods to the TravelAdvice model. This information only exists for
Travel Advice, so it doesn't need to be added to the generic
ContentItem model.

Audit trail:
travel_advice_presenter.rb: https://github.com/alphagov/government-frontend/blob/3cd7f33a5de36271c837137be0137d2458f306e7/app/presenters/travel_advice_presenter.rb#L15-L16
This takes the metadata presenter method from government-frontend, but
rather than recreating it, builds the params directly in the view.

The old presenter method need to use view_context to call the
`simple_format` helper method, which feels unnecessary for a method
that's only used once in this document type specific partial.

This code could probably be refactored into a more elegant helper method
in the future.

Audit trail:
travel_advice_presenter.rb: https://github.com/alphagov/government-frontend/blob/main/app/presenters/travel_advice_presenter.rb#L14-L28
This method was created for the travel advice index atom feed and is now
being reused for the individual country pages.
This is rather than replicating the web_url method from the
ContentItemPresenter in government-frontend that is doing the same
thing:

Audit trail:
content_item_presenter.rb: https://github.com/alphagov/government-frontend/blob/b3cbb8d7b8ff3ff792aa70c58ca8272a384d1773/app/presenters/content_item_presenter.rb#L70
This method only had one line and was unnecessary.

The public_updated_at field has already been added to the ContentItem
model as it feels generic enough to be there, and so that the json
object doesn't need to be directly accessed from the view.

Audit trail:
travel_advice_presenter.rb: https://github.com/alphagov/government-frontend/blob/b3cbb8d7b8ff3ff792aa70c58ca8272a384d1773/app/presenters/travel_advice_presenter.rb#L97C5-L97C21
This is to make space for the "show" tests
In government-frontend, the main wrapper is included in the
application layout. That's not case here, so it has to be added to
each view.

Audit trail:
application.html.erb: https://github.com/alphagov/government-frontend/blob/3cd7f33a5de36271c837137be0137d2458f306e7/app/views/layouts/application.html.erb#L1-L5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants