Skip to content

Commit

Permalink
Merge pull request #13100 from guardian/sa-remove-formattofeformat
Browse files Browse the repository at this point in the history
Remove unused article format functions
  • Loading branch information
SiAdcock authored Jan 10, 2025
2 parents f132152 + 7d24054 commit 0772f4f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 135 deletions.
22 changes: 0 additions & 22 deletions dotcom-rendering/src/lib/articleFormat.test.ts

This file was deleted.

111 changes: 1 addition & 110 deletions dotcom-rendering/src/lib/articleFormat.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isString } from '@guardian/libs';
import type { FEDesign, FEDisplay, FEFormat, FETheme } from '../types/frontend';
import type { FEFormat } from '../types/frontend';

export enum ArticleDesign {
Standard,
Expand Down Expand Up @@ -173,12 +173,6 @@ export const decideFormat = (format: Partial<FEFormat>): ArticleFormat => ({
theme: decideTheme(format),
});

export const getThemeNameAsString = (format: ArticleFormat): string => {
const themeName = Pillar[format.theme] ?? ArticleSpecial[format.theme];
if (!themeName) throw new Error('Unknown theme');
return themeName;
};

/**
* We need a type guard because TypeScript enums are (confusingly)
* returning both strings and numbers.
Expand Down Expand Up @@ -219,109 +213,6 @@ export const getAllDesigns = ({
design,
}));

const designToFEDesign = (design: ArticleDesign): FEDesign => {
switch (design) {
case ArticleDesign.Standard:
// Correction doesn't exist in `FEFormat`.
case ArticleDesign.Correction:
return 'ArticleDesign';
case ArticleDesign.Picture:
return 'PictureDesign';
case ArticleDesign.Gallery:
return 'GalleryDesign';
case ArticleDesign.Audio:
return 'AudioDesign';
case ArticleDesign.Video:
return 'VideoDesign';
case ArticleDesign.Crossword:
return 'CrosswordDesign';
case ArticleDesign.Review:
return 'ReviewDesign';
case ArticleDesign.Analysis:
return 'AnalysisDesign';
case ArticleDesign.Explainer:
return 'ExplainerDesign';
case ArticleDesign.Comment:
return 'CommentDesign';
case ArticleDesign.Letter:
return 'LetterDesign';
case ArticleDesign.Feature:
return 'FeatureDesign';
case ArticleDesign.LiveBlog:
return 'LiveBlogDesign';
case ArticleDesign.DeadBlog:
return 'DeadBlogDesign';
case ArticleDesign.Recipe:
return 'RecipeDesign';
case ArticleDesign.MatchReport:
return 'MatchReportDesign';
case ArticleDesign.Interview:
return 'InterviewDesign';
case ArticleDesign.Editorial:
return 'EditorialDesign';
case ArticleDesign.Quiz:
return 'QuizDesign';
case ArticleDesign.Interactive:
return 'InteractiveDesign';
case ArticleDesign.PhotoEssay:
return 'PhotoEssayDesign';
case ArticleDesign.Obituary:
return 'ObituaryDesign';
case ArticleDesign.FullPageInteractive:
return 'FullPageInteractiveDesign';
case ArticleDesign.NewsletterSignup:
return 'NewsletterSignupDesign';
case ArticleDesign.Timeline:
return 'TimelineDesign';
case ArticleDesign.Profile:
return 'ProfileDesign';
}
};

const displayToFEDisplay = (display: ArticleDisplay): FEDisplay => {
switch (display) {
case ArticleDisplay.Standard:
return 'StandardDisplay';
case ArticleDisplay.Immersive:
return 'ImmersiveDisplay';
case ArticleDisplay.Showcase:
return 'ShowcaseDisplay';
case ArticleDisplay.NumberedList:
return 'NumberedListDisplay';
}
};

const themeToFETheme = (theme: ArticleTheme): FETheme => {
switch (theme) {
case Pillar.News:
return 'NewsPillar';
case Pillar.Opinion:
return 'OpinionPillar';
case Pillar.Sport:
return 'SportPillar';
case Pillar.Culture:
return 'CulturePillar';
case Pillar.Lifestyle:
return 'LifestylePillar';
case ArticleSpecial.SpecialReport:
return 'SpecialReportTheme';
case ArticleSpecial.Labs:
return 'Labs';
case ArticleSpecial.SpecialReportAlt:
return 'SpecialReportAltTheme';
}
};

export const formatToFEFormat = ({
design,
display,
theme,
}: ArticleFormat): FEFormat => ({
design: designToFEDesign(design),
display: displayToFEDisplay(display),
theme: themeToFETheme(theme),
});

/**
* Creates a string representation of {@linkcode ArticleFormat}. Useful for
* logging, storybook UI etc.
Expand Down
6 changes: 3 additions & 3 deletions dotcom-rendering/src/types/frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ type ThemePillar =
| 'LifestylePillar';

type ThemeSpecial = 'SpecialReportTheme' | 'Labs' | 'SpecialReportAltTheme';
export type FETheme = ThemePillar | ThemeSpecial;
type FETheme = ThemePillar | ThemeSpecial;

// FEDesign is what frontend gives (originating in the capi scala client) us on the Format field
// https://github.com/guardian/content-api-scala-client/blob/master/client/src/main/scala/com.gu.contentapi.client/utils/format/Design.scala

export type FEDesign =
type FEDesign =
| 'ArticleDesign'
| 'PictureDesign'
| 'GalleryDesign'
Expand Down Expand Up @@ -206,7 +206,7 @@ export type FEDesign =
| 'ProfileDesign'; // FEDisplay is the display information passed through from frontend (originating in the capi scala client) and dictates the displaystyle of the content e.g. Immersive
// https://github.com/guardian/content-api-scala-client/blob/master/client/src/main/scala/com.gu.contentapi.client/utils/format/Display.scala

export type FEDisplay =
type FEDisplay =
| 'StandardDisplay'
| 'ImmersiveDisplay'
| 'ShowcaseDisplay'
Expand Down

0 comments on commit 0772f4f

Please sign in to comment.