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

use email-newsletter layout data from frontend #12795

Merged
merged 14 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions dotcom-rendering/docs/email-newsletters-page.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@ It is served using a dedicated route handler ([dotcom-rendering/src/server/handl

## Arranging the Newsletters

The page model from frontend includes an array of the `Newsletters` that can be rendered on the page, but how those newsletters are sorted and grouped on the layout is determined by the `enhanceNewslettersPage` function.
The page model from frontend includes an array of the `Newsletters` and an optional `layout` describing which of the `Newsletters` are rendered and how they are sorted and grouped on the page.

In effect, to add a new newsletter to the page, or change the ordering, update the data in this file:
dotcom-rendering/src/model/newsletter-grouping.ts
The `layout`s send from frontend are defined in the [newsletters tool](https://newsletters-tool.gutools.co.uk/layouts).

The file allows for alternative arrangements of newsletters based on the `EditionId`. The property used in the arrays of newsletters is the `Newsletter.identityName`.

To find the correct position of the newsletter check this [spreadsheet](https://docs.google.com/spreadsheets/d/1Pfdow0Yj8OzkrnIWqIC-oSzVhwtwwDBdLmFx5hY-Gt4/edit#gid=2084088730)

To find the `identityName` of a newsletter or whether it is launched or draft check the [newsletters tool](https://newsletters-tool.gutools.co.uk/)
If no `layout` is provided by frontend, the `enhanceNewslettersPage` uses a default grouping to arrange the `Newsletters`.
17 changes: 7 additions & 10 deletions dotcom-rendering/src/model/enhance-newsletters-page.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import type { Newsletter } from '../types/content';
import type { Newsletter, NewsletterLayout } from '../types/content';
import type {
DCRNewslettersPageType,
FENewslettersPageType,
GroupedNewsletters,
} from '../types/newslettersPage';
import type { StaticGroups } from './newsletter-grouping';
import { groups } from './newsletter-grouping';

const mapStaticGroups = (
staticGroups: StaticGroups,
const mapLayoutToGroups = (
layout: NewsletterLayout,
newsletters: Newsletter[],
): GroupedNewsletters => {
const newsletterRecord = newsletters.reduce<
Expand All @@ -18,7 +16,7 @@ const mapStaticGroups = (
return record;
}, {});

const mapped = staticGroups.map((group) => ({
const mapped = layout.groups.map((group) => ({
title: group.title,
subtitle: group.subtitle,
newsletters: group.newsletters.reduce<Newsletter[]>((list, name) => {
Expand Down Expand Up @@ -63,11 +61,10 @@ const reduceToDefaultGrouping = (
const getGroups = (
newsletterPageData: FENewslettersPageType,
): GroupedNewsletters => {
const { newsletters, editionId } = newsletterPageData;
const staticGroup = groups[editionId] ?? groups['UK'];
const { newsletters, layout } = newsletterPageData;

return staticGroup
? mapStaticGroups(staticGroup, newsletters)
return layout
? mapLayoutToGroups(layout, newsletters)
: reduceToDefaultGrouping(newsletters);
};

Expand Down
318 changes: 0 additions & 318 deletions dotcom-rendering/src/model/newsletter-grouping.ts

This file was deleted.

Loading
Loading