feat(BOOK-639): add all block types on startpage to refs cache key * feat(BOOK-639): add all block types on startpage to refs cache key Approved-by: Erik Tiekstra Approved-by: Matilda Landström
66 lines
1.9 KiB
TypeScript
66 lines
1.9 KiB
TypeScript
import type { z } from "zod"
|
|
|
|
import type { System } from "../schemas/system"
|
|
import type { startPageRefsSchema } from "./output"
|
|
|
|
export namespace StartPageEnum {
|
|
export namespace ContentStack {
|
|
export const enum blocks {
|
|
CardsGrid = "StartPageBlocksCardsGrid",
|
|
CarouselCards = "StartPageBlocksCarouselCards",
|
|
FullWidthCampaign = "StartPageBlocksFullWidthCampaign",
|
|
JoinScandicFriends = "StartPageBlocksJoinScandicFriends",
|
|
}
|
|
}
|
|
}
|
|
|
|
export interface StartPageRefs extends z.output<typeof startPageRefsSchema> {}
|
|
|
|
export function getConnections({ start_page }: StartPageRefs) {
|
|
const connections: System["system"][] = [start_page.system]
|
|
|
|
if (start_page.blocks) {
|
|
start_page.blocks.forEach((block) => {
|
|
const typeName = block.__typename
|
|
switch (typeName) {
|
|
case StartPageEnum.ContentStack.blocks.FullWidthCampaign: {
|
|
block.full_width_campaign.full_width_campaignConnection.edges.forEach(
|
|
({ node }) => {
|
|
if (node.system) {
|
|
connections.push(node.system)
|
|
}
|
|
}
|
|
)
|
|
break
|
|
}
|
|
case StartPageEnum.ContentStack.blocks.CardsGrid: {
|
|
block.cards_grid.forEach((card) => {
|
|
connections.push(card)
|
|
})
|
|
break
|
|
}
|
|
case StartPageEnum.ContentStack.blocks.CarouselCards: {
|
|
block.carousel_cards.card_groups.forEach((group) => {
|
|
group.cardConnection.edges.forEach((node) => {
|
|
connections.push(node.node.system)
|
|
})
|
|
})
|
|
break
|
|
}
|
|
case StartPageEnum.ContentStack.blocks.JoinScandicFriends: {
|
|
if (block.join_scandic_friends.primary_button) {
|
|
connections.push(block.join_scandic_friends.primary_button)
|
|
}
|
|
break
|
|
}
|
|
default: {
|
|
const _exhaustiveCheck: never = typeName
|
|
break
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
return connections
|
|
}
|