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

fix(example): Calendar Event was not handling relationships correctly #29868

Merged
Merged
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
59 changes: 41 additions & 18 deletions examples/nextjs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion examples/nextjs/src/app/[[...slug]]/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ export default async function Home({ searchParams, params }) {
path,
params: searchParams,
});
const pageAsset = await client.page.get(pageRequestParams);
const pageAsset = await client.page.get({
...pageRequestParams,
depth: 3,
});
const nav = await client.nav.get({
path: "/",
depth: 2,
Expand Down
81 changes: 47 additions & 34 deletions examples/nextjs/src/components/content-types/calendarEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@ import Image from "next/image";
import Link from "next/link";

function extractLocationsAndActivities(contentlet) {
return contentlet.reduce(
(acc, { activities, ...location }) => {
const initialValue = {
locations: [],
activities: [],
};

return (
contentlet?.reduce((acc, { activities, ...location }) => {
// This is a relationship between Contentlets
// Event -> Location -> Activities
// Depth 3
acc.activities = acc.activities.concat(activities);
acc.locations.push(location);

return acc;
},
{ locations: [], activities: [] }
}, initialValue) ?? initialValue
);
}

Expand All @@ -31,36 +38,42 @@ function CalendarEvent({ image, title, urlMap, description, location }) {
<h4 className="block mb-2 text-2xl antialiased font-semibold leading-snug tracking-normal text-blue-gray-900">
{title}
</h4>
<div className="block mb-2 text-base antialiased leading-snug tracking-normal text-blue-gray-900 break-all">
<span className="cursor-auto select-none font-semibold underline">
Locations:
</span>
&nbsp;
{locations.map(({ title, url }, index) => {
return (
<Link key={index} href={url}>
<span className="bg-yellow-100 text-yellow-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded dark:bg-yellow-900 dark:text-yellow-300">
{title}
</span>
</Link>
);
})}
</div>
<div className="block mb-2 text-base antialiased leading-snug tracking-normal text-blue-gray-900 break-all">
<span className="cursor-auto select-none font-semibold underline">
Activities:
</span>
&nbsp;
{activities.slice(0, 3).map(({ title, urlMap }, index) => {
return (
<Link key={index} href={urlMap}>
<span className="bg-indigo-100 text-indigo-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded dark:bg-indigo-900 dark:text-indigo-300">
{title}
</span>
</Link>
);
})}
</div>
{!!locations.length && !!locations[0]?.title && (
<div className="block mb-2 text-base antialiased leading-snug tracking-normal text-blue-gray-900 break-all">
<span className="cursor-auto select-none font-semibold underline">
Locations:
</span>
&nbsp;
{locations.map(({ title, url }, index) => {
return (
<Link key={index} href={url ?? ""}>
<span className="bg-yellow-100 text-yellow-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded dark:bg-yellow-900 dark:text-yellow-300">
{title}
</span>
</Link>
);
})}
</div>
)}
{!!activities.length && !!activities[0]?.title && (
<div className="block mb-2 text-base antialiased leading-snug tracking-normal text-blue-gray-900 break-all">
<span className="cursor-auto select-none font-semibold underline">
Activities:
</span>
&nbsp;
{activities
.slice(0, 3)
.map(({ title, urlMap }, index) => {
return (
<Link key={index} href={urlMap ?? ""}>
<span className="bg-indigo-100 text-indigo-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded dark:bg-indigo-900 dark:text-indigo-300">
{title}
</span>
</Link>
);
})}
</div>
)}
<div
className="block mb-8 text-base antialiased font-normal leading-relaxed line-clamp-3"
dangerouslySetInnerHTML={{ __html: description }}
Expand Down
9 changes: 7 additions & 2 deletions examples/nextjs/src/components/my-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const componentsMap = {
calendarEvent: CalendarEvent,
CallToAction: CallToAction,
CustomNoComponent: CustomNoComponent,
BlockEditorItem: BlogWithBlockEditor
BlockEditorItem: BlogWithBlockEditor,
};

export function MyPage({ pageAsset, nav }) {
Expand Down Expand Up @@ -77,7 +77,12 @@ export function MyPage({ pageAsset, nav }) {
pageAsset: pageAsset,
}}
config={{
pathname
pathname,
editor: {
params: {
depth: 3,
},
},
}}
/>
</main>
Expand Down