From 425d9e8088961d2f56b2e469ee50d758ed9dab6f Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 22 Feb 2026 12:21:05 +0100 Subject: [PATCH] feat: Add Bulk AI Analyzer component to process products, call an AI analysis API with concurrency and retry logic, and update grid insights and recommendations. --- src/features/grid/components/bulk-ai-analyzer.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/features/grid/components/bulk-ai-analyzer.tsx b/src/features/grid/components/bulk-ai-analyzer.tsx index b5bb03c..73bd347 100644 --- a/src/features/grid/components/bulk-ai-analyzer.tsx +++ b/src/features/grid/components/bulk-ai-analyzer.tsx @@ -20,15 +20,18 @@ export function BulkAiAnalyzer() { }; const handleAnalyze = async () => { - const totalQtySum = rows.reduce((sum, r) => sum + (r.totalQuantite || 0), 0); + const { rows } = useGridStore.getState(); + isCancelledRef.current = false; + + const totalQtySum = rows.reduce((sum: number, r: any) => sum + (r.totalQuantite || 0), 0); const avgQty = rows.length > 0 ? totalQtySum / rows.length : 0; // Benchmarks par groupe de magasins const rowsGroup1 = rows.filter(r => (r.workingStores?.length || 1) === 1); const rowsGroup2 = rows.filter(r => (r.workingStores?.length || 1) >= 2); - const avgQty1 = rowsGroup1.length > 0 ? rowsGroup1.reduce((s, r) => s + (r.totalQuantite || 0), 0) / rowsGroup1.length : 0; - const avgQty2 = rowsGroup2.length > 0 ? rowsGroup2.reduce((s, r) => s + (r.totalQuantite || 0), 0) / rowsGroup2.length : 0; + const avgQty1 = rowsGroup1.length > 0 ? rowsGroup1.reduce((s: number, r: any) => s + (r.totalQuantite || 0), 0) / rowsGroup1.length : 0; + const avgQty2 = rowsGroup2.length > 0 ? rowsGroup2.reduce((s: number, r: any) => s + (r.totalQuantite || 0), 0) / rowsGroup2.length : 0; const productPayloads: ProductAnalysisInput[] = rows.map(r => ({ codein: r.codein,