mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 16:45:24 +02:00
Fix: Ensure product metadata is built globally for Forecast View
This commit is contained in:
@@ -90,7 +90,7 @@ const App: React.FC = () => {
|
|||||||
console.log('[App] Successfully loaded', data.length, 'rows');
|
console.log('[App] Successfully loaded', data.length, 'rows');
|
||||||
|
|
||||||
// Refresh forecast too
|
// Refresh forecast too
|
||||||
handleForecastFetch(data, filters);
|
handleForecastFetch(data, data, filters);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to fetch/parse CSV", error);
|
console.error("Failed to fetch/parse CSV", error);
|
||||||
alert("Error loading data. Please refresh the page.");
|
alert("Error loading data. Please refresh the page.");
|
||||||
@@ -143,7 +143,7 @@ const App: React.FC = () => {
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleForecastFetch = useCallback(async (sales: SalesRecord[], activeFilters: FilterState) => {
|
const handleForecastFetch = useCallback(async (sales: SalesRecord[], globalSales: SalesRecord[], activeFilters: FilterState) => {
|
||||||
try {
|
try {
|
||||||
const isUK = activeFilters.customer.includes('Amazon UK');
|
const isUK = activeFilters.customer.includes('Amazon UK');
|
||||||
const filename = isUK ? '/fc UK 26.xlsx' : '/fc 26.xlsx';
|
const filename = isUK ? '/fc UK 26.xlsx' : '/fc 26.xlsx';
|
||||||
@@ -155,9 +155,11 @@ const App: React.FC = () => {
|
|||||||
const buffer = await response.arrayBuffer();
|
const buffer = await response.arrayBuffer();
|
||||||
const fcRecords = await processForecastExcel(buffer);
|
const fcRecords = await processForecastExcel(buffer);
|
||||||
|
|
||||||
// Build precise metadata map from sales records
|
// Build precise metadata map from GLOBAL sales records to ensure info is found even if filtered for market
|
||||||
const meta = new Map<string, { sku: string; title: string; line: string }>();
|
const meta = new Map<string, { sku: string; title: string; line: string }>();
|
||||||
sales.forEach(r => {
|
const metaDataSource = globalSales.length > 0 ? globalSales : sales;
|
||||||
|
|
||||||
|
metaDataSource.forEach(r => {
|
||||||
const asin = r.asin.trim().toUpperCase();
|
const asin = r.asin.trim().toUpperCase();
|
||||||
const existing = meta.get(asin);
|
const existing = meta.get(asin);
|
||||||
if (!existing || (r.title && r.title.length > (existing.title?.length || 0))) {
|
if (!existing || (r.title && r.title.length > (existing.title?.length || 0))) {
|
||||||
@@ -181,7 +183,7 @@ const App: React.FC = () => {
|
|||||||
...filters,
|
...filters,
|
||||||
year: [] // Ensure we don't filter out 2025/2026 if a single year is selected in UI
|
year: [] // Ensure we don't filter out 2025/2026 if a single year is selected in UI
|
||||||
});
|
});
|
||||||
handleForecastFetch(forecastRelevantData, filters);
|
handleForecastFetch(forecastRelevantData, rawData, filters);
|
||||||
}
|
}
|
||||||
}, [filters, rawData, handleForecastFetch]);
|
}, [filters, rawData, handleForecastFetch]);
|
||||||
|
|
||||||
@@ -260,7 +262,7 @@ const App: React.FC = () => {
|
|||||||
handleTrafficFetch();
|
handleTrafficFetch();
|
||||||
|
|
||||||
// 1d. Fetch Forecast data
|
// 1d. Fetch Forecast data
|
||||||
handleForecastFetch(cachedData || [], filters);
|
handleForecastFetch(cachedData || [], cachedData || [], filters);
|
||||||
};
|
};
|
||||||
initApp();
|
initApp();
|
||||||
}, [handleDataFetch]);
|
}, [handleDataFetch]);
|
||||||
|
|||||||
Reference in New Issue
Block a user