mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 13:35:24 +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: [],
|
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)
|
// Handle Data Fetch (Simplified)
|
||||||
const handleDataFetch = useCallback(async () => {
|
const handleDataFetch = useCallback(async () => {
|
||||||
setSyncing(true);
|
setSyncing(true);
|
||||||
@@ -407,13 +428,6 @@ const App: React.FC = () => {
|
|||||||
return metaMap;
|
return metaMap;
|
||||||
}, [rawData]);
|
}, [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 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 filteredAdsData = useMemo(() => filterAdsData(adsData, filters, globalAsinMetadata, stockMap, vendorStockMap, top50Mode), [adsData, filters, globalAsinMetadata, stockMap, vendorStockMap, top50Mode]);
|
||||||
const aggregatedData = useMemo(() => aggregateData(filteredData), [filteredData]);
|
const aggregatedData = useMemo(() => aggregateData(filteredData), [filteredData]);
|
||||||
@@ -450,18 +464,7 @@ const App: React.FC = () => {
|
|||||||
};
|
};
|
||||||
}, [rawData]);
|
}, [rawData]);
|
||||||
|
|
||||||
// Calculate 4-week Sales Velocity Map (Context-Aware)
|
// Determine which dataset to use for velocity calculation based on top50Mode
|
||||||
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]);
|
|
||||||
|
|
||||||
// Combine Sales & Ads Data dynamically based on current filters
|
// Combine Sales & Ads Data dynamically based on current filters
|
||||||
const combinedAdsData = useMemo(() => {
|
const combinedAdsData = useMemo(() => {
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ const ForecastRow: React.FC<{
|
|||||||
{stockMap && (
|
{stockMap && (
|
||||||
<StockBadge stock={stockMap.get(item.sku?.replace(/(DE|EN)$/i, ''))} />
|
<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>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
Reference in New Issue
Block a user