From 16588c7f13df0fe5523504ee0b2cbfa711a4783b Mon Sep 17 00:00:00 2001 From: elcharitas Date: Tue, 9 Dec 2025 09:24:25 +0100 Subject: [PATCH] feat: Add support for image links --- .../frontend/src/api/utils/customDataUtils.tsx | 14 ++++++++++++++ .../src/components/image/ImageModule.tsx | 3 +++ .../src/components/image/ImageWidget.tsx | 15 ++++++++++++++- .../containers/image/OneColImageContainer.tsx | 17 +++++------------ .../containers/image/TwoColImageContainer.tsx | 17 +++++------------ 5 files changed, 41 insertions(+), 25 deletions(-) diff --git a/packages/frontend/src/api/utils/customDataUtils.tsx b/packages/frontend/src/api/utils/customDataUtils.tsx index 319d60979..3a43cf39e 100644 --- a/packages/frontend/src/api/utils/customDataUtils.tsx +++ b/packages/frontend/src/api/utils/customDataUtils.tsx @@ -741,3 +741,17 @@ export const customDataAsCardData: ( return undefined; } }; + +export const validateImageCustomData = ( + customData: TRemoteCustomData | undefined +): { imageUrl: string | undefined; imageLink: string | undefined } => { + let imageUrl = customData?.[0]?.image_url; + let imageLink = customData?.[0]?.image_link; + if (typeof imageUrl !== "string") { + imageUrl = undefined; + } + if (typeof imageLink !== "string") { + imageLink = undefined; + } + return { imageUrl, imageLink }; +}; diff --git a/packages/frontend/src/components/image/ImageModule.tsx b/packages/frontend/src/components/image/ImageModule.tsx index e81958b25..7d10cb2e3 100644 --- a/packages/frontend/src/components/image/ImageModule.tsx +++ b/packages/frontend/src/components/image/ImageModule.tsx @@ -4,6 +4,7 @@ import ImageWidget from "./ImageWidget"; interface IImageModule { imageUrl: string | undefined; + imageLink?: string; title: string; contentHeight?: string; isLoading: boolean; @@ -14,6 +15,7 @@ interface IImageModule { export const ImageModule: FC = ({ imageUrl, + imageLink, title, contentHeight, isLoading, @@ -36,6 +38,7 @@ export const ImageModule: FC = ({ > void; @@ -13,6 +14,7 @@ interface IImageWidget { const ImageWidget: FC = memo(function ImageWidget({ title, imageUrl, + imageLink, isLoading, showImage, onAspectRatioDetected, @@ -55,7 +57,18 @@ const ImageWidget: FC = memo(function ImageWidget({ } return ( -
+ // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions +
{ + if (imageLink) { + window.open(imageLink, "_blank"); + } + }} + style={{ cursor: imageLink ? "pointer" : "default" }} + role="banner" + > {imageLoading && } { - let imageUrl = customData?.[0]?.image_url; - if (typeof imageUrl !== "string") { - imageUrl = undefined; - } - return { imageUrl }; -}; - const OneColImageContainer: FC = ({ moduleData }) => { - const { imageUrl } = validateCustomData(moduleData.widget.custom_data); + const { imageUrl, imageLink } = validateImageCustomData( + moduleData.widget.custom_data + ); const contentHeight = useMemo(() => { return `${CONFIG.WIDGETS.ONE_COL_IMAGE.WIDGET_HEIGHT || 600}px`; @@ -26,6 +18,7 @@ const OneColImageContainer: FC = ({ moduleData }) => { }> { - let imageUrl = customData?.[0]?.image_url; - if (typeof imageUrl !== "string") { - imageUrl = undefined; - } - return { imageUrl }; -}; - const TwoColImageContainer: FC = ({ moduleData, onAspectRatioDetected, @@ -32,7 +22,9 @@ const TwoColImageContainer: FC = ({ number | null >(null); - const { imageUrl } = validateCustomData(moduleData.widget.custom_data); + const { imageUrl, imageLink } = validateImageCustomData( + moduleData.widget.custom_data + ); const previousImageUrl = useRef(imageUrl); if (previousImageUrl.current !== imageUrl) { @@ -75,6 +67,7 @@ const TwoColImageContainer: FC = ({ }>