fix(zigbee): strict tree edges + auto-select imported nodes
Edges - Z2M `links` is bidirectional and includes router mesh paths, which caused duplicate edges and edges entering the coordinator from the bottom. Walk `links` only to derive parent_id + LQI; build final edges strictly from the parent->child hierarchy (one edge per non-coordinator node). Result: parent bottom -> child top, every time. - Tests: bidirectional pair collapses to one edge, router-mesh siblings dropped, coordinator never receives an edge. Auto-select - After import, deselect existing canvas nodes and mark only the freshly-imported ones as selected, so the user can drag the whole subtree as a group.
This commit is contained in:
+12
-6
@@ -345,18 +345,24 @@ export default function App() {
|
||||
}
|
||||
addNode(newNode)
|
||||
})
|
||||
// Add IoT edges between Zigbee devices
|
||||
// Add IoT edges between Zigbee devices: parent bottom -> child top
|
||||
zigbeeEdges.forEach((ze) => {
|
||||
const sourceId = ze.source
|
||||
const targetId = ze.target
|
||||
onConnect({
|
||||
source: sourceId,
|
||||
sourceHandle: 'top',
|
||||
target: targetId,
|
||||
source: ze.source,
|
||||
sourceHandle: 'bottom',
|
||||
target: ze.target,
|
||||
targetHandle: 'top-t',
|
||||
type: 'iot',
|
||||
} as unknown as import('@xyflow/react').Connection)
|
||||
})
|
||||
// Auto-select only the freshly imported nodes so the user can drag the
|
||||
// whole subtree as a group.
|
||||
const importedIds = new Set(zigbeeNodes.map((zn) => zn.id))
|
||||
useCanvasStore.setState((state) => ({
|
||||
nodes: state.nodes.map((n) => ({ ...n, selected: importedIds.has(n.id) })),
|
||||
selectedNodeIds: Array.from(importedIds),
|
||||
selectedNodeId: importedIds.size === 1 ? Array.from(importedIds)[0] : null,
|
||||
}))
|
||||
markUnsaved()
|
||||
}, [addNode, onConnect, snapshotHistory, markUnsaved])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user