Fix: Implement dynamic column detection to handle Excel structure changes (insertion of PM Classification). This fixes the Missing data error in Pricing Units and other views.

This commit is contained in:
Christian Vidal Wolf
2026-04-22 16:52:59 +02:00
parent 8471a69529
commit d43d9931c6
15 changed files with 176 additions and 55 deletions
+3 -1
View File
@@ -1,5 +1,6 @@
import React, { useState, useMemo } from 'react';
import { ExcelRow, COLUMNS } from '../types';
import { ExcelRow } from '../types';
import { useColumns } from '../contexts/ColumnsContext';
import { Search, Filter, Edit2, ChevronDown, ChevronUp, Info, Package, X } from 'lucide-react';
import { cn } from '../lib/utils';
import { ColumnFilterPopover } from './ColumnFilterPopover';
@@ -13,6 +14,7 @@ interface ArticleDetailsProps {
type TabType = 'all' | 'missingDetailsDE' | 'missingDetailsEN' | 'missingAnyDetails' | 'lowStock';
export function ArticleDetails({ data, onEdit, rowStatuses }: ArticleDetailsProps) {
const COLUMNS = useColumns();
const [activeTab, setActiveTab] = useState<TabType>('all');
const [search, setSearch] = useState('');
const [lineFilter, setLineFilter] = useState('');
+3 -1
View File
@@ -1,5 +1,6 @@
import React, { useMemo, useState } from 'react';
import { ExcelRow, COLUMNS } from '../types';
import { ExcelRow } from '../types';
import { useColumns } from '../contexts/ColumnsContext';
import { ChevronDown, ChevronUp } from 'lucide-react';
import { cn } from '../lib/utils';
@@ -9,6 +10,7 @@ interface DataCompletenessProps {
}
export function DataCompleteness({ data, headers }: DataCompletenessProps) {
const COLUMNS = useColumns();
const [sortCol, setSortCol] = useState<number | 'score'>('score');
const [sortDesc, setSortDesc] = useState(false);
const [page, setPage] = useState(1);
+3 -1
View File
@@ -1,5 +1,6 @@
import React, { useState, useMemo } from 'react';
import { ExcelRow, COLUMNS } from '../types';
import { ExcelRow } from '../types';
import { useColumns } from '../contexts/ColumnsContext';
import { AlertTriangle, CheckCircle2, ChevronDown, ChevronRight, Edit2, Package, Boxes, Scale, Loader2, RefreshCw, Layers, Link2, Search, Filter, X, Undo2 } from 'lucide-react';
import { cn } from '../lib/utils';
import { ConfirmModal } from './ConfirmModal';
@@ -35,6 +36,7 @@ interface NearDuplicateCluster {
}
export function DimensionsView({ data, headers, onEdit, onSaveRow, onCaptureState, rowStatuses, onRevertRow }: DimensionsViewProps) {
const COLUMNS = useColumns();
const [expandedGroups, setExpandedGroups] = useState<Set<string>>(new Set());
const [expandedNearDuplicates, setExpandedNearDuplicates] = useState<Set<number>>(new Set());
const [showOnlyInconsistent, setShowOnlyInconsistent] = useState(true);
+3 -1
View File
@@ -1,5 +1,6 @@
import React, { useState, useRef, useCallback } from 'react';
import { ExcelRow, COLUMNS } from '../types';
import { ExcelRow } from '../types';
import { useColumns } from '../contexts/ColumnsContext';
import { X, Sparkles, Save, Loader2, Languages, Package, CheckCircle2, Mic, MicOff } from 'lucide-react';
import { generateGemini } from '../services/gemini';
import { cn } from '../lib/utils';
@@ -126,6 +127,7 @@ const FieldEditor = ({
);
export function EditPanel({ row, rowIndex, onSave, onClose, onCaptureState }: EditPanelProps) {
const COLUMNS = useColumns();
const [formData, setFormData] = useState({
longDe: row[COLUMNS.LONG_DE] || '',
longEn: row[COLUMNS.LONG_EN] || '',
+3 -1
View File
@@ -1,7 +1,8 @@
import React, { useState, useEffect } from 'react';
import { History, RotateCcw, ChevronDown, ChevronRight, User, Calendar, Tag, Search, X, Edit2 } from 'lucide-react';
import { getHistory, deleteHistoryEntry, HistoryEntry } from '../lib/supabase';
import { ExcelRow, COLUMNS } from '../types';
import { ExcelRow } from '../types';
import { useColumns } from '../contexts/ColumnsContext';
import { cn } from '../lib/utils';
interface HistoryViewProps {
@@ -13,6 +14,7 @@ interface HistoryViewProps {
}
export function HistoryView({ headers, data, onRevert, onEdit, sessionToken }: HistoryViewProps) {
const COLUMNS = useColumns();
const [history, setHistory] = useState<HistoryEntry[]>([]);
const [loading, setLoading] = useState(true);
const [expandedId, setExpandedId] = useState<string | null>(null);
+3 -1
View File
@@ -1,5 +1,6 @@
import React, { useState, useMemo } from 'react';
import { ExcelRow, COLUMNS } from '../types';
import { ExcelRow } from '../types';
import { useColumns } from '../contexts/ColumnsContext';
import { Search, ChevronDown, ChevronUp, X, Edit2, Save } from 'lucide-react';
import { cn } from '../lib/utils';
import { ColumnFilterPopover } from './ColumnFilterPopover';
@@ -65,6 +66,7 @@ interface EditingState {
}
export function MissingDataView({ data, headers, onSaveRow, onCaptureState }: MissingDataViewProps) {
const COLUMNS = useColumns();
const [activeTab, setActiveTab] = useState<TabType>('missingLaunch');
const [search, setSearch] = useState('');
const [sortCol, setSortCol] = useState<number | null>(null);
+3 -1
View File
@@ -1,5 +1,6 @@
import React, { useState } from 'react';
import { ExcelRow, COLUMNS } from '../types';
import { ExcelRow } from '../types';
import { useColumns } from '../contexts/ColumnsContext';
import { Clock, Undo2, Package, Box, DollarSign, FileText, Search, Filter, X } from 'lucide-react';
import { cn } from '../lib/utils';
@@ -12,6 +13,7 @@ interface PendingValidationViewProps {
}
export function PendingValidationView({ data, pendingRows, rowStatuses, onRevertRow, onEdit }: PendingValidationViewProps) {
const COLUMNS = useColumns();
const [search, setSearch] = useState('');
const pendingEntries = Object.entries(pendingRows);
+5 -8
View File
@@ -1,5 +1,6 @@
import React, { useState, useMemo, useRef, useCallback, useEffect } from 'react';
import { ExcelRow, COLUMNS } from '../types';
import { ExcelRow } from '../types';
import { useColumns } from '../contexts/ColumnsContext';
import {
AlertTriangle,
AlertCircle,
@@ -48,6 +49,7 @@ function findCol(headers: string[], ...keywords: string[]): number {
}
export function PricingView({ data, headers, onSaveRow, onCaptureState, onEdit, rowStatuses }: PricingViewProps) {
const COLUMNS = useColumns();
const [filterMode, setFilterMode] = useState<FilterMode>('all_errors');
const [search, setSearch] = useState('');
const [searchMode, setSearchMode] = useState<'all' | 'selected'>('all');
@@ -193,15 +195,10 @@ export function PricingView({ data, headers, onSaveRow, onCaptureState, onEdit,
const nwIdx = findCol(headers, 'nw');
const gwIdx = findCol(headers, 'gw');
// Units/Outer column — try dynamic detection first, fall back to hardcoded index
const unitsOuterIdx = findCol(headers, 'units', 'outer') >= 0
? findCol(headers, 'units', 'outer')
: findCol(headers, 'vpe') >= 0
? findCol(headers, 'vpe')
: COLUMNS.UNITS_OUTER;
const unitsOuterIdx = COLUMNS.UNITS_OUTER;
return { uvpIdx, srpCols: srp, containerCols: container, nwIdx, gwIdx, unitsOuterIdx };
}, [headers]);
}, [headers, COLUMNS]);
// ── Error analysis per row ────────────────────────────────────────────────
const analyzedRows = useMemo(() => {
+6 -6
View File
@@ -1,5 +1,6 @@
import React, { useState, useMemo } from 'react';
import { ExcelRow, COLUMNS } from '../types';
import { ExcelRow } from '../types';
import { useColumns } from '../contexts/ColumnsContext';
import { Search, Filter, Edit2, ChevronDown, ChevronUp, X } from 'lucide-react';
import { cn } from '../lib/utils';
import { ColumnFilterPopover } from './ColumnFilterPopover';
@@ -12,12 +13,11 @@ interface ProductDescriptionsProps {
rowStatuses: Record<string, string>;
}
type TabType = 'all' | 'missingLongDE' | 'missingLongEN' | 'missingShortDE' | 'missingShortEN' | 'complete' | 'incomplete';
// Description columns that should only have Present/Missing filters
const DESCRIPTION_COLUMNS = [COLUMNS.LONG_DE, COLUMNS.LONG_EN, COLUMNS.SHORT_DE, COLUMNS.SHORT_EN, COLUMNS.DETAILS_DE, COLUMNS.DETAILS_EN];
export function ProductDescriptions({ data, headers, asinColumnIndex, onEdit, rowStatuses }: ProductDescriptionsProps) {
const COLUMNS = useColumns();
// Description columns that should only have Present/Missing filters
const DESCRIPTION_COLUMNS = [COLUMNS.LONG_DE, COLUMNS.LONG_EN, COLUMNS.SHORT_DE, COLUMNS.SHORT_EN, COLUMNS.DETAILS_DE, COLUMNS.DETAILS_EN];
const [activeTab, setActiveTab] = useState<TabType>('all');
const [search, setSearch] = useState('');
const [lineFilter, setLineFilter] = useState('');