Skip to content

Self-improving AI Employees for everyone

refactor(nodes): extract <EditableNodeLabel> + apply to 5 canvas nodes

trohitg79e2d7b04b0b
diff --git a/client/src/components/GenericNode.tsx b/client/src/components/GenericNode.tsx
index d8689be7..3e5c470a 100644
--- a/client/src/components/GenericNode.tsx
+++ b/client/src/components/GenericNode.tsx
@@ -1,4 +1,4 @@
-import React, { memo, useState, useEffect, useRef, useCallback } from 'react';
+import React, { memo, useCallback } from 'react';
import { nodePropsEqual } from './nodeMemoEquality';
import { Handle, Position, NodeProps } from 'reactflow';
import { resolveNodeDescription } from '../lib/nodeSpec';
@@ -9,10 +9,11 @@ import { INodeInputDefinition, INodeOutputDefinition, NodeConnectionType } from
import { useAppStore } from '../store/useAppStore';
import { useAppTheme } from '../hooks/useAppTheme';
import { useWebSocket } from '../contexts/WebSocketContext';
+import EditableNodeLabel from './ui/EditableNodeLabel';
const GenericNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnectable, selected }) => {
const theme = useAppTheme();
- const { setSelectedNode, renamingNodeId, setRenamingNodeId, updateNodeData } = useAppStore();
+ const { setSelectedNode, setRenamingNodeId, updateNodeData } = useAppStore();
const { getNodeStatus } = useWebSocket();
const isDisabled = data?.disabled === true;
@@ -27,54 +28,15 @@ const GenericNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnecta
// moment the prefetch lands (no waiting for parent re-render).
const iconSpec = useNodeSpec(type);
- // Inline rename state
- const [isRenaming, setIsRenaming] = useState(false);
- const [editLabel, setEditLabel] = useState('');
- const inputRef = useRef<HTMLInputElement>(null);
-
- // Sync with global renaming state
- useEffect(() => {
- if (renamingNodeId === id) {
- setIsRenaming(true);
- setEditLabel(data?.label || definition?.displayName || type || '');
- } else {
- setIsRenaming(false);
- }
- }, [renamingNodeId, id, data?.label, definition?.displayName, type]);
-
- // Focus and select input when entering rename mode
- useEffect(() => {
- if (isRenaming && inputRef.current) {
- inputRef.current.focus();
- inputRef.current.select();
- }
- }, [isRenaming]);
-
- // Handle save rename
- const handleSaveRename = useCallback(() => {
- const newLabel = editLabel.trim();
- const originalLabel = data?.label || definition?.displayName || type || '';
-
- // Only save if label changed and is not empty
- if (newLabel && newLabel !== originalLabel) {
- updateNodeData(id, { ...data, label: newLabel });
- }
-
- setIsRenaming(false);
- setRenamingNodeId(null);
- }, [editLabel, data, definition?.displayName, type, id, updateNodeData, setRenamingNodeId]);
-
- // Handle cancel rename
- const handleCancelRename = useCallback(() => {
- setIsRenaming(false);
- setRenamingNodeId(null);
- }, [setRenamingNodeId]);
-
- // Handle double-click to rename
- const handleLabelDoubleClick = useCallback((e: React.MouseEvent) => {
- e.stopPropagation();
- setRenamingNodeId(id);
- }, [id, setRenamingNodeId]);
+ const defaultLabel = definition?.displayName || type || '';
+ const handleLabelChange = useCallback(
+ (newLabel: string) => updateNodeData(id, { ...data, label: newLabel }),
+ [id, data, updateNodeData]
+ );
+ const handleLabelActivate = useCallback(
+ () => setRenamingNodeId(id),
+ [id, setRenamingNodeId]
+ );
const handleParametersClick = (e: React.MouseEvent) => {
e.stopPropagation();
@@ -273,50 +235,14 @@ const GenericNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnecta
<span className="flex items-center text-2xl">
{renderIcon(iconSpec?.icon ?? definition.icon)}
</span>
- {isRenaming ? (
- <input
- ref={inputRef}
- type="text"
- value={editLabel}
- onChange={(e) => setEditLabel(e.target.value)}
- onKeyDown={(e) => {
- if (e.key === 'Enter') {
- handleSaveRename();
- } else if (e.key === 'Escape') {
- handleCancelRename();
- }
- e.stopPropagation();
- }}
- onBlur={handleSaveRename}
- onClick={(e) => e.stopPropagation()}
- style={{
- padding: '2px 4px',
- fontSize: theme.fontSize.sm,
- fontWeight: theme.fontWeight.medium,
- color: theme.colors.text,
- backgroundColor: theme.colors.backgroundElevated,
- border: `1px solid ${theme.dracula.purple}`,
- borderRadius: theme.borderRadius.sm,
- outline: 'none',
- minWidth: '60px',
- maxWidth: '120px',
- }}
- />
- ) : (
- <span
- onDoubleClick={handleLabelDoubleClick}
- style={{
- whiteSpace: 'nowrap',
- overflow: 'hidden',
- textOverflow: 'ellipsis',
- maxWidth: '100%',
- cursor: 'text',
- }}
- title="Double-click to rename"
- >
- {data?.label || definition.displayName}
- </span>
- )}
+ <EditableNodeLabel
+ nodeId={id}
+ label={data?.label}
+ defaultLabel={defaultLabel}
+ onLabelChange={handleLabelChange}
+ onActivate={handleLabelActivate}
+ className="m-0 max-w-full truncate"
+ />
</div>
diff --git a/client/src/components/SquareNode.tsx b/client/src/components/SquareNode.tsx
index 0afef55d..dc68436e 100644
--- a/client/src/components/SquareNode.tsx
+++ b/client/src/components/SquareNode.tsx
@@ -4,6 +4,7 @@ import { Handle, Position, NodeProps } from 'reactflow';
import { NodeData } from '../types/NodeTypes';
import { useAppStore } from '../store/useAppStore';
import { useAppTheme } from '../hooks/useAppTheme';
+import EditableNodeLabel from './ui/EditableNodeLabel';
import { useWebSocket, useWhatsAppStatus } from '../contexts/WebSocketContext';
import { getCachedNodeSpec, isNodeInBackendGroup, resolveNodeDescription, useNodeSpec } from '../lib/nodeSpec';
import { resolveIcon, resolveLibraryIcon } from '../assets/icons';
@@ -30,14 +31,9 @@ const CREDENTIAL_TO_PROVIDER: Record<string, string> = {
const SquareNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnectable, selected }) => {
const theme = useAppTheme();
- const { setSelectedNode, renamingNodeId, setRenamingNodeId, updateNodeData } = useAppStore();
+ const { setSelectedNode, setRenamingNodeId, updateNodeData } = useAppStore();
const isDisabled = data?.disabled === true;
- // Inline rename state
- const [isRenaming, setIsRenaming] = useState(false);
- const [editLabel, setEditLabel] = useState('');
- const inputRef = useRef<HTMLInputElement>(null);
-
// Get Android status, node status, and API key status from WebSocket context
const { androidStatus, getNodeStatus, getApiKeyStatus } = useWebSocket();
const nodeStatus = getNodeStatus(id);
@@ -115,48 +111,15 @@ const SquareNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnectab
const isExecuting = executionStatus === 'executing' || executionStatus === 'waiting' || isGlowing;
- // Sync with global renaming state
- useEffect(() => {
- if (renamingNodeId === id) {
- setIsRenaming(true);
- setEditLabel(data?.label || definition?.displayName || type || '');
- } else {
- setIsRenaming(false);
- }
- }, [renamingNodeId, id, data?.label, definition?.displayName, type]);
-
- // Focus and select input when entering rename mode
- useEffect(() => {
- if (isRenaming && inputRef.current) {
- inputRef.current.focus();
- inputRef.current.select();
- }
- }, [isRenaming]);
-
- // Handle save rename
- const handleSaveRename = useCallback(() => {
- const newLabel = editLabel.trim();
- const originalLabel = data?.label || definition?.displayName || type || '';
-
- // Only save if label changed and is not empty
- if (newLabel && newLabel !== originalLabel) {
- updateNodeData(id, { ...data, label: newLabel });
- }
-
- setIsRenaming(false);
- setRenamingNodeId(null);
- }, [editLabel, data, definition?.displayName, type, id, updateNodeData, setRenamingNodeId]);
-
- // Handle cancel rename
- const handleCancelRename = useCallback(() => {
- setIsRenaming(false);
- setRenamingNodeId(null);
- }, [setRenamingNodeId]);
-
- // Handle double-click to rename
- const handleLabelDoubleClick = useCallback(() => {
- setRenamingNodeId(id);
- }, [id, setRenamingNodeId]);
+ const defaultLabel = definition?.displayName || type || '';
+ const handleLabelChange = useCallback(
+ (newLabel: string) => updateNodeData(id, { ...data, label: newLabel }),
+ [id, data, updateNodeData]
+ );
+ const handleLabelActivate = useCallback(
+ () => setRenamingNodeId(id),
+ [id, setRenamingNodeId]
+ );
// Provider id for legacy credentialed nodes (non-AI, non-maps). AI
// model nodes route through `aiProviderId` above, Google Maps through
@@ -525,55 +488,13 @@ const SquareNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnectab
</div>
{/* Service Name Below Square */}
- {isRenaming ? (
- <input
- ref={inputRef}
- type="text"
- value={editLabel}
- onChange={(e) => setEditLabel(e.target.value)}
- onKeyDown={(e) => {
- if (e.key === 'Enter') {
- handleSaveRename();
- } else if (e.key === 'Escape') {
- handleCancelRename();
- }
- e.stopPropagation();
- }}
- onBlur={handleSaveRename}
- onClick={(e) => e.stopPropagation()}
- style={{
- marginTop: theme.spacing.sm,
- width: '100%',
- maxWidth: '120px',
- padding: '2px 4px',
- fontSize: theme.fontSize.sm,
- fontWeight: theme.fontWeight.medium,
- color: theme.colors.text,
- backgroundColor: theme.colors.backgroundElevated,
- border: `1px solid ${theme.dracula.purple}`,
- borderRadius: theme.borderRadius.sm,
- outline: 'none',
- textAlign: 'center',
- }}
- />
- ) : (
- <div
- onDoubleClick={handleLabelDoubleClick}
- style={{
- marginTop: theme.spacing.sm,
- fontSize: theme.fontSize.sm,
- fontWeight: theme.fontWeight.medium,
- color: theme.colors.text,
- lineHeight: '1.2',
- textAlign: 'center',
- maxWidth: '120px',
- cursor: 'text',
- }}
- title="Double-click to rename"
- >
- {data?.label || definition?.displayName}
- </div>
- )}
+ <EditableNodeLabel
+ nodeId={id}
+ label={data?.label}
+ defaultLabel={defaultLabel}
+ onLabelChange={handleLabelChange}
+ onActivate={handleLabelActivate}
+ />
</div>
);
diff --git a/client/src/components/StartNode.tsx b/client/src/components/StartNode.tsx
index 31e55c4f..e57067ee 100644
--- a/client/src/components/StartNode.tsx
+++ b/client/src/components/StartNode.tsx
@@ -1,64 +1,27 @@
-import React, { memo, useState, useEffect, useRef, useCallback } from 'react';
+import React, { memo, useCallback } from 'react';
import { nodePropsEqual } from './nodeMemoEquality';
import { Handle, Position, NodeProps } from 'reactflow';
import { NodeData } from '../types/NodeTypes';
import { useAppStore } from '../store/useAppStore';
import { useAppTheme } from '../hooks/useAppTheme';
import { PlayCircle } from 'lucide-react';
+import EditableNodeLabel from './ui/EditableNodeLabel';
const StartNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnectable, selected }) => {
- const { setSelectedNode, renamingNodeId, setRenamingNodeId, updateNodeData } = useAppStore();
+ const { setSelectedNode, setRenamingNodeId, updateNodeData } = useAppStore();
const theme = useAppTheme();
- // Inline rename state
- const [isRenaming, setIsRenaming] = useState(false);
- const [editLabel, setEditLabel] = useState('');
- const inputRef = useRef<HTMLInputElement>(null);
-
const defaultLabel = 'Start';
- // Sync with global renaming state
- useEffect(() => {
- if (renamingNodeId === id) {
- setIsRenaming(true);
- setEditLabel(data?.label || defaultLabel);
- } else {
- setIsRenaming(false);
- }
- }, [renamingNodeId, id, data?.label]);
-
- // Focus and select input when entering rename mode
- useEffect(() => {
- if (isRenaming && inputRef.current) {
- inputRef.current.focus();
- inputRef.current.select();
- }
- }, [isRenaming]);
-
- // Handle save rename
- const handleSaveRename = useCallback(() => {
- const newLabel = editLabel.trim();
- const originalLabel = data?.label || defaultLabel;
-
- // Only save if label changed and is not empty
- if (newLabel && newLabel !== originalLabel) {
- updateNodeData(id, { ...data, label: newLabel });
- }
-
- setIsRenaming(false);
- setRenamingNodeId(null);
- }, [editLabel, data, id, updateNodeData, setRenamingNodeId]);
-
- // Handle cancel rename
- const handleCancelRename = useCallback(() => {
- setIsRenaming(false);
- setRenamingNodeId(null);
- }, [setRenamingNodeId]);
+ const handleLabelChange = useCallback(
+ (newLabel: string) => updateNodeData(id, { ...data, label: newLabel }),
+ [id, data, updateNodeData]
+ );
- // Handle double-click to rename
- const handleLabelDoubleClick = useCallback(() => {
- setRenamingNodeId(id);
- }, [id, setRenamingNodeId]);
+ const handleLabelActivate = useCallback(
+ () => setRenamingNodeId(id),
+ [id, setRenamingNodeId]
+ );
const handleParametersClick = (e: React.MouseEvent) => {
e.stopPropagation();
@@ -194,55 +157,13 @@ const StartNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnectabl
</div>
{/* Name Below Square */}
- {isRenaming ? (
- <input
- ref={inputRef}
- type="text"
- value={editLabel}
- onChange={(e) => setEditLabel(e.target.value)}
- onKeyDown={(e) => {
- if (e.key === 'Enter') {
- handleSaveRename();
- } else if (e.key === 'Escape') {
- handleCancelRename();
- }
- e.stopPropagation();
- }}
- onBlur={handleSaveRename}
- onClick={(e) => e.stopPropagation()}
- style={{
- marginTop: '8px',
- width: '100%',
- maxWidth: '120px',
- padding: '2px 4px',
- fontSize: '12px',
- fontWeight: '500',
- color: theme.colors.text,
- backgroundColor: theme.colors.backgroundElevated,
- border: `1px solid ${theme.dracula.purple}`,
- borderRadius: theme.borderRadius.sm,
- outline: 'none',
- textAlign: 'center',
- }}
- />
- ) : (
- <div
- onDoubleClick={handleLabelDoubleClick}
- style={{
- marginTop: '8px',
- fontSize: '12px',
- fontWeight: '500',
- color: theme.colors.text,
- lineHeight: '1.2',
- textAlign: 'center',
- maxWidth: '120px',
- cursor: 'text',
- }}
- title="Double-click to rename"
- >
- {data?.label || defaultLabel}
- </div>
- )}
+ <EditableNodeLabel
+ nodeId={id}
+ label={data?.label}
+ defaultLabel={defaultLabel}
+ onLabelChange={handleLabelChange}
+ onActivate={handleLabelActivate}
+ />
</div>
);
diff --git a/client/src/components/ToolkitNode.tsx b/client/src/components/ToolkitNode.tsx
index c6830743..932a9d52 100644
--- a/client/src/components/ToolkitNode.tsx
+++ b/client/src/components/ToolkitNode.tsx
@@ -10,7 +10,7 @@
* - Input handle at BOTTOM (receives Android service nodes)
*/
-import React, { memo, useState, useEffect, useRef, useCallback } from 'react';
+import React, { memo, useCallback } from 'react';
import { nodePropsEqual } from './nodeMemoEquality';
import { Handle, Position, NodeProps } from 'reactflow';
import { NodeData } from '../types/NodeTypes';
@@ -20,18 +20,14 @@ import { resolveIcon, resolveLibraryIcon } from '../assets/icons';
import { useNodeSpec } from '../lib/nodeSpec';
import { useAppTheme } from '../hooks/useAppTheme';
import { useWebSocket } from '../contexts/WebSocketContext';
+import EditableNodeLabel from './ui/EditableNodeLabel';
// Toolkit node types that render rectangular (wider than tall)
const TOOLKIT_NODE_TYPES = ['androidTool'];
const ToolkitNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnectable, selected }) => {
const theme = useAppTheme();
- const { setSelectedNode, renamingNodeId, setRenamingNodeId, updateNodeData } = useAppStore();
-
- // Inline rename state
- const [isRenaming, setIsRenaming] = useState(false);
- const [editLabel, setEditLabel] = useState('');
- const inputRef = useRef<HTMLInputElement>(null);
+ const { setSelectedNode, setRenamingNodeId, updateNodeData } = useAppStore();
// Get node status from WebSocket context
const { getNodeStatus } = useWebSocket();
@@ -47,47 +43,15 @@ const ToolkitNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnecta
// Execution state
const isExecuting = executionStatus === 'executing' || executionStatus === 'waiting';
- // Sync with global renaming state
- useEffect(() => {
- if (renamingNodeId === id) {
- setIsRenaming(true);
- setEditLabel(data?.label || definition?.displayName || type || '');
- } else {
- setIsRenaming(false);
- }
- }, [renamingNodeId, id, data?.label, definition?.displayName, type]);
-
- // Focus and select input when entering rename mode
- useEffect(() => {
- if (isRenaming && inputRef.current) {
- inputRef.current.focus();
- inputRef.current.select();
- }
- }, [isRenaming]);
-
- // Handle save rename
- const handleSaveRename = useCallback(() => {
- const newLabel = editLabel.trim();
- const originalLabel = data?.label || definition?.displayName || type || '';
-
- if (newLabel && newLabel !== originalLabel) {
- updateNodeData(id, { ...data, label: newLabel });
- }
-
- setIsRenaming(false);
- setRenamingNodeId(null);
- }, [editLabel, data, definition?.displayName, type, id, updateNodeData, setRenamingNodeId]);
-
- // Handle cancel rename
- const handleCancelRename = useCallback(() => {
- setIsRenaming(false);
- setRenamingNodeId(null);
- }, [setRenamingNodeId]);
-
- // Handle double-click to rename
- const handleLabelDoubleClick = useCallback(() => {
- setRenamingNodeId(id);
- }, [id, setRenamingNodeId]);
+ const defaultLabel = definition?.displayName || type || '';
+ const handleLabelChange = useCallback(
+ (newLabel: string) => updateNodeData(id, { ...data, label: newLabel }),
+ [id, data, updateNodeData]
+ );
+ const handleLabelActivate = useCallback(
+ () => setRenamingNodeId(id),
+ [id, setRenamingNodeId]
+ );
// Handle parameters click
const handleParametersClick = (e: React.MouseEvent) => {
@@ -304,48 +268,13 @@ const ToolkitNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnecta
</div>
{/* Node Name Below */}
- {isRenaming ? (
- <input
- ref={inputRef}
- type="text"
- value={editLabel}
- onChange={(e) => setEditLabel(e.target.value)}
- onBlur={handleSaveRename}
- onKeyDown={(e) => {
- if (e.key === 'Enter') handleSaveRename();
- if (e.key === 'Escape') handleCancelRename();
- }}
- style={{
- marginTop: theme.spacing.sm,
- fontSize: theme.fontSize.sm,
- fontWeight: theme.fontWeight.medium,
- color: theme.colors.text,
- backgroundColor: theme.colors.background,
- border: `1px solid ${theme.colors.focus}`,
- borderRadius: theme.borderRadius.sm,
- padding: '2px 6px',
- textAlign: 'center',
- width: '100px',
- outline: 'none',
- }}
- />
- ) : (
- <div
- onDoubleClick={handleLabelDoubleClick}
- style={{
- marginTop: theme.spacing.sm,
- fontSize: theme.fontSize.sm,
- fontWeight: theme.fontWeight.medium,
- color: theme.colors.text,
- lineHeight: '1.2',
- textAlign: 'center',
- maxWidth: '120px',
- cursor: 'text',
- }}
- >
- {data?.label || definition?.displayName}
- </div>
- )}
+ <EditableNodeLabel
+ nodeId={id}
+ label={data?.label}
+ defaultLabel={defaultLabel}
+ onLabelChange={handleLabelChange}
+ onActivate={handleLabelActivate}
+ />
</div>
);
};
diff --git a/client/src/components/TriggerNode.tsx b/client/src/components/TriggerNode.tsx
index 0a1d5fa5..80a8cb32 100644
--- a/client/src/components/TriggerNode.tsx
+++ b/client/src/components/TriggerNode.tsx
@@ -6,7 +6,7 @@
*
* Used for: cronScheduler, webhookTrigger, whatsappReceive, start
*/
-import React, { memo, useState, useEffect, useRef, useCallback } from 'react';
+import React, { memo, useState, useEffect, useCallback } from 'react';
import { nodePropsEqual } from './nodeMemoEquality';
import { Handle, Position, NodeProps } from 'reactflow';
import { NodeData } from '../types/NodeTypes';
@@ -15,18 +15,14 @@ import { resolveNodeDescription, useNodeSpec } from '../lib/nodeSpec';
import { resolveIcon, resolveLibraryIcon } from '../assets/icons';
import { useAppTheme } from '../hooks/useAppTheme';
import { useWebSocket, useWhatsAppStatus } from '../contexts/WebSocketContext';
+import EditableNodeLabel from './ui/EditableNodeLabel';
const TriggerNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnectable, selected }) => {
const theme = useAppTheme();
- const { setSelectedNode, renamingNodeId, setRenamingNodeId, updateNodeData } = useAppStore();
+ const { setSelectedNode, setRenamingNodeId, updateNodeData } = useAppStore();
const [isConfigured, setIsConfigured] = useState(false);
const isDisabled = data?.disabled === true;
- // Inline rename state
- const [isRenaming, setIsRenaming] = useState(false);
- const [editLabel, setEditLabel] = useState('');
- const inputRef = useRef<HTMLInputElement>(null);
-
// Get node status from WebSocket context
const { getNodeStatus } = useWebSocket();
const nodeStatus = getNodeStatus(id);
@@ -51,48 +47,15 @@ const TriggerNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnecta
setIsConfigured(hasRequiredParams);
}, [data]);
- // Sync with global renaming state
- useEffect(() => {
- if (renamingNodeId === id) {
- setIsRenaming(true);
- setEditLabel(data?.label || definition?.displayName || type || '');
- } else {
- setIsRenaming(false);
- }
- }, [renamingNodeId, id, data?.label, definition?.displayName, type]);
-
- // Focus and select input when entering rename mode
- useEffect(() => {
- if (isRenaming && inputRef.current) {
- inputRef.current.focus();
- inputRef.current.select();
- }
- }, [isRenaming]);
-
- // Handle save rename
- const handleSaveRename = useCallback(() => {
- const newLabel = editLabel.trim();
- const originalLabel = data?.label || definition?.displayName || type || '';
-
- // Only save if label changed and is not empty
- if (newLabel && newLabel !== originalLabel) {
- updateNodeData(id, { ...data, label: newLabel });
- }
-
- setIsRenaming(false);
- setRenamingNodeId(null);
- }, [editLabel, data, definition?.displayName, type, id, updateNodeData, setRenamingNodeId]);
-
- // Handle cancel rename
- const handleCancelRename = useCallback(() => {
- setIsRenaming(false);
- setRenamingNodeId(null);
- }, [setRenamingNodeId]);
-
- // Handle double-click to rename
- const handleLabelDoubleClick = useCallback(() => {
- setRenamingNodeId(id);
- }, [id, setRenamingNodeId]);
+ const defaultLabel = definition?.displayName || type || '';
+ const handleLabelChange = useCallback(
+ (newLabel: string) => updateNodeData(id, { ...data, label: newLabel }),
+ [id, data, updateNodeData]
+ );
+ const handleLabelActivate = useCallback(
+ () => setRenamingNodeId(id),
+ [id, setRenamingNodeId]
+ );
const handleParametersClick = (e: React.MouseEvent) => {
e.stopPropagation();
@@ -377,55 +340,13 @@ const TriggerNode: React.FC<NodeProps<NodeData>> = ({ id, type, data, isConnecta
</div>
{/* Trigger Name Below Node */}
- {isRenaming ? (
- <input
- ref={inputRef}
- type="text"
- value={editLabel}
- onChange={(e) => setEditLabel(e.target.value)}
- onKeyDown={(e) => {
- if (e.key === 'Enter') {
- handleSaveRename();
- } else if (e.key === 'Escape') {
- handleCancelRename();
- }
- e.stopPropagation();
- }}
- onBlur={handleSaveRename}
- onClick={(e) => e.stopPropagation()}
- style={{
- marginTop: theme.spacing.sm,
- width: '100%',
- maxWidth: '120px',
- padding: '2px 4px',
- fontSize: theme.fontSize.sm,
- fontWeight: theme.fontWeight.medium,
- color: theme.colors.text,
- backgroundColor: theme.colors.backgroundElevated,
- border: `1px solid ${theme.dracula.purple}`,
- borderRadius: theme.borderRadius.sm,
- outline: 'none',
- textAlign: 'center',
- }}
- />
- ) : (
- <div
- onDoubleClick={handleLabelDoubleClick}
- style={{
- marginTop: theme.spacing.sm,
- fontSize: theme.fontSize.sm,
- fontWeight: theme.fontWeight.medium,
- color: theme.colors.text,
- lineHeight: '1.2',
- textAlign: 'center',
- maxWidth: '120px',
- cursor: 'text',
- }}
- title="Double-click to rename"
- >
- {data?.label || definition?.displayName}
- </div>
- )}
+ <EditableNodeLabel
+ nodeId={id}
+ label={data?.label}
+ defaultLabel={defaultLabel}
+ onLabelChange={handleLabelChange}
+ onActivate={handleLabelActivate}
+ />
</div>
);
diff --git a/client/src/components/ui/EditableNodeLabel.tsx b/client/src/components/ui/EditableNodeLabel.tsx
new file mode 100644
index 00000000..b349dfea
--- /dev/null
+++ b/client/src/components/ui/EditableNodeLabel.tsx
@@ -0,0 +1,122 @@
+/**
+ * EditableNodeLabel — shared inline-rename input for canvas node components.
+ *
+ * Encapsulates the dup'd pattern across StartNode, SquareNode, TriggerNode,
+ * ToolkitNode, GenericNode:
+ * - sync local edit state with the global `useAppStore.renamingNodeId`
+ * - focus + select the input on enter
+ * - Enter saves, Escape cancels, blur saves
+ * - call updateNodeData with the new label (no-op when unchanged or empty)
+ *
+ * Render is two states:
+ * - editing: an <Input> wired to the rename keymap
+ * - idle: a div that calls onActivate on double-click (the parent owns
+ * the activation gesture; it usually pipes into setRenamingNodeId)
+ */
+
+import React, { useEffect, useRef, useState, useCallback } from 'react';
+import { Input } from '@/components/ui/input';
+import { cn } from '@/lib/utils';
+import { useAppStore } from '../../store/useAppStore';
+
+export interface EditableNodeLabelProps {
+ /** React Flow node id; the global rename state is keyed on this. */
+ nodeId: string;
+ /** Current label to display. Falls back to `defaultLabel` when empty. */
+ label: string | undefined;
+ /** Fallback label text rendered when no label is set. */
+ defaultLabel: string;
+ /** Persists the new label (only fired when changed and non-empty). */
+ onLabelChange: (newLabel: string) => void;
+ /** Called when the user double-clicks the idle label. Usually
+ * `() => setRenamingNodeId(nodeId)` in the parent. */
+ onActivate?: () => void;
+ /** Extra Tailwind classes for the rendered input + idle div. */
+ className?: string;
+}
+
+const EditableNodeLabel: React.FC<EditableNodeLabelProps> = ({
+ nodeId,
+ label,
+ defaultLabel,
+ onLabelChange,
+ onActivate,
+ className,
+}) => {
+ const renamingNodeId = useAppStore((s) => s.renamingNodeId);
+ const setRenamingNodeId = useAppStore((s) => s.setRenamingNodeId);
+
+ const [isRenaming, setIsRenaming] = useState(false);
+ const [editLabel, setEditLabel] = useState('');
+ const inputRef = useRef<HTMLInputElement>(null);
+
+ // Sync with global rename state.
+ useEffect(() => {
+ if (renamingNodeId === nodeId) {
+ setIsRenaming(true);
+ setEditLabel(label || defaultLabel);
+ } else {
+ setIsRenaming(false);
+ }
+ }, [renamingNodeId, nodeId, label, defaultLabel]);
+
+ // Focus + select on enter.
+ useEffect(() => {
+ if (isRenaming && inputRef.current) {
+ inputRef.current.focus();
+ inputRef.current.select();
+ }
+ }, [isRenaming]);
+
+ const handleSave = useCallback(() => {
+ const newLabel = editLabel.trim();
+ const original = label || defaultLabel;
+ if (newLabel && newLabel !== original) {
+ onLabelChange(newLabel);
+ }
+ setIsRenaming(false);
+ setRenamingNodeId(null);
+ }, [editLabel, label, defaultLabel, onLabelChange, setRenamingNodeId]);
+
+ const handleCancel = useCallback(() => {
+ setIsRenaming(false);
+ setRenamingNodeId(null);
+ }, [setRenamingNodeId]);
+
+ if (isRenaming) {
+ return (
+ <Input
+ ref={inputRef}
+ type="text"
+ value={editLabel}
+ onChange={(e) => setEditLabel(e.target.value)}
+ onKeyDown={(e) => {
+ if (e.key === 'Enter') handleSave();
+ else if (e.key === 'Escape') handleCancel();
+ e.stopPropagation();
+ }}
+ onBlur={handleSave}
+ onClick={(e) => e.stopPropagation()}
+ className={cn(
+ 'mt-2 h-auto max-w-[120px] border-accent px-1 py-0.5 text-center text-xs font-medium',
+ className
+ )}
+ />
+ );
+ }
+
+ return (
+ <div
+ onDoubleClick={onActivate}
+ title="Double-click to rename"
+ className={cn(
+ 'mt-2 max-w-[120px] cursor-text text-center text-xs leading-tight font-medium text-foreground',
+ className
+ )}
+ >
+ {label || defaultLabel}
+ </div>
+ );
+};
+
+export default EditableNodeLabel;