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

Remote render email newsletters #25876

Merged
merged 30 commits into from
Feb 21, 2023
Merged

Conversation

dblatcher
Copy link
Contributor

@dblatcher dblatcher commented Feb 6, 2023

What does this change?

  • Creates a DotcomNewslettersPageRenderingDataModel for the Newsletters page
  • adds a method to the DotComRenderingService to request the page from DCR
  • SignupPageController will:
    • request the DCR service to render the page when the "dcr" query param is set to "true" (IE "/email-newsletters?dcr")
    • render the JSON for the DotcomNewslettersPageRenderingDataModel for requests to "/email-newsletters.json"

Does this change need to be reproduced in dotcom-rendering ?

  • No
  • Yes (please indicate your plans for DCR Implementation)

See guardian/dotcom-rendering#7169

What is the value of this and can you measure success?

We have a new design of the newsletters page to implement in DCR. Adding this option for DCR to render a placeholder version of the page while the design is implemented will be the first step replacing the frontend-rendered version.

By using the existing pattern for dotcom data models, the new methods provide the metadata, config, Nav and PageFooter data etc needed for the DCR page template, as well as the newsletters data needed for the main content.

As well as modernising the page design, this will allow us to remove a lot of legacy rendering code from frontend used to generate the current version of the page.

Checklist

Does this affect other platforms?

  • AMP
  • Apps
  • Other (please specify)

Does this affect GLabs Paid Content Pages? Should it have support for Paid Content?

  • No
  • Yes (please give details)

Does this change break ad-free?

  • No
  • It did, but tests caught it and I fixed it
  • It did, but there was no test coverage so I added that then fixed it

Does this change update the version of CAPI we're using?

Accessibility test checklist

Tested

  • Locally
  • On CODE (optional)

@dblatcher dblatcher marked this pull request as ready for review February 6, 2023 15:43
@dblatcher dblatcher requested a review from a team as a code owner February 6, 2023 15:43
@dblatcher dblatcher requested a review from cemms1 February 8, 2023 10:54
Comment on lines 32 to 36
private def getShouldUseRemoteRender()(implicit
request: RequestHeader,
): Boolean = {
request.getQueryString("dcr").contains("true")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand we shouldn't need this function, you should be able to use the request.forceDCR property as this is an implicit added to RequestHeader.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - I wasn't familiar with implicits, but I'll push a change to make use of it.

@@ -53,4 +53,21 @@ object StaticPages {
),
groupedNewsletterResponses,
)

def dcrSimpleNewsletterPage(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any background info on how this works? It's not something I'm particularly familiar with?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand it, SimplePage is a class which extends the Page and uses the StandalonePage trait and they are used to represent pages on the site which have metaData but no "content" (ie its not a ContentPage or a GalleryPage etc). They get constructed with a few fields and the class provide a set of helper methods return the meta data values based on the Configuration setting etc

I think the idea behind them is to provide an extendable container or helper class for keeping the meta data for all pages in a consistent format. For the purpose of this PR, the dcrSimpleNewsletterPage passed to the dcr service to build the rendering model.

The StaticPages object is a collection of these SimplePages - the existing simpleNewslettersPage is extended to include the groupedNewsletterResponses which the current frontend-rendered view needs as page for the page model. We don't need this for DCR, so it seemed to make sense to define the dcrSimpleNewsletterPage (same metadata but no groupedNewsletterResponses ) inStaticPages to avoid building it unnecessarily for a DCR request.

val dataModel =
DotcomNewslettersPageRenderingDataModel.apply(page, newsletters, request)
val dataJson = DotcomNewslettersPageRenderingDataModel.toJson(dataModel)
common.renderJson(dataJson, page).as("application/json")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An interesting note on this is that we've never had a .json endpoint return DCR optimised data without requiring .json?dcr before. However unlike other cases, these pages didn't support .json as others have (generally /some-page.json returns the HTML in a .json with the html & the config object).

I'm not sure whether we should continue this restriction of requiring ?dcr or not. I will ask around and see if it might be a problem!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: advice is to keep the .json?dcr pattern, so I guess 404 on .json & return the DCR json on .json?dcr :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made an update - it will now return a 404 for .json - however I couldn't find any example of a similar pattern so I'm not 100% sure I'm doing it right.

Copy link
Contributor

@OllysCoding OllysCoding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 LGTM! Seems like the build is failing though?

@dblatcher
Copy link
Contributor Author

dblatcher commented Feb 21, 2023

+1 LGTM! Seems like the build is failing though?

Thanks! I think it was just out of sync - I've merge main and its passing now.

@prout-bot
Copy link
Collaborator

Seen on ADMIN-PROD (merged by @dblatcher 16 minutes and 43 seconds ago)

@prout-bot
Copy link
Collaborator

Seen on FRONTS-PROD (merged by @dblatcher 17 minutes and 1 second ago)

@cemms1
Copy link
Contributor

cemms1 commented Feb 27, 2023

OllysCoding pushed a commit that referenced this pull request Mar 14, 2023
* throw an error if the path requests dcr=true

* add stub service module for requesting the page from dcr

* RemoteRenderPage can await Futures

* can post test json to DCR and get a response

* provide newsletterData list to DCR

* adjust timing

* scalafmt

* use  capitalised path for Dcr request

* provide some metaData

* build a Page object, hard code the JSON string properties, add TO DO's

* delegate creating the simple page to the StaticPages module

* use some page metaData for the JSON

* rename renderer object

* add edtion to page model

* add urls from config

* provide the full config object

* provide essentials for navMenu data

* construct nav menu

* build rendering data model for newsletters page

* move the data model building to the DCR service

* rename method

* all dcr service directly from controller

* fix casing

* tidy imports

* provide canonicalUrl

* use forceDCR from RichRequestHeader

* add a render json method

* 404 error for .json without ?dcr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants