From ac953ccd97e8cf645e5a19d0e1bf5a529a777068 Mon Sep 17 00:00:00 2001 From: Erik Tiekstra Date: Mon, 9 Jun 2025 09:28:17 +0000 Subject: [PATCH] feat(SW-1818): Refactored sysAsset handling to support PDF links MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Approved-by: Matilda Landström --- .../components/JsonToHtml/renderOptions.tsx | 6 +--- .../Fragments/Blocks/Accordion.graphql | 12 +++---- .../graphql/Fragments/Blocks/Content.graphql | 6 ++-- .../lib/graphql/Fragments/Blocks/Text.graphql | 4 +-- .../Fragments/Blocks/TextContent.graphql | 4 +-- .../CurrentFooter/AppDownloads.graphql | 6 ++-- .../Fragments/CurrentFooter/Logo.graphql | 4 +-- .../CurrentFooter/TripAdvisor.graphql | 4 +-- .../lib/graphql/Fragments/Hero.graphql | 4 +-- .../lib/graphql/Fragments/Preamble.graphql | 4 +-- .../lib/graphql/Fragments/Puff.graphql | 4 +-- .../graphql/Fragments/Sidebar/Content.graphql | 6 ++-- .../{Image.graphql => SysAsset.graphql} | 2 +- .../lib/graphql/Query/Current/Header.graphql | 4 +-- .../contentstack/schemas/blocks/accordion.ts | 4 +-- .../schemas/blocks/cards/teaserCard.ts | 4 +-- .../contentstack/schemas/blocks/content.ts | 6 ++-- .../schemas/blocks/contentEmbeds.ts | 4 +-- .../contentstack/schemas/blocks/image.ts | 30 ---------------- .../contentstack/schemas/blocks/sysAsset.ts | 36 +++++++++++++++++++ .../contentstack/schemas/blocks/textCols.ts | 6 ++-- .../schemas/blocks/textContent.ts | 4 +-- .../contentstack/schemas/sidebar/content.ts | 6 ++-- 23 files changed, 86 insertions(+), 84 deletions(-) rename apps/scandic-web/lib/graphql/Fragments/{Image.graphql => SysAsset.graphql} (78%) delete mode 100644 apps/scandic-web/server/routers/contentstack/schemas/blocks/image.ts create mode 100644 apps/scandic-web/server/routers/contentstack/schemas/blocks/sysAsset.ts diff --git a/apps/scandic-web/components/JsonToHtml/renderOptions.tsx b/apps/scandic-web/components/JsonToHtml/renderOptions.tsx index 8f1080509..2ec90aab4 100644 --- a/apps/scandic-web/components/JsonToHtml/renderOptions.tsx +++ b/apps/scandic-web/components/JsonToHtml/renderOptions.tsx @@ -429,11 +429,7 @@ export const renderOptions: RenderOptions = { embeds, fullRenderOptions )} - + ) } diff --git a/apps/scandic-web/lib/graphql/Fragments/Blocks/Accordion.graphql b/apps/scandic-web/lib/graphql/Fragments/Blocks/Accordion.graphql index 619124266..4b08d8f7a 100644 --- a/apps/scandic-web/lib/graphql/Fragments/Blocks/Accordion.graphql +++ b/apps/scandic-web/lib/graphql/Fragments/Blocks/Accordion.graphql @@ -1,4 +1,4 @@ -#import "../Image.graphql" +#import "../SysAsset.graphql" #import "../PageLink/AccountPageLink.graphql" #import "../PageLink/CollectionPageLink.graphql" @@ -33,7 +33,7 @@ fragment AccordionBlock on Accordion { edges { node { __typename - ...Image + ...SysAsset ...AccountPageLink ...CollectionPageLink ...ContentPageLink @@ -60,7 +60,7 @@ fragment GlobalAccordionBlock on GlobalAccordion { edges { node { __typename - ...Image + ...SysAsset ...AccountPageLink ...CollectionPageLink ...ContentPageLink @@ -113,7 +113,7 @@ fragment SpecificAccordion_ContentPage on ContentPageBlocksAccordionBlockAccordi edges { node { __typename - ...Image + ...SysAsset ...AccountPageLink ...CollectionPageLink ...ContentPageLink @@ -214,7 +214,7 @@ fragment SpecificAccordion_DestinationCityPage on DestinationCityPageBlocksAccor edges { node { __typename - ...Image + ...SysAsset ...AccountPageLink ...CollectionPageLink ...ContentPageLink @@ -315,7 +315,7 @@ fragment SpecificAccordion_DestinationCountryPage on DestinationCountryPageBlock edges { node { __typename - ...Image + ...SysAsset ...AccountPageLink ...CollectionPageLink ...ContentPageLink diff --git a/apps/scandic-web/lib/graphql/Fragments/Blocks/Content.graphql b/apps/scandic-web/lib/graphql/Fragments/Blocks/Content.graphql index e36ea7b21..6f17ed4a9 100644 --- a/apps/scandic-web/lib/graphql/Fragments/Blocks/Content.graphql +++ b/apps/scandic-web/lib/graphql/Fragments/Blocks/Content.graphql @@ -1,4 +1,4 @@ -#import "../Image.graphql" +#import "../SysAsset.graphql" #import "../ImageContainer.graphql" #import "../PageLink/AccountPageLink.graphql" @@ -28,7 +28,7 @@ fragment Content_ContentPage on ContentPageBlocksContent { edges { node { __typename - ...Image + ...SysAsset ...ImageContainer ...AccountPageLink ...CollectionPageLink @@ -78,7 +78,7 @@ fragment Content_LoyaltyPage on LoyaltyPageBlocksContent { edges { node { __typename - ...Image + ...SysAsset ...ImageContainer ...AccountPageLink ...CollectionPageLink diff --git a/apps/scandic-web/lib/graphql/Fragments/Blocks/Text.graphql b/apps/scandic-web/lib/graphql/Fragments/Blocks/Text.graphql index 25e39b0cb..5172145b8 100644 --- a/apps/scandic-web/lib/graphql/Fragments/Blocks/Text.graphql +++ b/apps/scandic-web/lib/graphql/Fragments/Blocks/Text.graphql @@ -1,4 +1,4 @@ -#import "../Image.graphql" +#import "../SysAsset.graphql" fragment TextBlock on CurrentBlocksPageBlocksText { text { @@ -8,7 +8,7 @@ fragment TextBlock on CurrentBlocksPageBlocksText { edges { node { __typename - ...Image + ...SysAsset } } } diff --git a/apps/scandic-web/lib/graphql/Fragments/Blocks/TextContent.graphql b/apps/scandic-web/lib/graphql/Fragments/Blocks/TextContent.graphql index 2aac6d1b5..5da55815b 100644 --- a/apps/scandic-web/lib/graphql/Fragments/Blocks/TextContent.graphql +++ b/apps/scandic-web/lib/graphql/Fragments/Blocks/TextContent.graphql @@ -1,4 +1,4 @@ -#import "../Image.graphql" +#import "../SysAsset.graphql" fragment TextContent_AccountPage on AccountPageContentTextContent { text_content { @@ -9,7 +9,7 @@ fragment TextContent_AccountPage on AccountPageContentTextContent { edges { node { __typename - ...Image + ...SysAsset } } } diff --git a/apps/scandic-web/lib/graphql/Fragments/CurrentFooter/AppDownloads.graphql b/apps/scandic-web/lib/graphql/Fragments/CurrentFooter/AppDownloads.graphql index efac1cc31..745f68728 100644 --- a/apps/scandic-web/lib/graphql/Fragments/CurrentFooter/AppDownloads.graphql +++ b/apps/scandic-web/lib/graphql/Fragments/CurrentFooter/AppDownloads.graphql @@ -1,4 +1,4 @@ -#import "../Image.graphql" +#import "../SysAsset.graphql" fragment CurrentFooterAppDownloads on CurrentFooter { app_downloads { @@ -8,7 +8,7 @@ fragment CurrentFooterAppDownloads on CurrentFooter { imageConnection { edges { node { - ...Image + ...SysAsset } } } @@ -18,7 +18,7 @@ fragment CurrentFooterAppDownloads on CurrentFooter { imageConnection { edges { node { - ...Image + ...SysAsset } } } diff --git a/apps/scandic-web/lib/graphql/Fragments/CurrentFooter/Logo.graphql b/apps/scandic-web/lib/graphql/Fragments/CurrentFooter/Logo.graphql index cf18b5923..e4781cd60 100644 --- a/apps/scandic-web/lib/graphql/Fragments/CurrentFooter/Logo.graphql +++ b/apps/scandic-web/lib/graphql/Fragments/CurrentFooter/Logo.graphql @@ -1,10 +1,10 @@ -#import "../Image.graphql" +#import "../SysAsset.graphql" fragment Logo on CurrentFooter { logoConnection { edges { node { - ...Image + ...SysAsset } } } diff --git a/apps/scandic-web/lib/graphql/Fragments/CurrentFooter/TripAdvisor.graphql b/apps/scandic-web/lib/graphql/Fragments/CurrentFooter/TripAdvisor.graphql index 05818e1bd..bee84de7e 100644 --- a/apps/scandic-web/lib/graphql/Fragments/CurrentFooter/TripAdvisor.graphql +++ b/apps/scandic-web/lib/graphql/Fragments/CurrentFooter/TripAdvisor.graphql @@ -1,11 +1,11 @@ -#import "../Image.graphql" +#import "../SysAsset.graphql" fragment TripAdvisor on CurrentFooter { trip_advisor { logoConnection { edges { node { - ...Image + ...SysAsset } } } diff --git a/apps/scandic-web/lib/graphql/Fragments/Hero.graphql b/apps/scandic-web/lib/graphql/Fragments/Hero.graphql index a232e4bc0..5424b6ce2 100644 --- a/apps/scandic-web/lib/graphql/Fragments/Hero.graphql +++ b/apps/scandic-web/lib/graphql/Fragments/Hero.graphql @@ -1,11 +1,11 @@ -#import "./Image.graphql" +#import "./SysAsset.graphql" fragment Hero on Hero { imagesConnection { totalCount edges { node { - ...Image + ...SysAsset } } } diff --git a/apps/scandic-web/lib/graphql/Fragments/Preamble.graphql b/apps/scandic-web/lib/graphql/Fragments/Preamble.graphql index a02586296..215919ff5 100644 --- a/apps/scandic-web/lib/graphql/Fragments/Preamble.graphql +++ b/apps/scandic-web/lib/graphql/Fragments/Preamble.graphql @@ -1,4 +1,4 @@ -#import "./Image.graphql" +#import "./SysAsset.graphql" fragment Preamble on CurrentBlocksPage { preamble { @@ -8,7 +8,7 @@ fragment Preamble on CurrentBlocksPage { edges { node { __typename - ...Image + ...SysAsset } } } diff --git a/apps/scandic-web/lib/graphql/Fragments/Puff.graphql b/apps/scandic-web/lib/graphql/Fragments/Puff.graphql index c28a46358..05276c051 100644 --- a/apps/scandic-web/lib/graphql/Fragments/Puff.graphql +++ b/apps/scandic-web/lib/graphql/Fragments/Puff.graphql @@ -1,10 +1,10 @@ -#import "./Image.graphql" +#import "./SysAsset.graphql" fragment Puff on Puff { imageConnection { edges { node { - ...Image + ...SysAsset } } } diff --git a/apps/scandic-web/lib/graphql/Fragments/Sidebar/Content.graphql b/apps/scandic-web/lib/graphql/Fragments/Sidebar/Content.graphql index a2fe10478..61df8d784 100644 --- a/apps/scandic-web/lib/graphql/Fragments/Sidebar/Content.graphql +++ b/apps/scandic-web/lib/graphql/Fragments/Sidebar/Content.graphql @@ -1,4 +1,4 @@ -#import "../Image.graphql" +#import "../SysAsset.graphql" #import "../ImageContainer.graphql" #import "../PageLink/AccountPageLink.graphql" @@ -29,7 +29,7 @@ fragment ContentSidebar_ContentPage on ContentPageSidebarContent { edges { node { __typename - ...Image + ...SysAsset ...ImageContainer ...AccountPageLink ...CollectionPageLink @@ -79,7 +79,7 @@ fragment ContentSidebar_LoyaltyPage on LoyaltyPageSidebarContent { edges { node { __typename - ...Image + ...SysAsset ...ImageContainer ...AccountPageLink ...CollectionPageLink diff --git a/apps/scandic-web/lib/graphql/Fragments/Image.graphql b/apps/scandic-web/lib/graphql/Fragments/SysAsset.graphql similarity index 78% rename from apps/scandic-web/lib/graphql/Fragments/Image.graphql rename to apps/scandic-web/lib/graphql/Fragments/SysAsset.graphql index 5e9271a90..499e05778 100644 --- a/apps/scandic-web/lib/graphql/Fragments/Image.graphql +++ b/apps/scandic-web/lib/graphql/Fragments/SysAsset.graphql @@ -1,4 +1,4 @@ -fragment Image on SysAsset { +fragment SysAsset on SysAsset { content_type description dimension { diff --git a/apps/scandic-web/lib/graphql/Query/Current/Header.graphql b/apps/scandic-web/lib/graphql/Query/Current/Header.graphql index dfced2ba3..21d1b4aa7 100644 --- a/apps/scandic-web/lib/graphql/Query/Current/Header.graphql +++ b/apps/scandic-web/lib/graphql/Query/Current/Header.graphql @@ -1,4 +1,4 @@ -#import "../../Fragments/Image.graphql" +#import "../../Fragments/SysAsset.graphql" #import "../../Fragments/System.graphql" query GetCurrentHeader($locale: String!) { @@ -8,7 +8,7 @@ query GetCurrentHeader($locale: String!) { logoConnection { edges { node { - ...Image + ...SysAsset } } } diff --git a/apps/scandic-web/server/routers/contentstack/schemas/blocks/accordion.ts b/apps/scandic-web/server/routers/contentstack/schemas/blocks/accordion.ts index f5e84da59..2daacfb31 100644 --- a/apps/scandic-web/server/routers/contentstack/schemas/blocks/accordion.ts +++ b/apps/scandic-web/server/routers/contentstack/schemas/blocks/accordion.ts @@ -5,11 +5,11 @@ import { linkUnionSchema, transformPageLink, } from "../pageLinks" -import { imageSchema } from "./image" +import { sysAssetSchema } from "./sysAsset" import { BlocksEnums } from "@/types/enums/blocks" -export const embeddedContentSchema = z.union([linkUnionSchema, imageSchema]) +export const embeddedContentSchema = z.union([linkUnionSchema, sysAssetSchema]) export const accordionItemsSchema = z.array( z.object({ diff --git a/apps/scandic-web/server/routers/contentstack/schemas/blocks/cards/teaserCard.ts b/apps/scandic-web/server/routers/contentstack/schemas/blocks/cards/teaserCard.ts index 2519e9a2f..128d0f1a2 100644 --- a/apps/scandic-web/server/routers/contentstack/schemas/blocks/cards/teaserCard.ts +++ b/apps/scandic-web/server/routers/contentstack/schemas/blocks/cards/teaserCard.ts @@ -14,8 +14,8 @@ import { transformPageLink, } from "../../pageLinks" import { systemSchema } from "../../system" -import { imageSchema } from "../image" import { imageContainerSchema } from "../imageContainer" +import { sysAssetSchema } from "../sysAsset" import { buttonSchema } from "../utils/buttonLinkSchema" import { linkConnectionRefsSchema } from "../utils/linkConnection" @@ -47,7 +47,7 @@ export const teaserCardBlockSchema = z.object({ node: z .discriminatedUnion("__typename", [ imageContainerSchema, - imageSchema, + sysAssetSchema, accountPageSchema, collectionPageSchema, contentPageSchema, diff --git a/apps/scandic-web/server/routers/contentstack/schemas/blocks/content.ts b/apps/scandic-web/server/routers/contentstack/schemas/blocks/content.ts index 1ee078b35..fdd451054 100644 --- a/apps/scandic-web/server/routers/contentstack/schemas/blocks/content.ts +++ b/apps/scandic-web/server/routers/contentstack/schemas/blocks/content.ts @@ -12,11 +12,11 @@ import { startPageSchema, transformPageLink, } from "../pageLinks" -import { imageRefsSchema, imageSchema } from "./image" import { imageContainerRefsSchema, imageContainerSchema, } from "./imageContainer" +import { sysAssetRefsSchema, sysAssetSchema } from "./sysAsset" import { BlocksEnums } from "@/types/enums/blocks" import { ContentEnum } from "@/types/enums/content" @@ -36,7 +36,7 @@ export const contentSchema = z.object({ node: z .discriminatedUnion("__typename", [ imageContainerSchema, - imageSchema, + sysAssetSchema, accountPageSchema, collectionPageSchema, contentPageSchema, @@ -72,7 +72,7 @@ export const contentRefsSchema = z.object({ edges: z.array( z.object({ node: z.discriminatedUnion("__typename", [ - imageRefsSchema, + sysAssetRefsSchema, imageContainerRefsSchema, accountPageSchema, collectionPageSchema, diff --git a/apps/scandic-web/server/routers/contentstack/schemas/blocks/contentEmbeds.ts b/apps/scandic-web/server/routers/contentstack/schemas/blocks/contentEmbeds.ts index eed8f4765..49ab70d5f 100644 --- a/apps/scandic-web/server/routers/contentstack/schemas/blocks/contentEmbeds.ts +++ b/apps/scandic-web/server/routers/contentstack/schemas/blocks/contentEmbeds.ts @@ -12,13 +12,13 @@ import { startPageSchema, transformPageLink, } from "../pageLinks" -import { imageSchema } from "./image" import { imageContainerSchema } from "./imageContainer" +import { sysAssetSchema } from "./sysAsset" export const contentEmbedsSchema = z .discriminatedUnion("__typename", [ imageContainerSchema, - imageSchema, + sysAssetSchema, accountPageSchema, collectionPageSchema, contentPageSchema, diff --git a/apps/scandic-web/server/routers/contentstack/schemas/blocks/image.ts b/apps/scandic-web/server/routers/contentstack/schemas/blocks/image.ts deleted file mode 100644 index 113564a46..000000000 --- a/apps/scandic-web/server/routers/contentstack/schemas/blocks/image.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { z } from "zod" - -import { ContentEnum } from "@/types/enums/content" - -export const imageSchema = z.object({ - __typename: z.literal(ContentEnum.blocks.SysAsset), - content_type: z.string(), - description: z.string().nullable().optional(), - dimension: z - .object({ - height: z.number(), - width: z.number(), - }) - .nullable(), - metadata: z.any(), // JSON - // system for SysAssets is not the same type - // as for all other types eventhough they have - // the exact same structure, that's why systemSchema - // is not used as that correlates to the - // EntrySystemField type - system: z.object({ - uid: z.string(), - }), - title: z.string().optional(), - url: z.string().optional(), -}) - -export const imageRefsSchema = z.object({ - __typename: z.literal(ContentEnum.blocks.SysAsset), -}) diff --git a/apps/scandic-web/server/routers/contentstack/schemas/blocks/sysAsset.ts b/apps/scandic-web/server/routers/contentstack/schemas/blocks/sysAsset.ts new file mode 100644 index 000000000..dbd3ad791 --- /dev/null +++ b/apps/scandic-web/server/routers/contentstack/schemas/blocks/sysAsset.ts @@ -0,0 +1,36 @@ +import { z } from "zod" + +import { ContentEnum } from "@/types/enums/content" + +// SysAsset is used for several different assets in ContentStack, such as images, pdf-files, etc. +// It is a generic asset type that can represent any file type. +// A lot of the fields are optional/nullable, hence the use of `.nullish()`. +// The properties of this schema should be handled inside the components that use it, fe. web/apps/scandic-web/components/JsonToHtml/renderOptions.tsx. +export const sysAssetSchema = z.object({ + __typename: z.literal(ContentEnum.blocks.SysAsset), + content_type: z.string().nullish(), + description: z.string().nullish(), + dimension: z + .object({ + height: z.number(), + width: z.number(), + }) + .nullish(), + metadata: z.any(), // JSON + // system for SysAssets is not the same type + // as for all other types eventhough they have + // the exact same structure, that's why systemSchema + // is not used as that correlates to the + // EntrySystemField type + system: z + .object({ + uid: z.string(), + }) + .nullish(), + title: z.string().nullish(), + url: z.string().nullish(), +}) + +export const sysAssetRefsSchema = z.object({ + __typename: z.literal(ContentEnum.blocks.SysAsset), +}) diff --git a/apps/scandic-web/server/routers/contentstack/schemas/blocks/textCols.ts b/apps/scandic-web/server/routers/contentstack/schemas/blocks/textCols.ts index 0964a96ba..099497f17 100644 --- a/apps/scandic-web/server/routers/contentstack/schemas/blocks/textCols.ts +++ b/apps/scandic-web/server/routers/contentstack/schemas/blocks/textCols.ts @@ -5,7 +5,7 @@ import { linkUnionSchema, transformPageLink, } from "../pageLinks" -import { imageRefsSchema, imageSchema } from "./image" +import { sysAssetRefsSchema, sysAssetSchema } from "./sysAsset" import { BlocksEnums } from "@/types/enums/blocks" import { ContentEnum } from "@/types/enums/content" @@ -26,7 +26,7 @@ export const textColsSchema = z.object({ z.object({ node: z .discriminatedUnion("__typename", [ - imageSchema, + sysAssetSchema, ...linkUnionSchema.options, ]) .transform((data) => { @@ -59,7 +59,7 @@ export const textColsRefsSchema = z.object({ edges: z.array( z.object({ node: z.discriminatedUnion("__typename", [ - imageRefsSchema, + sysAssetRefsSchema, ...linkRefsUnionSchema.options, ]), }) diff --git a/apps/scandic-web/server/routers/contentstack/schemas/blocks/textContent.ts b/apps/scandic-web/server/routers/contentstack/schemas/blocks/textContent.ts index 39eccdb07..27ec6e1f9 100644 --- a/apps/scandic-web/server/routers/contentstack/schemas/blocks/textContent.ts +++ b/apps/scandic-web/server/routers/contentstack/schemas/blocks/textContent.ts @@ -1,6 +1,6 @@ import { z } from "zod" -import { imageSchema } from "./image" +import { sysAssetSchema } from "./sysAsset" import { BlocksEnums } from "@/types/enums/blocks" @@ -15,7 +15,7 @@ export const textContentSchema = z.object({ embedded_itemsConnection: z.object({ edges: z.array( z.object({ - node: z.discriminatedUnion("__typename", [imageSchema]), + node: z.discriminatedUnion("__typename", [sysAssetSchema]), }) ), totalCount: z.number(), diff --git a/apps/scandic-web/server/routers/contentstack/schemas/sidebar/content.ts b/apps/scandic-web/server/routers/contentstack/schemas/sidebar/content.ts index 186c9bc27..9d287d5f0 100644 --- a/apps/scandic-web/server/routers/contentstack/schemas/sidebar/content.ts +++ b/apps/scandic-web/server/routers/contentstack/schemas/sidebar/content.ts @@ -1,10 +1,10 @@ import { z } from "zod" -import { imageRefsSchema, imageSchema } from "../blocks/image" import { imageContainerRefsSchema, imageContainerSchema, } from "../blocks/imageContainer" +import { sysAssetRefsSchema, sysAssetSchema } from "../blocks/sysAsset" import { linkRefsUnionSchema, linkUnionSchema, @@ -29,7 +29,7 @@ export const contentSchema = z.object({ node: z .discriminatedUnion("__typename", [ imageContainerSchema, - imageSchema, + sysAssetSchema, ...linkUnionSchema.options, ]) .transform((data) => { @@ -70,7 +70,7 @@ export const contentRefsSchema = z.object({ edges: z.array( z.object({ node: z.discriminatedUnion("__typename", [ - imageRefsSchema, + sysAssetRefsSchema, ...actualRefs.options, ]), })