fix: ensure SKU filter applies to Ads data

- dataProcessor.ts: Update filterAdsData to correctly handle SKU filtering using global metadata
- Ensures that drill-down from Weekly Sales correctly isolates the target product in the Ads tab
This commit is contained in:
Christian Vidal Wolf
2026-01-22 14:13:16 +01:00
parent 8832ee0760
commit f774bb47a7
+14 -6
View File
@@ -629,13 +629,16 @@ export const mergeSalesAndAdsData = (
// --- EXISTING HELPERS ---
// Filter Ads Data by Country, Year, Week, ASIN, and Product Line
// Filter Ads Data by Country, Year, Week, ASIN, SKU, and Product Line
export const filterAdsData = (
adsData: AdsRecord[],
filters: FilterState,
asinMetadata?: Map<string, { line: string }>
asinMetadata?: Map<string, { sku: string; line: string }>
): AdsRecord[] => {
return adsData.filter(ad => {
const asin = ad.asin.trim().toUpperCase();
const meta = asinMetadata?.get(asin);
// Country/Customer match (ads use 'country', sales use 'customer')
const countryMatch = filters.customer.length === 0
? PAN_EU_COUNTRIES.some(c => c.toUpperCase() === ad.country.toUpperCase())
@@ -651,16 +654,21 @@ export const filterAdsData = (
// ASIN match
const asinMatch = filters.asin.length === 0 ||
filters.asin.some(a => a.toUpperCase() === ad.asin.toUpperCase());
filters.asin.some(a => a.toUpperCase() === asin);
// SKU match (Requires metadata)
let skuMatch = true;
if (filters.sku.length > 0) {
skuMatch = meta ? filters.sku.some(s => s.toUpperCase() === meta.sku.toUpperCase()) : false;
}
// Line match (Requires metadata)
let lineMatch = true;
if (filters.line.length > 0 && asinMetadata) {
const meta = asinMetadata.get(ad.asin.trim().toUpperCase());
if (filters.line.length > 0) {
lineMatch = meta ? filters.line.includes(meta.line) : false;
}
return countryMatch && yearMatch && weekMatch && asinMatch && lineMatch;
return countryMatch && yearMatch && weekMatch && asinMatch && skuMatch && lineMatch;
});
};