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

Add transaction model #4548

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Add transaction model #4548

wants to merge 8 commits into from

Conversation

leenagupte
Copy link
Contributor

@leenagupte leenagupte commented Dec 19, 2024

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

What

Move modelling code from TransactionPresenter to a Transaction model.

Why

We currently have two ways to model content items and two content item presenters.

  • ContentItem models the response from content store
  • ContentItemModelPresenter takes a ContentItem object and adds a presentation layer to it.
  • ContentItemPresenter does both, it models the response from content store and adds presentation to it.

Ideally there would be content item models that inherit from ContentItem and content item presenters that inherit from ContentItemModelPresenter.
And when the original ContentItemPresenter is finally removed, to rename ContentItemModelPresenter to ContentItemPresenter.

To achieve this we need to look at the existing presenters one by one and move the logic to the appropriate place.

How

The code that was in the original TransactionPresenter has been split between the TransactionPresenter and the new Transaction model.
TransactionPresenter has also been updated so that it's now initialized with an instance of the model.

Screenshots?

N/A - There shouldn't be any visible changes.

Example transaction: https://govuk-frontend-app-pr-4548.herokuapp.com/register-to-vote

@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4548 December 19, 2024 17:57 Inactive
@leenagupte leenagupte force-pushed the create-transaction-model branch from c8dc6e1 to 8f32535 Compare December 20, 2024 10:35
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4548 December 20, 2024 10:35 Inactive
@leenagupte leenagupte force-pushed the create-transaction-model branch from 8f32535 to 6248af7 Compare December 20, 2024 11:16
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4548 December 20, 2024 11:16 Inactive
@leenagupte leenagupte force-pushed the create-transaction-model branch from 6248af7 to dcd176c Compare December 20, 2024 11:51
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4548 December 20, 2024 11:51 Inactive
@leenagupte leenagupte force-pushed the create-transaction-model branch from dcd176c to 9496f3e Compare December 20, 2024 12:41
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4548 December 20, 2024 12:42 Inactive
@leenagupte leenagupte force-pushed the create-transaction-model branch from 9496f3e to 7f78b62 Compare December 20, 2024 12:59
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4548 December 20, 2024 12:59 Inactive
@leenagupte leenagupte force-pushed the create-transaction-model branch from 7f78b62 to 396c791 Compare December 20, 2024 13:10
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4548 December 20, 2024 13:11 Inactive
@leenagupte leenagupte force-pushed the create-transaction-model branch from 396c791 to 796598d Compare December 20, 2024 14:25
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4548 December 20, 2024 14:25 Inactive
@leenagupte leenagupte force-pushed the create-transaction-model branch from 796598d to 4e24bd8 Compare December 20, 2024 15:13
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4548 December 20, 2024 15:14 Inactive
@leenagupte leenagupte force-pushed the create-transaction-model branch from 4e24bd8 to 34acded Compare December 20, 2024 15:19
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4548 December 20, 2024 15:19 Inactive
@leenagupte leenagupte requested a review from KludgeKML December 20, 2024 15:22
@leenagupte leenagupte changed the title [WIP] Create transaction model Add transaction model Dec 20, 2024
@leenagupte leenagupte marked this pull request as ready for review December 20, 2024 15:22
@leenagupte leenagupte force-pushed the create-transaction-model branch from 34acded to f73d075 Compare December 20, 2024 15:26
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4548 December 20, 2024 15:27 Inactive
This value hasn't been needed since the tracking was switched to use
the built-in tracking provided by the tab component.

See: a030c99#diff-8ca3371a119b5d7075182adfa23a45626a4e44e8a1cd3185ffe335ec1488354bL20
We currently have two ways to model content items and two content item
presenters.

* ContentItem models the response from content store
* ContentItemModelPresenter takes a ContentItem object and adds a
presentation layer to it.
* ContentItemPresenter does both, it models the response from content
store and adds presentation to it.

Ideally there would be content item models that inherit from ContentItem
and content item presenters that inherit from ContentItemModelPresenter.
And when the original ContentItemPresenter is removed, to rename
ContentItemModelPresenter to ContentItemPresenter.

To achieve this we need to look at the existing presenters one by one
and move the logic to the appropriate place.

In the [TransactionPresenter] only the "start_button_text" methods should
remain in the presenter. All of the other methods, especially the "pass
through" methods model items from the content store, and need to be
moved to the model.

The `tab_count` method from the presenter has been renamed to
`section_count` in the model as this sounds less presentational and it
matches the naming of the `multiple_more_information_sections?` method.
The `section_count` method has been made private as it is no longer
being used in the views.

A `start_button_text` attribute as been added so that it can be used in
the `start_button_text` method in the presenter, the only method that
should remain.

Transactions can have variants, so it wasn't as simple as adding
attributes for every item as these rely on knowing whether a variant
was selected and what that variant is.
This information is known when the controller is called, but the way
models are instantiated means that we can't pass in document type
specific extra parameters.
Instead the pattern that was established by travel advice parts is being
used here. A "set variant" method has been added to set the value of
the variant after the model instance has been created.
The first time any of the attributes will be used in the view, but
which point the variant value should be known to the model instance.

The transaction presenter will then be updated to accept an instance of
this model as a parameter in the next commit.

[TransactionPresenter]: https://github.com/alphagov/frontend/blob/0ff9340c529ccd85072c2d9bd660fdbfb3f0fab1/app/presenters/transaction_presenter.rb

Fix up to model
Also removes the modelling code from the presenter, and updates the
`start_button_text` method to use attributes from the model.
This modifies the content item object to return values from
the variant if requested.
@leenagupte leenagupte force-pushed the create-transaction-model branch from f73d075 to 4d3661b Compare December 20, 2024 15:41
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4548 December 20, 2024 15:41 Inactive
Replaces the use of "publication" object in the views and wraps the
content item object as a publication.

The publication object cannot be removed completely as the application
layout uses it to determine whether to show a breadcrumb.

Also fixes failing transaction request tests. These tests relied on a
publication instance being created, whereas now the publication method
just returns the content item instance.
The partial templates have access to the content item object, so
locals aren't needed.
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