@@ -10,7 +10,9 @@ import {
1010 FlexItem ,
1111 Title ,
1212} from "@patternfly/react-core" ;
13- import React from "react" ;
13+ import React , { useState } from "react" ;
14+
15+ import ErrorPlaceholder from "./ErrorPlaceholder" ;
1416
1517interface DataField {
1618 name : string ;
@@ -35,6 +37,29 @@ const OneCardWrapper: React.FC<OneCardProps> = ({
3537 imageSize = "md" ,
3638 className,
3739} ) => {
40+ const [ hasImageError , setHasImageError ] = useState ( false ) ;
41+
42+ const handleImageError = ( ) => {
43+ setHasImageError ( true ) ;
44+ } ;
45+
46+ // Check for missing or invalid data
47+ const hasNoFields = ! fields || fields . length === 0 ;
48+ const hasNoTitle = ! title || title . trim ( ) === "" ;
49+
50+ // If no title and no fields, show error
51+ if ( hasNoTitle && hasNoFields ) {
52+ return (
53+ < Card id = { id } className = { `onecard-component-container ${ className || '' } ` } >
54+ < CardBody >
55+ < ErrorPlaceholder
56+ hasError = { false }
57+ noContentMessage = "No content available"
58+ />
59+ </ CardBody >
60+ </ Card >
61+ ) ;
62+ }
3863
3964 return (
4065 < Card
@@ -44,15 +69,24 @@ const OneCardWrapper: React.FC<OneCardProps> = ({
4469 < CardBody >
4570 < Flex spaceItems = { { default : "spaceItemsLg" } } alignItems = { { default : "alignItemsFlexStart" } } >
4671 { /* Left Column - Image */ }
47- { image && (
72+ { image && ! hasImageError ? (
4873 < FlexItem className = { `onecard-component-image-container size-${ imageSize } ` } >
4974 < img
5075 src = { image }
5176 alt = { title }
5277 className = "onecard-component-img"
78+ onError = { handleImageError }
79+ />
80+ </ FlexItem >
81+ ) : image && hasImageError ? (
82+ < FlexItem className = { `onecard-component-image-container size-${ imageSize } ` } >
83+ < ErrorPlaceholder
84+ hasError = { true }
85+ errorMessage = "Image failed to load"
86+ noContentMessage = ""
5387 />
5488 </ FlexItem >
55- ) }
89+ ) : null }
5690
5791 { /* Right Column - Title + Fields */ }
5892 < FlexItem grow = { { default : "grow" } } >
@@ -61,18 +95,25 @@ const OneCardWrapper: React.FC<OneCardProps> = ({
6195 </ Title >
6296 < Divider component = "div" className = "onecard-component-divider" />
6397 < div >
64- < DescriptionList isAutoFit >
65- { fields ?. map ( ( field , idx ) => (
66- < DescriptionListGroup key = { idx } >
67- < DescriptionListTerm > { field . name } </ DescriptionListTerm >
68- < DescriptionListDescription >
69- { field . data . map ( ( item ) =>
70- item === null ? "N/A" : String ( item )
71- ) . join ( ", " ) }
72- </ DescriptionListDescription >
73- </ DescriptionListGroup >
74- ) ) }
75- </ DescriptionList >
98+ { hasNoFields ? (
99+ < ErrorPlaceholder
100+ hasError = { false }
101+ noContentMessage = "No data fields available"
102+ />
103+ ) : (
104+ < DescriptionList isAutoFit >
105+ { fields ?. map ( ( field , idx ) => (
106+ < DescriptionListGroup key = { idx } >
107+ < DescriptionListTerm > { field . name } </ DescriptionListTerm >
108+ < DescriptionListDescription >
109+ { field . data . map ( ( item ) =>
110+ item === null ? "N/A" : String ( item )
111+ ) . join ( ", " ) }
112+ </ DescriptionListDescription >
113+ </ DescriptionListGroup >
114+ ) ) }
115+ </ DescriptionList >
116+ ) }
76117 </ div >
77118 </ FlexItem >
78119 </ Flex >
0 commit comments