Skip to content

Commit 7d6fa8e

Browse files
authored
Move and rename TagPage types (#13372)
The purpose of this change is to refactor and simplify the codebase, making it clearer which types and files relate to the data that comes from frontend. A new `frontend` directory has been created to contain frontend types and their corresponding schemas. Currently these are distributed across the codebase and it can be difficult to follow their usage. The first files to be moved into this directory are `feTagPage.ts`, a new file to hold the `FETagPage` type, and `feTagPage.json`, the existing tag page JSON schema file. The other frontend types and schemas will follow in later changes, as moving them all together would constitute a very large diff. This change also renames `FETagPageType` to `FETagPage` and `DCRTagPageType` to `TagPage`. Removal of the `DCR` prefix has occurred for two reasons. Firstly, the project is now called DCAR. Secondly, we're in DCAR (previously DCR), so we can assume all types without a prefix belong to this project. By contrast, any type that's derived from frontend remains prefixed with `FE` to differentiate it. The `Type` suffix has been removed because it's not necessary to suffix a type with the word `Type`, and this convention was applied inconsistently, so removing it reduces noise in the codebase. `FrontPagination` has also been renamed to `TagPagePagination`. Tag pages are paginated but fronts are not, and this was already partially reflected by the fact this type was defined in `tagPage.ts` rather than `front.ts`.
1 parent 22415a4 commit 7d6fa8e

File tree

14 files changed

+62
-55
lines changed

14 files changed

+62
-55
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pnpm-lock.yaml
55

66
# generated files
77
dotcom-rendering/src/model/*-schema.json
8+
dotcom-rendering/src/frontend/schemas
89
dotcom-rendering/stories/generated
910

1011
# specific files

dotcom-rendering/scripts/jsonSchema/schema.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const program = TJS.getProgramFromFiles(
1111
[
1212
path.resolve(`${root}/index.d.ts`),
1313
path.resolve(`${root}/src/types/frontend.ts`),
14-
path.resolve(`${root}/src/types/tagPage.ts`),
14+
path.resolve(`${root}/src/frontend/feTagPage.ts`),
1515
path.resolve(`${root}/src/types/newslettersPage.ts`),
1616
path.resolve(`${root}/src/types/editionsCrossword.ts`),
1717
path.resolve(`${root}/src/feFootballDataPage.ts`),
@@ -42,8 +42,8 @@ const schemas = [
4242
file: `${root}/src/model/front-schema.json`,
4343
},
4444
{
45-
typeName: 'FETagPageType',
46-
file: `${root}/src/model/tag-page-schema.json`,
45+
typeName: 'FETagPage',
46+
file: `${root}/src/frontend/schemas/feTagPage.json`,
4747
},
4848
{
4949
typeName: 'FENewslettersPageType',

dotcom-rendering/src/components/FrontSection.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {
1111
DCRContainerPalette,
1212
TreatType,
1313
} from '../types/front';
14-
import type { DCRFrontPagination } from '../types/tagPage';
14+
import type { TagPagePagination } from '../types/tagPage';
1515
import { isAustralianTerritory, type Territory } from '../types/territory';
1616
import { AustralianTerritorySwitcher } from './AustralianTerritorySwitcher.importable';
1717
import { ContainerOverrides } from './ContainerOverrides';
@@ -74,7 +74,7 @@ type Props = {
7474
ajaxUrl?: string;
7575
/** Puts pagination at the bottom of the container allowing the user to navigate to other pages,
7676
* usually used on the last container on a page */
77-
pagination?: DCRFrontPagination;
77+
pagination?: TagPagePagination;
7878
/** Does this front section reside on a "paid for" content front */
7979
isOnPaidContentFront?: boolean;
8080
/** Indicates if the container is targetted to a specific territory */

dotcom-rendering/src/components/TagPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ArticleDesign, ArticleDisplay, Pillar } from '../lib/articleFormat';
66
import { rootStyles } from '../lib/rootStyles';
77
import { filterABTestSwitches } from '../model/enhance-switches';
88
import type { NavType } from '../model/extract-nav';
9-
import type { DCRTagPageType } from '../types/tagPage';
9+
import type { TagPage as TagPageModel } from '../types/tagPage';
1010
import { AlreadyVisited } from './AlreadyVisited.importable';
1111
import { useConfig } from './ConfigContext';
1212
import { DarkModeMessage } from './DarkModeMessage';
@@ -18,7 +18,7 @@ import { SetAdTargeting } from './SetAdTargeting.importable';
1818
import { SkipTo } from './SkipTo';
1919

