mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 14:35:23 +02:00
feat: add Excel-like column filters and License/Classification columns to Product Descriptions
- Added per-column filter popover (Excel-style) with search, multi-select checkboxes, and clear button - Filter icon appears on hover for each column header; turns blue when active - "Clear All Column Filters" button appears in toolbar when any column filter is active - Added License and Classification columns to the table with OOC badge styling Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
8fa001c6ed
commit
04d198ea59
@@ -1,6 +1,6 @@
|
|||||||
import React, { useState, useMemo } from 'react';
|
import React, { useState, useMemo } from 'react';
|
||||||
import { ExcelRow, COLUMNS } from '../types';
|
import { ExcelRow, COLUMNS } from '../types';
|
||||||
import { Search, Filter, Edit2, ChevronDown, ChevronUp } from 'lucide-react';
|
import { Search, Filter, Edit2, ChevronDown, ChevronUp, X, Check } from 'lucide-react';
|
||||||
import { cn } from '../lib/utils';
|
import { cn } from '../lib/utils';
|
||||||
|
|
||||||
interface ProductDescriptionsProps {
|
interface ProductDescriptionsProps {
|
||||||
@@ -19,6 +19,8 @@ export function ProductDescriptions({ data, onEdit }: ProductDescriptionsProps)
|
|||||||
const [sortDesc, setSortDesc] = useState(false);
|
const [sortDesc, setSortDesc] = useState(false);
|
||||||
const [pageSize, setPageSize] = useState(25);
|
const [pageSize, setPageSize] = useState(25);
|
||||||
const [page, setPage] = useState(1);
|
const [page, setPage] = useState(1);
|
||||||
|
const [columnFilters, setColumnFilters] = useState<Record<number, string[]>>({});
|
||||||
|
const [openFilterCol, setOpenFilterCol] = useState<number | null>(null);
|
||||||
|
|
||||||
const lines = useMemo(() => Array.from(new Set(data.map(r => r[COLUMNS.LINE]).filter(Boolean))), [data]);
|
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 licenses = useMemo(() => Array.from(new Set(data.map(r => r[COLUMNS.LICENSE]).filter(Boolean))), [data]);
|
||||||
@@ -56,6 +58,14 @@ export function ProductDescriptions({ data, onEdit }: ProductDescriptionsProps)
|
|||||||
if (lineFilter) result = result.filter(r => r.row[COLUMNS.LINE] === lineFilter);
|
if (lineFilter) result = result.filter(r => r.row[COLUMNS.LINE] === lineFilter);
|
||||||
if (licenseFilter) result = result.filter(r => r.row[COLUMNS.LICENSE] === licenseFilter);
|
if (licenseFilter) result = result.filter(r => r.row[COLUMNS.LICENSE] === licenseFilter);
|
||||||
|
|
||||||
|
// Column-specific filters (Excel-like)
|
||||||
|
Object.entries(columnFilters).forEach(([colIdx, selectedValues]) => {
|
||||||
|
const vals = selectedValues as string[];
|
||||||
|
if (vals.length > 0) {
|
||||||
|
result = result.filter(r => vals.includes(String(r.row[Number(colIdx)] || '')));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Sorting
|
// Sorting
|
||||||
if (sortCol !== null) {
|
if (sortCol !== null) {
|
||||||
result.sort((a, b) => {
|
result.sort((a, b) => {
|
||||||
@@ -84,6 +94,22 @@ export function ProductDescriptions({ data, onEdit }: ProductDescriptionsProps)
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getUniqueValues = (col: number) => {
|
||||||
|
const values = data.map(r => String(r[col] || ''));
|
||||||
|
return Array.from(new Set(values)).sort();
|
||||||
|
};
|
||||||
|
|
||||||
|
const toggleColumnFilter = (col: number, value: string) => {
|
||||||
|
setColumnFilters(prev => {
|
||||||
|
const current = prev[col] || [];
|
||||||
|
const next = current.includes(value)
|
||||||
|
? current.filter(v => v !== value)
|
||||||
|
: [...current, value];
|
||||||
|
return { ...prev, [col]: next };
|
||||||
|
});
|
||||||
|
setPage(1);
|
||||||
|
};
|
||||||
|
|
||||||
const getRowColor = (row: ExcelRow) => {
|
const getRowColor = (row: ExcelRow) => {
|
||||||
// EOL Rule: OOC Classification and 0 or negative stock (Item Available)
|
// EOL Rule: OOC Classification and 0 or negative stock (Item Available)
|
||||||
const classification = String(row[COLUMNS.CLASSIFICATION] || '').toUpperCase().trim();
|
const classification = String(row[COLUMNS.CLASSIFICATION] || '').toUpperCase().trim();
|
||||||
@@ -159,6 +185,18 @@ export function ProductDescriptions({ data, onEdit }: ProductDescriptionsProps)
|
|||||||
className="w-full pl-9 pr-4 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"
|
className="w-full pl-9 pr-4 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"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
{(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>
|
||||||
|
)}
|
||||||
<select
|
<select
|
||||||
value={lineFilter}
|
value={lineFilter}
|
||||||
onChange={e => { setLineFilter(e.target.value); setPage(1); }}
|
onChange={e => { setLineFilter(e.target.value); setPage(1); }}
|
||||||
@@ -186,6 +224,8 @@ export function ProductDescriptions({ data, onEdit }: ProductDescriptionsProps)
|
|||||||
{ col: COLUMNS.ARTICLE_NO, label: 'Article No.' },
|
{ col: COLUMNS.ARTICLE_NO, label: 'Article No.' },
|
||||||
{ col: COLUMNS.ARTICLE_NAME, label: 'Article Name' },
|
{ col: COLUMNS.ARTICLE_NAME, label: 'Article Name' },
|
||||||
{ col: COLUMNS.LINE, label: 'Line' },
|
{ col: COLUMNS.LINE, label: 'Line' },
|
||||||
|
{ col: COLUMNS.LICENSE, label: 'License' },
|
||||||
|
{ col: COLUMNS.CLASSIFICATION, label: 'Classification' },
|
||||||
{ col: COLUMNS.LONG_DE, label: 'Long DE' },
|
{ col: COLUMNS.LONG_DE, label: 'Long DE' },
|
||||||
{ col: COLUMNS.LONG_EN, label: 'Long EN' },
|
{ col: COLUMNS.LONG_EN, label: 'Long EN' },
|
||||||
{ col: COLUMNS.SHORT_DE, label: 'Short DE' },
|
{ col: COLUMNS.SHORT_DE, label: 'Short DE' },
|
||||||
@@ -193,15 +233,45 @@ export function ProductDescriptions({ data, onEdit }: ProductDescriptionsProps)
|
|||||||
].map(({ col, label }) => (
|
].map(({ col, label }) => (
|
||||||
<th
|
<th
|
||||||
key={col}
|
key={col}
|
||||||
className="px-4 py-3 font-medium cursor-pointer hover:text-white transition-colors select-none"
|
className="px-4 py-3 font-medium transition-colors select-none group relative"
|
||||||
onClick={() => handleSort(col)}
|
|
||||||
>
|
>
|
||||||
<div className="flex items-center gap-1">
|
<div className="flex items-center justify-between gap-1">
|
||||||
{label}
|
<div className="flex items-center gap-1 cursor-pointer hover:text-white" onClick={() => handleSort(col)}>
|
||||||
{sortCol === col && (
|
{label}
|
||||||
sortDesc ? <ChevronDown className="w-4 h-4" /> : <ChevronUp className="w-4 h-4" />
|
{sortCol === col && (
|
||||||
)}
|
sortDesc ? <ChevronDown className="w-4 h-4" /> : <ChevronUp className="w-4 h-4" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
setOpenFilterCol(openFilterCol === col ? null : col);
|
||||||
|
}}
|
||||||
|
className={cn(
|
||||||
|
"p-1 rounded hover:bg-slate-700 transition-colors",
|
||||||
|
(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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{openFilterCol === col && (
|
||||||
|
<ColumnFilterPopover
|
||||||
|
uniqueValues={getUniqueValues(col)}
|
||||||
|
selectedValues={columnFilters[col] || []}
|
||||||
|
onToggle={(val) => toggleColumnFilter(col, val)}
|
||||||
|
onClear={() => {
|
||||||
|
setColumnFilters(prev => {
|
||||||
|
const next = { ...prev };
|
||||||
|
delete next[col];
|
||||||
|
return next;
|
||||||
|
});
|
||||||
|
setOpenFilterCol(null);
|
||||||
|
}}
|
||||||
|
onClose={() => setOpenFilterCol(null)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</th>
|
</th>
|
||||||
))}
|
))}
|
||||||
<th className="px-4 py-3 font-medium text-right">Actions</th>
|
<th className="px-4 py-3 font-medium text-right">Actions</th>
|
||||||
@@ -213,6 +283,17 @@ export function ProductDescriptions({ data, onEdit }: ProductDescriptionsProps)
|
|||||||
<td className="px-4 py-3 font-mono text-slate-300 text-xs">{row[COLUMNS.ARTICLE_NO]}</td>
|
<td className="px-4 py-3 font-mono text-slate-300 text-xs">{row[COLUMNS.ARTICLE_NO]}</td>
|
||||||
<td className="px-4 py-3 font-medium text-white max-w-[200px] truncate" title={row[COLUMNS.ARTICLE_NAME]}>{row[COLUMNS.ARTICLE_NAME]}</td>
|
<td className="px-4 py-3 font-medium text-white max-w-[200px] truncate" title={row[COLUMNS.ARTICLE_NAME]}>{row[COLUMNS.ARTICLE_NAME]}</td>
|
||||||
<td className="px-4 py-3 text-slate-300 text-xs">{row[COLUMNS.LINE]}</td>
|
<td className="px-4 py-3 text-slate-300 text-xs">{row[COLUMNS.LINE]}</td>
|
||||||
|
<td className="px-4 py-3 text-slate-300 text-xs truncate max-w-[120px]" title={row[COLUMNS.LICENSE]}>{row[COLUMNS.LICENSE] || '—'}</td>
|
||||||
|
<td className="px-4 py-3">
|
||||||
|
<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>
|
||||||
<td className="px-4 py-3"><Badge content={row[COLUMNS.LONG_DE]} row={row} /></td>
|
<td className="px-4 py-3"><Badge content={row[COLUMNS.LONG_DE]} row={row} /></td>
|
||||||
<td className="px-4 py-3"><Badge content={row[COLUMNS.LONG_EN]} row={row} /></td>
|
<td className="px-4 py-3"><Badge content={row[COLUMNS.LONG_EN]} row={row} /></td>
|
||||||
<td className="px-4 py-3"><Badge content={row[COLUMNS.SHORT_DE]} row={row} /></td>
|
<td className="px-4 py-3"><Badge content={row[COLUMNS.SHORT_DE]} row={row} /></td>
|
||||||
@@ -274,3 +355,73 @@ export function ProductDescriptions({ data, onEdit }: ProductDescriptionsProps)
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ColumnFilterPopoverProps {
|
||||||
|
uniqueValues: string[];
|
||||||
|
selectedValues: string[];
|
||||||
|
onToggle: (val: string) => void;
|
||||||
|
onClear: () => void;
|
||||||
|
onClose: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ColumnFilterPopover({ uniqueValues, selectedValues, onToggle, onClear, onClose }: ColumnFilterPopoverProps) {
|
||||||
|
const [search, setSearch] = useState('');
|
||||||
|
|
||||||
|
const filteredValues = useMemo(() => {
|
||||||
|
return uniqueValues.filter(v => v.toLowerCase().includes(search.toLowerCase()));
|
||||||
|
}, [uniqueValues, search]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="absolute top-full left-0 mt-1 w-64 bg-slate-800 border border-slate-700 rounded-lg shadow-2xl z-50 p-3 flex flex-col gap-3 animate-in fade-in zoom-in-95 duration-100">
|
||||||
|
<div className="relative">
|
||||||
|
<Search className="absolute left-2 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-slate-500" />
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="Filter values..."
|
||||||
|
value={search}
|
||||||
|
onChange={e => setSearch(e.target.value)}
|
||||||
|
className="w-full bg-slate-900 border border-slate-700 rounded p-1.5 pl-8 text-xs text-white focus:outline-none focus:border-blue-500"
|
||||||
|
autoFocus
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="max-h-48 overflow-y-auto space-y-1 pr-1 custom-scrollbar">
|
||||||
|
{filteredValues.map(val => (
|
||||||
|
<label key={val} className="flex items-center gap-2 p-1.5 hover:bg-slate-700/50 rounded cursor-pointer group">
|
||||||
|
<div className={cn(
|
||||||
|
"w-4 h-4 rounded border flex items-center justify-center transition-colors",
|
||||||
|
selectedValues.includes(val) ? "bg-blue-600 border-blue-600" : "border-slate-600 bg-slate-900 group-hover:border-slate-500"
|
||||||
|
)}>
|
||||||
|
{selectedValues.includes(val) && <Check className="w-3 h-3 text-white" />}
|
||||||
|
</div>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
className="hidden"
|
||||||
|
checked={selectedValues.includes(val)}
|
||||||
|
onChange={() => onToggle(val)}
|
||||||
|
/>
|
||||||
|
<span className="text-xs text-slate-300 truncate" title={val}>{val || '(Empty)'}</span>
|
||||||
|
</label>
|
||||||
|
))}
|
||||||
|
{filteredValues.length === 0 && (
|
||||||
|
<div className="text-[10px] text-slate-500 text-center py-2">No values found</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center justify-between pt-2 border-t border-slate-700 mt-1">
|
||||||
|
<button
|
||||||
|
onClick={onClear}
|
||||||
|
className="text-[10px] font-medium text-slate-400 hover:text-white transition-colors"
|
||||||
|
>
|
||||||
|
Clear Current
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={onClose}
|
||||||
|
className="px-3 py-1 bg-blue-600 hover:bg-blue-700 text-white text-[10px] font-bold rounded transition-colors shadow-sm"
|
||||||
|
>
|
||||||
|
OK
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user