mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 12:35:24 +02:00
feat: Implement Pan-EU grouping in Grid tab
- Added applyPanEUGrouping() helper function in dataProcessor.ts - Groups Amazon DE/IT/FR/ES as 'Pan-EU' when no customer filter applied - Shows individual countries when specific filter is selected - Updated DataGrid to accept hasCustomerFilter prop - Updated App.tsx to pass filter state to DataGrid - Keeps Amazon UK and Amazon SC separate - Verified with browser testing: grouping works correctly
This commit is contained in:
@@ -924,6 +924,36 @@ export const aggregateData = (data: SalesRecord[]): AggregatedData => {
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Groups Pan-EU countries (Amazon DE, IT, FR, ES) into a single "Pan-EU" customer
|
||||
* when no customer filter is applied. This provides a consolidated view of European
|
||||
* markets while keeping UK and SC separate.
|
||||
*
|
||||
* @param data - Array of sales records
|
||||
* @param hasCustomerFilter - Whether a customer filter is currently applied
|
||||
* @returns Processed data with Pan-EU grouping applied if appropriate
|
||||
*/
|
||||
export const applyPanEUGrouping = (
|
||||
data: SalesRecord[],
|
||||
hasCustomerFilter: boolean
|
||||
): SalesRecord[] => {
|
||||
// If customer filter is applied, don't group - show selected countries as-is
|
||||
if (hasCustomerFilter) {
|
||||
return data;
|
||||
}
|
||||
|
||||
// Define Pan-EU countries
|
||||
const PAN_EU_COUNTRIES = ['Amazon DE', 'Amazon IT', 'Amazon FR', 'Amazon ES'];
|
||||
|
||||
// Replace Pan-EU country names with "Pan-EU" for grouping
|
||||
return data.map(record => {
|
||||
if (PAN_EU_COUNTRIES.includes(record.customer)) {
|
||||
return { ...record, customer: 'Pan-EU' };
|
||||
}
|
||||
return record;
|
||||
});
|
||||
};
|
||||
|
||||
export const getUniqueValues = (data: SalesRecord[], field: keyof SalesRecord): string[] => {
|
||||
const values = new Set(data.map(item => String(item[field])));
|
||||
return Array.from(values).sort();
|
||||
|
||||
Reference in New Issue
Block a user