From 4d52928321668438be2a25143461f0e3ca0b40b6 Mon Sep 17 00:00:00 2001 From: Christian Vidal Wolf Date: Thu, 30 Apr 2026 10:51:56 +0200 Subject: [PATCH] fix: resolve DataGrid search and filtering issues by consolidating search logic in filterData and fixing aggregation-aware filtering --- components/DataGrid.tsx | 41 ++++----------------------------------- services/dataProcessor.ts | 10 +++++++++- 2 files changed, 13 insertions(+), 38 deletions(-) diff --git a/components/DataGrid.tsx b/components/DataGrid.tsx index ec42931..d738421 100644 --- a/components/DataGrid.tsx +++ b/components/DataGrid.tsx @@ -435,43 +435,10 @@ const DataGrid: React.FC = ({ data, filters, hasCustomerFilter, a }); } - // 0. Global Search Filter - if (searchTerm) { - const rawTerm = searchTerm.trim(); - // Check if it looks like a bulk search (contains newlines or commas) - const isBulk = rawTerm.includes('\n') || rawTerm.includes(',') || rawTerm.includes(' '); - - if (isBulk) { - const searchTerms = rawTerm - .split(/[\s,\n]+/) - .map(t => t.trim().toLowerCase()) - .filter(t => t.length > 0); - - if (searchTerms.length > 0) { - result = result.filter(row => { - const rowSku = row.sku?.toLowerCase() || ''; - const rowAsin = row.asin?.toLowerCase() || ''; - const rowTitle = row.title?.toLowerCase() || ''; - return searchTerms.some(term => - rowSku.includes(term) || - rowAsin.includes(term) || - rowTitle.includes(term) - ); - }); - } - } else { - const term = rawTerm.toLowerCase(); - result = result.filter(row => { - return ( - (row.sku?.toLowerCase().includes(term)) || - (row.asin?.toLowerCase().includes(term)) || - (row.title?.toLowerCase().includes(term)) || - (row.line?.toLowerCase().includes(term)) || - (row.customer?.toLowerCase().includes(term)) - ); - }); - } - } + // Note: Global Search Filter (searchTerm) is now handled at the flat data level + // in pivotRows using filterData. This ensures that even when grouped by + // dimensions like 'customer', the search correctly filters the underlying + // products before aggregation. // 1. Filter (Legacy Row Filters) if (rowFilters.length > 0) { diff --git a/services/dataProcessor.ts b/services/dataProcessor.ts index 94afb06..2a23e44 100644 --- a/services/dataProcessor.ts +++ b/services/dataProcessor.ts @@ -1232,8 +1232,16 @@ export const filterData = ( if (searchTerms.length > 0) { const itemAsin = (item.asin || '').toUpperCase(); const itemSku = (item.sku || '').toUpperCase(); + const itemTitle = (item.title || '').toUpperCase(); + const itemLine = (item.line || '').toUpperCase(); + const itemCustomer = (item.customer || '').toUpperCase(); + bulkMatch = searchTerms.some(term => - itemAsin.includes(term) || itemSku.includes(term) + itemAsin.includes(term) || + itemSku.includes(term) || + itemTitle.includes(term) || + itemLine.includes(term) || + itemCustomer.includes(term) ); } }