Project discover neighbors from scanned seeds only.

Accept optional seed ids on project-neighbors; canvas discover passes scanned fabric nodes and places new peers near them.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-08-05 21:34:20 +08:00
parent 7cd89aaae9
commit 03ef9eb39a
9 changed files with 137 additions and 18 deletions

View file

@ -1486,7 +1486,7 @@ const en = {
snapGrid: "Snap to grid",
autoLayoutDiscover: "Auto-layout after discover",
discoverAutoAddUnmatched: "Auto-add unmatched NEs as placeholders on discover",
discoverProjectNeighbors: "Project direct neighbors onto canvas after discover",
discoverProjectNeighbors: "After discover, project neighbors of scanned NEs onto the canvas",
undo: "Undo",
redo: "Redo",
discoverSelected: "Discover selected ({{count}})",

View file

@ -1477,7 +1477,7 @@ const zh = {
snapGrid: "网格吸附",
autoLayoutDiscover: "发现后自动布局",
discoverAutoAddUnmatched: "发现时自动入库未匹配网元(占位)",
discoverProjectNeighbors: "发现后将直连邻居加入画布",
discoverProjectNeighbors: "发现后将本次扫描网元的直连邻居加入画布",
undo: "撤销",
redo: "重做",
discoverSelected: "发现选中 ({{count}})",

View file

@ -1620,13 +1620,16 @@ export function TopologyPage() {
throw new Error(job.error || "discover_failed");
}
const projected = discoverProjectNeighbors
? await projectTopologyNeighbors(mapId)
? await projectTopologyNeighbors(mapId, {
seed_fabric_node_ids: scoped.map((n) => n.id),
})
: await fetchTopologyGraph(mapId);
queryClient.setQueryData(queryKeys.topologyGraph(mapId), projected);
appliedMapIdRef.current = mapId;
let { rfNodes, rfEdges } = graphToFlow(projected.nodes, projected.edges, edgeDefaults);
// Keep existing node positions when we did not auto-layout.
const localPos = new Map(nodes.map((n) => [n.id, n.position]));
const beforeIds = new Set(nodes.map((n) => n.id));
rfNodes = rfNodes.map((n) => {
const p = localPos.get(n.id);
return p ? { ...n, position: { ...p } } : n;
@ -1649,7 +1652,8 @@ export function TopologyPage() {
setNodes(rfNodes);
setEdges(rfEdges);
historyLockRef.current = false;
if (didAutoLayout) {
const addedNodes = rfNodes.filter((n) => !beforeIds.has(n.id)).length;
if (didAutoLayout || addedNodes > 0) {
needsInitialFitRef.current = true;
scheduleFitView(FIT_VIEW_OPTS);
}

View file

@ -1084,8 +1084,14 @@ export const removeTopologyViewNodes = (viewId: string, fabricNodeIds: string[])
fabric_node_ids: fabricNodeIds,
});
export const projectTopologyNeighbors = (viewId: string) =>
apiPost<TopologyViewGraph>(`/v1/topology/views/${encodeURIComponent(viewId)}/project-neighbors`, {});
export const projectTopologyNeighbors = (
viewId: string,
body?: { seed_fabric_node_ids?: string[]; managed_ne_ids?: string[] },
) =>
apiPost<TopologyViewGraph>(
`/v1/topology/views/${encodeURIComponent(viewId)}/project-neighbors`,
body || {},
);
export const patchTopologyEdgeStyle = (
viewId: string,