-
Notifications
You must be signed in to change notification settings - Fork 20
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] Move specialist document pages #4600
Draft
leenagupte
wants to merge
38
commits into
main
Choose a base branch
from
move-specialist-document-pages
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b259d63
to
35c7372
Compare
35c7372
to
6f7fd4c
Compare
6f7fd4c
to
66bf67d
Compare
a88293a
to
90dfd7b
Compare
4b7f7e0
to
51f1c69
Compare
00b72a6
to
f34f815
Compare
This was referenced Feb 11, 2025
Specialist documents need to use the "Full path routing constraint" as their routes are comprised of `/<document_type>/slug` rather than just `/slug`
b1470a7
to
fab491c
Compare
The list of headers is used to generate the contents list if there are more than 3 headers in the list. Confusingly this list of headers is generated in multiple places. [specialist-publisher] uses the govspeak gem to parse the body content and look for `h2` and `h3` tags and generate the `headers` list in `details` from them. If there are no `h2` or `h3` tags the entire `headers` element is removed from `details. government-frontend deals with `headers` in two different ways. It uses the `headers` element in details to [create the contents list], but then somewhat replicates the code from the govspeak gem by [parsing the `h2` tags] in the body content to determine whether or not so show the contents list. Those it's not being used to render the contents list in government-frontend the `headers` element does have a `level` attribute that indicates whether the header is a `h2` or `h3`. Therefore it should not be possible to greatly simplify the code from its current form in government-frontend. The first step is to just extract the headers list in the SpecialistPublisher model. The code to determine whether or not to display the contents list will be added to a presenter in a later commit. An example from content schemas is being used to initialise the SpecialistDocument model object, however the ["details"]["headers"] have been copied from the example into the test as unlike other model tests the values in the array are being modified and the test is easier to follow if you can see exactly what's changed. Audit trail: specialist_document_presenter: https://github.com/alphagov/government-frontend/blob/c6eead39b29192e692c802c9b5e8bc234e16692c/app/presenters/specialist_document_presenter.rb#L86-L100 [specialist-publisher](https://github.com/alphagov/specialist-publisher/blob/efadf3c4df33d045c0067e095f958d4b12638f29/app/presenters/document_presenter.rb#L50) [create the contents list]: https://github.com/alphagov/government-frontend/blob/c6eead39b29192e692c802c9b5e8bc234e16692c/app/presenters/specialist_document_presenter.rb#L86-L100 [parsing the `h2` tags]: https://github.com/alphagov/government-frontend/blob/main/app/presenters/content_item/contents_list.rb#L43
This adds a `contents` method. The method needs to know if there are any level two headers. Rather than parsing the html in the body attribute, the `level` is just being preserved in the `headers` list in the model. There is a lot of code in the original government-frontend code relating to images, and the character count and the number of table rows. This seems to be more related to document collections, rather specialist documents, so for now it has been omitted and rather than creating a shared presenter, a specialist document specific one has been created to minimise the code. Audit trail: contents_list_presenter.rb: https://github.com/alphagov/government-frontend/blob/main/app/presenters/content_item/contents_list.rb#L21
This updates the view to use the new `contents` method from SpecialistDocumentPresenter.
This updates the view to use the new `show_finder_link?` method from SpecialistDocumentPresenter.
This is to get the images when the document type is "protected_food_drink_name". It might be worth separating this into a separate model and presenter.
This method takes the facets the content item is mapped to from the metadata, and the full details of all of the facets from ["links"]["finders"] and returns one list that only contains the full details of the facets the document is mapped to. The specialist document presenter and view will need to know certain details to determine how to render the facet details in the metadata section. For example, if the facet is filterable a link to the finder will be rendered, so this information has been kept in.
The view_context is being passed to the presenter from controller. An array of selected facet values is returned from the model. Rather than looping through the model in the view to apply the helper methods it was was felt better to move the complexity to a presenter which is easier to test than a view. The compromise is that rather than recreating the date and link helper methods, they are instead being accessed in presenter via the view_context. There's no need to define a new view_context as the controller already has access to it. TO: DO add System tests Audit trail: specialist_document_presenter.rb: https://github.com/alphagov/government-frontend/blob/main/app/presenters/specialist_document_presenter.rb#L27 specialist_document_presenter_test.rb: https://github.com/alphagov/government-frontend/blob/868603abc5c2e3a50cd78dbb505e56ed3102f5a1/test/presenters/specialist_document_presenter_test.rb
Audit trail: specialist_document.html.erb: https://github.com/alphagov/government-frontend/blob/868603abc5c2e3a50cd78dbb505e56ed3102f5a1/app/views/content_items/specialist_document.html.erb#L61 updatable.rb: https://github.com/alphagov/government-frontend/blob/main/app/presenters/content_item/updatable.rb#L3-L5
This uses the Updatable concern and published_dates component to display the updated date and change history in the view. Audit trail: specialist_document.html.erb: https://github.com/alphagov/government-frontend/blob/868603abc5c2e3a50cd78dbb505e56ed3102f5a1/app/views/content_items/specialist_document.html.erb#L62-L63 updatable.rb: https://github.com/alphagov/government-frontend/blob/868603abc5c2e3a50cd78dbb505e56ed3102f5a1/app/presenters/content_item/updatable.rb#L7-L15
The change history is sorted into reverse chronological order, therefore if there is more than one item in the change history, the order the change history appears in the content store response will not match the order in the content item, causing the `eq` expectation to fail. The only options were to either only check the number of history items matched and that the first and last expected element appear in the change history or to replicate the code in the `reverse_chronological_change_history` method (the option chosen).
This partial was added an renamed in a previous PR. Audit trail: specialist_document.html.erb: https://github.com/alphagov/government-frontend/blob/a718ddf50ab81320b3586bfb31acf0a9ea7ef82e/app/views/content_items/specialist_document.html.erb#L20
Audit trail: specialist_document_test.rb: https://github.com/alphagov/government-frontend/blob/main/test/integration/specialist_document_test.rb test_helper.rb: https://github.com/alphagov/government-frontend/blob/main/test/test_helper.rb#L78-L146
ed3912e
to
6b8e9ea
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
Why
Trello card
How
Screenshots?
aaib-report:
business-finance-support:
cma-case:
maib-report: