Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix preview image #5153

Merged
merged 6 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/5153.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed PreviewImage component to work as Image component when testing image, and added show_default prop to PreviewImage
21 changes: 16 additions & 5 deletions src/components/theme/PreviewImage/PreviewImage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@ import DefaultImageSVG from '@plone/volto/components/manage/Blocks/Listing/defau
/**
* Renders a preview image for a catalog brain result item.
*/
function PreviewImage({ item, alt, ...rest }) {
function PreviewImage({
item,
alt,
image_field,
show_default = true,
giuliaghisini marked this conversation as resolved.
Show resolved Hide resolved
...rest
}) {
const Image = config.getComponent({ name: 'Image' }).component;

if (item.image_field && item.image_scales?.[item.image_field]?.[0]) {
return (
<Image item={item} imageField={item.image_field} alt={alt} {...rest} />
);
const image = (
<Image item={item} image_field={image_field} alt={alt} {...rest} />
);

if (!image && !show_default) return null;

if (image) {
return image;
} else {
return (
<img
Expand All @@ -38,6 +48,7 @@ PreviewImage.propTypes = {
title: PropTypes.string.isRequired,
image_field: PropTypes.string,
image_scales: PropTypes.object,
show_default: PropTypes.bool,
}),
alt: PropTypes.string.isRequired,
};
Expand Down