Skip to content

Commit 7888535

Browse files
committed
Add debug mode for viewing ReactFlow Node ids
1 parent 9c8c8f8 commit 7888535

File tree

5 files changed

+98
-25
lines changed

5 files changed

+98
-25
lines changed

.env.example

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@ VITE_ENABLE_GOOGLE_CLOUD_SUBMITTER=<boolean>
1717

1818
# Github
1919
VITE_REQUIRE_AUTHORIZATION=<boolean>
20-
VITE_GITHUB_CLIENT_ID=<string>
20+
VITE_GITHUB_CLIENT_ID=<string>
21+
22+
# Dev Tools
23+
VITE_ENABLE_DEBUG_MODE=<boolean>

src/components/shared/ReactFlow/FlowCanvas/IONode/IONode.tsx

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
import { Handle, Position } from "@xyflow/react";
2-
import { memo, useEffect, useMemo } from "react";
2+
import { memo, useCallback, useEffect, useMemo } from "react";
33

44
import { InputValueEditor } from "@/components/Editor/IOEditor/InputValueEditor";
55
import { OutputNameEditor } from "@/components/Editor/IOEditor/OutputNameEditor";
66
import { getOutputConnectedDetails } from "@/components/Editor/utils/getOutputConnectedDetails";
77
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
88
import { BlockStack, InlineStack } from "@/components/ui/layout";
99
import { Paragraph } from "@/components/ui/typography";
10+
import { useNodeManager } from "@/hooks/useNodeManager";
1011
import { cn } from "@/lib/utils";
1112
import { useComponentSpec } from "@/providers/ComponentSpecProvider";
1213
import { useContextPanel } from "@/providers/ContextPanelProvider";
1314
import type { IONodeData } from "@/types/nodes";
1415
import type { InputSpec, TypeSpecType } from "@/utils/componentSpec";
16+
import { ENABLE_DEBUG_MODE } from "@/utils/constants";
17+
import {
18+
inputNameToInputId,
19+
outputNameToOutputId,
20+
} from "@/utils/nodes/conversions";
1521

