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

Add container level context fairground containers #12710

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
27 changes: 26 additions & 1 deletion dotcom-rendering/src/components/ContainerTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import {
between,
headlineBold17,
headlineBold24,
headlineBold28,
space,
textEgyptian17,
textSansBold17,
until,
} from '@guardian/source/foundations';
import { type EditionId, getEditionFromId } from '../lib/edition';
import { palette as schemePalette } from '../palette';
import type { DCRContainerLevel } from '../types/front';
import { localisedTitle } from './Localisation';

type Props = {
Expand All @@ -20,6 +23,7 @@ type Props = {
showDateHeader?: boolean;
editionId?: EditionId;
lightweightHeader?: boolean;
containerLevel?: DCRContainerLevel;
};

const linkStyles = css`
Expand All @@ -33,6 +37,20 @@ const headerStyles = css`
overflow-wrap: break-word; /*if a single word is too long, this will break the word up rather than have the display be affected*/
`;

const containerLevelStyling = (level: DCRContainerLevel) => {
if (level === 'Primary') {
return css`
${headlineBold28};
`;
}
if (level === 'Secondary') {
return css`
${textSansBold17};
`;
}
return null;
};

const headerStylesWithUrl = css`
:hover {
text-decoration: underline;
Expand Down Expand Up @@ -94,6 +112,7 @@ export const ContainerTitle = ({
showDateHeader,
editionId,
fontColour = schemePalette('--article-section-title'),
containerLevel,
}: Props) => {
if (!title) return null;

Expand All @@ -115,6 +134,8 @@ export const ContainerTitle = ({
headerStylesWithUrl,
headerStyles,
lightweightHeader && article17,
containerLevel &&
containerLevelStyling(containerLevel),
]}
>
{localisedTitle(title, editionId)}
Expand All @@ -123,7 +144,11 @@ export const ContainerTitle = ({
) : (
<h2
style={{ color: fontColour }}
css={[headerStyles, lightweightHeader && article17]}
css={[
headerStyles,
lightweightHeader && article17,
containerLevel && containerLevelStyling(containerLevel),
]}
>
{localisedTitle(title, editionId)}
</h2>
Expand Down
17 changes: 17 additions & 0 deletions dotcom-rendering/src/components/FrontSection.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,23 @@ export const ContainerStory = {
args: { title: 'Default Container', showTopBorder: false },
};

export const PrimaryContainerStory = {
name: 'primary container',
args: {
title: 'Primary Container',
showTopBorder: false,
containerLevel: 'Primary',
},
};
export const SecondaryContainerStory = {
name: 'secondary container',
args: {
title: 'Secondary Container',
showTopBorder: false,
containerLevel: 'Secondary',
},
};

export const NoTitleStory = {
name: 'with no title',
args: { showTopBorder: false },
Expand Down
11 changes: 10 additions & 1 deletion dotcom-rendering/src/components/FrontSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import type { EditionId } from '../lib/edition';
import { hideAge } from '../lib/hideAge';
import { palette, palette as schemePalette } from '../palette';
import type { CollectionBranding } from '../types/branding';
import type { DCRContainerPalette, TreatType } from '../types/front';
import type {
DCRContainerLevel,
DCRContainerPalette,
TreatType,
} from '../types/front';
import type { DCRFrontPagination } from '../types/tagPage';
import { isAustralianTerritory, type Territory } from '../types/territory';
import { AustralianTerritorySwitcher } from './AustralianTerritorySwitcher.importable';
Expand Down Expand Up @@ -48,6 +52,9 @@ type Props = {
containerName?: string;
/** Fronts containers can have their styling overridden using a `containerPalette` */
containerPalette?: DCRContainerPalette;
/** Fronts containers can have their styling overridden using a `containerLevel`. If used, this can be either "Primary" or "Secondary", both of which have different styles*/
containerLevel?: DCRContainerLevel;

/** Defaults to `false`. If true a Hide button is show top right allowing this section
* to be collapsed
*/
Expand Down Expand Up @@ -421,6 +428,7 @@ export const FrontSection = ({
children,
containerName,
containerPalette,
containerLevel,
description,
editionId,
leftContent,
Expand Down Expand Up @@ -513,6 +521,7 @@ export const FrontSection = ({
url={!isOnPaidContentFront ? url : undefined}
showDateHeader={showDateHeader}
editionId={editionId}
containerLevel={containerLevel}
/>
}
collectionBranding={collectionBranding}
Expand Down
1 change: 1 addition & 0 deletions dotcom-rendering/src/layouts/FrontLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ export const FrontLayout = ({ front, NAV }: Props) => {
collectionBranding={
collection.collectionBranding
}
containerLevel={collection.containerLevel}
>
<DecideContainer
trails={trailsWithoutBranding}
Expand Down
35 changes: 34 additions & 1 deletion dotcom-rendering/src/model/enhanceCollections.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { decideCollectionBranding } from '../lib/branding';
import type { EditionId } from '../lib/edition';
import type { Branding } from '../types/branding';
import type { DCRCollectionType, FECollectionType } from '../types/front';
import type {
DCRCollectionType,
DCRContainerLevel,
FECollectionType,
FEContainerPalette,
} from '../types/front';
import { decideContainerPalette } from './decideContainerPalette';
import { enhanceCards } from './enhanceCards';
import { enhanceTreats } from './enhanceTreats';
Expand All @@ -15,6 +20,16 @@ const FORBIDDEN_CONTAINERS = [

const UNSUPPORTED_CONTAINERS = ['scrollable/feature', 'static/feature/2'];

const FAIRGROUND_CONTAINERS = [
'scrollable/feature',
'static/feature/2',
'flexible/special',
'flexible/general',
'scrollable/small',
'scrollable/medium',
'static/medium/4',
];
Comment on lines +23 to +31
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree ideally these shouldn't need to be here - this should come from upstream data


const PALETTE_STYLES_URI =
'https://content.guardianapis.com/atom/interactive/interactives/2022/03/29/fronts-container-colours/default';

Expand Down Expand Up @@ -45,6 +60,14 @@ const findCollectionSuitableForFrontBranding = (
return index;
};

const getContainerLevel = (
levels?: FEContainerPalette[],
Copy link
Contributor Author

@abeddow91 abeddow91 Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, the level is included in the config meta from frontend. This is largely only used for container palette which is why the type here might seem strange.

There are 3 options here:

  1. Leave as is with the comment
  2. Rename FEContainerPalette to be more generic and better represent the metadata.
  3. Separate out the container level tags from the container palette tags on frontend model. There is a spike here for this work Pass collection level on the Frontend config model frontend#27574

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for writing up these options! I think option 1 is fine for now with a view that we could improve to do 2 and/or 3 as a follow up improvement

): DCRContainerLevel | undefined => {
if (levels?.includes('Primary')) return 'Primary';
if (levels?.includes('Secondary')) return 'Secondary';
return undefined;
};

export const enhanceCollections = ({
collections,
editionId,
Expand Down Expand Up @@ -92,6 +115,15 @@ export const enhanceCollections = ({
},
);

/** "Primary" or "Secondary" container level styling should only be applied to fairground containers
* Ideally this logic would (and might) exist in the fronts tool.
*/
const containerLevel = FAIRGROUND_CONTAINERS.includes(collectionType)
? getContainerLevel(
collection.config.metadata?.map((meta) => meta.type),
)
: undefined;

return {
id,
displayName,
Expand Down Expand Up @@ -131,6 +163,7 @@ export const enhanceCollections = ({
},
canShowMore: hasMore && !collection.config.hideShowMore,
targetedTerritory: collection.targetedTerritory,
containerLevel,
};
});
};
2 changes: 2 additions & 0 deletions dotcom-rendering/src/model/front-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3244,6 +3244,8 @@
"LongRunningAltPalette",
"LongRunningPalette",
"Podcast",
"Primary",
"Secondary",
"SombreAltPalette",
"SombrePalette",
"Special",
Expand Down
7 changes: 6 additions & 1 deletion dotcom-rendering/src/types/front.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ export type FEContainerPalette =
| 'Podcast'
| 'Branded'
| 'BreakingPalette'
| 'SpecialReportAltPalette';
| 'SpecialReportAltPalette'
| 'Primary'
| 'Secondary';

export type FEFrontCardStyle =
| 'SpecialReport'
Expand Down Expand Up @@ -153,6 +155,8 @@ export type DCRContainerPalette =
// TODO: These may need to be declared differently than the front types in the future
export type DCRContainerType = FEContainerType;

export type DCRContainerLevel = 'Primary' | 'Secondary';

/** @see https://github.com/guardian/frontend/blob/0bf69f55a/common/app/model/content/Atom.scala#L191-L196 */
interface MediaAsset {
id: string;
Expand Down Expand Up @@ -407,6 +411,7 @@ export type DCRCollectionType = {
description?: string;
collectionType: DCRContainerType;
containerPalette?: DCRContainerPalette;
containerLevel?: DCRContainerLevel;
grouped: DCRGroupedTrails;
curated: DCRFrontCard[];
backfill: DCRFrontCard[];
Expand Down
Loading