mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 12:45:23 +02:00
Fix ReferenceError crash: Move velocityMap calculation to top of App component
This commit is contained in:
@@ -67,6 +67,27 @@ const App: React.FC = () => {
|
||||
vendorStock: [],
|
||||
});
|
||||
|
||||
const top50Mode = useMemo(() => {
|
||||
const hasUK = filters.customer.includes('Amazon UK');
|
||||
const hasEU = filters.customer.some(c => ['Amazon DE', 'Amazon IT', 'Amazon FR', 'Amazon ES'].includes(c));
|
||||
if (hasUK) return 'uk';
|
||||
return 'eu';
|
||||
}, [filters.customer]);
|
||||
|
||||
// Calculate 4-week Sales Velocity Map (Context-Aware)
|
||||
// MOVED HERE TO AVOID REFERENCE ERROR in handleForecastFetch
|
||||
const velocityMap = useMemo(() => {
|
||||
// Determine which dataset to use for velocity calculation based on region filter
|
||||
// If 'uk', use UK data. If 'eu', use EU data.
|
||||
// IMPOTANT: We do NOT filter by Week/Month here, so we get the full history for velocity calculation
|
||||
const regionData = rawData.filter(r => {
|
||||
if (top50Mode === 'uk') return r.customer.toLowerCase().includes('uk');
|
||||
// for EU, exclude UK
|
||||
return !r.customer.toLowerCase().includes('uk');
|
||||
});
|
||||
return calculateVelocityMap(regionData);
|
||||
}, [rawData, top50Mode]);
|
||||
|
||||
// Handle Data Fetch (Simplified)
|
||||
const handleDataFetch = useCallback(async () => {
|
||||
setSyncing(true);
|
||||
@@ -407,13 +428,6 @@ const App: React.FC = () => {
|
||||
return metaMap;
|
||||
}, [rawData]);
|
||||
|
||||
const top50Mode = useMemo(() => {
|
||||
const hasUK = filters.customer.includes('Amazon UK');
|
||||
const hasEU = filters.customer.some(c => ['Amazon DE', 'Amazon IT', 'Amazon FR', 'Amazon ES'].includes(c));
|
||||
if (hasUK) return 'uk';
|
||||
return 'eu';
|
||||
}, [filters.customer]);
|
||||
|
||||
const filteredData = useMemo(() => filterData(rawData, filters, stockMap, vendorStockMap, top50Mode), [rawData, filters, stockMap, vendorStockMap, top50Mode]);
|
||||
const filteredAdsData = useMemo(() => filterAdsData(adsData, filters, globalAsinMetadata, stockMap, vendorStockMap, top50Mode), [adsData, filters, globalAsinMetadata, stockMap, vendorStockMap, top50Mode]);
|
||||
const aggregatedData = useMemo(() => aggregateData(filteredData), [filteredData]);
|
||||
@@ -450,18 +464,7 @@ const App: React.FC = () => {
|
||||
};
|
||||
}, [rawData]);
|
||||
|
||||
// Calculate 4-week Sales Velocity Map (Context-Aware)
|
||||
const velocityMap = useMemo(() => {
|
||||
// Determine which dataset to use for velocity calculation based on top50Mode (which reflects region filter)
|
||||
// If 'uk', use UK data. If 'eu', use EU data.
|
||||
// IMPOTANT: We do NOT filter by Week/Month here, so we get the full history for velocity calculation
|
||||
const regionData = rawData.filter(r => {
|
||||
if (top50Mode === 'uk') return r.customer.toLowerCase().includes('uk');
|
||||
// for EU, exclude UK
|
||||
return !r.customer.toLowerCase().includes('uk');
|
||||
});
|
||||
return calculateVelocityMap(regionData);
|
||||
}, [rawData, top50Mode]);
|
||||
// Determine which dataset to use for velocity calculation based on top50Mode
|
||||
|
||||
// Combine Sales & Ads Data dynamically based on current filters
|
||||
const combinedAdsData = useMemo(() => {
|
||||
|
||||
@@ -73,7 +73,7 @@ const ForecastRow: React.FC<{
|
||||
{stockMap && (
|
||||
<StockBadge stock={stockMap.get(item.sku?.replace(/(DE|EN)$/i, ''))} />
|
||||
)}
|
||||
{/* <VendorStockBadge asin={item.asin} vendorStockMap={vendorStockMap} mode={top50Mode} avgWeeklySales={item.avgWeeklySales} /> */}
|
||||
<VendorStockBadge asin={item.asin} vendorStockMap={vendorStockMap} mode={top50Mode} avgWeeklySales={item.avgWeeklySales} />
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
Reference in New Issue
Block a user