Skip to content

Commit e80b4f2

Browse files
nartcFrozenPandaz
authored andcommitted
feat(graph): task graph support multiple targets (#32418)
- [x] graph-client supports multiple targets with multiselect and query params `?targets` - [x] `nx graph` supports multiple targets (i.e: `nx run-many -t build,test --graph` <img width="277" height="385" alt="image" src="https://github.com/user-attachments/assets/6869b652-2ecb-4afb-9ae5-ec29628afec1" /> (cherry picked from commit a277074)
1 parent e4cf6e1 commit e80b4f2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2652
-3519
lines changed

graph/client-e2e/src/fixtures/nx-examples-task-graphs.json

Lines changed: 448 additions & 709 deletions
Large diffs are not rendered by default.

graph/client/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"defaultConfiguration": "release"
4444
},
4545
"typecheck": {
46-
"dependsOn": ["^typecheck", "build-native"]
46+
"dependsOn": ["^typecheck"]
4747
},
4848
"serve-base": {
4949
"configurations": {

graph/client/src/app/console-migrate/migrate.machine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @nx/enforce-module-boundaries */
2-
// nx-ignore-next-line
32
import { assign } from '@xstate/immer';
3+
// nx-ignore-next-line
44
import type {
55
GeneratedMigrationDetails,
66
MigrationDetailsWithId,

graph/client/src/app/feature-projects/machines/interfaces.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,14 @@ import type {
88
} from '@nx/devkit';
99
/* eslint-enable @nx/enforce-module-boundaries */
1010
import {
11-
InitGraphEvent,
1211
ProjectGraphClient,
1312
ProjectGraphClientScratchData,
14-
ProjectGraphClientScratchPad,
1513
ProjectGraphEvent,
1614
ProjectGraphHandleEventResult,
1715
ProjectGraphRenderScratchData,
18-
UpdateGraphEvent,
1916
} from '@nx/graph/projects';
2017
import { ActionObject, ActorRef, State, StateNodeConfig } from 'xstate';
21-
import { GraphRenderEvents } from '../../machines/interfaces';
22-
import {
23-
CompositeProjectNodeElementData,
24-
RenderGraphConfigEvent,
25-
RenderGraphScratchData,
26-
} from '@nx/graph';
18+
import { RenderGraphConfigEvent, RenderGraphScratchData } from '@nx/graph';
2719

2820
// The hierarchical schema for the states
2921
export interface ProjectGraphSchema {

graph/client/src/app/feature-projects/machines/selectors.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ import {
99
WorkspaceLayout,
1010
} from '../../interfaces';
1111
import { TracingAlgorithmType } from './interfaces';
12-
import {
13-
CompositeProjectEdgeElementData,
14-
CompositeProjectNodeElementData,
15-
} from '@nx/graph';
1612

1713
export const allProjectsSelector: ProjectGraphSelector<
1814
ProjectGraphProjectNode[]

graph/client/src/app/feature-tasks/task-list.tsx

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
// nx-ignore-next-line
33
import type { ProjectGraphProjectNode } from '@nx/devkit';
44
/* eslint-enable @nx/enforce-module-boundaries */
5-
import {
6-
createTaskName,
7-
getProjectsByType,
8-
groupProjectsByDirectory,
9-
} from '../util';
5+
import { getProjectsByType, groupProjectsByDirectory } from '../util';
106
import { WorkspaceLayout } from '../interfaces';
117
import { ExclamationCircleIcon, EyeIcon } from '@heroicons/react/24/outline';
128
import { ReactNode } from 'react';
@@ -109,40 +105,45 @@ function SubProjectList({
109105
function mapToSidebarProjectWithTasks(
110106
project: ProjectGraphProjectNode,
111107
selectedProjects: string[],
112-
selectedTarget: string,
113-
errors: Record<string, string>
108+
selectedTargets: string[],
109+
error: string | null
114110
): SidebarProject {
115-
const taskId = createTaskName(project.name, selectedTarget);
111+
// If there's a global error, show it for the project
112+
const hasError = error !== null;
116113

117114
return {
118115
projectGraphNode: project,
119116
isSelected: selectedProjects.includes(project.name),
120-
error: errors?.[taskId] ?? null,
117+
error: hasError ? error : null,
121118
};
122119
}
123120

124121
export interface TaskListProps {
125122
projects: ProjectGraphProjectNode[];
126123
workspaceLayout: WorkspaceLayout;
127-
selectedTarget: string;
124+
selectedTargets: string[];
128125
selectedProjects: string[];
129126
toggleProject: (projectName: string) => void;
130127
children: ReactNode | ReactNode[];
131-
errors: Record<string, string>;
128+
error: string | null;
132129
}
133130

134131
export function TaskList({
135132
projects,
136133
workspaceLayout,
137-
selectedTarget,
134+
selectedTargets,
138135
selectedProjects,
139136
toggleProject,
140137
children,
141-
errors,
138+
error,
142139
}: TaskListProps) {
143140
const filteredProjects = projects
144-
.filter((project) =>
145-
(project.data as any).targets?.hasOwnProperty(selectedTarget)
141+
.filter(
142+
(project) =>
143+
selectedTargets.length > 0 &&
144+
selectedTargets.some((target) =>
145+
(project.data as any).targets?.hasOwnProperty(target)
146+
)
146147
)
147148
.sort((a, b) => a.name.localeCompare(b.name));
148149
const appProjects = getProjectsByType('app', filteredProjects);
@@ -182,8 +183,8 @@ export function TaskList({
182183
mapToSidebarProjectWithTasks(
183184
project,
184185
selectedProjects,
185-
selectedTarget,
186-
errors
186+
selectedTargets,
187+
error
187188
)
188189
)}
189190
toggleTask={toggleProject}
@@ -204,8 +205,8 @@ export function TaskList({
204205
mapToSidebarProjectWithTasks(
205206
project,
206207
selectedProjects,
207-
selectedTarget,
208-
errors
208+
selectedTargets,
209+
error
209210
)
210211
)}
211212
toggleTask={toggleProject}
@@ -226,8 +227,8 @@ export function TaskList({
226227
mapToSidebarProjectWithTasks(
227228
project,
228229
selectedProjects,
229-
selectedTarget,
230-
errors
230+
selectedTargets,
231+
error
231232
)
232233
)}
233234
toggleTask={toggleProject}

0 commit comments

Comments
 (0)