2026-04-08 19:30:41 +02:00
|
|
|
import React, { useState, useMemo } from 'react';
|
2026-04-22 16:52:59 +02:00
|
|
|
import { ExcelRow } from '../types';
|
|
|
|
|
import { useColumns } from '../contexts/ColumnsContext';
|
2026-04-22 20:38:06 +02:00
|
|
|
import { Search, Filter, Edit2, ChevronDown, ChevronUp, X, Maximize2 } from 'lucide-react';
|
2026-03-27 11:34:09 +01:00
|
|
|
import { cn } from '../lib/utils';
|
2026-04-08 16:56:43 +02:00
|
|
|
import { ColumnFilterPopover } from './ColumnFilterPopover';
|
2026-04-24 14:19:09 +02:00
|
|
|
import { usePersistentState } from '../contexts/FilterContext';
|
2026-03-27 11:34:09 +01:00
|
|
|
|
|
|
|
|
interface ProductDescriptionsProps {
|
|
|
|
|
data: ExcelRow[];
|
2026-04-09 16:33:05 +02:00
|
|
|
headers: string[];
|
|
|
|
|
asinColumnIndex: number | null;
|
2026-03-27 11:34:09 +01:00
|
|
|
onEdit: (index: number) => void;
|
2026-04-08 19:49:48 +02:00
|
|
|
rowStatuses: Record<string, string>;
|
2026-03-27 11:34:09 +01:00
|
|
|
}
|
|
|
|
|
|
2026-04-09 16:33:05 +02:00
|
|
|
export function ProductDescriptions({ data, headers, asinColumnIndex, onEdit, rowStatuses }: ProductDescriptionsProps) {
|
2026-04-22 16:52:59 +02:00
|
|
|
const COLUMNS = useColumns();
|
2026-04-22 20:38:06 +02:00
|
|
|
const [isFullscreen, setIsFullscreen] = useState(false);
|
2026-04-22 16:52:59 +02:00
|
|
|
|
|
|
|
|
// 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];
|
2026-04-24 14:19:09 +02:00
|
|
|
const [activeTab, setActiveTab] = usePersistentState<string>('descriptions-tab', 'all');
|
2026-04-24 16:09:49 +02:00
|
|
|
const [search, setSearch] = usePersistentState('descriptions-search', '');
|
2026-04-24 14:19:09 +02:00
|
|
|
const [lineFilter, setLineFilter] = usePersistentState('descriptions-lineFilter', '');
|
|
|
|
|
const [licenseFilter, setLicenseFilter] = usePersistentState('descriptions-licenseFilter', '');
|
|
|
|
|
const [sortCol, setSortCol] = usePersistentState<number | null>('descriptions-sortCol', null);
|
|
|
|
|
const [sortDesc, setSortDesc] = usePersistentState('descriptions-sortDesc', false);
|
|
|
|
|
const [pageSize, setPageSize] = usePersistentState('descriptions-pageSize', 100);
|
2026-03-27 11:34:09 +01:00
|
|
|
const [page, setPage] = useState(1);
|
2026-04-24 14:19:09 +02:00
|
|
|
const [columnFilters, setColumnFilters] = usePersistentState<Record<number, string[]>>('descriptions-columnFilters', {});
|
2026-04-08 16:18:24 +02:00
|
|
|
const [openFilterCol, setOpenFilterCol] = useState<number | null>(null);
|
2026-04-08 20:21:36 +02:00
|
|
|
const [columnWidths, setColumnWidths] = useState<Record<number, number>>({
|
2026-04-10 09:28:49 +02:00
|
|
|
[COLUMNS.ARTICLE_NO]: 110,
|
|
|
|
|
[COLUMNS.ARTICLE_NAME]: 450, // More flexible space for name
|
|
|
|
|
...(asinColumnIndex !== null ? { [asinColumnIndex]: 100 } : {}),
|
2026-04-08 20:21:36 +02:00
|
|
|
[COLUMNS.LINE]: 80,
|
|
|
|
|
[COLUMNS.LICENSE]: 120,
|
|
|
|
|
[COLUMNS.CLASSIFICATION]: 100,
|
2026-04-11 11:15:41 +02:00
|
|
|
[COLUMNS.LONG_DE]: 110,
|
|
|
|
|
[COLUMNS.LONG_EN]: 110,
|
|
|
|
|
[COLUMNS.SHORT_DE]: 110,
|
|
|
|
|
[COLUMNS.SHORT_EN]: 110,
|
2026-04-08 20:21:36 +02:00
|
|
|
});
|
2026-03-27 11:34:09 +01:00
|
|
|
|
|
|
|
|
const lines = useMemo(() => Array.from(new Set(data.map(r => r[COLUMNS.LINE]).filter(Boolean))), [data]);
|
|
|
|
|
const licenses = useMemo(() => Array.from(new Set(data.map(r => r[COLUMNS.LICENSE]).filter(Boolean))), [data]);
|
|
|
|
|
|
|
|
|
|
const filteredData = useMemo(() => {
|
|
|
|
|
let result = data.map((row, index) => ({ row, index }));
|
|
|
|
|
|
|
|
|
|
// Tab filter
|
2026-04-08 16:10:14 +02:00
|
|
|
if (activeTab === 'missingLongDE') result = result.filter(r => !r.row[COLUMNS.LONG_DE]);
|
|
|
|
|
if (activeTab === 'missingLongEN') result = result.filter(r => !r.row[COLUMNS.LONG_EN]);
|
|
|
|
|
if (activeTab === 'missingShortDE') result = result.filter(r => !r.row[COLUMNS.SHORT_DE]);
|
|
|
|
|
if (activeTab === 'missingShortEN') result = result.filter(r => !r.row[COLUMNS.SHORT_EN]);
|
2026-04-08 17:11:27 +02:00
|
|
|
|
|
|
|
|
if (activeTab === 'complete') result = result.filter(r =>
|
|
|
|
|
r.row[COLUMNS.LONG_DE] && r.row[COLUMNS.LONG_EN] &&
|
2026-04-08 16:10:14 +02:00
|
|
|
r.row[COLUMNS.SHORT_DE] && r.row[COLUMNS.SHORT_EN]
|
2026-04-07 13:38:21 +02:00
|
|
|
);
|
2026-04-08 17:11:27 +02:00
|
|
|
if (activeTab === 'incomplete') result = result.filter(r =>
|
|
|
|
|
!r.row[COLUMNS.LONG_DE] || !r.row[COLUMNS.LONG_EN] ||
|
2026-04-08 16:10:14 +02:00
|
|
|
!r.row[COLUMNS.SHORT_DE] || !r.row[COLUMNS.SHORT_EN]
|
2026-04-07 13:38:21 +02:00
|
|
|
);
|
2026-03-27 11:34:09 +01:00
|
|
|
|
|
|
|
|
// Search filter
|
|
|
|
|
if (search) {
|
2026-04-24 12:20:14 +02:00
|
|
|
const terms = search.toLowerCase().split(/\s+/).filter(Boolean);
|
|
|
|
|
if (terms.length > 0) {
|
|
|
|
|
result = result.filter(r => {
|
|
|
|
|
const articleNo = String(r.row[COLUMNS.ARTICLE_NO] || '').toLowerCase();
|
|
|
|
|
const articleName = String(r.row[COLUMNS.ARTICLE_NAME] || '').toLowerCase();
|
|
|
|
|
return terms.every(term => articleNo.includes(term) || articleName.includes(term));
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-03-27 11:34:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Dropdown filters
|
|
|
|
|
if (lineFilter) result = result.filter(r => r.row[COLUMNS.LINE] === lineFilter);
|
|
|
|
|
if (licenseFilter) result = result.filter(r => r.row[COLUMNS.LICENSE] === licenseFilter);
|
|
|
|
|
|
2026-04-08 16:18:24 +02:00
|
|
|
// Column-specific filters (Excel-like)
|
|
|
|
|
Object.entries(columnFilters).forEach(([colIdx, selectedValues]) => {
|
2026-04-08 17:11:27 +02:00
|
|
|
const col = Number(colIdx);
|
2026-04-08 16:18:24 +02:00
|
|
|
const vals = selectedValues as string[];
|
|
|
|
|
if (vals.length > 0) {
|
2026-04-20 16:37:33 +02:00
|
|
|
result = result.filter(r => {
|
|
|
|
|
const cellVal = r.row[col];
|
|
|
|
|
|
|
|
|
|
if (DESCRIPTION_COLUMNS.includes(col)) {
|
|
|
|
|
// For description columns, we match synthetic 'Present'/'Missing' values
|
|
|
|
|
const hasValue = cellVal !== undefined && cellVal !== null && String(cellVal).trim() !== '';
|
|
|
|
|
const matchPresent = vals.includes('Present') && hasValue;
|
|
|
|
|
const matchMissing = vals.includes('Missing') && !hasValue;
|
|
|
|
|
return matchPresent || matchMissing;
|
|
|
|
|
} else {
|
|
|
|
|
// For other columns, use regular value matching with improved empty value handling
|
|
|
|
|
const cellStr = String(cellVal ?? '').trim();
|
|
|
|
|
// If the cell is empty/null/undefined, it matches if 'Empty' or '' is selected
|
|
|
|
|
return vals.some(v => {
|
|
|
|
|
const filterVal = String(v ?? '').trim();
|
|
|
|
|
return filterVal === cellStr;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-04-08 16:18:24 +02:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2026-03-27 11:34:09 +01:00
|
|
|
// Sorting
|
|
|
|
|
if (sortCol !== null) {
|
|
|
|
|
result.sort((a, b) => {
|
|
|
|
|
const valA = String(a.row[sortCol] || '');
|
|
|
|
|
const valB = String(b.row[sortCol] || '');
|
|
|
|
|
return sortDesc ? valB.localeCompare(valA) : valA.localeCompare(valB);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
2026-04-08 19:49:48 +02:00
|
|
|
}, [data, activeTab, search, lineFilter, licenseFilter, columnFilters, sortCol, sortDesc]);
|
2026-03-27 11:34:09 +01:00
|
|
|
|
|
|
|
|
const paginatedData = useMemo(() => {
|
|
|
|
|
const start = (page - 1) * pageSize;
|
|
|
|
|
return filteredData.slice(start, start + pageSize);
|
|
|
|
|
}, [filteredData, page, pageSize]);
|
|
|
|
|
|
|
|
|
|
const totalPages = Math.ceil(filteredData.length / pageSize);
|
|
|
|
|
|
|
|
|
|
const handleSort = (col: number) => {
|
|
|
|
|
if (sortCol === col) {
|
|
|
|
|
setSortDesc(!sortDesc);
|
|
|
|
|
} else {
|
|
|
|
|
setSortCol(col);
|
|
|
|
|
setSortDesc(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-08 20:21:36 +02:00
|
|
|
const handleResize = (colIndex: number, e: React.MouseEvent) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
const startX = e.pageX;
|
|
|
|
|
const startWidth = columnWidths[colIndex] || 100;
|
|
|
|
|
|
|
|
|
|
const onMouseMove = (moveEvent: MouseEvent) => {
|
|
|
|
|
const newWidth = Math.max(60, startWidth + (moveEvent.pageX - startX));
|
|
|
|
|
setColumnWidths(prev => ({ ...prev, [colIndex]: newWidth }));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onMouseUp = () => {
|
|
|
|
|
window.removeEventListener('mousemove', onMouseMove);
|
|
|
|
|
window.removeEventListener('mouseup', onMouseUp);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
window.addEventListener('mousemove', onMouseMove);
|
|
|
|
|
window.addEventListener('mouseup', onMouseUp);
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-08 16:18:24 +02:00
|
|
|
const getUniqueValues = (col: number) => {
|
2026-04-08 17:11:27 +02:00
|
|
|
// For description columns, return only 'Present' and 'Missing'
|
|
|
|
|
if (DESCRIPTION_COLUMNS.includes(col)) {
|
|
|
|
|
return ['Present', 'Missing'];
|
|
|
|
|
}
|
|
|
|
|
// For other columns, return actual unique values
|
2026-04-08 16:18:24 +02:00
|
|
|
const values = data.map(r => String(r[col] || ''));
|
|
|
|
|
return Array.from(new Set(values)).sort();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const toggleColumnFilter = (col: number, value: string) => {
|
2026-04-08 19:59:11 +02:00
|
|
|
console.log('[Filter] toggleColumnFilter called, col:', col, 'value:', JSON.stringify(value));
|
2026-04-08 16:18:24 +02:00
|
|
|
setColumnFilters(prev => {
|
|
|
|
|
const current = prev[col] || [];
|
|
|
|
|
const next = current.includes(value)
|
|
|
|
|
? current.filter(v => v !== value)
|
|
|
|
|
: [...current, value];
|
2026-04-08 19:59:11 +02:00
|
|
|
const updated = { ...prev, [col]: next };
|
|
|
|
|
console.log('[Filter] new columnFilters:', updated);
|
|
|
|
|
return updated;
|
2026-04-08 16:18:24 +02:00
|
|
|
});
|
|
|
|
|
setPage(1);
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-08 16:50:53 +02:00
|
|
|
const setBatchColumnFilter = (col: number, values: string[]) => {
|
|
|
|
|
setColumnFilters(prev => ({ ...prev, [col]: values }));
|
|
|
|
|
setPage(1);
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-27 11:34:09 +01:00
|
|
|
const getRowColor = (row: ExcelRow) => {
|
2026-04-07 13:38:21 +02:00
|
|
|
const fields = [
|
2026-04-08 17:11:27 +02:00
|
|
|
row[COLUMNS.LONG_DE], row[COLUMNS.LONG_EN],
|
2026-04-08 16:10:14 +02:00
|
|
|
row[COLUMNS.SHORT_DE], row[COLUMNS.SHORT_EN]
|
2026-04-07 13:38:21 +02:00
|
|
|
];
|
2026-03-27 11:34:09 +01:00
|
|
|
const filled = fields.filter(Boolean).length;
|
2026-04-08 16:10:14 +02:00
|
|
|
if (filled === 4) return 'bg-green-900/10 hover:bg-green-900/20';
|
2026-03-27 11:34:09 +01:00
|
|
|
if (filled === 0) return 'bg-red-900/10 hover:bg-red-900/20';
|
|
|
|
|
return 'bg-yellow-900/10 hover:bg-yellow-900/20';
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-27 13:26:16 +01:00
|
|
|
const Badge = ({ content, row }: { content: any, row: ExcelRow }) => {
|
2026-04-10 12:50:15 +02:00
|
|
|
if (content !== undefined && content !== null && content !== '') return <span className="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-green-500/20 text-green-400 border border-green-500/30">✓</span>;
|
2026-04-08 17:11:27 +02:00
|
|
|
|
|
|
|
|
|
2026-03-27 13:26:16 +01:00
|
|
|
|
2026-03-27 11:34:09 +01:00
|
|
|
return <span className="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-red-500/20 text-red-400 border border-red-500/30">✗ Missing</span>;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const tabs: { id: TabType; label: string }[] = [
|
|
|
|
|
{ id: 'all', label: 'All Products' },
|
2026-04-08 16:10:14 +02:00
|
|
|
{ id: 'missingLongDE', label: 'Missing Long DE' },
|
|
|
|
|
{ id: 'missingLongEN', label: 'Missing Long EN' },
|
|
|
|
|
{ id: 'missingShortDE', label: 'Missing Short DE' },
|
|
|
|
|
{ id: 'missingShortEN', label: 'Missing Short EN' },
|
2026-03-27 11:34:09 +01:00
|
|
|
{ id: 'complete', label: 'Complete' },
|
|
|
|
|
{ id: 'incomplete', label: 'Incomplete' },
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return (
|
2026-04-23 14:53:43 +02:00
|
|
|
<div className={isFullscreen ? "fixed inset-0 z-40 bg-[#041021] p-6 overflow-auto" : "flex flex-col h-full"}>
|
|
|
|
|
{isFullscreen && (
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => setIsFullscreen(false)}
|
|
|
|
|
className="fixed top-4 right-4 z-50 w-10 h-10 flex items-center justify-center bg-slate-800/90 backdrop-blur border border-slate-600 text-white rounded hover:bg-slate-700 hover:scale-105 transition-all"
|
|
|
|
|
title="Exit fullscreen"
|
|
|
|
|
>
|
|
|
|
|
<X className="w-5 h-5" />
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
2026-03-27 11:34:09 +01:00
|
|
|
<div className="flex flex-wrap gap-2 mb-6">
|
|
|
|
|
{tabs.map(tab => (
|
|
|
|
|
<button
|
|
|
|
|
key={tab.id}
|
|
|
|
|
onClick={() => { setActiveTab(tab.id); setPage(1); }}
|
|
|
|
|
className={cn(
|
|
|
|
|
"px-4 py-2 rounded-md text-sm font-medium transition-colors",
|
2026-04-08 17:11:27 +02:00
|
|
|
activeTab === tab.id
|
|
|
|
|
? "bg-blue-600 text-white shadow-md"
|
2026-03-27 11:34:09 +01:00
|
|
|
: "bg-slate-800 text-slate-400 hover:bg-slate-700 hover:text-white"
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{tab.label}
|
|
|
|
|
</button>
|
|
|
|
|
))}
|
2026-04-23 14:53:43 +02:00
|
|
|
<button
|
|
|
|
|
onClick={() => setIsFullscreen(true)}
|
|
|
|
|
className="ml-auto p-2 text-slate-400 hover:text-white hover:bg-slate-700 rounded transition-colors"
|
|
|
|
|
title="Fullscreen"
|
|
|
|
|
>
|
|
|
|
|
<Maximize2 className="w-5 h-5" />
|
|
|
|
|
</button>
|
2026-03-27 11:34:09 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="flex flex-wrap gap-4 mb-6 bg-slate-800 p-4 rounded-xl border border-slate-700 shadow-sm">
|
|
|
|
|
<div className="flex-1 min-w-[200px] relative">
|
|
|
|
|
<Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400" />
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
placeholder="Search Article Name or No..."
|
|
|
|
|
value={search}
|
|
|
|
|
onChange={e => { setSearch(e.target.value); setPage(1); }}
|
2026-04-10 12:39:31 +02:00
|
|
|
className="w-full pl-9 pr-10 py-2 bg-slate-900 border border-slate-700 rounded-md text-sm text-white focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500"
|
2026-03-27 11:34:09 +01:00
|
|
|
/>
|
2026-04-10 12:39:31 +02:00
|
|
|
{search && (
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => { setSearch(''); setPage(1); }}
|
|
|
|
|
className="absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-white"
|
|
|
|
|
>
|
|
|
|
|
<X className="w-4 h-4" />
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
2026-03-27 11:34:09 +01:00
|
|
|
</div>
|
2026-04-08 16:18:24 +02:00
|
|
|
{(Object.values(columnFilters) as string[][]).some(v => v.length > 0) && (
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => {
|
|
|
|
|
setColumnFilters({});
|
|
|
|
|
setPage(1);
|
|
|
|
|
}}
|
|
|
|
|
className="flex items-center gap-2 px-4 py-2 bg-red-600/10 text-red-400 hover:bg-red-600 hover:text-white rounded-md text-sm font-medium transition-colors border border-red-600/20"
|
|
|
|
|
>
|
|
|
|
|
<X className="w-4 h-4" />
|
|
|
|
|
Clear All Column Filters
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
2026-03-27 11:34:09 +01:00
|
|
|
<select
|
|
|
|
|
value={lineFilter}
|
|
|
|
|
onChange={e => { setLineFilter(e.target.value); setPage(1); }}
|
|
|
|
|
className="bg-slate-900 border border-slate-700 rounded-md px-4 py-2 text-sm text-white focus:outline-none focus:border-blue-500"
|
|
|
|
|
>
|
|
|
|
|
<option value="">All Lines</option>
|
|
|
|
|
{lines.map(l => <option key={l} value={String(l)}>{String(l)}</option>)}
|
|
|
|
|
</select>
|
|
|
|
|
<select
|
|
|
|
|
value={licenseFilter}
|
|
|
|
|
onChange={e => { setLicenseFilter(e.target.value); setPage(1); }}
|
|
|
|
|
className="bg-slate-900 border border-slate-700 rounded-md px-4 py-2 text-sm text-white focus:outline-none focus:border-blue-500"
|
|
|
|
|
>
|
|
|
|
|
<option value="">All Licenses</option>
|
|
|
|
|
{licenses.map(l => <option key={l} value={String(l)}>{String(l)}</option>)}
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="flex-1 bg-slate-800 rounded-xl border border-slate-700 shadow-xl overflow-hidden flex flex-col">
|
|
|
|
|
<div className="overflow-x-auto flex-1">
|
2026-04-08 20:21:36 +02:00
|
|
|
<table className="w-full text-left text-sm" style={{ tableLayout: 'fixed' }}>
|
2026-03-27 11:34:09 +01:00
|
|
|
<thead className="bg-slate-900/50 text-slate-400 sticky top-0 z-10">
|
|
|
|
|
<tr>
|
|
|
|
|
{[
|
|
|
|
|
{ col: COLUMNS.ARTICLE_NO, label: 'Article No.' },
|
|
|
|
|
{ col: COLUMNS.ARTICLE_NAME, label: 'Article Name' },
|
2026-04-09 16:33:05 +02:00
|
|
|
...(asinColumnIndex !== null ? [{ col: asinColumnIndex, label: 'ASIN' }] : []),
|
2026-03-27 11:34:09 +01:00
|
|
|
{ col: COLUMNS.LINE, label: 'Line' },
|
2026-04-08 16:18:24 +02:00
|
|
|
{ col: COLUMNS.LICENSE, label: 'License' },
|
|
|
|
|
{ col: COLUMNS.CLASSIFICATION, label: 'Classification' },
|
2026-03-27 11:34:09 +01:00
|
|
|
{ col: COLUMNS.LONG_DE, label: 'Long DE' },
|
2026-03-27 13:53:01 +01:00
|
|
|
{ col: COLUMNS.LONG_EN, label: 'Long EN' },
|
|
|
|
|
{ col: COLUMNS.SHORT_DE, label: 'Short DE' },
|
2026-03-27 11:34:09 +01:00
|
|
|
{ col: COLUMNS.SHORT_EN, label: 'Short EN' },
|
|
|
|
|
].map(({ col, label }) => (
|
2026-04-08 17:11:27 +02:00
|
|
|
<th
|
|
|
|
|
key={col}
|
2026-04-08 20:21:36 +02:00
|
|
|
className="px-4 py-3 font-medium transition-colors select-none group relative border-r border-slate-700/30"
|
|
|
|
|
style={{ width: columnWidths[col] || 'auto', minWidth: columnWidths[col] || 'auto' }}
|
2026-03-27 11:34:09 +01:00
|
|
|
>
|
2026-04-10 10:05:59 +02:00
|
|
|
<div className="flex items-center overflow-hidden">
|
|
|
|
|
<span className="flex items-center gap-1 cursor-pointer hover:text-white truncate" onClick={() => handleSort(col)}>
|
2026-04-08 16:18:24 +02:00
|
|
|
{label}
|
|
|
|
|
{sortCol === col && (
|
2026-04-10 10:05:59 +02:00
|
|
|
sortDesc ? <ChevronDown className="w-4 h-4" /> : <ChevronUp className="w-4 h-4" />
|
2026-04-08 16:18:24 +02:00
|
|
|
)}
|
2026-04-10 10:05:59 +02:00
|
|
|
</span>
|
2026-04-08 16:18:24 +02:00
|
|
|
<button
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
setOpenFilterCol(openFilterCol === col ? null : col);
|
|
|
|
|
}}
|
|
|
|
|
className={cn(
|
2026-04-10 10:05:59 +02:00
|
|
|
"p-0.5 rounded hover:bg-slate-700 transition-colors -my-1",
|
2026-04-08 16:18:24 +02:00
|
|
|
(columnFilters[col]?.length || 0) > 0 ? "text-blue-400 bg-blue-400/10" : "text-slate-500 opacity-0 group-hover:opacity-100"
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<Filter className="w-3.5 h-3.5" />
|
|
|
|
|
</button>
|
2026-03-27 11:34:09 +01:00
|
|
|
</div>
|
2026-04-08 16:18:24 +02:00
|
|
|
|
2026-04-08 20:21:36 +02:00
|
|
|
{/* Resizer handle */}
|
|
|
|
|
<div
|
|
|
|
|
onMouseDown={(e) => handleResize(col, e)}
|
|
|
|
|
className="absolute right-0 top-0 bottom-0 w-1 cursor-col-resize hover:bg-blue-500/50 group-hover:bg-slate-700/50 transition-colors z-20"
|
|
|
|
|
/>
|
|
|
|
|
|
2026-04-08 16:18:24 +02:00
|
|
|
{openFilterCol === col && (
|
|
|
|
|
<ColumnFilterPopover
|
|
|
|
|
uniqueValues={getUniqueValues(col)}
|
|
|
|
|
selectedValues={columnFilters[col] || []}
|
|
|
|
|
onToggle={(val) => toggleColumnFilter(col, val)}
|
2026-04-08 16:50:53 +02:00
|
|
|
onSelectAll={(vals) => setBatchColumnFilter(col, vals)}
|
2026-04-08 16:18:24 +02:00
|
|
|
onClear={() => {
|
|
|
|
|
setColumnFilters(prev => {
|
|
|
|
|
const next = { ...prev };
|
|
|
|
|
delete next[col];
|
|
|
|
|
return next;
|
|
|
|
|
});
|
|
|
|
|
setOpenFilterCol(null);
|
|
|
|
|
}}
|
|
|
|
|
onClose={() => setOpenFilterCol(null)}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2026-03-27 11:34:09 +01:00
|
|
|
</th>
|
|
|
|
|
))}
|
2026-04-08 20:21:36 +02:00
|
|
|
<th className="px-4 py-3 font-medium text-right" style={{ width: 100 }}>Actions</th>
|
2026-03-27 11:34:09 +01:00
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody className="divide-y divide-slate-700/50">
|
2026-04-08 19:49:48 +02:00
|
|
|
{paginatedData.map(({ row, index }) => {
|
2026-04-09 08:22:58 +02:00
|
|
|
const saveStatus = rowStatuses[String(row[COLUMNS.ARTICLE_NO])];
|
2026-04-08 19:49:48 +02:00
|
|
|
return (
|
|
|
|
|
<tr
|
|
|
|
|
key={index}
|
|
|
|
|
className={cn(
|
|
|
|
|
"transition-colors",
|
|
|
|
|
getRowColor(row),
|
2026-04-09 08:22:58 +02:00
|
|
|
saveStatus === 'error' ? "bg-red-400/20 border-l-4 border-l-red-500" :
|
|
|
|
|
saveStatus === 'pending' ? "bg-yellow-400/20 border-l-4 border-l-yellow-400" : ""
|
2026-04-08 19:49:48 +02:00
|
|
|
)}
|
|
|
|
|
>
|
2026-04-08 20:21:36 +02:00
|
|
|
<td className="px-4 py-3 font-mono text-slate-300 text-xs truncate" style={{ width: columnWidths[COLUMNS.ARTICLE_NO] }}>{row[COLUMNS.ARTICLE_NO]}</td>
|
|
|
|
|
<td className="px-4 py-3 font-medium text-white truncate" style={{ width: columnWidths[COLUMNS.ARTICLE_NAME] }} title={row[COLUMNS.ARTICLE_NAME]}>{row[COLUMNS.ARTICLE_NAME]}</td>
|
2026-04-09 16:33:05 +02:00
|
|
|
{asinColumnIndex !== null && (
|
2026-04-10 09:28:49 +02:00
|
|
|
<td className="px-4 py-3 font-mono text-slate-300 text-xs truncate" style={{ width: columnWidths[asinColumnIndex] || 100 }} title={row[asinColumnIndex]}>{row[asinColumnIndex] || '—'}</td>
|
2026-04-09 16:33:05 +02:00
|
|
|
)}
|
2026-04-08 20:21:36 +02:00
|
|
|
<td className="px-4 py-3 text-slate-300 text-xs truncate" style={{ width: columnWidths[COLUMNS.LINE] }}>{row[COLUMNS.LINE]}</td>
|
|
|
|
|
<td className="px-4 py-3 text-slate-300 text-xs truncate" style={{ width: columnWidths[COLUMNS.LICENSE] }} title={row[COLUMNS.LICENSE]}>{row[COLUMNS.LICENSE] || '—'}</td>
|
|
|
|
|
<td className="px-4 py-3 truncate" style={{ width: columnWidths[COLUMNS.CLASSIFICATION] }}>
|
2026-04-08 19:32:28 +02:00
|
|
|
<span className={cn(
|
|
|
|
|
"px-2 py-0.5 rounded text-[10px] font-bold border",
|
|
|
|
|
String(row[COLUMNS.CLASSIFICATION]).includes('OOC')
|
|
|
|
|
? "bg-amber-500/10 text-amber-500 border-amber-500/20"
|
|
|
|
|
: "bg-slate-700/50 text-slate-400 border-slate-600/50"
|
|
|
|
|
)}>
|
|
|
|
|
{row[COLUMNS.CLASSIFICATION] || '—'}
|
|
|
|
|
</span>
|
|
|
|
|
</td>
|
2026-04-08 20:21:36 +02:00
|
|
|
<td className="px-4 py-3" style={{ width: columnWidths[COLUMNS.LONG_DE] }}><Badge content={row[COLUMNS.LONG_DE]} row={row} /></td>
|
|
|
|
|
<td className="px-4 py-3" style={{ width: columnWidths[COLUMNS.LONG_EN] }}><Badge content={row[COLUMNS.LONG_EN]} row={row} /></td>
|
|
|
|
|
<td className="px-4 py-3" style={{ width: columnWidths[COLUMNS.SHORT_DE] }}><Badge content={row[COLUMNS.SHORT_DE]} row={row} /></td>
|
|
|
|
|
<td className="px-4 py-3" style={{ width: columnWidths[COLUMNS.SHORT_EN] }}><Badge content={row[COLUMNS.SHORT_EN]} row={row} /></td>
|
2026-04-08 19:32:28 +02:00
|
|
|
<td className="px-4 py-3 text-right">
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => onEdit(index)}
|
|
|
|
|
className="inline-flex items-center gap-2 px-3 py-1.5 bg-blue-600/10 text-blue-400 hover:bg-blue-600 hover:text-white rounded-md transition-colors font-medium"
|
|
|
|
|
>
|
|
|
|
|
<Edit2 className="w-4 h-4" />
|
|
|
|
|
Edit
|
|
|
|
|
</button>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
2026-04-08 19:49:48 +02:00
|
|
|
);
|
|
|
|
|
})}
|
2026-03-27 11:34:09 +01:00
|
|
|
{paginatedData.length === 0 && (
|
|
|
|
|
<tr>
|
2026-04-09 16:33:05 +02:00
|
|
|
<td colSpan={asinColumnIndex !== null ? 10 : 9} className="px-4 py-8 text-center text-slate-500">
|
2026-03-27 11:34:09 +01:00
|
|
|
No products found matching the criteria.
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
)}
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
</div>
|
2026-04-08 17:11:27 +02:00
|
|
|
|
2026-03-27 11:34:09 +01:00
|
|
|
<div className="bg-slate-900 border-t border-slate-700 p-4 flex items-center justify-between text-sm text-slate-400">
|
|
|
|
|
<div className="flex items-center gap-4">
|
|
|
|
|
<span>Showing {Math.min((page - 1) * pageSize + 1, filteredData.length)} to {Math.min(page * pageSize, filteredData.length)} of {filteredData.length} entries</span>
|
|
|
|
|
<select
|
|
|
|
|
value={pageSize}
|
|
|
|
|
onChange={e => { setPageSize(Number(e.target.value)); setPage(1); }}
|
|
|
|
|
className="bg-slate-800 border border-slate-700 rounded px-2 py-1 focus:outline-none focus:border-blue-500"
|
|
|
|
|
>
|
|
|
|
|
<option value={25}>25 per page</option>
|
|
|
|
|
<option value={50}>50 per page</option>
|
|
|
|
|
<option value={100}>100 per page</option>
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<button
|
|
|
|
|
disabled={page === 1}
|
|
|
|
|
onClick={() => setPage(p => p - 1)}
|
|
|
|
|
className="px-3 py-1 rounded bg-slate-800 hover:bg-slate-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors"
|
|
|
|
|
>
|
|
|
|
|
Previous
|
|
|
|
|
</button>
|
|
|
|
|
<span className="px-3 py-1 font-medium text-white">Page {page} of {totalPages || 1}</span>
|
|
|
|
|
<button
|
|
|
|
|
disabled={page === totalPages || totalPages === 0}
|
|
|
|
|
onClick={() => setPage(p => p + 1)}
|
|
|
|
|
className="px-3 py-1 rounded bg-slate-800 hover:bg-slate-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors"
|
|
|
|
|
>
|
|
|
|
|
Next
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|