Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export const ScrollableProduct = ({ products, format }: Props) => {
<div css={countStyles} id={'at-a-glance-carousel-count'}></div>
</div>
<div css={[baseContainerStyles]}>
<ol
<ul
ref={carouselRef}
css={carouselStyles}
data-heatphan-type="carousel"
Expand All @@ -337,7 +337,7 @@ export const ScrollableProduct = ({ products, format }: Props) => {
/>
</li>
))}
</ol>
</ul>
<CarouselNavigationButtons
previousButtonEnabled={previousButtonEnabled}
nextButtonEnabled={nextButtonEnabled}
Expand Down
22 changes: 22 additions & 0 deletions dotcom-rendering/src/frontend/schemas/feArticle.json
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,9 @@
},
{
"$ref": "#/definitions/ProductBlockElement"
},
{
"$ref": "#/definitions/ProductCarouselElement"
}
]
},
Expand Down Expand Up @@ -4613,6 +4616,25 @@
],
"type": "string"
},
"ProductCarouselElement": {
"type": "object",
"properties": {
"_type": {
"type": "string",
"const": "model.dotcomrendering.pageElements.ProductCarouselElement"
},
"matchedProducts": {
"type": "array",
"items": {
"$ref": "#/definitions/ProductBlockElement"
}
}
},
"required": [
"_type",
"matchedProducts"
]
},
"Block": {
"type": "object",
"properties": {
Expand Down
10 changes: 10 additions & 0 deletions dotcom-rendering/src/lib/renderElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { PullQuoteBlockComponent } from '../components/PullQuoteBlockComponent';
import { QandaAtom } from '../components/QandaAtom.importable';
import { QAndAExplainers } from '../components/QAndAExplainers';
import { RichLinkComponent } from '../components/RichLinkComponent.importable';
import { ScrollableProduct } from '../components/ScrollableProduct.importable';
import { SelfHostedVideoInArticle } from '../components/SelfHostedVideoInArticle';
import { SoundcloudBlockComponent } from '../components/SoundcloudBlockComponent';
import { SpotifyBlockComponent } from '../components/SpotifyBlockComponent.importable';
Expand Down Expand Up @@ -976,6 +977,15 @@ export const renderElement = ({
/>
</Island>
);
case 'model.dotcomrendering.pageElements.ProductCarouselElement':
return (
<Island priority="critical" defer={{ until: 'idle' }}>
<ScrollableProduct
products={element.matchedProducts}
format={format}
/>
</Island>
);
case 'model.dotcomrendering.pageElements.AudioBlockElement':
case 'model.dotcomrendering.pageElements.ContentAtomBlockElement':
case 'model.dotcomrendering.pageElements.GenericAtomBlockElement':
Expand Down
22 changes: 22 additions & 0 deletions dotcom-rendering/src/model/block-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@
},
{
"$ref": "#/definitions/ProductBlockElement"
},
{
"$ref": "#/definitions/ProductCarouselElement"
}
]
},
Expand Down Expand Up @@ -4101,6 +4104,25 @@
],
"type": "string"
},
"ProductCarouselElement": {
"type": "object",
"properties": {
"_type": {
"type": "string",
"const": "model.dotcomrendering.pageElements.ProductCarouselElement"
},
"matchedProducts": {
"type": "array",
"items": {
"$ref": "#/definitions/ProductBlockElement"
}
}
},
"required": [
"_type",
"matchedProducts"
]
},
"Attributes": {
"type": "object",
"properties": {
Expand Down
6 changes: 5 additions & 1 deletion dotcom-rendering/src/model/enhance-H2s.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ export const slugify = (text: string): string => {
/**
* This function attempts to create a slugified string to use as the id. It fails over to elementId.
*/
const generateId = (elementId: string, html: string, existingIds: string[]) => {
export const generateId = (
elementId: string,
html: string,
existingIds: string[],
): string => {
const text = extractText(html);
if (!text) return elementId;
const slug = slugify(text);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import type { FEElement, ProductBlockElement } from '../types/content';

export const linkElement = (url: string, label: string): FEElement =>
({
_type: 'model.dotcomrendering.pageElements.LinkBlockElement',
url,
label,
}) as FEElement;

export const productElement = (urls: string[]): ProductBlockElement =>
({
_type: 'model.dotcomrendering.pageElements.ProductBlockElement',
productCtas: urls.map((url) => ({ url })),
}) as ProductBlockElement;

export const atAGlanceHeading = (): FEElement =>
({
_type: 'model.dotcomrendering.pageElements.SubheadingBlockElement',
text: 'At a glance',
html: 'At a glance',
elementId: 'at-a-glance',
}) as FEElement;

export const dividerElement = (): FEElement =>
({
_type: 'model.dotcomrendering.pageElements.DividerBlockElement',
elementId: 'divider',
}) as FEElement;

export const textElement = (html: string): FEElement =>
({
_type: 'model.dotcomrendering.pageElements.TextBlockElement',
html,
elementId: '4',
}) as FEElement;

export type ProductCarouselTestElement = FEElement & {
_type: 'model.dotcomrendering.pageElements.ProductCarouselElement';
matchedProducts: ProductBlockElement[];
};

export const findCarousel = (
elements: FEElement[],
): ProductCarouselTestElement | undefined =>
elements.find(
(el): el is ProductCarouselTestElement =>
el._type ===
'model.dotcomrendering.pageElements.ProductCarouselElement',
);
Loading
Loading