feat(SW-1818): Refactored sysAsset handling to support PDF links

Approved-by: Matilda Landström
This commit is contained in:
Erik Tiekstra
2025-06-09 09:28:17 +00:00
parent bff34b034e
commit ac953ccd97
23 changed files with 86 additions and 84 deletions

View File

@@ -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({

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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),
})

View File

@@ -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),
})

View File

@@ -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,
]),
})

View File

@@ -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(),

View File

@@ -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,
]),
})