mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 13:35:24 +02:00
Implement Excel-style filters (SKU, ASIN, Title, Line) across GRID, WEEKLY SALES, and FC26 tabs
This commit is contained in:
@@ -871,7 +871,46 @@ export const filterData = (
|
||||
vendorStockMap?: Map<string, { eu: number; uk: number }>,
|
||||
top50Mode: 'eu' | 'uk' = 'eu'
|
||||
): SalesRecord[] => {
|
||||
return data.filter(item => {
|
||||
let result = data; // Changed from rawData to data
|
||||
|
||||
// 1. Column Filters (Excel-style)
|
||||
if (filters.columnFilters) {
|
||||
Object.entries(filters.columnFilters).forEach(([key, condition]) => {
|
||||
if (!condition) return;
|
||||
|
||||
// Apply selected values filter
|
||||
if (condition.selectedValues && condition.selectedValues.length > 0) {
|
||||
result = result.filter(r => {
|
||||
const val = String((r as any)[key] || '');
|
||||
return condition.selectedValues?.includes(val);
|
||||
});
|
||||
}
|
||||
|
||||
// Apply text condition filter
|
||||
if (condition.textFilter) {
|
||||
const { operator, value } = condition.textFilter;
|
||||
const lowerValue = value.toLowerCase();
|
||||
|
||||
result = result.filter(r => {
|
||||
const rowVal = String((r as any)[key] || '').toLowerCase();
|
||||
switch (operator) {
|
||||
case 'equals': return rowVal === lowerValue;
|
||||
case 'notEquals': return rowVal !== lowerValue;
|
||||
case 'contains': return rowVal.includes(lowerValue);
|
||||
case 'notContains': return !rowVal.includes(lowerValue);
|
||||
case 'startsWith': return rowVal.startsWith(lowerValue);
|
||||
case 'notStartsWith': return !rowVal.startsWith(lowerValue);
|
||||
case 'endsWith': return rowVal.endsWith(lowerValue);
|
||||
case 'notEndsWith': return !rowVal.endsWith(lowerValue);
|
||||
default: return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 2. Standard Filters
|
||||
return result.filter(item => { // Apply remaining filters to the 'result'
|
||||
// 1. Month Logic: Handle "Apr-23" matching "Apr" filter
|
||||
const recordMonth = item.month; // e.g. "Apr-23"
|
||||
const pureMonth = recordMonth.split('-')[0]; // "Apr"
|
||||
|
||||
Reference in New Issue
Block a user