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,