fix: add null safety checks for years in TopMovers

- Add || null to years array access to prevent undefined values
- Add !currentYear || !previousYear to insufficient data check
- This prevents errors when filtered data has less than 2 years

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
Christian Vidal Wolf
2026-03-16 15:12:10 +01:00
co-authored by Qwen-Coder
parent 3c199715b9
commit 579e96cf5d
+3 -3
View File
@@ -190,8 +190,8 @@ const TopMovers: React.FC<TopMoversProps> = ({ data, stockMap, vendorStockMap, b
const { currentYear, previousYear, availableYears } = useMemo(() => {
const years = Array.from(new Set(data.map(d => d.year))).sort((a: number, b: number) => b - a);
return {
currentYear: years[0],
previousYear: years[1],
currentYear: years[0] || null,
previousYear: years[1] || null,
availableYears: years
};
}, [data]);
@@ -263,7 +263,7 @@ const TopMovers: React.FC<TopMoversProps> = ({ data, stockMap, vendorStockMap, b
}, [data, metric, currentYear, previousYear]);
if (availableYears.length < 2) {
if (availableYears.length < 2 || !currentYear || !previousYear) {
return (
<div className="flex flex-col items-center justify-center h-96 bg-slate-900 rounded-xl border border-border p-8">
<h3 className="text-xl font-bold text-slate-300 mb-2">Insufficient Data for Comparison</h3>