({ field, startDate, endDate, compact = false, gradientIdSuffix = "" }: FieldComparisonColumnProps)
| 77 | gradientIdSuffix?: string; |
| 78 | } |
| 79 | |
| 80 | const FieldComparisonColumn = ({ field, startDate, endDate, compact = false, gradientIdSuffix = "" }: FieldComparisonColumnProps) => { |
| 81 | const [monthlyData, setMonthlyData] = useState<any[]>([]); |
| 82 | const [dailyData, setDailyData] = useState<any[]>([]); |
| 83 | const [soilMoistureData, setSoilMoistureData] = useState<any[]>([]); |
| 84 | const [loading, setLoading] = useState(false); |
| 85 | const [geeData, setGeeData] = useState<any>(null); |
| 86 | const [geeLoading, setGeeLoading] = useState(false); |
| 87 | const [ndviTimeSeries, setNdviTimeSeries] = useState<any>(null); |
| 88 | const [ndviTsLoading, setNdviTsLoading] = useState(false); |
| 89 | |
| 90 | // Fetch GEE analytics |
| 91 | useEffect(() => { |
| 92 | const cached = getFreshLocalCacheValue<any>(GEE_ANALYTICS_CACHE_KEY, field.id, QUERY_CACHE_TTL_MS); |
| 93 | if (cached) { |
| 94 | setGeeData(cached); |
| 95 | return; |
| 96 | } |
| 97 | const fetchGee = async () => { |
| 98 | setGeeLoading(true); |
| 99 | try { |
| 100 | const polygon = field.coordinates[0]; |
| 101 | const { data, error } = await callBackend("gee-analytics", { polygon, analyses: ["land_use", "vegetation", "suitability"] }); |
| 102 | if (error) throw error; |
| 103 | if (hasGeeAnalyticsPayload(data)) { |
| 104 | setGeeData(data); |
| 105 | setLocalCache(GEE_ANALYTICS_CACHE_KEY, field.id, data); |
| 106 | } else if (isFallbackPayload(data)) { |
| 107 | setGeeData(cached ?? null); |
| 108 | } else { |
| 109 | setGeeData(null); |
| 110 | } |
| 111 | } catch (e) { |
| 112 | console.error("GEE analytics error:", e); |
| 113 | setGeeData(cached ?? null); |
| 114 | } finally { setGeeLoading(false); } |
| 115 | }; |
| 116 | fetchGee(); |
| 117 | }, [field.id]); |
| 118 | |
| 119 | // Fetch NDVI time-series |
| 120 | useEffect(() => { |
| 121 | const cacheKey = `ts-${field.id}`; |
| 122 | const cached = getFreshLocalCacheValue<any>(GEE_ANALYTICS_CACHE_KEY, cacheKey, QUERY_CACHE_TTL_MS); |
| 123 | if (cached) { |
| 124 | setNdviTimeSeries(cached); |
| 125 | return; |
| 126 | } |
| 127 | const fetchTs = async () => { |
| 128 | setNdviTsLoading(true); |
| 129 | try { |
| 130 | const polygon = field.coordinates[0]; |
| 131 | const { data, error } = await callBackend("ndvi-timeseries", { polygon }); |
| 132 | if (error) throw error; |
| 133 | if (hasNdviPayload(data)) { |
| 134 | setNdviTimeSeries(data); |
| 135 | setLocalCache(GEE_ANALYTICS_CACHE_KEY, cacheKey, data); |
| 136 | } else if (isFallbackPayload(data)) { |
nothing calls this directly
no test coverage detected