From 09a08c6cefee99ae1ebb552b99920b596d848db6 Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Mon, 17 Jun 2024 09:28:58 -0700 Subject: [PATCH] fix(graph): improve layout when target groups are empty or there are no groups (#26555) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR fixes empty target groups and adds consistency between grouped and ungrouped targets. ## Before Empty groups have bad empty state -- we should not show it. The ungrouped targets being on their own without a group is also inconsistent. Screenshot 2024-06-14 at 9 46 11 AM ## After If group is empty, don't render it. Also, if there are no groups then don't nest the ungrouped targets. Screenshot 2024-06-14 at 9 46 29 AM If there are groups, put the ungrouped targets into `Others`. Screenshot 2024-06-14 at 9 45 55 AM --- ...arget-configuration-details-group-list.tsx | 82 +++++++++++++------ 1 file changed, 59 insertions(+), 23 deletions(-) diff --git a/graph/ui-project-details/src/lib/target-configuration-details-group-list/target-configuration-details-group-list.tsx b/graph/ui-project-details/src/lib/target-configuration-details-group-list/target-configuration-details-group-list.tsx index f9bb4cc4d1df7..04755a85e82d1 100644 --- a/graph/ui-project-details/src/lib/target-configuration-details-group-list/target-configuration-details-group-list.tsx +++ b/graph/ui-project-details/src/lib/target-configuration-details-group-list/target-configuration-details-group-list.tsx @@ -5,6 +5,7 @@ import type { ProjectGraphProjectNode } from '@nx/devkit'; import { TargetConfigurationDetailsListItem } from '../target-configuration-details-list-item/target-configuration-details-list-item'; import { TargetConfigurationGroupContainer } from '../target-configuration-details-group-container/target-configuration-details-group-container'; import { groupTargets } from '../utils/group-targets'; +import { useMemo } from 'react'; export interface TargetConfigurationGroupListProps { project: ProjectGraphProjectNode; @@ -26,22 +27,54 @@ export function TargetConfigurationGroupList({ onViewInTaskGraph, className = '', }: TargetConfigurationGroupListProps) { - const targetsGroup = groupTargets(project); + const targetsGroup = useMemo(() => groupTargets(project), [project]); + const hasGroups = useMemo(() => { + for (const group of Object.entries(targetsGroup.groups)) { + if (group[1]?.length > 0) return true; + } + return false; + }, [targetsGroup]); - return ( - <> - {Object.entries(targetsGroup.groups).map(([targetGroupName, targets]) => { - if (targets.length === 0) { - return null; - } - return ( - -