From 6c8bed9679b1fcf89faea02e533838988ac9dddf Mon Sep 17 00:00:00 2001 From: josh Date: Fri, 8 May 2026 15:26:07 -0400 Subject: [PATCH] Prefill asset ID from last added item instead of global max Co-Authored-By: Claude Opus 4.6 --- web/src/components/modals/AddInventoryFlow.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/web/src/components/modals/AddInventoryFlow.tsx b/web/src/components/modals/AddInventoryFlow.tsx index 1d0d645..cbcc328 100644 --- a/web/src/components/modals/AddInventoryFlow.tsx +++ b/web/src/components/modals/AddInventoryFlow.tsx @@ -359,11 +359,12 @@ function InstanceDetailsStep({ })(); const nextAssetId = useMemo(() => { - const max = data.inventoryItems.reduce( - (m, i) => Math.max(m, parseInt(i.assetId, 10) || 0), - 0, + if (data.inventoryItems.length === 0) return ""; + const latest = data.inventoryItems.reduce((best, i) => + i.id > best.id ? i : best, ); - return max > 0 ? String(max + 1).padStart(6, "0") : ""; + const num = parseInt(latest.assetId, 10); + return isNaN(num) ? "" : String(num + 1).padStart(6, "0"); }, [data.inventoryItems]); const [assetId, setAssetId] = useState(nextAssetId);