mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 13:05:24 +02:00
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:
@@ -629,13 +629,16 @@ export const mergeSalesAndAdsData = (
|
|||||||
|
|
||||||
// --- EXISTING HELPERS ---
|
// --- 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 = (
|
export const filterAdsData = (
|
||||||
adsData: AdsRecord[],
|
adsData: AdsRecord[],
|
||||||
filters: FilterState,
|
filters: FilterState,
|
||||||
asinMetadata?: Map<string, { line: string }>
|
asinMetadata?: Map<string, { sku: string; line: string }>
|
||||||
): AdsRecord[] => {
|
): AdsRecord[] => {
|
||||||
return adsData.filter(ad => {
|
return adsData.filter(ad => {
|
||||||
|
const asin = ad.asin.trim().toUpperCase();
|
||||||
|
const meta = asinMetadata?.get(asin);
|
||||||
|
|
||||||
// Country/Customer match (ads use 'country', sales use 'customer')
|
// Country/Customer match (ads use 'country', sales use 'customer')
|
||||||
const countryMatch = filters.customer.length === 0
|
const countryMatch = filters.customer.length === 0
|
||||||
? PAN_EU_COUNTRIES.some(c => c.toUpperCase() === ad.country.toUpperCase())
|
? PAN_EU_COUNTRIES.some(c => c.toUpperCase() === ad.country.toUpperCase())
|
||||||
@@ -651,16 +654,21 @@ export const filterAdsData = (
|
|||||||
|
|
||||||
// ASIN match
|
// ASIN match
|
||||||
const asinMatch = filters.asin.length === 0 ||
|
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)
|
// Line match (Requires metadata)
|
||||||
let lineMatch = true;
|
let lineMatch = true;
|
||||||
if (filters.line.length > 0 && asinMetadata) {
|
if (filters.line.length > 0) {
|
||||||
const meta = asinMetadata.get(ad.asin.trim().toUpperCase());
|
|
||||||
lineMatch = meta ? filters.line.includes(meta.line) : false;
|
lineMatch = meta ? filters.line.includes(meta.line) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return countryMatch && yearMatch && weekMatch && asinMatch && lineMatch;
|
return countryMatch && yearMatch && weekMatch && asinMatch && skuMatch && lineMatch;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user