Skip to content

Commit

Permalink
feat(graph): show open config button in graph web (#21181)
Browse files Browse the repository at this point in the history
Co-authored-by: FrozenPandaz <[email protected]>
  • Loading branch information
Coly010 and FrozenPandaz authored Jan 19, 2024
1 parent 8bd20e5 commit b97037e
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 42 deletions.
96 changes: 78 additions & 18 deletions graph/client/src/app/ui-tooltips/graph-tooltip-display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,94 @@ import {
} from '@nx/graph/ui-tooltips';
import { ProjectNodeActions } from './project-node-actions';
import { TaskNodeActions } from './task-node-actions';
import { useEnvironmentConfig, useRouteConstructor } from '@nx/graph/shared';
import { useNavigate } from 'react-router-dom';

const tooltipService = getTooltipService();

export function TooltipDisplay() {
const environment = useEnvironmentConfig()?.environment;
const navigate = useNavigate();
const routeConstructor = useRouteConstructor();

const currentTooltip = useSyncExternalStore(
(callback) => tooltipService.subscribe(callback),
() => tooltipService.currentTooltip
);

let tooltipToRender;
if (currentTooltip) {
switch (currentTooltip.type) {
case 'projectNode':
tooltipToRender = (
<ProjectNodeToolTip {...currentTooltip.props}>
<ProjectNodeActions {...currentTooltip.props} />
</ProjectNodeToolTip>
);
break;
case 'projectEdge':
tooltipToRender = <ProjectEdgeNodeTooltip {...currentTooltip.props} />;
break;
case 'taskNode':
tooltipToRender = (
<TaskNodeTooltip {...currentTooltip.props}>
<TaskNodeActions {...currentTooltip.props} />
</TaskNodeTooltip>
);
break;
if (currentTooltip.type === 'projectNode') {
const onConfigClick = (() => {
if (environment !== 'nx-console') {
return () => {
navigate(
routeConstructor(
{
pathname: `/project-details/${currentTooltip.props.id}`,
},
false
)
);
};
} else {
return () =>
this.externalApiService.postEvent({
type: 'open-project-config',
payload: {
projectName: currentTooltip.props.id,
},
});
}
})();

tooltipToRender = (
<ProjectNodeToolTip
{...currentTooltip.props}
openConfigCallback={onConfigClick}
isNxConsole={environment === 'nx-console'}
>
<ProjectNodeActions {...currentTooltip.props} />
</ProjectNodeToolTip>
);
} else if (currentTooltip.type === 'projectEdge') {
tooltipToRender = <ProjectEdgeNodeTooltip {...currentTooltip.props} />;
} else if (currentTooltip.type === 'taskNode') {
const onConfigClick = (() => {
const [projectName, targetName] = currentTooltip.props.id.split(':');
if (environment !== 'nx-console') {
return () => {
navigate(
routeConstructor(
{
pathname: `/project-details/${projectName}`,
search: `expanded=${targetName}`,
},
false
)
);
};
} else {
return () =>
this.externalApiService.postEvent({
type: 'open-project-config',
payload: {
projectName,
targetName,
},
});
}
})();

tooltipToRender = (
<TaskNodeTooltip
{...currentTooltip.props}
openConfigCallback={onConfigClick}
isNxConsole={environment === 'nx-console'}
>
<TaskNodeActions {...currentTooltip.props} />
</TaskNodeTooltip>
);
}
}

Expand Down
11 changes: 0 additions & 11 deletions graph/ui-graph/src/lib/tooltip-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,11 @@ export class GraphTooltipService {
this.hideAll();
break;
case 'ProjectNodeClick':
const openConfigCallback =
graph.renderMode === 'nx-console'
? () =>
this.externalApiService.postEvent({
type: 'open-project-config',
payload: {
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':
Expand Down
30 changes: 21 additions & 9 deletions graph/ui-tooltips/src/lib/project-node-tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { PencilSquareIcon } from '@heroicons/react/24/outline';
import {
PencilSquareIcon,
DocumentMagnifyingGlassIcon,
} from '@heroicons/react/24/outline';
import { Tag } from '@nx/graph/ui-components';
import { ReactNode } from 'react';
import { useEnvironmentConfig } from '@nx/graph/shared';

export interface ProjectNodeToolTipProps {
type: 'app' | 'lib' | 'e2e';
id: string;
tags: string[];
description?: string;
openConfigCallback?: () => void;
isNxConsole?: boolean;

children?: ReactNode | ReactNode[];
}
Expand All @@ -19,6 +24,7 @@ export function ProjectNodeToolTip({
children,
description,
openConfigCallback,
isNxConsole,
}: ProjectNodeToolTipProps) {
return (
<div className="text-sm text-slate-700 dark:text-slate-400">
Expand All @@ -27,15 +33,21 @@ export function ProjectNodeToolTip({
<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}
>
<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={
isNxConsole
? 'Open project details in editor'
: 'Open project details'
}
onClick={openConfigCallback}
>
{isNxConsole ? (
<PencilSquareIcon className="h-5 w-5" />
</button>
) : undefined}
) : (
<DocumentMagnifyingGlassIcon className="h-5 w-5" />
)}
</button>
</h4>
{tags.length > 0 ? (
<p className="my-2">
Expand Down
33 changes: 29 additions & 4 deletions graph/ui-tooltips/src/lib/task-node-tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { PlayIcon } from '@heroicons/react/24/outline';
import {
DocumentMagnifyingGlassIcon,
PencilSquareIcon,
PlayIcon,
} from '@heroicons/react/24/outline';
import { Tag } from '@nx/graph/ui-components';
import { ReactNode } from 'react';

Expand All @@ -8,6 +12,8 @@ export interface TaskNodeTooltipProps {
runTaskCallback?: () => void;
description?: string;
inputs?: Record<string, string[]>;
isNxConsole?: boolean;
openConfigCallback?: () => void;

children?: ReactNode | ReactNode[];
}
Expand All @@ -17,14 +23,33 @@ export function TaskNodeTooltip({
executor,
description,
runTaskCallback: runTargetCallback,
isNxConsole,
openConfigCallback,
children,
}: TaskNodeTooltipProps) {
return (
<div className="text-sm text-slate-700 dark:text-slate-400">
<h4 className="flex justify-between items-center gap-4 mb-3">
<div className="flex items-center">
<Tag className="mr-3">{executor}</Tag>
<span className="font-mono">{id}</span>
<div className="flex grow items-center justify-between">
<div className="flex items-center">
<Tag className="mr-3">{executor}</Tag>
<span className="font-mono">{id}</span>
</div>
<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={
isNxConsole
? 'Open project details in editor'
: 'Open project details'
}
onClick={openConfigCallback}
>
{isNxConsole ? (
<PencilSquareIcon className="h-5 w-5" />
) : (
<DocumentMagnifyingGlassIcon className="h-5 w-5" />
)}
</button>
</div>
{runTargetCallback ? (
<button
Expand Down

1 comment on commit b97037e

@vercel
Copy link

@vercel vercel bot commented on b97037e Jan 19, 2024

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-five.vercel.app
nx.dev
nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app

Please sign in to comment.