1622
interface IONodeProps {
1723
type: "input" | "output";
@@ -21,6 +27,7 @@ interface IONodeProps {
2127
}
2228

2329
const IONode = ({ type, data, selected = false }: IONodeProps) => {
30+
const { getInputNodeId, getOutputNodeId } = useNodeManager();
2431
const { graphSpec, componentSpec } = useComponentSpec();
2532
const { setContent, clearContent } = useContextPanel();
2633

@@ -51,6 +58,24 @@ const IONode = ({ type, data, selected = false }: IONodeProps) => {
5158
[componentSpec.outputs, spec.name],
5259
);
5360

61+
const nodeId = isInput
62+
? getInputNodeId(inputNameToInputId(spec.name))
63+
: getOutputNodeId(outputNameToOutputId(spec.name));
64+
65+
const nodeHandleId = isInput
66+
? getInputNodeId(inputNameToInputId(spec.name + "handle"))
67+
: getOutputNodeId(outputNameToOutputId(spec.name + "handle"));
68+
69+
const handleHandleClick = useCallback(() => {
70+
if (ENABLE_DEBUG_MODE) {
71+
console.log(`${isInput ? "Input" : "Output"} Handle clicked:`, {
72+
name: isInput ? input?.name : output?.name,
73+
nodeId,
74+
handleId: nodeHandleId,
75+
});
76+
}
77+
}, [isInput, input, output, nodeId, nodeHandleId]);
78+
5479
useEffect(() => {
5580
if (selected) {
5681
if (input && isInput) {
@@ -112,6 +137,11 @@ const IONode = ({ type, data, selected = false }: IONodeProps) => {
112137
<Card className={cn("border-2 max-w-[300px] p-0", borderColor)}>
113138
<CardHeader className="px-2 py-2.5">
114139
<CardTitle className="break-words">{spec.name}</CardTitle>
140+
{ENABLE_DEBUG_MODE && (
141+
<Paragraph size="xs" tone="subdued">
142+
Node Id: {nodeId}
143+
</Paragraph>
144+
)}
115145
</CardHeader>
116146
<CardContent className="p-2 max-w-[250px]">
117147
<BlockStack gap="2">
@@ -147,9 +177,11 @@ const IONode = ({ type, data, selected = false }: IONodeProps) => {
147177
</InlineStack>
148178
</BlockStack>
149179
<Handle
180+
id={nodeHandleId}
150181
type={handleType}
151182
position={handlePosition}
152183
className={cn(handleDefaultClassName, handleClassName)}
184+
onClick={handleHandleClick}
153185
/>
154186
</CardContent>
155187
</Card>

src/components/shared/ReactFlow/FlowCanvas/TaskNode/TaskNodeCard/Handles.tsx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { useNodeManager } from "@/hooks/useNodeManager";
1515
import { cn } from "@/lib/utils";
1616
import { useTaskNode } from "@/providers/TaskNodeProvider";
1717
import type { InputSpec, OutputSpec } from "@/utils/componentSpec";
18+
import { ENABLE_DEBUG_MODE } from "@/utils/constants";
1819

1920
type InputHandleProps = {
2021
input: InputSpec;
@@ -34,7 +35,7 @@ export const InputHandle = ({
3435
onHandleSelectionChange,
3536
}: InputHandleProps) => {
3637
const { getTaskInputNodeId } = useNodeManager();
37-
const { taskId, nodeId, state } = useTaskNode();
38+
const { taskId, nodeId, state, name } = useTaskNode();
3839

3940
const fromHandle = useConnection((connection) => connection.fromHandle?.id);
4041
const toHandle = useConnection((connection) => connection.toHandle?.id);
@@ -56,8 +57,17 @@ export const InputHandle = ({
5657
(e: ReactMouseEvent<HTMLDivElement>) => {
5758
e.stopPropagation();
5859
setSelected(!selected);
60+
61+
if (ENABLE_DEBUG_MODE) {
62+
console.log("Input Handle clicked:", {
63+
name: input.name,
64+
handleId,
65+
nodeId,
66+
taskName: name,
67+
});
68+
}
5969
},
60-
[selected],
70+
[selected, name, input, handleId, nodeId],
6171
);
6272

6373
const handleLabelClick = useCallback(
@@ -221,7 +231,7 @@ export const OutputHandle = ({
221231
onHandleSelectionChange,
222232
}: OutputHandleProps) => {
223233
const { getTaskOutputNodeId } = useNodeManager();
224-
const { taskId, nodeId, state } = useTaskNode();
234+
const { taskId, nodeId, state, name } = useTaskNode();
225235

226236
const fromHandle = useConnection((connection) => connection.fromHandle?.id);
227237
const toHandle = useConnection((connection) => connection.toHandle?.id);
@@ -240,8 +250,17 @@ export const OutputHandle = ({
240250
(e: ReactMouseEvent<HTMLDivElement>) => {
241251
e.stopPropagation();
242252
setSelected(!selected);
253+
254+
if (ENABLE_DEBUG_MODE) {
255+
console.log("Output Handle clicked:", {
256+
name: output.name,
257+
handleId,
258+
nodeId,
259+
taskName: name,
260+
});
261+
}
243262
},
244-
[selected],
263+
[selected, output, handleId, nodeId, name],
245264
);
246265

247266
const handleLabelClick = useCallback(

src/components/shared/ReactFlow/FlowCanvas/TaskNode/TaskNodeCard/TaskNodeCard.tsx

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import { PublishedComponentBadge } from "@/components/shared/ManageComponent/Pub
66
import { trimDigest } from "@/components/shared/ManageComponent/utils/digest";
77
import { useBetaFlagValue } from "@/components/shared/Settings/useBetaFlags";
88
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
9-
import { BlockStack } from "@/components/ui/layout";
9+
import { BlockStack, InlineStack } from "@/components/ui/layout";
1010
import { QuickTooltip } from "@/components/ui/tooltip";
1111
import { Text } from "@/components/ui/typography";
1212
import { cn } from "@/lib/utils";
1313
import { useContextPanel } from "@/providers/ContextPanelProvider";
1414
import { useTaskNode } from "@/providers/TaskNodeProvider";
15+
import { ENABLE_DEBUG_MODE } from "@/utils/constants";
1516

1617
import {
1718
type NotifyMessage,
@@ -172,27 +173,42 @@ const TaskNodeCard = () => {
172173
}}
173174
ref={nodeRef}
174175
>
175-
<CardHeader className="border-b border-slate-200 px-2 py-2.5 flex flex-row justify-between items-start">
176+
<CardHeader className="border-b border-slate-200 px-2 py-2.5 items-start">
176177
<BlockStack>
177-
<CardTitle className="break-words text-left text-xs text-slate-900">
178-
{name}
179-
</CardTitle>
180-
{taskId &&
181-
taskId !== name &&
182-
!taskId.match(new RegExp(`^${name}\\s*\\d+$`)) && (
183-
<Text size="xs" tone="subdued" className="font-light">
184-
{taskId}
185-
</Text>
178+
<InlineStack
179+
align="space-between"
180+
blockAlign="start"
181+
wrap="nowrap"
182+
className="w-full"
183+
>
184+
<BlockStack>
185+
<CardTitle className="break-words text-left text-xs text-slate-900">
186+
{name}
187+
</CardTitle>
188+
{taskId &&
189+
taskId !== name &&
190+
!taskId.match(new RegExp(`^${name}\\s*\\d+$`)) && (
191+
<Text size="xs" tone="subdued" className="font-light">
192+
{taskId}
193+
</Text>
194+
)}
195+
</BlockStack>
196+
197+
{isRemoteComponentLibrarySearchEnabled ? (
198+
<PublishedComponentBadge componentRef={taskSpec.componentRef}>
199+
{digestMarkup}
200+
</PublishedComponentBadge>
201+
) : (
202+
digestMarkup
186203
)}
187-
</BlockStack>
204+
</InlineStack>
188205

189-
{isRemoteComponentLibrarySearchEnabled ? (
190-
<PublishedComponentBadge componentRef={taskSpec.componentRef}>
191-
{digestMarkup}
192-
</PublishedComponentBadge>
193-
) : (
194-
digestMarkup
195-
)}
206+
{ENABLE_DEBUG_MODE && (
207+
<Text size="xs" tone="subdued">
208+
Node Id: {nodeId}
209+
</Text>
210+
)}
211+
</BlockStack>
196212
</CardHeader>
197213
<CardContent className="p-2 flex flex-col gap-2">
198214
<div

src/utils/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
/* Environment Config */
2+
export const ENABLE_DEBUG_MODE =
3+
import.meta.env.VITE_ENABLE_DEBUG_MODE === "true";
4+
25
export const ABOUT_URL =
36
import.meta.env.VITE_ABOUT_URL || "https://cloud-pipelines.net/";
47

0 commit comments

Comments
 (0)