2020
type Props = {
21-
tagPage: DCRTagPageType;
21+
tagPage: TagPageModel;
2222
NAV: NavType;
2323
};
2424

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# The `frontend` Directory
2+
3+
This contains code related to the requests sent to DCAR from frontend. In practice this means the TypeScript types representing JSON data sent via POST request to DCAR, and the JSON schema files that are generated from them by `scripts/jsonSchema`.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import type { EditionId } from '../lib/edition';
2+
import type { CommercialProperties } from '../types/commercial';
3+
import type { FooterType } from '../types/footer';
4+
import type { FEFrontCard, FEFrontConfigType } from '../types/front';
5+
import type { FENavType } from '../types/frontend';
6+
import type { FEPagination, FETagType } from '../types/tag';
7+
8+
export type FETagPage = {
9+
contents: FEFrontCard[];
10+
pagination?: FEPagination;
11+
nav: FENavType;
12+
tags: {
13+
tags: FETagType[];
14+
};
15+
editionId: EditionId;
16+
editionLongForm: string;
17+
guardianBaseURL: string;
18+
pageId: string;
19+
webTitle: string;
20+
webURL: string;
21+
config: FEFrontConfigType;
22+
commercialProperties: CommercialProperties;
23+
pageFooter: FooterType;
24+
isAdFreeUser: boolean;
25+
forceDay: boolean;
26+
canonicalUrl?: string;
27+
contributionsServiceUrl: string;
28+
};

dotcom-rendering/src/layouts/TagPageLayout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ import {
2626
} from '../lib/getTagPageAdPositions';
2727
import { enhanceTags } from '../model/enhanceTags';
2828
import type { NavType } from '../model/extract-nav';
29-
import type { DCRTagPageType } from '../types/tagPage';
29+
import type { TagPage as TagPageModel } from '../types/tagPage';
3030
import { BannerWrapper, Stuck } from './lib/stickiness';
3131

3232
interface Props {
33-
tagPage: DCRTagPageType;
33+
tagPage: TagPageModel;
3434
NAV: NavType;
3535
}
3636

dotcom-rendering/src/lib/canRenderAds.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import type { ArticleDeprecated } from '../types/article';
22
import type { DCRFrontType } from '../types/front';
33
import type { RenderingTarget } from '../types/renderingTarget';
4-
import type { DCRTagPageType } from '../types/tagPage';
4+
import type { TagPage } from '../types/tagPage';
55

66
/**
77
* Checks the page for a number of conditions that should
88
* prevent ads from being displayed.
99
*/
1010
export const canRenderAds = (
11-
pageData: ArticleDeprecated | DCRFrontType | DCRTagPageType,
11+
pageData: ArticleDeprecated | DCRFrontType | TagPage,
1212
renderingTarget?: RenderingTarget,
1313
): boolean => {
1414
if (renderingTarget === 'Apps') {

dotcom-rendering/src/lib/contributions.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { userBenefitsDataIsUpToDate } from '../client/userFeatures/cookies/userB
1111
import type { ArticleDeprecated } from '../types/article';
1212
import type { DCRFrontType } from '../types/front';
1313
import type { DCRNewslettersPageType } from '../types/newslettersPage';
14-
import type { DCRTagPageType } from '../types/tagPage';
14+
import type { TagPage } from '../types/tagPage';
1515

1616
// User Attributes API cookies (created on sign-in)
1717
export const RECURRING_CONTRIBUTOR_COOKIE = 'gu_recurring_contributor';
@@ -195,11 +195,7 @@ export const recentlyClosedBanner = (
195195
};
196196

197197
export const getContributionsServiceUrl = (
198-
config:
199-
| ArticleDeprecated
200-
| DCRFrontType
201-
| DCRTagPageType
202-
| DCRNewslettersPageType,
198+
config: ArticleDeprecated | DCRFrontType | TagPage | DCRNewslettersPageType,
203199
): string => process.env.SDC_URL ?? config.contributionsServiceUrl;
204200

205201
type PurchaseInfo = HeaderPayload['targeting']['purchaseInfo'];

0 commit comments

Comments
 (0)