diff --git a/packages/app/src/domain/behavior/behavior-per-age-group-tile.tsx b/packages/app/src/domain/behavior/behavior-per-age-group-tile.tsx index 242ea8433d..807b63d523 100644 --- a/packages/app/src/domain/behavior/behavior-per-age-group-tile.tsx +++ b/packages/app/src/domain/behavior/behavior-per-age-group-tile.tsx @@ -39,8 +39,10 @@ export function BehaviorPerAgeGroup({ }: BehaviorPerAgeGroupProps) { const breakpoints = useBreakpoints(); - const complianceValue = data[`${currentId}_compliance` as keyof typeof data]; - const supportValue = data[`${currentId}_support` as keyof typeof data]; + const complianceValue = + data[`${currentId}_compliance` as keyof typeof data] || undefined; + const supportValue = + data[`${currentId}_support` as keyof typeof data] || undefined; assert( typeof complianceValue !== 'number', @@ -52,9 +54,11 @@ export function BehaviorPerAgeGroup({ ); const hasComplianceValues = + complianceValue && keys(complianceValue).every((key) => complianceValue[key] === null) === - false; + false; const hasSupportValues = + supportValue && keys(supportValue).every((key) => supportValue[key] === null) === false; const dataAvailable = hasComplianceValues || hasSupportValues; @@ -85,41 +89,42 @@ export function BehaviorPerAgeGroup({ - {AGE_KEYS.map((age, index) => ( - - {(isPresent(complianceValue[age]) || - isPresent(supportValue[age])) && ( - - {text.shared.leeftijden.tabel[age]} - - {isPresent(complianceValue[age]) ? ( - - ) : ( - - { - text.shared.leeftijden.tabel - .compliance_no_data - } - - )} - {isPresent(supportValue[age]) ? ( - - ) : ( - - {text.shared.leeftijden.tabel.support_no_data} - - )} - - - )} - - ))} + {AGE_KEYS.map((age, index) => { + const ageValueCompliance = complianceValue?.[age]; + const ageValueSupport = supportValue?.[age]; + + if (!ageValueCompliance && !ageValueSupport) { + return null; + } + + return ( + + {text.shared.leeftijden.tabel[age]} + + {ageValueCompliance ? ( + + ) : ( + + {text.shared.leeftijden.tabel.compliance_no_data} + + )} + {ageValueSupport ? ( + + ) : ( + + {text.shared.leeftijden.tabel.support_no_data} + + )} + + + ); + })}