fix: address code review findings for React Flow UI integration

- Use screenToFlowPosition() for drop coordinates (fixes zoom/pan bug)
- Remove duplicate selection border from DeviceNode (BaseNode handles it)
- Add w-full to GroupNode for proper container sizing
- Remove unused 'selected' destructuring from DeviceNode

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
chihlasm
2026-04-04 14:33:00 +00:00
parent a9c4bcc08b
commit 3c62a6993c
3 changed files with 6 additions and 12 deletions

View File

@@ -25,7 +25,7 @@ function TooltipRow({ label, value }: { label: string; value: string | null | un
)
}
function DeviceNodeComponent({ data, selected }: NodeProps) {
function DeviceNodeComponent({ data }: NodeProps) {
const nodeData = data as unknown as DeviceNodeData
const { icon: Icon, color } = getDeviceRenderConfig(nodeData.deviceType, nodeData.category)
const status = (nodeData.properties?.status || 'unknown') as NodeStatus
@@ -38,7 +38,7 @@ function DeviceNodeComponent({ data, selected }: NodeProps) {
<NodeStatusIndicator status={status}>
<NodeTooltip>
<NodeTooltipTrigger>
<BaseNode className={`min-w-[120px] group ${selected ? 'border-accent' : ''}`}>
<BaseNode className="min-w-[120px] group">
<BaseNodeHeader className="flex-col gap-1 items-center py-3 px-4">
<Icon size={28} style={{ color }} />
<BaseNodeHeaderTitle className="text-center text-xs">

View File

@@ -45,7 +45,7 @@ export function GroupNode({ data, selected }: NodeProps) {
return (
<BaseNode
className={cn(
'h-full min-h-[200px] min-w-[300px] overflow-hidden rounded-lg bg-elevated/30 border-default/50',
'h-full w-full min-h-[200px] min-w-[300px] overflow-hidden rounded-lg bg-elevated/30 border-default/50',
selected && 'border-accent',
)}
>

View File

@@ -25,7 +25,7 @@ import type { DeviceNodeData } from '@/components/network/nodes/DeviceNode'
function DiagramEditorInner() {
const { id } = useParams<{ id: string }>()
const navigate = useNavigate()
const { getNodes, fitView } = useReactFlow()
const { getNodes, fitView, screenToFlowPosition } = useReactFlow()
const [diagramId, setDiagramId] = useState<string | null>(id || null)
const [name, setName] = useState('Untitled Diagram')
@@ -201,13 +201,7 @@ function DiagramEditorInner() {
const onDrop = useCallback((event: React.DragEvent) => {
event.preventDefault()
const reactFlowBounds = (event.target as HTMLElement).closest('.react-flow')?.getBoundingClientRect()
if (!reactFlowBounds) return
const position = {
x: event.clientX - reactFlowBounds.left,
y: event.clientY - reactFlowBounds.top,
}
const position = screenToFlowPosition({ x: event.clientX, y: event.clientY })
// Handle device drops
const deviceRaw = event.dataTransfer.getData('application/reactflow-device')
@@ -256,7 +250,7 @@ function DiagramEditorInner() {
setNodes(nds => [...nds, newNode])
setIsDirty(true)
}
}, [setNodes])
}, [setNodes, screenToFlowPosition])
const handleNodeUpdate = useCallback((nodeId: string, updates: Partial<DeviceNodeData>) => {
setNodes(nds => nds.map(n => {