Skip to content

Commit b405f4f

Browse files
authored
Move and rename Front types (#13622)
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. The new `frontend` directory has been used 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 files in this change to be moved into this directory are `feFront.ts`, a new file to hold the `FEFront` type, and `feFront.json`, the existing front 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 `FEFrontType` to `FEFront` and `DCRFrontType` to `Front`. 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. The removal of the `Type` suffix has also been applied to any types that now live in the new `feFront.ts` file. However, the `DCR` prefix and `Type` suffix remain on any types that still live in the `front.ts` file. These types are used more widely, so a rename would have resulted in changes to many more files. They will instead be renamed in a subsequent change, to avoid making this change too large.
1 parent a77312f commit b405f4f

26 files changed

+522
-500
lines changed

dotcom-rendering/fixtures/manual/show-more-trails.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Exporting this 'as' FEFrontCard because we know it should be of the right shape.
55
*/
66

7-
import type { FEFrontCard } from '../../src/types/front';
7+
import type { FEFrontCard } from '../../src/frontend/feFront';
88

99
export const trails: [
1010
FEFrontCard,

dotcom-rendering/scripts/jsonSchema/schema.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +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/frontend/feFront.ts`),
1415
path.resolve(`${root}/src/frontend/feTagPage.ts`),
1516
path.resolve(`${root}/src/types/newslettersPage.ts`),
1617
path.resolve(`${root}/src/types/editionsCrossword.ts`),
@@ -38,8 +39,8 @@ const schemas = [
3839
file: `${root}/src/model/article-schema.json`,
3940
},
4041
{
41-
typeName: 'FEFrontType',
42-
file: `${root}/src/model/front-schema.json`,
42+
typeName: 'FEFront',
43+
file: `${root}/src/frontend/schemas/feFront.json`,
4344
},
4445
{
4546
typeName: 'FETagPage',

dotcom-rendering/src/components/FrontPage.tsx

Lines changed: 3 additions & 3 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 { DCRFrontType } from '../types/front';
9+
import type { Front } from '../types/front';
1010
import { AlreadyVisited } from './AlreadyVisited.importable';
1111
import { BrazeMessaging } from './BrazeMessaging.importable';
1212
import { useConfig } from './ConfigContext';
@@ -21,7 +21,7 @@ import { ShowHideContainers } from './ShowHideContainers.importable';
2121
import { SkipTo } from './SkipTo';
2222

2323
type Props = {
24-
front: DCRFrontType;
24+
front: Front;
2525
NAV: NavType;
2626
};
2727

@@ -30,7 +30,7 @@ type Props = {
3030
* FrontPage is a high level wrapper for front pages on Dotcom. Sets strict mode and some globals
3131
*
3232
* @param {Props} props
33-
* @param {DCRFrontType} props.front - The article JSON data
33+
* @param {Front} props.front - The article JSON data
3434
* @param {NAVType} props.NAV - The article JSON data
3535
* */
3636
export const FrontPage = ({ front, NAV }: Props) => {

dotcom-rendering/src/components/ShowMore.importable.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ import {
1414
SvgPlus,
1515
} from '@guardian/source/react-components';
1616
import { useEffect, useState } from 'react';
17+
import type { FEFrontCard } from '../frontend/feFront';
1718
import { shouldPadWrappableRows } from '../lib/dynamicSlices';
1819
import type { EditionId } from '../lib/edition';
1920
import { useApi } from '../lib/useApi';
2021
import { enhanceCards } from '../model/enhanceCards';
21-
import type { DCRContainerPalette, FEFrontCard } from '../types/front';
22+
import type { DCRContainerPalette } from '../types/front';
2223
import { LI } from './Card/components/LI';
2324
import { UL } from './Card/components/UL';
2425
import { FrontCard } from './FrontCard';

dotcom-rendering/src/feFootballDataPage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import type { FEFrontConfig } from './frontend/feFront';
12
import type { EditionId } from './lib/edition';
23
import type { FooterType } from './types/footer';
3-
import type { FEFrontConfigType } from './types/front';
44
import type { FENavType } from './types/frontend';
55

66
type FECompetitionSummary = {
@@ -100,7 +100,7 @@ export type FEMatchByDateAndCompetition = {
100100
};
101101

102102
export type FEFootballPageConfig = Omit<
103-
FEFrontConfigType,
103+
FEFrontConfig,
104104
'keywordIds' | 'keywords' | 'isFront'
105105
> & {
106106
isFront: boolean;

0 commit comments

Comments
 (0)