Skip to content

Commit

Permalink
🐛 Add a fallback image if the image path is broken for whatever reason
Browse files Browse the repository at this point in the history
Signed-off-by: ibolton336 <[email protected]>
  • Loading branch information
ibolton336 committed Sep 27, 2023
1 parent 9cf7840 commit 6e16089
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion client/src/app/components/TargetCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { KebabDropdown } from "./KebabDropdown";
import DefaultRulesetIcon from "@app/images/Icon-Red_Hat-Virtual_server_stack-A-Black-RGB.svg";
import { Target, TargetLabel } from "@app/api/models";
import "./TargetCard.css";
import { FILES } from "@app/api/rest";

export interface TargetCardProps {
item: Target;
Expand Down Expand Up @@ -108,14 +109,17 @@ export const TargetCard: React.FC<TargetCardProps> = ({
const getImage = (): React.ComponentType => {
let result: React.ComponentType<any> = CubesIcon;
const imagePath = target?.image?.id
? `/hub/files/${target?.image.id}`
? `${FILES}${target?.image.id}`

Check warning on line 112 in client/src/app/components/TargetCard.tsx

View check run for this annotation

Codecov / codecov/patch

client/src/app/components/TargetCard.tsx#L112

Added line #L112 was not covered by tests
: DefaultRulesetIcon;
if (target.image) {
result = () => (
<img
src={imagePath}
alt="Card logo"
style={{ height: 80, pointerEvents: "none" }}
onError={(e) => {
e.currentTarget.src = DefaultRulesetIcon;

Check warning on line 121 in client/src/app/components/TargetCard.tsx

View check run for this annotation

Codecov / codecov/patch

client/src/app/components/TargetCard.tsx#L120-L121

Added lines #L120 - L121 were not covered by tests
}}
/>
);
}
Expand Down

0 comments on commit 6e16089

Please sign in to comment.