From 23342fbb8fe3d012064663e26b094e8caeac9f34 Mon Sep 17 00:00:00 2001 From: Alex Sanders Date: Thu, 12 Dec 2024 10:28:23 +0000 Subject: [PATCH] =?UTF-8?q?don=E2=80=99t=20override=20crossword=20`format.?= =?UTF-8?q?design`=20in=20enhancer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dotcom-rendering/src/types/article.ts | 66 +++++++++++++-------------- 1 file changed, 31 insertions(+), 35 deletions(-) diff --git a/dotcom-rendering/src/types/article.ts b/dotcom-rendering/src/types/article.ts index a15e90c8398..b1b56980715 100644 --- a/dotcom-rendering/src/types/article.ts +++ b/dotcom-rendering/src/types/article.ts @@ -1,9 +1,5 @@ -import { randomUUID } from 'node:crypto'; -import { - ArticleDesign, - type ArticleFormat, - decideFormat, -} from '../lib/articleFormat'; +import { isUndefined } from '@guardian/libs'; +import { type ArticleFormat, decideFormat } from '../lib/articleFormat'; import type { ImageForAppsLightbox } from '../model/appsLightboxImages'; import { appsLightboxImages } from '../model/appsLightboxImages'; import { buildLightboxImages } from '../model/buildLightboxImages'; @@ -36,37 +32,37 @@ export type Article = { }; export const enhanceCrossword = (article: Article): Article => { - if (article.frontendData.crossword) { - const element = { - _type: 'model.dotcomrendering.pageElements.CrosswordElement' as const, - crossword: article.frontendData.crossword, - }; - return { - ...article, - format: { ...article.format, design: ArticleDesign.Crossword }, - frontendData: { - ...article.frontendData, - blocks: [ - { - id: randomUUID(), - elements: [element], - attributes: { - pinned: false, - keyEvent: false, - summary: false, - }, - primaryDateLine: - article.frontendData.webPublicationDateDisplay, - secondaryDateLine: - article.frontendData - .webPublicationSecondaryDateDisplay, - }, - ], - }, - }; + if (isUndefined(article.frontendData.crossword)) { + throw new TypeError('article does not contain a crossword'); } - throw new TypeError('article did not contain a crossword'); + const element = { + _type: 'model.dotcomrendering.pageElements.CrosswordElement' as const, + crossword: article.frontendData.crossword, + }; + + return { + ...article, + format: { ...article.format }, + frontendData: { + ...article.frontendData, + blocks: [ + { + id: article.frontendData.crossword.id, + elements: [element], + attributes: { + pinned: false, + keyEvent: false, + summary: false, + }, + primaryDateLine: + article.frontendData.webPublicationDateDisplay, + secondaryDateLine: + article.frontendData.webPublicationSecondaryDateDisplay, + }, + ], + }, + }; }; export const enhanceArticleType = (