Skip to content

Commit

Permalink
feat: Always Show ReplicaSets as Pod Groups (#12051)
Browse files Browse the repository at this point in the history
Signed-off-by: Keith Chong <kykchong@redhat.com>
  • Loading branch information
keithchong committed Jan 20, 2023
1 parent 584428e commit 2f38abf
Showing 1 changed file with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function getGraphSize(nodes: dagre.Node[]): {width: number; height: number} {
return {width, height};
}

function groupNodes(nodes: any[], graph: dagre.graphlib.Graph) {
function groupNodes(nodes: ResourceTreeNode[], graph: dagre.graphlib.Graph) {
function getNodeGroupingInfo(nodeId: string) {
const node = graph.node(nodeId);
return {
Expand Down Expand Up @@ -173,22 +173,34 @@ function groupNodes(nodes: any[], graph: dagre.graphlib.Graph) {
groupedNodesArr.forEach((obj: {kind: string; nodeIds: string[]; parentIds: dagre.Node[]}) => {
const {nodeIds, kind, parentIds} = obj;
const groupedNodeIds: string[] = [];
const podGroupIds: string[] = [];
nodeIds.forEach((nodeId: string) => {
const index = nodes.findIndex(node => nodeId === node.uid || nodeId === nodeKey(node));
if (index > -1) {
const graphNode = graph.node(nodeId);
if (!graphNode.podGroup && index > -1) {
groupedNodeIds.push(nodeId);
} else {
podGroupIds.push(nodeId);
}
graph.removeNode(nodeId);
});
graph.setNode(`${parentIds[0].toString()}/child/${kind}`, {
kind,
groupedNodeIds,
height: NODE_HEIGHT,
width: NODE_WIDTH,
count: nodeIds.length,
type: NODE_TYPES.groupedNodes
});
graph.setEdge(parentIds[0].toString(), `${parentIds[0].toString()}/child/${kind}`);
const reducedNodeIds = nodeIds.reduce((acc, aNodeId) => {
if (podGroupIds.findIndex(i => i === aNodeId) < 0) {
acc.push(aNodeId);
}
return acc;
}, []);
if (groupedNodeIds.length > 1) {
groupedNodeIds.forEach(n => graph.removeNode(n));
graph.setNode(`${parentIds[0].toString()}/child/${kind}`, {
kind,
groupedNodeIds,
height: NODE_HEIGHT,
width: NODE_WIDTH,
count: reducedNodeIds.length,
type: NODE_TYPES.groupedNodes
});
graph.setEdge(parentIds[0].toString(), `${parentIds[0].toString()}/child/${kind}`);
}
});
}
}
Expand Down

0 comments on commit 2f38abf

Please sign in to comment.