mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 19:15:22 +02:00
fix: resolve vendor data upload error by implementing client-side parsing and sequential batching
This commit is contained in:
@@ -5,7 +5,7 @@ import Dashboard from './components/Dashboard';
|
||||
import FilterBar from './components/FilterBar';
|
||||
import AIChat from './components/AIChat';
|
||||
import CrazeLogo from './components/CrazeLogo';
|
||||
import { processCSV, processExcel, filterData, aggregateData, processAdsCSV, processAdsExcel, mergeSalesAndAdsData, processTrafficExcel, processStockExcel, filterAdsData, calculateForecastViewData, processVendorStockExcel, processUKInventoryExcel, calculateVelocityMap, getUniqueValues, processForecastExcel, processBuyBoxExcel } from './services/dataProcessor';
|
||||
import { processCSV, processExcel, filterData, aggregateData, processAdsCSV, processAdsExcel, mergeSalesAndAdsData, processTrafficExcel, processStockExcel, filterAdsData, calculateForecastViewData, processVendorStockExcel, processUKInventoryExcel, calculateVelocityMap, getUniqueValues, processForecastExcel, processBuyBoxExcel, processVendorCSV } from './services/dataProcessor';
|
||||
import { SalesRecord, FilterState, AggregatedData, AdsRecord, TrafficRecord, ForecastRecord, ProductForecastData } from './types';
|
||||
import { queryGemini } from './services/geminiService';
|
||||
import { ChartIcon, TableIcon, UploadIcon, DownloadIcon, CloseIcon, TrendingIcon, MegaphoneIcon } from './components/Icons';
|
||||
@@ -438,19 +438,39 @@ const App: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
// Handle uploaded Vendor CSV (sends to Supabase via API)
|
||||
// Handle uploaded Vendor CSV (sends to Supabase via API with batching)
|
||||
const handleVendorUpload = async (file: File) => {
|
||||
setSyncing(true);
|
||||
try {
|
||||
const text = await file.text();
|
||||
const response = await fetch('/api/upload-vendor-data', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'text/csv' },
|
||||
body: text,
|
||||
});
|
||||
const result = await response.json();
|
||||
if (!response.ok) throw new Error(result.error);
|
||||
alert(`Vendor data uploaded: ${result.rowsUpserted} rows processed.`);
|
||||
console.log("[App] Parsing Vendor CSV on client...");
|
||||
const rows = await processVendorCSV(file);
|
||||
|
||||
if (rows.length === 0) {
|
||||
alert("No valid rows found in CSV.");
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`[App] Uploading ${rows.length} rows in batches...`);
|
||||
|
||||
const BATCH_SIZE = 500;
|
||||
let totalUpserted = 0;
|
||||
|
||||
for (let i = 0; i < rows.length; i += BATCH_SIZE) {
|
||||
const batch = rows.slice(i, i + BATCH_SIZE);
|
||||
const response = await fetch('/api/upload-vendor-data', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(batch),
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
if (!response.ok) throw new Error(result.error || `Batch ${i / BATCH_SIZE + 1} failed`);
|
||||
|
||||
totalUpserted += result.rowsUpserted;
|
||||
console.log(`[App] Batch ${Math.floor(i / BATCH_SIZE) + 1} complete. Total: ${totalUpserted}`);
|
||||
}
|
||||
|
||||
alert(`Vendor data uploaded: ${totalUpserted} rows processed successfully.`);
|
||||
setIsDataModalOpen(false);
|
||||
} catch (error: any) {
|
||||
console.error("Failed to upload vendor data", error);
|
||||
|
||||
Reference in New Issue
Block a user