Implement Excel-style filters (SKU, ASIN, Title, Line) across GRID, WEEKLY SALES, and FC26 tabs

This commit is contained in:
Christian Vidal Wolf
2026-02-09 12:00:39 +01:00
parent 827135a517
commit ac791b5265
6 changed files with 574 additions and 28 deletions
+40 -1
View File
@@ -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"