Merged in fix/BOOK-456-destination-city-validation-error (pull request #2975)
fix(BOOK-456): Added nullish() to destination pages content and sidepeek content schema to avoid unexpected errors * fix(BOOK-456): Added nullish() to destination pages content and sidepeek content schema to avoid unexpected errors Approved-by: Linus Flood
This commit is contained in:
committed by
Linus Flood
parent
e2403e11b3
commit
c6f76b83cc
@@ -35,6 +35,10 @@ export default function DestinationPageSidepeek({
|
|||||||
trackOpenSidePeekOnDestinationPagesEvent(location)
|
trackOpenSidePeekOnDestinationPagesEvent(location)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!content) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ export function getConnections({ content_page }: ContentPageRefs) {
|
|||||||
}
|
}
|
||||||
case ContentPageEnum.ContentStack.blocks.Content:
|
case ContentPageEnum.ContentStack.blocks.Content:
|
||||||
{
|
{
|
||||||
if (block.content.length) {
|
if (block?.content?.length) {
|
||||||
connections.push(...block.content)
|
connections.push(...block.content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,22 +144,24 @@ export const destinationCityPageSchema = z.object({
|
|||||||
sidepeek_content: z
|
sidepeek_content: z
|
||||||
.object({
|
.object({
|
||||||
heading: z.string(),
|
heading: z.string(),
|
||||||
content: z.object({
|
content: z
|
||||||
json: z.any(),
|
.object({
|
||||||
embedded_itemsConnection: z.object({
|
json: z.any(),
|
||||||
edges: z.array(
|
embedded_itemsConnection: z.object({
|
||||||
z.object({
|
edges: z.array(
|
||||||
node: linkUnionSchema.transform((data) => {
|
z.object({
|
||||||
const link = transformPageLink(data)
|
node: linkUnionSchema.transform((data) => {
|
||||||
if (link) {
|
const link = transformPageLink(data)
|
||||||
return link
|
if (link) {
|
||||||
}
|
return link
|
||||||
return data
|
}
|
||||||
}),
|
return data
|
||||||
})
|
}),
|
||||||
),
|
})
|
||||||
}),
|
),
|
||||||
}),
|
}),
|
||||||
|
})
|
||||||
|
.nullish(),
|
||||||
})
|
})
|
||||||
.nullish(),
|
.nullish(),
|
||||||
blocks: discriminatedUnionArray(blocksSchema.options).nullable(),
|
blocks: discriminatedUnionArray(blocksSchema.options).nullable(),
|
||||||
@@ -251,15 +253,17 @@ export const destinationCityPageRefsSchema = z.object({
|
|||||||
destination_settings: destinationCityPageDestinationSettingsSchema,
|
destination_settings: destinationCityPageDestinationSettingsSchema,
|
||||||
sidepeek_content: z
|
sidepeek_content: z
|
||||||
.object({
|
.object({
|
||||||
content: z.object({
|
content: z
|
||||||
embedded_itemsConnection: z.object({
|
.object({
|
||||||
edges: z.array(
|
embedded_itemsConnection: z.object({
|
||||||
z.object({
|
edges: z.array(
|
||||||
node: linkRefsUnionSchema,
|
z.object({
|
||||||
})
|
node: linkRefsUnionSchema,
|
||||||
),
|
})
|
||||||
}),
|
),
|
||||||
}),
|
}),
|
||||||
|
})
|
||||||
|
.nullish(),
|
||||||
})
|
})
|
||||||
.nullish(),
|
.nullish(),
|
||||||
blocks: discriminatedUnionArray(blocksRefsSchema.options).nullable(),
|
blocks: discriminatedUnionArray(blocksRefsSchema.options).nullable(),
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ export function getConnections({
|
|||||||
}
|
}
|
||||||
case DestinationCityPageEnum.ContentStack.blocks.Content:
|
case DestinationCityPageEnum.ContentStack.blocks.Content:
|
||||||
{
|
{
|
||||||
if (block.content.length) {
|
if (block?.content?.length) {
|
||||||
// TS has trouble infering the filtered types
|
// TS has trouble infering the filtered types
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
connections.push(...block.content)
|
connections.push(...block.content)
|
||||||
@@ -58,7 +58,7 @@ export function getConnections({
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (destination_city_page.sidepeek_content) {
|
if (destination_city_page.sidepeek_content) {
|
||||||
destination_city_page.sidepeek_content.content.embedded_itemsConnection.edges.forEach(
|
destination_city_page.sidepeek_content?.content?.embedded_itemsConnection.edges.forEach(
|
||||||
({ node }) => {
|
({ node }) => {
|
||||||
connections.push(node.system)
|
connections.push(node.system)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,22 +73,24 @@ export const destinationCountryPageSchema = z.object({
|
|||||||
sidepeek_content: z
|
sidepeek_content: z
|
||||||
.object({
|
.object({
|
||||||
heading: z.string(),
|
heading: z.string(),
|
||||||
content: z.object({
|
content: z
|
||||||
json: z.any(),
|
.object({
|
||||||
embedded_itemsConnection: z.object({
|
json: z.any(),
|
||||||
edges: z.array(
|
embedded_itemsConnection: z.object({
|
||||||
z.object({
|
edges: z.array(
|
||||||
node: linkUnionSchema.transform((data) => {
|
z.object({
|
||||||
const link = transformPageLink(data)
|
node: linkUnionSchema.transform((data) => {
|
||||||
if (link) {
|
const link = transformPageLink(data)
|
||||||
return link
|
if (link) {
|
||||||
}
|
return link
|
||||||
return data
|
}
|
||||||
}),
|
return data
|
||||||
})
|
}),
|
||||||
),
|
})
|
||||||
}),
|
),
|
||||||
}),
|
}),
|
||||||
|
})
|
||||||
|
.nullish(),
|
||||||
})
|
})
|
||||||
.nullish(),
|
.nullish(),
|
||||||
blocks: discriminatedUnionArray(blocksSchema.options).nullable(),
|
blocks: discriminatedUnionArray(blocksSchema.options).nullable(),
|
||||||
@@ -153,17 +155,21 @@ const blocksRefsSchema = z.discriminatedUnion("__typename", [
|
|||||||
])
|
])
|
||||||
export const destinationCountryPageRefsSchema = z.object({
|
export const destinationCountryPageRefsSchema = z.object({
|
||||||
destination_country_page: z.object({
|
destination_country_page: z.object({
|
||||||
sidepeek_content: z.object({
|
sidepeek_content: z
|
||||||
content: z.object({
|
.object({
|
||||||
embedded_itemsConnection: z.object({
|
content: z
|
||||||
edges: z.array(
|
.object({
|
||||||
z.object({
|
embedded_itemsConnection: z.object({
|
||||||
node: linkRefsUnionSchema,
|
edges: z.array(
|
||||||
})
|
z.object({
|
||||||
),
|
node: linkRefsUnionSchema,
|
||||||
}),
|
})
|
||||||
}),
|
),
|
||||||
}),
|
}),
|
||||||
|
})
|
||||||
|
.nullish(),
|
||||||
|
})
|
||||||
|
.nullish(),
|
||||||
blocks: discriminatedUnionArray(blocksRefsSchema.options).nullable(),
|
blocks: discriminatedUnionArray(blocksRefsSchema.options).nullable(),
|
||||||
seo_filters: destinationFiltersRefsSchema,
|
seo_filters: destinationFiltersRefsSchema,
|
||||||
system: systemSchema,
|
system: systemSchema,
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export function getConnections({
|
|||||||
}
|
}
|
||||||
case DestinationCountryPageEnum.ContentStack.blocks.Content:
|
case DestinationCountryPageEnum.ContentStack.blocks.Content:
|
||||||
{
|
{
|
||||||
if (block.content.length) {
|
if (block?.content?.length) {
|
||||||
// TS has trouble infering the filtered types
|
// TS has trouble infering the filtered types
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
connections.push(...block.content)
|
connections.push(...block.content)
|
||||||
@@ -56,7 +56,7 @@ export function getConnections({
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (destination_country_page.sidepeek_content) {
|
if (destination_country_page.sidepeek_content) {
|
||||||
destination_country_page.sidepeek_content.content.embedded_itemsConnection.edges.forEach(
|
destination_country_page.sidepeek_content?.content?.embedded_itemsConnection.edges.forEach(
|
||||||
({ node }) => {
|
({ node }) => {
|
||||||
connections.push(node.system)
|
connections.push(node.system)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export function getConnections({ loyalty_page }: LoyaltyPageRefs) {
|
|||||||
}
|
}
|
||||||
break
|
break
|
||||||
case LoyaltyPageEnum.ContentStack.blocks.Content:
|
case LoyaltyPageEnum.ContentStack.blocks.Content:
|
||||||
if (block.content.length) {
|
if (block?.content?.length) {
|
||||||
// TS has trouble infering the filtered types
|
// TS has trouble infering the filtered types
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
connections.push(...block.content)
|
connections.push(...block.content)
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ export function getConnections({ promo_campaign_page }: PromoCampaignPageRefs) {
|
|||||||
}
|
}
|
||||||
case PromoCampaignPageEnum.ContentStack.blocks.Content:
|
case PromoCampaignPageEnum.ContentStack.blocks.Content:
|
||||||
{
|
{
|
||||||
if (block.content.length) {
|
if (block?.content?.length) {
|
||||||
connections.push(...block.content)
|
connections.push(...block.content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,28 +20,30 @@ export const contentSchema = z.object({
|
|||||||
.default(BlocksEnums.block.Content),
|
.default(BlocksEnums.block.Content),
|
||||||
content: z
|
content: z
|
||||||
.object({
|
.object({
|
||||||
content: z.object({
|
content: z
|
||||||
json: z.any(), // JSON
|
.object({
|
||||||
embedded_itemsConnection: z.object({
|
json: z.any(), // JSON
|
||||||
edges: z.array(
|
embedded_itemsConnection: z.object({
|
||||||
z.object({
|
edges: z.array(
|
||||||
node: z
|
z.object({
|
||||||
.discriminatedUnion("__typename", [
|
node: z
|
||||||
imageContainerSchema,
|
.discriminatedUnion("__typename", [
|
||||||
sysAssetSchema,
|
imageContainerSchema,
|
||||||
...linkUnionSchema.options,
|
sysAssetSchema,
|
||||||
])
|
...linkUnionSchema.options,
|
||||||
.transform((data) => {
|
])
|
||||||
const link = transformPageLink(data)
|
.transform((data) => {
|
||||||
if (link) {
|
const link = transformPageLink(data)
|
||||||
return link
|
if (link) {
|
||||||
}
|
return link
|
||||||
return data
|
}
|
||||||
}),
|
return data
|
||||||
})
|
}),
|
||||||
),
|
})
|
||||||
}),
|
),
|
||||||
}),
|
}),
|
||||||
|
})
|
||||||
|
.nullish(),
|
||||||
})
|
})
|
||||||
.nullish()
|
.nullish()
|
||||||
.transform((data) => {
|
.transform((data) => {
|
||||||
@@ -52,22 +54,25 @@ export const contentSchema = z.object({
|
|||||||
export const contentRefsSchema = z.object({
|
export const contentRefsSchema = z.object({
|
||||||
content: z
|
content: z
|
||||||
.object({
|
.object({
|
||||||
content: z.object({
|
content: z
|
||||||
embedded_itemsConnection: z.object({
|
.object({
|
||||||
edges: z.array(
|
embedded_itemsConnection: z.object({
|
||||||
z.object({
|
edges: z.array(
|
||||||
node: z.discriminatedUnion("__typename", [
|
z.object({
|
||||||
sysAssetRefsSchema,
|
node: z.discriminatedUnion("__typename", [
|
||||||
imageContainerRefsSchema,
|
sysAssetRefsSchema,
|
||||||
...linkRefsUnionSchema.options,
|
imageContainerRefsSchema,
|
||||||
]),
|
...linkRefsUnionSchema.options,
|
||||||
})
|
]),
|
||||||
),
|
})
|
||||||
}),
|
),
|
||||||
}),
|
}),
|
||||||
|
})
|
||||||
|
.nullish(),
|
||||||
})
|
})
|
||||||
|
.nullish()
|
||||||
.transform((data) => {
|
.transform((data) => {
|
||||||
return data.content.embedded_itemsConnection.edges
|
return data?.content?.embedded_itemsConnection.edges
|
||||||
.filter(({ node }) => node.__typename !== ContentEnum.blocks.SysAsset)
|
.filter(({ node }) => node.__typename !== ContentEnum.blocks.SysAsset)
|
||||||
.map(({ node }) => {
|
.map(({ node }) => {
|
||||||
if ("system" in node) {
|
if ("system" in node) {
|
||||||
|
|||||||
Reference in New Issue
Block a user