diff --git a/examples/kit-nextjs-skate-park/src/__tests__/components/image/Image.test.tsx b/examples/kit-nextjs-skate-park/src/__tests__/components/image/Image.test.tsx index 60fe74dcf..6e7e70f8d 100644 --- a/examples/kit-nextjs-skate-park/src/__tests__/components/image/Image.test.tsx +++ b/examples/kit-nextjs-skate-park/src/__tests__/components/image/Image.test.tsx @@ -172,8 +172,8 @@ describe('Image Component Edge Cases should', () => { const propsWithoutImage = { ...mockImagePropsComplete, fields: { - ImageCaption: mockImagePropsComplete.fields.ImageCaption, - TargetUrl: mockImagePropsComplete.fields.TargetUrl, + ImageCaption: mockImagePropsComplete.fields?.ImageCaption, + TargetUrl: mockImagePropsComplete.fields?.TargetUrl, } as unknown as typeof mockImagePropsComplete.fields, }; diff --git a/examples/kit-nextjs-skate-park/src/__tests__/components/link-list/LinkList.test.tsx b/examples/kit-nextjs-skate-park/src/__tests__/components/link-list/LinkList.test.tsx index 61cbc4324..a402e6127 100644 --- a/examples/kit-nextjs-skate-park/src/__tests__/components/link-list/LinkList.test.tsx +++ b/examples/kit-nextjs-skate-park/src/__tests__/components/link-list/LinkList.test.tsx @@ -211,7 +211,7 @@ describe('LinkList Component Edge Cases should', () => { fields: { data: { datasource: { - field: mockLinkListProps.fields.data.datasource.field, + field: mockLinkListProps.fields?.data?.datasource?.field, children: { results: [], }, diff --git a/examples/kit-nextjs-skate-park/src/components/content-block/ContentBlock.tsx b/examples/kit-nextjs-skate-park/src/components/content-block/ContentBlock.tsx index 3540e3db8..651191b4d 100644 --- a/examples/kit-nextjs-skate-park/src/components/content-block/ContentBlock.tsx +++ b/examples/kit-nextjs-skate-park/src/components/content-block/ContentBlock.tsx @@ -11,9 +11,9 @@ import { ContentBlockProps } from './content-block.props'; */ const ContentBlock = ({ fields }: ContentBlockProps): JSX.Element => (
- + - +
); diff --git a/examples/kit-nextjs-skate-park/src/components/content-block/content-block.props.ts b/examples/kit-nextjs-skate-park/src/components/content-block/content-block.props.ts index 444a9d0f8..adead62ac 100644 --- a/examples/kit-nextjs-skate-park/src/components/content-block/content-block.props.ts +++ b/examples/kit-nextjs-skate-park/src/components/content-block/content-block.props.ts @@ -2,8 +2,8 @@ import { Field } from '@sitecore-content-sdk/nextjs'; import { ComponentProps } from 'lib/component-props'; export type ContentBlockProps = ComponentProps & { - fields: { - heading: Field; - content: Field; + fields?: { + heading?: Field; + content?: Field; }; }; diff --git a/examples/kit-nextjs-skate-park/src/components/image/Image.tsx b/examples/kit-nextjs-skate-park/src/components/image/Image.tsx index ca170acf9..61793f0d5 100644 --- a/examples/kit-nextjs-skate-park/src/components/image/Image.tsx +++ b/examples/kit-nextjs-skate-park/src/components/image/Image.tsx @@ -21,7 +21,7 @@ const ImageDefault: React.FC = ({ params }) => ( export const Banner: React.FC = ({ params, fields }) => { const { styles, RenderingIdentifier: id } = params; - const baseImageField = getFieldValue(fields.Image); + const baseImageField = getFieldValue(fields?.Image); const imageField = baseImageField && { ...baseImageField, value: { diff --git a/examples/kit-nextjs-skate-park/src/components/image/image.props.ts b/examples/kit-nextjs-skate-park/src/components/image/image.props.ts index ccb0fe3b2..09b319bac 100644 --- a/examples/kit-nextjs-skate-park/src/components/image/image.props.ts +++ b/examples/kit-nextjs-skate-park/src/components/image/image.props.ts @@ -3,13 +3,13 @@ import { Field, ImageField, LinkField } from '@sitecore-content-sdk/nextjs'; import type React from 'react'; export interface ImageFields { - Image: CompatibleField; - ImageCaption: CompatibleField>; - TargetUrl: CompatibleField; + Image?: CompatibleField; + ImageCaption?: CompatibleField>; + TargetUrl?: CompatibleField; } export interface ImageProps extends ComponentProps { - fields: ImageFields; + fields?: ImageFields; } export interface ImageWrapperProps { diff --git a/examples/kit-nextjs-skate-park/src/components/link-list/LinkList.tsx b/examples/kit-nextjs-skate-park/src/components/link-list/LinkList.tsx index 5fec203ad..eba99f886 100644 --- a/examples/kit-nextjs-skate-park/src/components/link-list/LinkList.tsx +++ b/examples/kit-nextjs-skate-park/src/components/link-list/LinkList.tsx @@ -36,10 +36,12 @@ export const Default = ({ params, fields }: LinkListProps) => { } const links = results - .filter((element) => element?.field?.link) + .filter((element): element is typeof element & { field: { link: LinkField } } => + Boolean(element?.field?.link) + ) .map((element, index) => ( ; }; - field: { - title: TextField; + field?: { + title?: TextField; }; }>; } diff --git a/examples/kit-nextjs-skate-park/src/components/navigation/Navigation.tsx b/examples/kit-nextjs-skate-park/src/components/navigation/Navigation.tsx index 94a4e4c6e..fa2398e25 100644 --- a/examples/kit-nextjs-skate-park/src/components/navigation/Navigation.tsx +++ b/examples/kit-nextjs-skate-park/src/components/navigation/Navigation.tsx @@ -5,7 +5,11 @@ import { CompatibleLink } from 'components/content-sdk/CompatibleLink'; import { getFieldValue } from 'lib/component-props'; import { NavigationFields as Fields, NavigationListItemProps, NavigationProps } from './navigation.props'; -const getTextContent = (fields: Fields): JSX.Element | string => { +const getTextContent = (fields?: Fields): JSX.Element | string => { + if (!fields) { + return ''; + } + const navigationTitle = getFieldValue(fields.NavigationTitle); const title = getFieldValue(fields.Title); @@ -14,14 +18,14 @@ const getTextContent = (fields: Fields): JSX.Element | string => { return fields.DisplayName; }; -const getLinkField = (fields: Fields): LinkField => ({ +const getLinkField = (fields?: Fields): LinkField => ({ value: { - href: fields.Href, + href: fields?.Href ?? '', title: - getFieldValue(fields.NavigationTitle)?.value?.toString() ?? - getFieldValue(fields.Title)?.value?.toString() ?? - fields.DisplayName, - querystring: fields.Querystring, + getFieldValue(fields?.NavigationTitle)?.value?.toString() ?? + getFieldValue(fields?.Title)?.value?.toString() ?? + fields?.DisplayName, + querystring: fields?.Querystring ?? '', }, }); @@ -30,6 +34,10 @@ const NavigationListItem: React.FC = ({ handleClick, relativeLevel, }) => { + if (!fields) { + return null; + } + const [isActive, setIsActive] = useState(false); const { page } = useSitecore(); @@ -69,7 +77,7 @@ export const Default = ({ params, fields }: NavigationProps) => { const { page } = useSitecore(); const { styles, RenderingIdentifier: id } = params; - if (!Object.values(fields).length) { + if (!fields || !Object.values(fields).length) { return (
[Navigation]
diff --git a/examples/kit-nextjs-skate-park/src/components/navigation/navigation.props.ts b/examples/kit-nextjs-skate-park/src/components/navigation/navigation.props.ts index 731e8fe15..1ebac02b6 100644 --- a/examples/kit-nextjs-skate-park/src/components/navigation/navigation.props.ts +++ b/examples/kit-nextjs-skate-park/src/components/navigation/navigation.props.ts @@ -13,13 +13,13 @@ export interface NavigationFields { } export interface NavigationListItemProps { - fields: NavigationFields; + fields?: NavigationFields; handleClick: (event?: React.MouseEvent) => void; relativeLevel: number; } export interface NavigationProps extends ComponentProps { - fields: NavigationFields; + fields?: NavigationFields; } export type NavigationLinkField = LinkField; diff --git a/examples/kit-nextjs-skate-park/src/components/page-content/page-content.props.ts b/examples/kit-nextjs-skate-park/src/components/page-content/page-content.props.ts index a2924ef08..7e783e757 100644 --- a/examples/kit-nextjs-skate-park/src/components/page-content/page-content.props.ts +++ b/examples/kit-nextjs-skate-park/src/components/page-content/page-content.props.ts @@ -2,9 +2,9 @@ import { RichTextField } from '@sitecore-content-sdk/nextjs'; import { ComponentProps } from 'lib/component-props'; export interface PageContentFields { - Content: RichTextField; + Content?: RichTextField; } export type PageContentProps = ComponentProps & { - fields: PageContentFields; + fields?: PageContentFields; }; diff --git a/examples/kit-nextjs-skate-park/src/components/promo/promo.props.ts b/examples/kit-nextjs-skate-park/src/components/promo/promo.props.ts index 15c2c4bf2..abaaf3592 100644 --- a/examples/kit-nextjs-skate-park/src/components/promo/promo.props.ts +++ b/examples/kit-nextjs-skate-park/src/components/promo/promo.props.ts @@ -3,14 +3,14 @@ import { ImageField, Field, LinkField } from '@sitecore-content-sdk/nextjs'; import type { JSX } from 'react'; export interface PromoFields { - PromoIcon: CompatibleField; - PromoText: CompatibleField>; - PromoLink: CompatibleField; - PromoText2: CompatibleField>; + PromoIcon?: CompatibleField; + PromoText?: CompatibleField>; + PromoLink?: CompatibleField; + PromoText2?: CompatibleField>; } export type PromoProps = ComponentProps & { - fields: PromoFields; + fields?: PromoFields; }; export interface PromoContentProps extends PromoProps { diff --git a/examples/kit-nextjs-skate-park/src/components/rich-text/RichText.tsx b/examples/kit-nextjs-skate-park/src/components/rich-text/RichText.tsx index 90188b28b..907bf6400 100644 --- a/examples/kit-nextjs-skate-park/src/components/rich-text/RichText.tsx +++ b/examples/kit-nextjs-skate-park/src/components/rich-text/RichText.tsx @@ -9,7 +9,7 @@ export const Default = ({ params, fields }: RichTextProps): JSX.Element => {
{fields ? ( - + ) : ( Rich text )} diff --git a/examples/kit-nextjs-skate-park/src/components/rich-text/rich-text.props.ts b/examples/kit-nextjs-skate-park/src/components/rich-text/rich-text.props.ts index bf97c410a..118a4dd16 100644 --- a/examples/kit-nextjs-skate-park/src/components/rich-text/rich-text.props.ts +++ b/examples/kit-nextjs-skate-park/src/components/rich-text/rich-text.props.ts @@ -2,9 +2,9 @@ import { Field } from '@sitecore-content-sdk/nextjs'; import { ComponentProps } from 'lib/component-props'; export interface RichTextFields { - Text: Field; + Text?: Field; } export type RichTextProps = ComponentProps & { - fields: RichTextFields; + fields?: RichTextFields; }; diff --git a/examples/kit-nextjs-skate-park/src/components/title/title.props.ts b/examples/kit-nextjs-skate-park/src/components/title/title.props.ts index e048be868..f43b88cce 100644 --- a/examples/kit-nextjs-skate-park/src/components/title/title.props.ts +++ b/examples/kit-nextjs-skate-park/src/components/title/title.props.ts @@ -11,7 +11,7 @@ export interface TitleItem { } export interface TitleProps extends ComponentProps { - fields: CompatibleDatasource; + fields?: CompatibleDatasource; } export interface TitleComponentContentProps {