Skip to content

Commit

Permalink
Fix: Prevent rendering null content when origin is missing (#2297)
Browse files Browse the repository at this point in the history
* Fix: Prevent rendering null content when origin is missing

This prevents the alert and bullets from being null when origin is missing, ensuring proper rendering

Reference: CV2-6130
  • Loading branch information
danielevalverde committed Feb 13, 2025
1 parent a598541 commit 5e56b32
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/app/components/media/MediaOrigin.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ const getIconAndMessage = (origin, user) => {

const MediaOrigin = ({ projectMedia }) => {
const { media_cluster_origin: origin, media_cluster_origin_user: user } = projectMedia;

// We check for `origin == null` (instead of `!origin`) because TIPLINE_SUBMITTED is 0,
// which would evaluate as falsy in a `!origin` check. Using `== null` ensures we only
// fallback when `origin` is `null` , not when it's `0`.
if (origin == null) {
return null;
}

const { icon, message, tooltipMessage } = getIconAndMessage(origin, user?.name);

return (
Expand Down
8 changes: 8 additions & 0 deletions src/app/components/media/MediaOriginBanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ const MediaOriginBanner = ({ projectMedia }) => {
media_cluster_origin_user: user,
media_cluster_relationship: mediaClusterRelationship,
} = projectMedia;

// We check for `origin == null` (instead of `!origin`) because TIPLINE_SUBMITTED is 0,
// which would evaluate as falsy in a `!origin` check. Using `== null` ensures we only
// fallback when `origin` is `null` , not when it's `0`.
if (origin == null) {
return null;
}

const { icon, message } = getIconAndMessage(origin, mediaClusterRelationship, user?.name, originTimestamp);
return (
<div style={{ marginBottom: '8px' }}>
Expand Down
11 changes: 8 additions & 3 deletions src/app/components/media/Similarity/MediaRelationship.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,11 @@ const MediaRelationship = ({
variant="text"
/>
), (
<MediaOrigin
projectMedia={relationship?.target}
/>
relationship?.target.media_cluster_origin_user?.name ? (
<MediaOrigin
projectMedia={relationship?.target}
/>
) : null
)];

const maskContent = relationship?.target?.show_warning_cover;
Expand Down Expand Up @@ -386,6 +388,9 @@ export default createFragmentContainer(withSetFlashMessage(injectIntl(MediaRelat
quote
imported_from_feed_id
requests_count
media_cluster_origin_user {
name
}
media {
...SmallMediaCard_media
}
Expand Down

0 comments on commit 5e56b32

Please sign in to comment.