Skip to content

Commit

Permalink
Merge pull request #11399 from wellcomecollection/featured-text-position
Browse files Browse the repository at this point in the history
Add 'featuredText' to page model (instead of text with a label)
  • Loading branch information
davidpmccormick authored Nov 14, 2024
2 parents 9140f1d + 29c22f7 commit 1e96dd2
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 21 deletions.
9 changes: 9 additions & 0 deletions common/customtypes/pages/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@
"placeholder": ""
}
},
"introText": {
"type": "StructuredText",
"config": {
"label": "Intro text",
"placeholder": "Introductory/important text to appear near the top of the page",
"allowTargetBlank": false,
"multi": "paragraph,strong,em,hyperlink"
}
},
"body": {
"type": "Slices",
"fieldset": "Slice Zone",
Expand Down
22 changes: 22 additions & 0 deletions common/prismicio-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3849,6 +3849,17 @@ interface PagesDocumentData {
*/
showOnThisPage: prismic.BooleanField;

/**
* Intro text field in *Page*
*
* - **Field Type**: Rich Text
* - **Placeholder**: Introductory/important text to appear near the top of the page
* - **API ID Path**: pages.introText
* - **Tab**: Page
* - **Documentation**: https://prismic.io/docs/field#rich-text-title
*/
introText: prismic.RichTextField;

/**
* Slice Zone field in *Page*
*
Expand Down Expand Up @@ -7203,6 +7214,17 @@ declare module '@prismicio/client' {
): prismic.Client<AllDocumentTypes>;
}

interface CreateWriteClient {
(
repositoryNameOrEndpoint: string,
options: prismic.WriteClientConfig
): prismic.WriteClient<AllDocumentTypes>;
}

interface CreateMigration {
(): prismic.Migration<AllDocumentTypes>;
}

namespace Content {
export type {
ArticleFormatsDocument,
Expand Down
28 changes: 7 additions & 21 deletions content/webapp/components/Body/Body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export const LayoutWidth: FunctionComponent<LayoutWidthProps> = ({

export type Props = {
untransformedBody: prismic.Slice[];
introText?: prismic.RichTextField;
onThisPage?: Link[];
showOnThisPage?: boolean;
isDropCapped?: boolean;
Expand Down Expand Up @@ -146,6 +147,7 @@ export const defaultContext: SliceZoneContext = {

const Body: FunctionComponent<Props> = ({
untransformedBody,
introText,
onThisPage,
showOnThisPage,
isDropCapped,
Expand All @@ -157,25 +159,9 @@ const Body: FunctionComponent<Props> = ({
comicPreviousNext,
contentType,
}: Props) => {
const isFirstFeaturedTextSliceFromUntransformedBody = (slice, i) =>
i === 0 && slice.slice_type === 'text' && slice.slice_label === 'featured';

const featuredTextFromUntransformedBody = untransformedBody.find(
isFirstFeaturedTextSliceFromUntransformedBody
) as prismic.Slice<'text', { text: prismic.RichTextField }>;

const filteredUntransformedBody = untransformedBody
.filter(
(slice, i) => !isFirstFeaturedTextSliceFromUntransformedBody(slice, i)
)
.filter(
slice =>
!(
slice.slice_type === 'editorialImage' &&
slice.slice_label === 'featured'
)
)
.filter(slice => slice.slice_type !== 'standfirst');
const filteredUntransformedBody = untransformedBody.filter(
slice => slice.slice_type !== 'standfirst'
);

const firstTextSliceIndex = filteredUntransformedBody
.map(slice => slice.slice_type)
Expand Down Expand Up @@ -317,7 +303,7 @@ const Body: FunctionComponent<Props> = ({
className={`content-type-${contentType}`}
$splitBackground={isShortFilm}
>
{featuredTextFromUntransformedBody && (
{introText && (
<ContaineredLayout gridSizes={gridSize8(!sectionLevelPage)}>
<div className="body-text spaced-text">
<Space
Expand All @@ -327,7 +313,7 @@ const Body: FunctionComponent<Props> = ({
}}
>
<FeaturedText
html={featuredTextFromUntransformedBody.primary.text}
html={introText}
htmlSerializer={defaultSerializer}
/>
</Space>
Expand Down
1 change: 1 addition & 0 deletions content/webapp/pages/pages/[pageId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ export const Page: FunctionComponent<Props> = ({
<Body
untransformedBody={untransformedBody}
pageId={page.id}
introText={page.introText}
onThisPage={page.onThisPage}
showOnThisPage={page.showOnThisPage}
isLanding={isLanding}
Expand Down
1 change: 1 addition & 0 deletions content/webapp/services/prismic/transformers/pages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const exampleTextSlice = {
export const pageWithoutBody: RawPagesDocument = {
...emptyDocumentWithUid<RawPagesDocument>({
title: [],
introText: exampleTextSlice.primary.text,
datePublished: null,
showOnThisPage: false,
metadataDescription: exampleTextSlice.primary.text,
Expand Down
2 changes: 2 additions & 0 deletions content/webapp/services/prismic/transformers/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export function transformPage(document: RawPagesDocument): Page {
})
: [];

const introText = data?.introText;
const siteSections = headerLinks.map(link => link.siteSection);
const siteSection = document.tags.find(tag =>
siteSections.includes(tag as SiteSection)
Expand Down Expand Up @@ -97,6 +98,7 @@ export function transformPage(document: RawPagesDocument): Page {
uid: document.uid,
format: transformFormat(document),
...genericFields,
introText,
metadataDescription,
seasons,
contributors,
Expand Down
3 changes: 3 additions & 0 deletions content/webapp/types/pages.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type * as prismic from '@prismicio/client';

import { SiteSection } from '@weco/common/model/site-section';

import { Contributor } from './contributors';
Expand All @@ -13,6 +15,7 @@ export type ParentPage = Page & {

export type Page = GenericContentFields & {
type: 'pages';
introText?: prismic.RichTextField;
uid: string;
format: Format | undefined;
seasons: Season[];
Expand Down

0 comments on commit 1e96dd2

Please sign in to comment.