mirror of
https://github.com/jcreek/OpenNetworkDiagram.git
synced 2026-07-13 02:53:45 +00:00
fix(#2): Address PR comments
This commit is contained in:
@@ -505,6 +505,9 @@
|
|||||||
if (!details || details.type !== 'device') {
|
if (!details || details.type !== 'device') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (typeof details.deviceType !== 'string') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return details.deviceType.toLowerCase().includes('switch');
|
return details.deviceType.toLowerCase().includes('switch');
|
||||||
};
|
};
|
||||||
const endpointSide = (angle: number): SwitchSide => {
|
const endpointSide = (angle: number): SwitchSide => {
|
||||||
@@ -938,7 +941,9 @@
|
|||||||
let resizeTimeoutId: ReturnType<typeof setTimeout> | null = null;
|
let resizeTimeoutId: ReturnType<typeof setTimeout> | null = null;
|
||||||
|
|
||||||
const initialize = async () => {
|
const initialize = async () => {
|
||||||
|
if (!cytoscape('layout', 'dagre')) {
|
||||||
cytoscape.use(dagre);
|
cytoscape.use(dagre);
|
||||||
|
}
|
||||||
cy = cytoscape({
|
cy = cytoscape({
|
||||||
container,
|
container,
|
||||||
elements: [],
|
elements: [],
|
||||||
|
|||||||
@@ -25,7 +25,9 @@ function toVmNodeId(hostName: string, vmName: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function parseConnectedTo(connection: Port['connectedTo']): ConnectedPortRef | null {
|
function parseConnectedTo(connection: Port['connectedTo']): ConnectedPortRef | null {
|
||||||
if (!connection?.device || !connection?.port) return null;
|
if (!connection?.device || !connection?.port) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
device: connection.device.trim(),
|
device: connection.device.trim(),
|
||||||
port: connection.port.trim()
|
port: connection.port.trim()
|
||||||
@@ -38,7 +40,9 @@ function hasReciprocalLink(
|
|||||||
expectedPortName: string
|
expectedPortName: string
|
||||||
): boolean {
|
): boolean {
|
||||||
const reverse = parseConnectedTo(targetPort?.connectedTo);
|
const reverse = parseConnectedTo(targetPort?.connectedTo);
|
||||||
if (!reverse) return false;
|
if (!reverse) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return reverse.device === expectedDeviceName && reverse.port === expectedPortName;
|
return reverse.device === expectedDeviceName && reverse.port === expectedPortName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,8 +51,16 @@ function connectionKey(a: string, b: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function edgeSpeed(a: number | undefined, b: number | undefined): number | undefined {
|
function edgeSpeed(a: number | undefined, b: number | undefined): number | undefined {
|
||||||
if (typeof a === 'number' && typeof b === 'number') return Math.min(a, b);
|
if (typeof a === 'number' && typeof b === 'number') {
|
||||||
return typeof a === 'number' ? a : b;
|
return Math.min(a, b);
|
||||||
|
}
|
||||||
|
if (typeof a === 'number') {
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
if (typeof b === 'number') {
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function transformNetworkDataToGraph(data: NetworkData): GraphTransformResult {
|
export function transformNetworkDataToGraph(data: NetworkData): GraphTransformResult {
|
||||||
@@ -89,7 +101,8 @@ export function transformNetworkDataToGraph(data: NetworkData): GraphTransformRe
|
|||||||
for (const machine of data.machines) {
|
for (const machine of data.machines) {
|
||||||
const machineNodeId = toMachineNodeId(machine.machineName);
|
const machineNodeId = toMachineNodeId(machine.machineName);
|
||||||
const machinePortsList = [...(machine.ports ?? [])];
|
const machinePortsList = [...(machine.ports ?? [])];
|
||||||
const machineVms = machine.software.vms.map((vm) => ({
|
const sourceMachineVms = machine.software?.vms ?? [];
|
||||||
|
const machineVms = sourceMachineVms.map((vm) => ({
|
||||||
name: vm.name,
|
name: vm.name,
|
||||||
ip: vm.ipAddress,
|
ip: vm.ipAddress,
|
||||||
role: vm.role
|
role: vm.role
|
||||||
@@ -122,10 +135,10 @@ export function transformNetworkDataToGraph(data: NetworkData): GraphTransformRe
|
|||||||
machineVmIndex[machineNodeId] = {
|
machineVmIndex[machineNodeId] = {
|
||||||
vmNodeIds: [],
|
vmNodeIds: [],
|
||||||
hostingEdgeIds: [],
|
hostingEdgeIds: [],
|
||||||
vmCount: machine.software.vms.length
|
vmCount: sourceMachineVms.length
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const vm of machine.software.vms) {
|
for (const vm of sourceMachineVms) {
|
||||||
const vmNodeId = toVmNodeId(machine.machineName, vm.name);
|
const vmNodeId = toVmNodeId(machine.machineName, vm.name);
|
||||||
|
|
||||||
nodes.push({
|
nodes.push({
|
||||||
@@ -218,7 +231,9 @@ export function transformNetworkDataToGraph(data: NetworkData): GraphTransformRe
|
|||||||
for (const owner of ownersByKey.values()) {
|
for (const owner of ownersByKey.values()) {
|
||||||
for (const port of owner.ports.values()) {
|
for (const port of owner.ports.values()) {
|
||||||
const connectedTo = parseConnectedTo(port.connectedTo);
|
const connectedTo = parseConnectedTo(port.connectedTo);
|
||||||
if (!connectedTo) continue;
|
if (!connectedTo) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const machineTargetOwner = ownersByKey.get(toOwnerKey('machine', connectedTo.device));
|
const machineTargetOwner = ownersByKey.get(toOwnerKey('machine', connectedTo.device));
|
||||||
const deviceTargetOwner = ownersByKey.get(toOwnerKey('device', connectedTo.device));
|
const deviceTargetOwner = ownersByKey.get(toOwnerKey('device', connectedTo.device));
|
||||||
@@ -248,7 +263,9 @@ export function transformNetworkDataToGraph(data: NetworkData): GraphTransformRe
|
|||||||
const a = `${owner.nodeId}:${port.portName}`;
|
const a = `${owner.nodeId}:${port.portName}`;
|
||||||
const b = `${targetOwner.nodeId}:${connectedTo.port}`;
|
const b = `${targetOwner.nodeId}:${connectedTo.port}`;
|
||||||
const dedupeKey = connectionKey(a, b);
|
const dedupeKey = connectionKey(a, b);
|
||||||
if (seenPhysicalConnections.has(dedupeKey)) continue;
|
if (seenPhysicalConnections.has(dedupeKey)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
seenPhysicalConnections.add(dedupeKey);
|
seenPhysicalConnections.add(dedupeKey);
|
||||||
|
|
||||||
const reciprocal = hasReciprocalLink(targetPort, owner.name, port.portName);
|
const reciprocal = hasReciprocalLink(targetPort, owner.name, port.portName);
|
||||||
|
|||||||
Reference in New Issue
Block a user