From 56f134f7f7a2ce6a3c3fcc22fbc088ce339da9a4 Mon Sep 17 00:00:00 2001 From: fullsizemalt <106900403+fullsizemalt@users.noreply.github.com> Date: Fri, 19 Dec 2025 12:18:15 -0800 Subject: [PATCH] fix: use section ID for reliable beacon positioning - Add sectionId to SearchResult interface - Search handler now looks up section by ID first - Falls back to code/name lookup for backwards compatibility - Fixes beacon offset in Room B (duplicate section codes) --- .../src/components/facility3d/PlantSearch.tsx | 2 ++ frontend/src/pages/Facility3DViewerPage.tsx | 22 +++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/facility3d/PlantSearch.tsx b/frontend/src/components/facility3d/PlantSearch.tsx index b90df0b..81cd264 100644 --- a/frontend/src/components/facility3d/PlantSearch.tsx +++ b/frontend/src/components/facility3d/PlantSearch.tsx @@ -9,6 +9,7 @@ interface SearchResult { sublabel: string; roomName: string; sectionCode: string; + sectionId: string; // For reliable section lookup position: { roomX: number; roomY: number; @@ -53,6 +54,7 @@ export function PlantSearch({ floorData, onSelectResult, onHighlightResults }: P sublabel: `${pos.plant.strain || 'Unknown'} • ${pos.plant.stage || 'N/A'}`, roomName: room.name, sectionCode: section.code || section.name, + sectionId: section.id, // Added for reliable lookup position: { roomX: room.posX, roomY: room.posY, diff --git a/frontend/src/pages/Facility3DViewerPage.tsx b/frontend/src/pages/Facility3DViewerPage.tsx index ae29d8d..5194412 100644 --- a/frontend/src/pages/Facility3DViewerPage.tsx +++ b/frontend/src/pages/Facility3DViewerPage.tsx @@ -233,10 +233,24 @@ export default function Facility3DViewerPage() { const handleSearchSelect = useCallback((result: any) => { if (!floorData) return; - // Find the actual section to use grid-based position calculation - const room = floorData.rooms.find(r => r.name === result.roomName); - const section = room?.sections.find(s => (s.code || s.name) === result.sectionCode); - if (!section) return; + // Find the section - prefer ID lookup for reliability, fall back to code/name + let section: Section3D | undefined; + for (const room of floorData.rooms) { + if (result.sectionId) { + section = room.sections.find(s => s.id === result.sectionId); + } else { + // Fallback: must match both room and section code + if (room.name === result.roomName) { + section = room.sections.find(s => (s.code || s.name) === result.sectionCode); + } + } + if (section) break; + } + + if (!section) { + console.warn('[handleSearchSelect] Could not find section for result:', result); + return; + } const { x, y, z } = calculatePlantCoords( section,