2026-04-12 15:11:57 +02:00
|
|
|
import React, { useState, useMemo } from 'react';
|
|
|
|
|
import { ExcelRow, COLUMNS } from '../types';
|
2026-04-12 22:27:04 +02:00
|
|
|
import { Search, ChevronDown, ChevronUp, X, Edit2, Save } from 'lucide-react';
|
2026-04-12 15:11:57 +02:00
|
|
|
import { cn } from '../lib/utils';
|
2026-04-12 22:27:04 +02:00
|
|
|
import { ColumnFilterPopover } from './ColumnFilterPopover';
|
2026-04-14 17:13:47 +02:00
|
|
|
import { DateFilterPopover } from './DateFilterPopover';
|
2026-04-12 15:11:57 +02:00
|
|
|
|
|
|
|
|
interface MissingDataViewProps {
|
|
|
|
|
data: ExcelRow[];
|
|
|
|
|
headers: string[];
|
2026-04-12 15:23:23 +02:00
|
|
|
onSaveRow: (rowIndex: number, updatedRow: ExcelRow) => void;
|
|
|
|
|
onCaptureState: (message: string) => void;
|
2026-04-12 15:11:57 +02:00
|
|
|
}
|
|
|
|
|
|
2026-04-14 17:09:12 +02:00
|
|
|
function formatDateForInput(val: string): string {
|
|
|
|
|
if (!val) return '';
|
2026-04-14 18:55:23 +02:00
|
|
|
// If it's already YYYY-MM-DD, return it
|
|
|
|
|
if (/^\d{4}-\d{2}-\d{2}$/.test(val)) return val;
|
|
|
|
|
// If it's DD/MM/YYYY, convert to YYYY-MM-DD
|
2026-04-14 17:09:12 +02:00
|
|
|
const parts = val.split('/');
|
|
|
|
|
if (parts.length === 3) {
|
2026-04-14 18:55:23 +02:00
|
|
|
return `${parts[2]}-${parts[1].padStart(2, '0')}-${parts[0].padStart(2, '0')}`;
|
2026-04-14 17:09:12 +02:00
|
|
|
}
|
|
|
|
|
return val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function formatDateFromInput(val: string): string {
|
2026-04-14 18:55:23 +02:00
|
|
|
// Always output YYYY-MM-DD as requested
|
|
|
|
|
return val || '';
|
2026-04-14 17:09:12 +02:00
|
|
|
}
|
|
|
|
|
|
2026-04-12 15:11:57 +02:00
|
|
|
function formatDateValue(val: any): string {
|
|
|
|
|
if (val === null || val === undefined || val === '') return '';
|
|
|
|
|
if (typeof val === 'number') {
|
|
|
|
|
if (val >= 25569 && val <= 60000) {
|
|
|
|
|
const excelEpoch = new Date(1899, 11, 30);
|
|
|
|
|
const date = new Date(excelEpoch.getTime() + val * 86400000);
|
2026-04-14 18:55:23 +02:00
|
|
|
return date.toISOString().split('T')[0]; // Returns YYYY-MM-DD
|
2026-04-12 15:11:57 +02:00
|
|
|
}
|
|
|
|
|
return '';
|
|
|
|
|
}
|
2026-04-14 18:55:23 +02:00
|
|
|
return formatDateForInput(String(val));
|
2026-04-12 15:11:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isEmptyOrEpoch(val: any): boolean {
|
|
|
|
|
if (val === null || val === undefined || val === '') return true;
|
|
|
|
|
if (typeof val === 'number') {
|
|
|
|
|
if (val === 0 || val === 1) return true;
|
2026-04-12 15:23:23 +02:00
|
|
|
if (val >= 25569 && val <= 60000) return false;
|
2026-04-12 15:11:57 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
const s = String(val).trim();
|
|
|
|
|
if (s === '' || s === '0' || s === '1') return true;
|
|
|
|
|
if (s.endsWith('/1900')) return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-20 18:46:50 +02:00
|
|
|
type TabType = 'missingLaunch' | 'launchInconsistent' | 'upcomingLaunch';
|
2026-04-12 15:11:57 +02:00
|
|
|
|
2026-04-12 15:23:23 +02:00
|
|
|
interface EditingState {
|
|
|
|
|
rowIndex: number;
|
|
|
|
|
classification: string;
|
|
|
|
|
launchDate: string;
|
|
|
|
|
readyToOrder: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function MissingDataView({ data, headers, onSaveRow, onCaptureState }: MissingDataViewProps) {
|
2026-04-12 22:23:43 +02:00
|
|
|
const [activeTab, setActiveTab] = useState<TabType>('missingLaunch');
|
2026-04-12 15:11:57 +02:00
|
|
|
const [search, setSearch] = useState('');
|
|
|
|
|
const [sortCol, setSortCol] = useState<number | null>(null);
|
|
|
|
|
const [sortDesc, setSortDesc] = useState(false);
|
|
|
|
|
const [page, setPage] = useState(1);
|
2026-04-12 15:23:23 +02:00
|
|
|
const [editing, setEditing] = useState<EditingState | null>(null);
|
2026-04-12 22:27:04 +02:00
|
|
|
const [columnFilters, setColumnFilters] = useState<Record<number, string[]>>({});
|
2026-04-14 17:13:47 +02:00
|
|
|
const [dateFilters, setDateFilters] = useState<Record<number, { start: string; end: string }>>({});
|
2026-04-12 22:27:04 +02:00
|
|
|
const [openFilter, setOpenFilter] = useState<number | null>(null);
|
2026-04-12 15:11:57 +02:00
|
|
|
const pageSize = 100;
|
|
|
|
|
|
2026-04-14 17:17:43 +02:00
|
|
|
const launchDateCol = useMemo(() => {
|
|
|
|
|
const idx = headers.findIndex(h => h.toLowerCase().includes('launch'));
|
|
|
|
|
if (idx >= 0) return idx;
|
|
|
|
|
return headers.findIndex(h => h.toLowerCase().includes('date'));
|
|
|
|
|
}, [headers]);
|
|
|
|
|
const readyToOrderCol = useMemo(() => {
|
|
|
|
|
const idx = headers.findIndex(h => h.toLowerCase().includes('ready'));
|
|
|
|
|
if (idx >= 0) return idx;
|
|
|
|
|
return headers.findIndex(h => h.toLowerCase().includes('order'));
|
|
|
|
|
}, [headers]);
|
2026-04-12 15:11:57 +02:00
|
|
|
|
2026-04-12 15:23:23 +02:00
|
|
|
const launchHeader = launchDateCol >= 0 ? headers[launchDateCol] : 'Launch Date';
|
|
|
|
|
const readyHeader = readyToOrderCol >= 0 ? headers[readyToOrderCol] : 'Ready to Order';
|
|
|
|
|
|
2026-04-12 18:38:47 +02:00
|
|
|
const columns = [
|
|
|
|
|
{ col: COLUMNS.ARTICLE_NO, label: 'SKU', width: 100 },
|
|
|
|
|
{ col: COLUMNS.ARTICLE_NAME, label: 'Name', width: 220 },
|
|
|
|
|
{ col: COLUMNS.CLASSIFICATION, label: 'Classification', width: 130 },
|
|
|
|
|
...(launchDateCol >= 0 ? [{ col: launchDateCol, label: launchHeader, width: 130 }] : []),
|
|
|
|
|
...(readyToOrderCol >= 0 ? [{ col: readyToOrderCol, label: readyHeader, width: 130 }] : []),
|
2026-04-20 18:48:30 +02:00
|
|
|
...((activeTab === 'launchInconsistent' || activeTab === 'upcomingLaunch') ? [{ col: -1, label: 'Days Until Launch', width: 120 }] : []),
|
2026-04-12 18:38:47 +02:00
|
|
|
];
|
|
|
|
|
|
2026-04-12 18:36:19 +02:00
|
|
|
const columnUniqueValues = useMemo(() => {
|
|
|
|
|
const cols = columns.map(c => c.col);
|
|
|
|
|
const result: Record<number, Set<string>> = {};
|
|
|
|
|
cols.forEach(col => result[col] = new Set());
|
|
|
|
|
|
|
|
|
|
data.forEach(row => {
|
|
|
|
|
cols.forEach(col => {
|
|
|
|
|
let val: any = row[col];
|
|
|
|
|
if (col === launchDateCol || col === readyToOrderCol) {
|
|
|
|
|
val = formatDateValue(val) || String(val ?? '');
|
|
|
|
|
} else {
|
|
|
|
|
val = String(val ?? '');
|
|
|
|
|
}
|
|
|
|
|
if (val) result[col].add(val);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
return result;
|
2026-04-12 18:38:47 +02:00
|
|
|
}, [data, columns, launchDateCol, readyToOrderCol]);
|
2026-04-12 18:36:19 +02:00
|
|
|
|
2026-04-12 22:27:04 +02:00
|
|
|
const getUniqueValues = (col: number): string[] => {
|
2026-04-12 18:36:19 +02:00
|
|
|
const values = columnUniqueValues[col];
|
|
|
|
|
if (!values) return [];
|
2026-04-12 22:27:04 +02:00
|
|
|
return Array.from(values).sort() as string[];
|
2026-04-12 18:36:19 +02:00
|
|
|
};
|
|
|
|
|
|
2026-04-12 15:11:57 +02:00
|
|
|
const filteredData = useMemo(() => {
|
2026-04-20 18:48:30 +02:00
|
|
|
let result = data.map((row, index) => ({ row, index, status: 'ok' as string, daysUntil: 0 }));
|
|
|
|
|
|
|
|
|
|
const today = new Date();
|
|
|
|
|
today.setHours(0, 0, 0, 0);
|
2026-04-12 15:11:57 +02:00
|
|
|
|
|
|
|
|
if (activeTab === 'missingLaunch') {
|
|
|
|
|
result = result.filter(r => {
|
|
|
|
|
const val = launchDateCol >= 0 ? r.row[launchDateCol] : undefined;
|
|
|
|
|
return isEmptyOrEpoch(val);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-20 18:48:30 +02:00
|
|
|
if (activeTab === 'launchInconsistent' || activeTab === 'upcomingLaunch') {
|
|
|
|
|
result = result.map(r => {
|
|
|
|
|
const launchVal = launchDateCol >= 0 ? r.row[launchDateCol] : undefined;
|
|
|
|
|
const readyVal = readyToOrderCol >= 0 ? r.row[readyToOrderCol] : undefined;
|
|
|
|
|
const launchDate = formatDateValue(launchVal);
|
|
|
|
|
const readyDate = formatDateValue(readyVal);
|
|
|
|
|
let daysUntil = 0;
|
|
|
|
|
let status = 'ok';
|
|
|
|
|
|
|
|
|
|
if (launchDate && /^\d{4}-\d{2}-\d{2}$/.test(launchDate)) {
|
|
|
|
|
const launchD = new Date(launchDate);
|
|
|
|
|
const diffTime = launchD.getTime() - today.getTime();
|
|
|
|
|
daysUntil = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
|
|
|
|
|
|
|
|
|
|
if (activeTab === 'launchInconsistent') {
|
|
|
|
|
if (readyDate && /^\d{4}-\d{2}-\d{2}$/.test(readyDate)) {
|
|
|
|
|
const readyD = new Date(readyDate);
|
|
|
|
|
if (readyD > launchD) {
|
|
|
|
|
status = 'error_ready_after_launch';
|
|
|
|
|
} else {
|
|
|
|
|
status = 'ok';
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
status = 'ok';
|
|
|
|
|
}
|
|
|
|
|
} else if (activeTab === 'upcomingLaunch') {
|
|
|
|
|
if (daysUntil <= 0) {
|
|
|
|
|
status = 'past';
|
|
|
|
|
} else if (daysUntil <= 120) {
|
|
|
|
|
status = 'critical';
|
|
|
|
|
} else if (daysUntil <= 180) {
|
|
|
|
|
status = 'warning';
|
|
|
|
|
} else {
|
|
|
|
|
status = 'ok';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
status = 'missing_launch';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return { ...r, status, daysUntil };
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (activeTab === 'launchInconsistent') {
|
|
|
|
|
result = result.filter(r =>
|
|
|
|
|
r.status === 'error_ready_after_launch' || (r.status === 'ok' && r.daysUntil > 0 && isEmptyOrEpoch(launchDateCol >= 0 ? r.row[readyToOrderCol] : undefined))
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (activeTab === 'upcomingLaunch') {
|
|
|
|
|
result = result.filter(r => r.status === 'warning' || r.status === 'critical' || r.status === 'past');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-12 15:11:57 +02:00
|
|
|
if (search) {
|
|
|
|
|
const s = search.toLowerCase();
|
|
|
|
|
result = result.filter(r =>
|
|
|
|
|
String(r.row[COLUMNS.ARTICLE_NO] || '').toLowerCase().includes(s) ||
|
|
|
|
|
String(r.row[COLUMNS.ARTICLE_NAME] || '').toLowerCase().includes(s)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-12 22:27:04 +02:00
|
|
|
(Object.entries(columnFilters) as [string, string[]][]).forEach(([colIdx, filterValues]) => {
|
|
|
|
|
if (!filterValues || filterValues.length === 0) return;
|
2026-04-12 18:32:08 +02:00
|
|
|
const colIdxNum = parseInt(colIdx);
|
2026-04-14 17:13:47 +02:00
|
|
|
if (colIdxNum === launchDateCol || colIdxNum === readyToOrderCol) return;
|
2026-04-12 18:32:08 +02:00
|
|
|
result = result.filter(r => {
|
|
|
|
|
const val: any = r.row[colIdxNum];
|
|
|
|
|
const displayVal = colIdxNum === launchDateCol || colIdxNum === readyToOrderCol
|
|
|
|
|
? formatDateValue(val) || String(val ?? '')
|
|
|
|
|
: String(val ?? '');
|
2026-04-12 22:27:04 +02:00
|
|
|
return filterValues.includes(displayVal);
|
2026-04-12 18:32:08 +02:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-14 17:13:47 +02:00
|
|
|
(Object.entries(dateFilters) as [string, { start: string; end: string }][]).forEach(([colIdx, range]) => {
|
|
|
|
|
if (!range.start && !range.end) return;
|
|
|
|
|
const colIdxNum = parseInt(colIdx);
|
|
|
|
|
result = result.filter(r => {
|
|
|
|
|
const val = r.row[colIdxNum];
|
2026-04-14 18:55:23 +02:00
|
|
|
const dateStr = formatDateValue(val);
|
|
|
|
|
if (!dateStr || !/^\d{4}-\d{2}-\d{2}$/.test(dateStr)) return false;
|
|
|
|
|
|
|
|
|
|
const rowDate = new Date(dateStr);
|
2026-04-14 17:13:47 +02:00
|
|
|
if (isNaN(rowDate.getTime())) return false;
|
2026-04-14 18:55:23 +02:00
|
|
|
|
2026-04-14 17:13:47 +02:00
|
|
|
if (range.start) {
|
|
|
|
|
const startDate = new Date(range.start);
|
|
|
|
|
if (rowDate < startDate) return false;
|
|
|
|
|
}
|
|
|
|
|
if (range.end) {
|
|
|
|
|
const endDate = new Date(range.end);
|
|
|
|
|
if (rowDate > endDate) return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-12 15:11:57 +02:00
|
|
|
if (sortCol !== null) {
|
|
|
|
|
result.sort((a, b) => {
|
|
|
|
|
const valA = a.row[sortCol];
|
|
|
|
|
const valB = b.row[sortCol];
|
|
|
|
|
if (typeof valA === 'number' && typeof valB === 'number') {
|
|
|
|
|
return sortDesc ? valB - valA : valA - valB;
|
|
|
|
|
}
|
|
|
|
|
const sA = String(valA || '');
|
|
|
|
|
const sB = String(valB || '');
|
|
|
|
|
return sortDesc ? sB.localeCompare(sA) : sA.localeCompare(sB);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
2026-04-12 18:32:08 +02:00
|
|
|
}, [data, activeTab, search, sortCol, sortDesc, launchDateCol, columnFilters]);
|
2026-04-12 15:11:57 +02:00
|
|
|
|
|
|
|
|
const paginatedData = useMemo(() => {
|
|
|
|
|
const start = (page - 1) * pageSize;
|
|
|
|
|
return filteredData.slice(start, start + pageSize);
|
|
|
|
|
}, [filteredData, page]);
|
|
|
|
|
|
|
|
|
|
const totalPages = Math.ceil(filteredData.length / pageSize);
|
|
|
|
|
|
|
|
|
|
const handleSort = (col: number) => {
|
|
|
|
|
if (sortCol === col) setSortDesc(d => !d);
|
|
|
|
|
else { setSortCol(col); setSortDesc(false); }
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-12 15:23:23 +02:00
|
|
|
const openEdit = (rowIndex: number, row: ExcelRow) => {
|
|
|
|
|
setEditing({
|
|
|
|
|
rowIndex,
|
|
|
|
|
classification: String(row[COLUMNS.CLASSIFICATION] || ''),
|
2026-04-14 17:09:12 +02:00
|
|
|
launchDate: launchDateCol >= 0 ? formatDateForInput(formatDateValue(row[launchDateCol]) || String(row[launchDateCol] ?? '')) : '',
|
|
|
|
|
readyToOrder: readyToOrderCol >= 0 ? formatDateForInput(formatDateValue(row[readyToOrderCol]) || String(row[readyToOrderCol] ?? '')) : '',
|
2026-04-12 15:23:23 +02:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleSave = () => {
|
|
|
|
|
if (!editing) return;
|
|
|
|
|
const row = data[editing.rowIndex];
|
|
|
|
|
onCaptureState(`Updated product ${row[COLUMNS.ARTICLE_NO]}`);
|
|
|
|
|
const newRow = [...row];
|
|
|
|
|
newRow[COLUMNS.CLASSIFICATION] = editing.classification;
|
2026-04-14 17:09:12 +02:00
|
|
|
if (launchDateCol >= 0) newRow[launchDateCol] = formatDateFromInput(editing.launchDate);
|
|
|
|
|
if (readyToOrderCol >= 0) newRow[readyToOrderCol] = formatDateFromInput(editing.readyToOrder);
|
2026-04-12 15:23:23 +02:00
|
|
|
onSaveRow(editing.rowIndex, newRow);
|
|
|
|
|
setEditing(null);
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-12 15:11:57 +02:00
|
|
|
const tabs: { id: TabType; label: string }[] = [
|
|
|
|
|
{ id: 'missingLaunch', label: 'Missing Launch Date' },
|
2026-04-20 18:48:30 +02:00
|
|
|
{ id: 'launchInconsistent', label: 'Launch Date Inconsistencies' },
|
|
|
|
|
{ id: 'upcomingLaunch', label: 'Upcoming Launch Date' },
|
2026-04-12 15:11:57 +02:00
|
|
|
];
|
|
|
|
|
|
2026-04-12 15:23:23 +02:00
|
|
|
const editingRow = editing ? data[editing.rowIndex] : null;
|
|
|
|
|
|
2026-04-12 15:11:57 +02:00
|
|
|
return (
|
|
|
|
|
<div className="flex flex-col h-full">
|
|
|
|
|
<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",
|
|
|
|
|
activeTab === tab.id
|
|
|
|
|
? "bg-indigo-600 text-white shadow-md"
|
|
|
|
|
: "bg-slate-800 text-slate-400 hover:bg-slate-700 hover:text-white"
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{tab.label}
|
|
|
|
|
</button>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="flex flex-wrap gap-4 mb-6 bg-slate-800/50 p-4 rounded-xl border border-slate-700/50">
|
|
|
|
|
<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-500" />
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
placeholder="Search SKU or Name..."
|
|
|
|
|
value={search}
|
|
|
|
|
onChange={e => { setSearch(e.target.value); setPage(1); }}
|
|
|
|
|
className="w-full pl-9 pr-10 py-2 bg-slate-900/50 border border-slate-700 rounded-md text-sm text-white focus:outline-none focus:border-indigo-500 focus:ring-1 focus:ring-indigo-500"
|
|
|
|
|
/>
|
|
|
|
|
{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>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center text-xs text-slate-500">
|
|
|
|
|
{filteredData.length} items
|
|
|
|
|
</div>
|
|
|
|
|
</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">
|
|
|
|
|
<table className="w-full text-left text-xs">
|
|
|
|
|
<thead className="bg-slate-900/80 text-slate-400 sticky top-0 z-10">
|
|
|
|
|
<tr>
|
2026-04-12 18:36:19 +02:00
|
|
|
{columns.map(({ col, label, width }) => {
|
2026-04-12 22:27:04 +02:00
|
|
|
const selectedFilters = columnFilters[col] || [];
|
|
|
|
|
const allValues = getUniqueValues(col);
|
|
|
|
|
const filterCount = selectedFilters.length;
|
2026-04-12 18:36:19 +02:00
|
|
|
return (
|
2026-04-12 15:11:57 +02:00
|
|
|
<th
|
|
|
|
|
key={col}
|
|
|
|
|
style={{ width, minWidth: width }}
|
2026-04-12 18:32:08 +02:00
|
|
|
className="px-2 py-2 font-medium border-r border-slate-700/30 relative"
|
2026-04-12 15:11:57 +02:00
|
|
|
>
|
2026-04-12 18:32:08 +02:00
|
|
|
<div
|
|
|
|
|
className="flex items-center gap-1 cursor-pointer select-none hover:text-white"
|
|
|
|
|
onClick={() => handleSort(col)}
|
|
|
|
|
>
|
2026-04-12 15:11:57 +02:00
|
|
|
{label}
|
|
|
|
|
{sortCol === col && (
|
|
|
|
|
sortDesc ? <ChevronDown className="w-3 h-3" /> : <ChevronUp className="w-3 h-3" />
|
|
|
|
|
)}
|
2026-04-12 18:32:08 +02:00
|
|
|
</div>
|
|
|
|
|
<div className="mt-1 relative">
|
2026-04-14 17:13:47 +02:00
|
|
|
{col === launchDateCol || col === readyToOrderCol ? (
|
|
|
|
|
<>
|
|
|
|
|
<button
|
|
|
|
|
onClick={(e) => { e.stopPropagation(); setOpenFilter(openFilter === col ? null : col); }}
|
|
|
|
|
className={cn(
|
|
|
|
|
"w-full flex items-center justify-between px-1.5 py-0.5 bg-slate-800 border rounded text-[10px] transition-colors",
|
|
|
|
|
dateFilters[col]?.start || dateFilters[col]?.end
|
|
|
|
|
? "border-indigo-500 text-white"
|
|
|
|
|
: "border-slate-600 text-slate-400 hover:border-slate-500"
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<span className="truncate">
|
|
|
|
|
{dateFilters[col]?.start || dateFilters[col]?.end
|
|
|
|
|
? `${dateFilters[col].start ? dateFilters[col].start : '...'} - ${dateFilters[col].end ? dateFilters[col].end : '...'}`
|
|
|
|
|
: 'Filter...'}
|
|
|
|
|
</span>
|
|
|
|
|
<ChevronDown className={cn("w-3 h-3 transition-transform", openFilter === col && "rotate-180")} />
|
|
|
|
|
</button>
|
|
|
|
|
{openFilter === col && (
|
|
|
|
|
<DateFilterPopover
|
|
|
|
|
selectedRange={dateFilters[col] || { start: '', end: '' }}
|
|
|
|
|
onRangeChange={(range) => setDateFilters(prev => ({ ...prev, [col]: range }))}
|
|
|
|
|
onClose={() => setOpenFilter(null)}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
<button
|
|
|
|
|
onClick={(e) => { e.stopPropagation(); setOpenFilter(openFilter === col ? null : col); }}
|
|
|
|
|
className={cn(
|
|
|
|
|
"w-full flex items-center justify-between px-1.5 py-0.5 bg-slate-800 border rounded text-[10px] transition-colors",
|
|
|
|
|
filterCount > 0 ? "border-indigo-500 text-white" : "border-slate-600 text-slate-400 hover:border-slate-500"
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<span className="truncate">{filterCount > 0 ? `${filterCount} selected` : 'Filter...'}</span>
|
|
|
|
|
<ChevronDown className={cn("w-3 h-3 transition-transform", openFilter === col && "rotate-180")} />
|
|
|
|
|
</button>
|
|
|
|
|
{openFilter === col && (
|
|
|
|
|
<ColumnFilterPopover
|
|
|
|
|
uniqueValues={allValues}
|
|
|
|
|
selectedValues={selectedFilters}
|
|
|
|
|
onToggle={(val) => setColumnFilters(prev => {
|
|
|
|
|
const current = prev[col] || [];
|
|
|
|
|
if (current.includes(val)) {
|
|
|
|
|
return { ...prev, [col]: current.filter(v => v !== val) };
|
|
|
|
|
}
|
|
|
|
|
return { ...prev, [col]: [...current, val] };
|
|
|
|
|
})}
|
|
|
|
|
onSelectAll={(vals) => setColumnFilters(prev => ({ ...prev, [col]: vals }))}
|
|
|
|
|
onClear={() => { setColumnFilters(prev => { const n = { ...prev }; delete n[col]; return n; }); }}
|
|
|
|
|
onClose={() => setOpenFilter(null)}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
2026-04-12 18:32:08 +02:00
|
|
|
)}
|
|
|
|
|
</div>
|
2026-04-12 15:11:57 +02:00
|
|
|
</th>
|
2026-04-12 18:36:19 +02:00
|
|
|
);})}
|
2026-04-12 18:32:08 +02:00
|
|
|
<th className="px-2 py-2 font-medium text-right" style={{ width: 60 }}></th>
|
2026-04-12 15:11:57 +02:00
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody className="divide-y divide-slate-700/30">
|
2026-04-20 18:48:30 +02:00
|
|
|
{paginatedData.map(({ row, index, status, daysUntil }) => (
|
|
|
|
|
<tr key={index} className={cn(
|
|
|
|
|
"hover:bg-slate-700/20 transition-colors",
|
|
|
|
|
activeTab === 'launchInconsistent' && status === 'error_ready_after_launch' && "bg-red-500/10",
|
|
|
|
|
activeTab === 'upcomingLaunch' && status === 'warning' && "bg-yellow-500/10",
|
|
|
|
|
activeTab === 'upcomingLaunch' && status === 'critical' && "bg-red-500/10",
|
|
|
|
|
activeTab === 'upcomingLaunch' && status === 'past' && "bg-red-600/20"
|
|
|
|
|
)}>
|
2026-04-12 15:11:57 +02:00
|
|
|
<td className="px-3 py-2 font-mono text-indigo-400 truncate" style={{ width: 100 }}>
|
|
|
|
|
{row[COLUMNS.ARTICLE_NO]}
|
|
|
|
|
</td>
|
|
|
|
|
<td className="px-3 py-2 font-medium text-slate-200 truncate" style={{ width: 220 }} title={row[COLUMNS.ARTICLE_NAME]}>
|
|
|
|
|
{row[COLUMNS.ARTICLE_NAME]}
|
|
|
|
|
</td>
|
|
|
|
|
<td className="px-3 py-2 truncate" style={{ width: 130 }}>
|
|
|
|
|
{row[COLUMNS.CLASSIFICATION] && String(row[COLUMNS.CLASSIFICATION]).trim() !== '' ? (
|
|
|
|
|
<span className={cn(
|
|
|
|
|
"px-1.5 py-0.5 rounded-[4px] 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>
|
|
|
|
|
) : (
|
|
|
|
|
<span className="inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-red-500/10 text-red-400 border border-red-500/20">Empty</span>
|
|
|
|
|
)}
|
|
|
|
|
</td>
|
|
|
|
|
{launchDateCol >= 0 && (
|
|
|
|
|
<td className="px-3 py-2 truncate font-mono text-slate-300" style={{ width: 130 }}>
|
|
|
|
|
{isEmptyOrEpoch(row[launchDateCol]) ? (
|
|
|
|
|
<span className="inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-red-500/10 text-red-400 border border-red-500/20">Empty</span>
|
|
|
|
|
) : (
|
|
|
|
|
formatDateValue(row[launchDateCol]) || String(row[launchDateCol])
|
|
|
|
|
)}
|
|
|
|
|
</td>
|
|
|
|
|
)}
|
|
|
|
|
{readyToOrderCol >= 0 && (
|
|
|
|
|
<td className="px-3 py-2 truncate font-mono text-slate-300" style={{ width: 130 }}>
|
|
|
|
|
{row[readyToOrderCol] !== null && row[readyToOrderCol] !== undefined && row[readyToOrderCol] !== '' ? (
|
|
|
|
|
formatDateValue(row[readyToOrderCol]) || String(row[readyToOrderCol])
|
|
|
|
|
) : (
|
|
|
|
|
<span className="inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-slate-700/50 text-slate-500 border border-slate-600/50">—</span>
|
2026-04-20 18:48:30 +02:00
|
|
|
)}
|
|
|
|
|
</td>
|
|
|
|
|
)}
|
|
|
|
|
{(activeTab === 'launchInconsistent' || activeTab === 'upcomingLaunch') && (
|
|
|
|
|
<td className="px-3 py-2 font-mono" style={{ width: 120 }}>
|
|
|
|
|
{status === 'error_ready_after_launch' ? (
|
|
|
|
|
<span className="inline-flex items-center px-2 py-0.5 rounded text-[10px] font-bold bg-red-500/20 text-red-400 border border-red-500/40">
|
|
|
|
|
Ready > Launch
|
|
|
|
|
</span>
|
|
|
|
|
) : status === 'warning' ? (
|
|
|
|
|
<span className="inline-flex items-center px-2 py-0.5 rounded text-[10px] font-bold bg-yellow-500/20 text-yellow-400 border border-yellow-500/40">
|
|
|
|
|
{daysUntil} days
|
|
|
|
|
</span>
|
|
|
|
|
) : status === 'critical' ? (
|
|
|
|
|
<span className="inline-flex items-center px-2 py-0.5 rounded text-[10px] font-bold bg-red-500/20 text-red-400 border border-red-500/40">
|
|
|
|
|
{daysUntil} days
|
|
|
|
|
</span>
|
|
|
|
|
) : status === 'past' ? (
|
|
|
|
|
<span className="inline-flex items-center px-2 py-0.5 rounded text-[10px] font-bold bg-red-600/30 text-red-300 border border-red-500/50">
|
|
|
|
|
Past
|
|
|
|
|
</span>
|
|
|
|
|
) : (
|
|
|
|
|
<span className="text-slate-500">—</span>
|
2026-04-12 15:11:57 +02:00
|
|
|
)}
|
|
|
|
|
</td>
|
|
|
|
|
)}
|
2026-04-12 15:19:20 +02:00
|
|
|
<td className="px-3 py-2 text-right" style={{ width: 60 }}>
|
|
|
|
|
<button
|
2026-04-12 15:23:23 +02:00
|
|
|
onClick={() => openEdit(index, row)}
|
2026-04-12 15:19:20 +02:00
|
|
|
className="p-1.5 text-slate-500 hover:text-indigo-400 hover:bg-indigo-400/10 rounded transition-colors"
|
|
|
|
|
>
|
|
|
|
|
<Edit2 className="w-4 h-4" />
|
|
|
|
|
</button>
|
|
|
|
|
</td>
|
2026-04-12 15:11:57 +02:00
|
|
|
</tr>
|
|
|
|
|
))}
|
|
|
|
|
{paginatedData.length === 0 && (
|
|
|
|
|
<tr>
|
2026-04-12 15:23:23 +02:00
|
|
|
<td colSpan={columns.length + 1} className="px-4 py-8 text-center text-slate-500">
|
2026-04-12 15:11:57 +02:00
|
|
|
No items found.
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
)}
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="bg-slate-900 border-t border-slate-700 p-4 flex items-center justify-between text-xs text-slate-500">
|
|
|
|
|
<div>Showing {paginatedData.length} of {filteredData.length} items</div>
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<button
|
|
|
|
|
disabled={page === 1}
|
|
|
|
|
onClick={() => setPage(p => p - 1)}
|
|
|
|
|
className="px-2 py-1 rounded bg-slate-800 hover:bg-slate-700 disabled:opacity-50 transition-colors"
|
|
|
|
|
>
|
|
|
|
|
Previous
|
|
|
|
|
</button>
|
|
|
|
|
<span className="text-slate-300">Page {page} of {totalPages || 1}</span>
|
|
|
|
|
<button
|
|
|
|
|
disabled={page === totalPages || totalPages === 0}
|
|
|
|
|
onClick={() => setPage(p => p + 1)}
|
|
|
|
|
className="px-2 py-1 rounded bg-slate-800 hover:bg-slate-700 disabled:opacity-50 transition-colors"
|
|
|
|
|
>
|
|
|
|
|
Next
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-04-12 15:23:23 +02:00
|
|
|
|
|
|
|
|
{/* Focused edit panel */}
|
|
|
|
|
{editing && editingRow && (
|
|
|
|
|
<>
|
|
|
|
|
<div className="fixed inset-0 bg-slate-950/50 backdrop-blur-sm z-40" onClick={() => setEditing(null)} />
|
|
|
|
|
<div className="fixed right-0 top-0 bottom-0 w-[400px] bg-slate-800 border-l border-slate-700 shadow-2xl z-50 flex flex-col animate-in slide-in-from-right duration-200">
|
|
|
|
|
<div className="flex items-center justify-between p-6 border-b border-slate-700 bg-slate-800/50">
|
|
|
|
|
<div>
|
|
|
|
|
<h2 className="text-lg font-bold text-white">Edit Fields</h2>
|
|
|
|
|
<p className="text-xs text-slate-400 mt-0.5">
|
|
|
|
|
{editingRow[COLUMNS.ARTICLE_NO]} — {editingRow[COLUMNS.ARTICLE_NAME]}
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => setEditing(null)}
|
|
|
|
|
className="p-2 text-slate-400 hover:text-white hover:bg-slate-700 rounded-full transition-colors"
|
|
|
|
|
>
|
|
|
|
|
<X className="w-5 h-5" />
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="flex-1 overflow-auto p-6 space-y-5">
|
|
|
|
|
<div className="flex flex-col gap-1.5">
|
|
|
|
|
<label className="text-xs font-medium text-slate-400 uppercase tracking-wider">Classification</label>
|
2026-04-14 17:06:06 +02:00
|
|
|
<select
|
2026-04-12 15:23:23 +02:00
|
|
|
value={editing.classification}
|
|
|
|
|
onChange={e => setEditing(prev => prev ? { ...prev, classification: e.target.value } : prev)}
|
|
|
|
|
className={cn(
|
|
|
|
|
"w-full bg-slate-900 border rounded-md px-3 py-2.5 text-sm text-white focus:outline-none focus:ring-1 transition-colors",
|
|
|
|
|
editing.classification !== String(editingRow[COLUMNS.CLASSIFICATION] || '')
|
|
|
|
|
? "border-blue-500 focus:ring-blue-500"
|
|
|
|
|
: "border-slate-700 focus:border-slate-500 focus:ring-slate-500"
|
|
|
|
|
)}
|
2026-04-14 17:06:06 +02:00
|
|
|
>
|
|
|
|
|
<option value="">Select classification...</option>
|
|
|
|
|
{getUniqueValues(COLUMNS.CLASSIFICATION).map(val => (
|
|
|
|
|
<option key={val} value={val}>{val}</option>
|
|
|
|
|
))}
|
|
|
|
|
</select>
|
2026-04-12 15:23:23 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{launchDateCol >= 0 && (
|
|
|
|
|
<div className="flex flex-col gap-1.5">
|
|
|
|
|
<label className="text-xs font-medium text-slate-400 uppercase tracking-wider">{launchHeader}</label>
|
|
|
|
|
<input
|
2026-04-14 17:09:12 +02:00
|
|
|
type="date"
|
2026-04-12 15:23:23 +02:00
|
|
|
value={editing.launchDate}
|
|
|
|
|
onChange={e => setEditing(prev => prev ? { ...prev, launchDate: e.target.value } : prev)}
|
2026-04-14 18:58:07 +02:00
|
|
|
onFocus={(e) => e.target.showPicker()}
|
|
|
|
|
onClick={(e) => e.currentTarget.showPicker()}
|
2026-04-12 15:23:23 +02:00
|
|
|
className={cn(
|
2026-04-14 18:58:07 +02:00
|
|
|
"w-full bg-slate-900 border rounded-md px-3 py-2.5 text-sm text-white focus:outline-none focus:ring-1 transition-colors cursor-pointer [color-scheme:dark]",
|
2026-04-12 15:23:23 +02:00
|
|
|
editing.launchDate !== (formatDateValue(editingRow[launchDateCol]) || String(editingRow[launchDateCol] ?? ''))
|
|
|
|
|
? "border-blue-500 focus:ring-blue-500"
|
|
|
|
|
: "border-slate-700 focus:border-slate-500 focus:ring-slate-500"
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{readyToOrderCol >= 0 && (
|
|
|
|
|
<div className="flex flex-col gap-1.5">
|
|
|
|
|
<label className="text-xs font-medium text-slate-400 uppercase tracking-wider">{readyHeader}</label>
|
|
|
|
|
<input
|
2026-04-14 17:09:12 +02:00
|
|
|
type="date"
|
2026-04-12 15:23:23 +02:00
|
|
|
value={editing.readyToOrder}
|
|
|
|
|
onChange={e => setEditing(prev => prev ? { ...prev, readyToOrder: e.target.value } : prev)}
|
2026-04-14 18:58:07 +02:00
|
|
|
onFocus={(e) => e.target.showPicker()}
|
|
|
|
|
onClick={(e) => e.currentTarget.showPicker()}
|
2026-04-12 15:23:23 +02:00
|
|
|
className={cn(
|
2026-04-14 18:58:07 +02:00
|
|
|
"w-full bg-slate-900 border rounded-md px-3 py-2.5 text-sm text-white focus:outline-none focus:ring-1 transition-colors cursor-pointer [color-scheme:dark]",
|
2026-04-12 15:23:23 +02:00
|
|
|
editing.readyToOrder !== (formatDateValue(editingRow[readyToOrderCol]) || String(editingRow[readyToOrderCol] ?? ''))
|
|
|
|
|
? "border-blue-500 focus:ring-blue-500"
|
|
|
|
|
: "border-slate-700 focus:border-slate-500 focus:ring-slate-500"
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="p-6 border-t border-slate-700 bg-slate-800/50 flex justify-end gap-3">
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => setEditing(null)}
|
|
|
|
|
className="px-4 py-2 text-sm font-medium text-slate-300 hover:text-white hover:bg-slate-700 rounded-md transition-colors"
|
|
|
|
|
>
|
|
|
|
|
Cancel
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
|
|
|
|
onClick={handleSave}
|
|
|
|
|
className="flex items-center gap-2 px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white text-sm font-medium rounded-md shadow-lg shadow-blue-900/20 transition-colors"
|
|
|
|
|
>
|
|
|
|
|
<Save className="w-4 h-4" />
|
|
|
|
|
Queue Changes
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2026-04-12 15:11:57 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|