From 86c3ace6f8c9f1cf97c6fc9d08d2d0dbc4d512c2 Mon Sep 17 00:00:00 2001 From: Christian Vidal Wolf Date: Mon, 20 Apr 2026 11:46:55 +0200 Subject: [PATCH] Add dropdown selector for individual row field changes in Dimensions tab - Added dropdown that shows unique values from the group (outer/units/moq) - Click icon to open dropdown and select value to change single row - Icon turns green on hover (emerald color) - Replaces sync all icon with ChevronDown dropdown icon --- src/components/DimensionsView.tsx | 135 +++++++++++++++++++++++++++--- 1 file changed, 123 insertions(+), 12 deletions(-) diff --git a/src/components/DimensionsView.tsx b/src/components/DimensionsView.tsx index 5727cb0..a65b788 100644 --- a/src/components/DimensionsView.tsx +++ b/src/components/DimensionsView.tsx @@ -60,6 +60,7 @@ export function DimensionsView({ data, headers, onEdit, onSaveRow, onCaptureStat const [hoveredIndex, setHoveredIndex] = useState(null); const [lastClickedIndex, setLastClickedIndex] = useState(null); const [activeClusterKey, setActiveClusterKey] = useState(null); + const [openDropdown, setOpenDropdown] = useState<{ rowIndex: number; field: 'outer' | 'units' | 'moq' } | null>(null); const isDraggingRef = React.useRef(false); const dragStartRef = React.useRef(null); @@ -253,6 +254,18 @@ export function DimensionsView({ data, headers, onEdit, onSaveRow, onCaptureStat return () => window.removeEventListener('mouseup', handleGlobalMouseUp); }, [nearDuplicateClusters]); + React.useEffect(() => { + const handleClickOutside = (e: MouseEvent) => { + if (openDropdown && !(e.target as Element)?.closest('.dropdown-container')) { + setOpenDropdown(null); + } + }; + if (openDropdown) { + document.addEventListener('click', handleClickOutside); + return () => document.removeEventListener('click', handleClickOutside); + } + }, [openDropdown]); + const toggleGroup = (key: string) => { const next = new Set(expandedGroups); if (next.has(key)) { @@ -271,6 +284,47 @@ export function DimensionsView({ data, headers, onEdit, onSaveRow, onCaptureStat setPendingAction({ group, sourceRow, fieldType: 'all' }); }; + const handleSingleFieldChange = async (rowIndex: number, field: 'outer' | 'units' | 'moq', value: string | number) => { + const row = data[rowIndex]; + const updatedRow = [...row]; + + if (field === 'outer') { + const parts = String(value).split('x').map(Number); + if (parts.length === 3) { + updatedRow[COLUMNS.OUTER_L] = parts[0]; + updatedRow[COLUMNS.OUTER_W] = parts[1]; + updatedRow[COLUMNS.OUTER_H] = parts[2]; + } + } else if (field === 'units') { + updatedRow[COLUMNS.UNITS_OUTER] = value; + } else if (field === 'moq') { + updatedRow[COLUMNS.MOQ] = value; + } + + await onSaveRow(rowIndex, updatedRow); + onCaptureState(`Updated ${field} for article ${row[COLUMNS.ARTICLE_NO]}`); + setOpenDropdown(null); + }; + + const getUniqueGroupValues = (group: DimensionGroup, field: 'outer' | 'units' | 'moq'): string[] => { + const values = new Set(); + group.rows.forEach(({ row }) => { + if (field === 'outer') { + const outer = `${row[COLUMNS.OUTER_L]}x${row[COLUMNS.OUTER_W]}x${row[COLUMNS.OUTER_H]}`; + if (outer !== 'undefinedxundefinedxundefined' && row[COLUMNS.OUTER_L] != null) { + values.add(outer); + } + } else if (field === 'units') { + const val = String(row[COLUMNS.UNITS_OUTER] ?? ''); + if (val) values.add(val); + } else if (field === 'moq') { + const val = String(row[COLUMNS.MOQ] ?? ''); + if (val) values.add(val); + } + }); + return Array.from(values).sort(); + }; + const handleVerifyGroup = (e: React.MouseEvent, group: DimensionGroup) => { e.stopPropagation(); group.rows.forEach(({ row, index }) => { @@ -738,48 +792,105 @@ export function DimensionsView({ data, headers, onEdit, onSaveRow, onCaptureStat "px-4 py-3 font-mono", group.discrepancies.outer ? "text-amber-300" : "text-slate-400" )}> -
+
{row[COLUMNS.OUTER_L] !== undefined && row[COLUMNS.OUTER_L] !== null ? row[COLUMNS.OUTER_L] : '-'} × {row[COLUMNS.OUTER_W] !== undefined && row[COLUMNS.OUTER_W] !== null ? row[COLUMNS.OUTER_W] : '-'} × {row[COLUMNS.OUTER_H] !== undefined && row[COLUMNS.OUTER_H] !== null ? row[COLUMNS.OUTER_H] : '-'} + {openDropdown?.rowIndex === index && openDropdown?.field === 'outer' && ( +
+ {getUniqueGroupValues(group, 'outer').map(val => ( + + ))} +
+ )}
-
+
{row[COLUMNS.UNITS_OUTER] !== undefined && row[COLUMNS.UNITS_OUTER] !== null ? row[COLUMNS.UNITS_OUTER] : '-'} + {openDropdown?.rowIndex === index && openDropdown?.field === 'units' && ( +
+ {getUniqueGroupValues(group, 'units').map(val => ( + + ))} +
+ )}
-
+
{row[COLUMNS.MOQ] !== undefined && row[COLUMNS.MOQ] !== null ? row[COLUMNS.MOQ] : '-'} + {openDropdown?.rowIndex === index && openDropdown?.field === 'moq' && ( +
+ {getUniqueGroupValues(group, 'moq').map(val => ( + + ))} +
+ )}