Skip to content

Commit d5ceca9

Browse files
authored
feat(graph): add more graph to editor communication (#18315)
1 parent 054a371 commit d5ceca9

File tree

5 files changed

+84
-7
lines changed

5 files changed

+84
-7
lines changed

graph/client/src/app/external-api.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ export class ExternalApi {
2323
};
2424

2525
private fileClickCallbackListeners: ((url: string) => void)[] = [];
26+
private openProjectConfigCallbackListeners: ((
27+
projectName: string
28+
) => void)[] = [];
29+
private runTaskCallbackListeners: ((taskId: string) => void)[] = [];
2630

2731
get depGraphService() {
2832
return this.projectGraphService;
@@ -34,6 +38,14 @@ export class ExternalApi {
3438
const url = `${event.sourceRoot}/${event.file}`;
3539
this.fileClickCallbackListeners.forEach((cb) => cb(url));
3640
}
41+
if (event.type === 'ProjectOpenConfigClick') {
42+
this.openProjectConfigCallbackListeners.forEach((cb) =>
43+
cb(event.projectName)
44+
);
45+
}
46+
if (event.type === 'RunTaskClick') {
47+
this.runTaskCallbackListeners.forEach((cb) => cb(event.taskId));
48+
}
3749
});
3850
}
3951

@@ -58,6 +70,12 @@ export class ExternalApi {
5870
registerFileClickCallback(callback: (url: string) => void) {
5971
this.fileClickCallbackListeners.push(callback);
6072
}
73+
registerOpenProjectConfigCallback(callback: (projectName: string) => void) {
74+
this.openProjectConfigCallbackListeners.push(callback);
75+
}
76+
registerRunTaskCallback(callback: (taskId: string) => void) {
77+
this.runTaskCallbackListeners.push(callback);
78+
}
6179

6280
private handleLegacyProjectGraphEvent(event: ProjectGraphMachineEvents) {
6381
switch (event.type) {

graph/ui-graph/src/lib/graph-interaction-events.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,22 @@ interface FileLinkClickEvent {
3838
file: string;
3939
}
4040

41+
interface ProjectOpenConfigClickEvent {
42+
type: 'ProjectOpenConfigClick';
43+
projectName: string;
44+
}
45+
46+
interface RunTaskClickEvent {
47+
type: 'RunTaskClick';
48+
taskId: string;
49+
}
50+
4151
export type GraphInteractionEvents =
4252
| ProjectNodeClickEvent
4353
| EdgeClickEvent
4454
| GraphRegeneratedEvent
4555
| TaskNodeClickEvent
4656
| BackgroundClickEvent
47-
| FileLinkClickEvent;
57+
| FileLinkClickEvent
58+
| ProjectOpenConfigClickEvent
59+
| RunTaskClickEvent;

graph/ui-graph/src/lib/tooltip-service.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,34 @@ export class GraphTooltipService {
2020
this.hideAll();
2121
break;
2222
case 'ProjectNodeClick':
23+
const openConfigCallback =
24+
graph.renderMode === 'nx-console'
25+
? () =>
26+
graph.broadcast({
27+
type: 'ProjectOpenConfigClick',
28+
projectName: event.data.id,
29+
})
30+
: undefined;
2331
this.openProjectNodeToolTip(event.ref, {
2432
id: event.data.id,
2533
tags: event.data.tags,
2634
type: event.data.type,
2735
description: event.data.description,
36+
openConfigCallback,
2837
});
2938
break;
3039
case 'TaskNodeClick':
40+
const runTaskCallback =
41+
graph.renderMode === 'nx-console'
42+
? () =>
43+
graph.broadcast({
44+
type: 'RunTaskClick',
45+
taskId: event.data.id,
46+
})
47+
: undefined;
3148
this.openTaskNodeTooltip(event.ref, {
3249
...event.data,
50+
runTaskCallback,
3351
});
3452
break;
3553
case 'EdgeClick':

graph/ui-tooltips/src/lib/project-node-tooltip.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { PencilSquareIcon } from '@heroicons/react/24/outline';
12
import { Tag } from '@nx/graph/ui-components';
23
import { ReactNode } from 'react';
34

@@ -6,6 +7,7 @@ export interface ProjectNodeToolTipProps {
67
id: string;
78
tags: string[];
89
description?: string;
10+
openConfigCallback?: () => void;
911

1012
children?: ReactNode | ReactNode[];
1113
}
@@ -16,12 +18,24 @@ export function ProjectNodeToolTip({
1618
tags,
1719
children,
1820
description,
21+
openConfigCallback,
1922
}: ProjectNodeToolTipProps) {
2023
return (
2124
<div className="text-sm text-slate-700 dark:text-slate-400">
22-
<h4>
23-
<Tag className="mr-3">{type}</Tag>
24-
<span className="font-mono">{id}</span>
25+
<h4 className="flex justify-between items-center gap-4">
26+
<div className="flex items-center">
27+
<Tag className="mr-3">{type}</Tag>
28+
<span className="font-mono">{id}</span>
29+
</div>
30+
{openConfigCallback ? (
31+
<button
32+
className=" flex items-center rounded-md border-slate-300 bg-white p-1 font-medium text-slate-500 shadow-sm ring-1 transition hover:bg-slate-50 dark:border-slate-600 dark:bg-slate-800 dark:text-slate-400 dark:ring-slate-600 hover:dark:bg-slate-700"
33+
title="Edit project.json in editor"
34+
onClick={openConfigCallback}
35+
>
36+
<PencilSquareIcon className="h-5 w-5" />
37+
</button>
38+
) : undefined}
2539
</h4>
2640
{tags.length > 0 ? (
2741
<p className="my-2">

graph/ui-tooltips/src/lib/task-node-tooltip.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,37 @@
1+
import { PlayIcon } from '@heroicons/react/24/outline';
12
import { Tag } from '@nx/graph/ui-components';
23

34
export interface TaskNodeTooltipProps {
45
id: string;
56
executor: string;
7+
runTaskCallback?: () => void;
68
description?: string;
79
}
810

911
export function TaskNodeTooltip({
1012
id,
1113
executor,
1214
description,
15+
runTaskCallback: runTargetCallback,
1316
}: TaskNodeTooltipProps) {
1417
return (
1518
<div className="text-sm text-slate-700 dark:text-slate-400">
16-
<h4>
17-
<Tag className="mr-3">{executor}</Tag>
18-
<span className="font-mono">{id}</span>
19+
<h4 className="flex justify-between items-center gap-4">
20+
<div className="flex items-center">
21+
<Tag className="mr-3">{executor}</Tag>
22+
<span className="font-mono">{id}</span>
23+
</div>
24+
{runTargetCallback ? (
25+
<button
26+
className=" flex items-center rounded-md border-slate-300 bg-white p-1 font-medium text-slate-500 shadow-sm ring-1 transition hover:bg-slate-50 dark:border-slate-600 dark:bg-slate-800 dark:text-slate-400 dark:ring-slate-600 hover:dark:bg-slate-700"
27+
title="Run Task"
28+
onClick={runTargetCallback}
29+
>
30+
<PlayIcon className="h-5 w-5" />
31+
</button>
32+
) : undefined}
1933
</h4>
34+
<h4></h4>
2035
{description ? <p className="mt-4">{description}</p> : null}
2136
</div>
2237
);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy