Merged in feat/SW-327-pdf-support (pull request #1276)

feat(SW-327): added support to link to pdf files from CS

* feat(SW-327): added support to link to pdf files from CS


Approved-by: Matilda Landström
This commit is contained in:
Erik Tiekstra
2025-02-10 07:26:56 +00:00
parent 8b47749508
commit ce445e3f0b
4 changed files with 62 additions and 26 deletions
+52 -21
View File
@@ -2,6 +2,7 @@ import Image from "@/components/Image"
import Link from "@/components/TempDesignSystem/Link"
import { insertResponseToImageVaultAsset } from "@/utils/imageVault"
import { OpenInNewSmallIcon } from "../Icons"
import ImageContainer from "../ImageContainer"
import Divider from "../TempDesignSystem/Divider"
import Table from "../TempDesignSystem/Table"
@@ -341,25 +342,49 @@ export const renderOptions: RenderOptions = {
if ("attrs" in node) {
const type = node.attrs.type
if (type === RTEItemTypeEnum.asset) {
const image = embeds?.[node?.attrs?.["asset-uid"]]
if (image?.node.__typename === ContentEnum.blocks.SysAsset) {
if (image.node.url) {
const alt = image?.node?.title ?? node.attrs.alt
const props = extractPossibleAttributes(node.attrs)
props.className = styles.image
return (
<div className={styles.imageContainer}>
<Image
alt={alt}
className={styles.image}
src={image.node.url}
fill
sizes="(min-width: 1367px) 800px, (max-width: 1366px) and (min-width: 1200px) 1200px, 100vw"
{...props}
/>
</div>
)
const imageTypeRegex = /^image\//
const isImage = imageTypeRegex.test(node.attrs["asset-type"])
if (isImage) {
const image = embeds?.[node?.attrs?.["asset-uid"]]
if (image?.node.__typename === ContentEnum.blocks.SysAsset) {
if (image.node.url) {
const alt = image?.node?.title ?? node.attrs.alt
const props = extractPossibleAttributes(node.attrs)
props.className = styles.image
return (
<div className={styles.imageContainer}>
<Image
alt={alt}
className={styles.image}
src={image.node.url}
fill
sizes="(min-width: 1367px) 800px, (max-width: 1366px) and (min-width: 1200px) 1200px, 100vw"
{...props}
/>
</div>
)
}
}
} else if (node.attrs["display-type"] === "link" && node.attrs.href) {
return (
<Link
href={node.attrs.href}
key={node.uid}
variant="icon"
textDecoration="underline"
color="burgundy"
target="_blank"
>
{next(
// Sometimes editors happen to nest a reference inside a link and vice versa.
// In that case use the outermost link, i.e. ignore nested links.
node.children.flatMap(noNestedLinksOrReferences),
embeds,
fullRenderOptions
)}
<OpenInNewSmallIcon color="burgundy" />
</Link>
)
}
} else if (type === RTEItemTypeEnum.entry) {
const entry = embeds?.[node?.attrs?.["entry-uid"]]
@@ -375,11 +400,17 @@ export const renderOptions: RenderOptions = {
}
return null
} else if (
entry?.node.__typename === ContentEnum.blocks.LoyaltyPage ||
entry?.node.__typename === ContentEnum.blocks.ContentPage ||
entry?.node.__typename === ContentEnum.blocks.AccountPage ||
entry?.node.__typename === ContentEnum.blocks.CollectionPage ||
entry?.node.__typename === ContentEnum.blocks.HotelPage
entry?.node.__typename === ContentEnum.blocks.ContentPage ||
entry?.node.__typename === ContentEnum.blocks.DestinationCityPage ||
entry?.node.__typename ===
ContentEnum.blocks.DestinationCountryPage ||
entry?.node.__typename ===
ContentEnum.blocks.DestinationOverviewPage ||
entry?.node.__typename === ContentEnum.blocks.HotelPage ||
entry?.node.__typename === ContentEnum.blocks.LoyaltyPage ||
entry?.node.__typename === ContentEnum.blocks.StartPage
) {
// If entry is not an ImageContainer, it is a page and we return it as a link
const props = extractPossibleAttributes(node.attrs)