mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 17:35:23 +02:00
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:
co-authored by
Qwen-Coder
parent
3c199715b9
commit
579e96cf5d
@@ -190,8 +190,8 @@ const TopMovers: React.FC<TopMoversProps> = ({ data, stockMap, vendorStockMap, b
|
|||||||
const { currentYear, previousYear, availableYears } = useMemo(() => {
|
const { currentYear, previousYear, availableYears } = useMemo(() => {
|
||||||
const years = Array.from(new Set(data.map(d => d.year))).sort((a: number, b: number) => b - a);
|
const years = Array.from(new Set(data.map(d => d.year))).sort((a: number, b: number) => b - a);
|
||||||
return {
|
return {
|
||||||
currentYear: years[0],
|
currentYear: years[0] || null,
|
||||||
previousYear: years[1],
|
previousYear: years[1] || null,
|
||||||
availableYears: years
|
availableYears: years
|
||||||
};
|
};
|
||||||
}, [data]);
|
}, [data]);
|
||||||
@@ -263,7 +263,7 @@ const TopMovers: React.FC<TopMoversProps> = ({ data, stockMap, vendorStockMap, b
|
|||||||
|
|
||||||
}, [data, metric, currentYear, previousYear]);
|
}, [data, metric, currentYear, previousYear]);
|
||||||
|
|
||||||
if (availableYears.length < 2) {
|
if (availableYears.length < 2 || !currentYear || !previousYear) {
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col items-center justify-center h-96 bg-slate-900 rounded-xl border border-border p-8">
|
<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>
|
<h3 className="text-xl font-bold text-slate-300 mb-2">Insufficient Data for Comparison</h3>
|
||||||
|
|||||||
Reference in New Issue
Block a user