Skip to content

Commit

Permalink
feat(graph): add more graph to editor communication (#18315)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKless committed Aug 2, 2023
1 parent 054a371 commit d5ceca9
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 7 deletions.
18 changes: 18 additions & 0 deletions graph/client/src/app/external-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export class ExternalApi {
};

private fileClickCallbackListeners: ((url: string) => void)[] = [];
private openProjectConfigCallbackListeners: ((
projectName: string
) => void)[] = [];
private runTaskCallbackListeners: ((taskId: string) => void)[] = [];

get depGraphService() {
return this.projectGraphService;
Expand All @@ -34,6 +38,14 @@ export class ExternalApi {
const url = `${event.sourceRoot}/${event.file}`;
this.fileClickCallbackListeners.forEach((cb) => cb(url));
}
if (event.type === 'ProjectOpenConfigClick') {
this.openProjectConfigCallbackListeners.forEach((cb) =>
cb(event.projectName)
);
}
if (event.type === 'RunTaskClick') {
this.runTaskCallbackListeners.forEach((cb) => cb(event.taskId));
}
});
}

Expand All @@ -58,6 +70,12 @@ export class ExternalApi {
registerFileClickCallback(callback: (url: string) => void) {
this.fileClickCallbackListeners.push(callback);
}
registerOpenProjectConfigCallback(callback: (projectName: string) => void) {
this.openProjectConfigCallbackListeners.push(callback);
}
registerRunTaskCallback(callback: (taskId: string) => void) {
this.runTaskCallbackListeners.push(callback);
}

private handleLegacyProjectGraphEvent(event: ProjectGraphMachineEvents) {
switch (event.type) {
Expand Down
14 changes: 13 additions & 1 deletion graph/ui-graph/src/lib/graph-interaction-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,22 @@ interface FileLinkClickEvent {
file: string;
}

interface ProjectOpenConfigClickEvent {
type: 'ProjectOpenConfigClick';
projectName: string;
}

interface RunTaskClickEvent {
type: 'RunTaskClick';
taskId: string;
}

export type GraphInteractionEvents =
| ProjectNodeClickEvent
| EdgeClickEvent
| GraphRegeneratedEvent
| TaskNodeClickEvent
| BackgroundClickEvent
| FileLinkClickEvent;
| FileLinkClickEvent
| ProjectOpenConfigClickEvent
| RunTaskClickEvent;
18 changes: 18 additions & 0 deletions graph/ui-graph/src/lib/tooltip-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,34 @@ export class GraphTooltipService {
this.hideAll();
break;
case 'ProjectNodeClick':
const openConfigCallback =
graph.renderMode === 'nx-console'
? () =>
graph.broadcast({
type: 'ProjectOpenConfigClick',
projectName: event.data.id,
})
: undefined;
this.openProjectNodeToolTip(event.ref, {
id: event.data.id,
tags: event.data.tags,
type: event.data.type,
description: event.data.description,
openConfigCallback,
});
break;
case 'TaskNodeClick':
const runTaskCallback =
graph.renderMode === 'nx-console'
? () =>
graph.broadcast({
type: 'RunTaskClick',
taskId: event.data.id,
})
: undefined;
this.openTaskNodeTooltip(event.ref, {
...event.data,
runTaskCallback,
});
break;
case 'EdgeClick':
Expand Down
20 changes: 17 additions & 3 deletions graph/ui-tooltips/src/lib/project-node-tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { PencilSquareIcon } from '@heroicons/react/24/outline';
import { Tag } from '@nx/graph/ui-components';
import { ReactNode } from 'react';

Expand All @@ -6,6 +7,7 @@ export interface ProjectNodeToolTipProps {
id: string;
tags: string[];
description?: string;
openConfigCallback?: () => void;

children?: ReactNode | ReactNode[];
}
Expand All @@ -16,12 +18,24 @@ export function ProjectNodeToolTip({
tags,
children,
description,
openConfigCallback,
}: ProjectNodeToolTipProps) {
return (
<div className="text-sm text-slate-700 dark:text-slate-400">
<h4>
<Tag className="mr-3">{type}</Tag>
<span className="font-mono">{id}</span>
<h4 className="flex justify-between items-center gap-4">
<div className="flex items-center">
<Tag className="mr-3">{type}</Tag>
<span className="font-mono">{id}</span>
</div>
{openConfigCallback ? (
<button
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"
title="Edit project.json in editor"
onClick={openConfigCallback}
>
<PencilSquareIcon className="h-5 w-5" />
</button>
) : undefined}
</h4>
{tags.length > 0 ? (
<p className="my-2">
Expand Down
21 changes: 18 additions & 3 deletions graph/ui-tooltips/src/lib/task-node-tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
import { PlayIcon } from '@heroicons/react/24/outline';
import { Tag } from '@nx/graph/ui-components';

export interface TaskNodeTooltipProps {
id: string;
executor: string;
runTaskCallback?: () => void;
description?: string;
}

export function TaskNodeTooltip({
id,
executor,
description,
runTaskCallback: runTargetCallback,
}: TaskNodeTooltipProps) {
return (
<div className="text-sm text-slate-700 dark:text-slate-400">
<h4>
<Tag className="mr-3">{executor}</Tag>
<span className="font-mono">{id}</span>
<h4 className="flex justify-between items-center gap-4">
<div className="flex items-center">
<Tag className="mr-3">{executor}</Tag>
<span className="font-mono">{id}</span>
</div>
{runTargetCallback ? (
<button
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"
title="Run Task"
onClick={runTargetCallback}
>
<PlayIcon className="h-5 w-5" />
</button>
) : undefined}
</h4>
<h4></h4>
{description ? <p className="mt-4">{description}</p> : null}
</div>
);
Expand Down

1 comment on commit d5ceca9

@vercel
Copy link

@vercel vercel bot commented on d5ceca9 Aug 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app
nx-dev-nrwl.vercel.app
nx.dev

Please sign in to comment.