Skip to content

Commit

Permalink
fix(console): hide invalid, unrelated or duplicated node relationships (
Browse files Browse the repository at this point in the history
#5862)

Sometimes, the Console would show relationships that don't make sense. This was due to inconsistent connection manipulation in the Console server.
  • Loading branch information
skyrpex authored Mar 7, 2024
1 parent 7d145c3 commit 4a9f821
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions apps/wing-console/console/server/src/router/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ export const createAppRouter = () => {
path: sourceNode.path,
type: getResourceType(sourceNode, simulator),
};
})
.filter(({ path }) => {
return path !== node.path;
}),
outbound: connections
.filter(({ source }) => {
Expand All @@ -281,6 +284,9 @@ export const createAppRouter = () => {
path: targetNode.path,
type: getResourceType(targetNode, simulator),
};
})
.filter(({ path }) => {
return path !== node.path;
}),
};
}),
Expand Down Expand Up @@ -633,6 +639,15 @@ function createMapEdgesFromConnectionData(
.filter((connection) => {
return connectionsBasicFilter(connection, nodeMap, showTests);
})
?.map((connection: NodeConnection) => {
const source = getVisualNodePath(connection.source, nodeMap);
const target = getVisualNodePath(connection.target, nodeMap);
return {
id: `${source} -> ${target}`,
source,
target,
};
})
?.filter(({ source, target }) => {
// Remove redundant connections to a parent resource if there's already a connection to a child resource.
if (
Expand All @@ -649,15 +664,6 @@ function createMapEdgesFromConnectionData(
}

return true;
})
?.map((connection: NodeConnection) => {
const source = getVisualNodePath(connection.source, nodeMap);
const target = getVisualNodePath(connection.target, nodeMap);
return {
id: `${source} -> ${target}`,
source,
target,
};
}),
].flat();
}
Expand Down Expand Up @@ -699,8 +705,8 @@ const connectionsBasicFilter = (
});
}

// Hide connections that go from a parent to its direct child (eg, API to an endpoint, queue to a consumer).
if (targetNode.parent === sourceNode.path) {
// Hide self loops.
if (sourceNode.path === targetNode.path) {
return false;
}

Expand Down

0 comments on commit 4a9f821

Please sign in to comment.