Skip to content

Commit

Permalink
feat: Always Show ReplicaSets as Pod Groups (argoproj#12051) (argopro…
Browse files Browse the repository at this point in the history
…j#12065)

Signed-off-by: Keith Chong <kykchong@redhat.com>
Co-authored-by: Remington Breeze <remington@breeze.software>
Signed-off-by: emirot <emirot.nolan@gmail.com>
  • Loading branch information
2 people authored and emirot committed Jan 27, 2023
1 parent 9fa1264 commit dc56aec
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 dc56aec

Please sign in to comment.