Merged in feat/rework-contentstack (pull request #3493)
Feat(SW-3708): refactor contentstack fetching (removing all refs) and cache invalidation * Remove all REFS * Revalidate correct language * PR fixes * PR fixes * Throw when errors from contentstack api Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -1,8 +1,3 @@
|
||||
import type { z } from "zod"
|
||||
|
||||
import type { AssetSystem, System } from "../schemas/system"
|
||||
import type { startPageRefsSchema } from "./output"
|
||||
|
||||
export namespace StartPageEnum {
|
||||
export namespace ContentStack {
|
||||
export const enum blocks {
|
||||
@@ -14,60 +9,3 @@ export namespace StartPageEnum {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export interface StartPageRefs extends z.output<typeof startPageRefsSchema> {}
|
||||
|
||||
export function getConnections({ start_page }: StartPageRefs) {
|
||||
const connections: System["system"][] = [start_page.system]
|
||||
const assetConnections: AssetSystem[] = []
|
||||
|
||||
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
|
||||
case StartPageEnum.ContentStack.blocks.VideoCard: {
|
||||
if (block.video_card?.system) {
|
||||
connections.push(block.video_card.system)
|
||||
}
|
||||
if (block.video_card?.video.sourceConnection.edges[0]) {
|
||||
assetConnections.push(
|
||||
block.video_card.video.sourceConnection.edges[0].node
|
||||
)
|
||||
}
|
||||
break
|
||||
}
|
||||
default:
|
||||
const _exhaustiveCheck: never = typeName
|
||||
break
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return { connections, assetConnections }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user