From 4ed611c2dd35d4af85b82ee6f82317ea8fcd8fb5 Mon Sep 17 00:00:00 2001 From: asingh <11219262+ashutosh16@users.noreply.github.com> Date: Mon, 24 Jul 2023 07:38:57 -0700 Subject: [PATCH] fix(ui): The default pod group filter should be removed if fewer than 15 pods (#14590) Signed-off-by: ashutosh16 <11219262+ashutosh16@users.noreply.github.com> --- .../application-resource-tree.tsx | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/ui/src/app/applications/components/application-resource-tree/application-resource-tree.tsx b/ui/src/app/applications/components/application-resource-tree/application-resource-tree.tsx index 96a8ea55b4f58..b5426ff1de2bf 100644 --- a/ui/src/app/applications/components/application-resource-tree/application-resource-tree.tsx +++ b/ui/src/app/applications/components/application-resource-tree/application-resource-tree.tsx @@ -179,7 +179,7 @@ function groupNodes(nodes: ResourceTreeNode[], graph: dagre.graphlib.Graph) { nodeIds.forEach((nodeId: string) => { const index = nodes.findIndex(node => nodeId === node.uid || nodeId === nodeKey(node)); const graphNode = graph.node(nodeId); - if (!graphNode.podGroup && index > -1) { + if (!graphNode?.podGroup && index > -1) { groupedNodeIds.push(nodeId); } else { podGroupIds.push(nodeId); @@ -935,22 +935,20 @@ export const ApplicationResourceTree = (props: ApplicationResourceTreeProps) => } }, [props.filters]); - const [defaultCompactView, setDefaultCompactView] = React.useState(false); + const podCount = nodes.filter(node => node.kind === 'Pod').length; React.useEffect(() => { const {podGroupCount, setShowCompactNodes, appContext} = props; - const podCount = nodes.filter(node => node.kind === 'Pod').length; - - if (!defaultCompactView && podCount > podGroupCount) { + if (podCount > podGroupCount) { setShowCompactNodes(true); - setDefaultCompactView(true); - appContext.apis.notifications.show({ content: `Since the number of pods has surpassed the threshold pod count of ${podGroupCount}, you will now be switched to the group node view. If you prefer the tree view, you can simply click on the Group Nodes toolbar button to deselect the current view.`, type: NotificationType.Success }); + } else { + props.setShowCompactNodes(false); } - }, [props.setShowCompactNodes, props.showCompactNodes, defaultCompactView]); + }, [podCount]); function filterGraph(app: models.Application, filteredIndicatorParent: string, graphNodesFilter: dagre.graphlib.Graph, predicate: (node: ResourceTreeNode) => boolean) { const appKey = appNodeKey(app);