Skip to content

Self-improving AI Employees for everyone

fix(canvas): double-click rename obeys the canvas lock

trohitg846510984073
diff --git a/CLAUDE.md b/CLAUDE.md
index e115a69c..1db5abf2 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -836,6 +836,8 @@ Three methods for renaming nodes, following n8n UX patterns:
- **Double-click on Label**: Click the node label twice to edit inline
- **Right-click Context Menu**: "Rename" option in the context menu
+All three are canvas edits and obey the canvas lock: F2 and the menu call Dashboard's `guardCanvasEdit`, and `EditableNodeLabel` reads the same guard through `contexts/canvasEditGuard.ts`, which Dashboard provides around `<ReactFlow>`.
+
#### Architecture
```
Global State (useAppStore) Node Components
diff --git a/client/src/Dashboard.tsx b/client/src/Dashboard.tsx
index db09c1cc..23ab3825 100644
--- a/client/src/Dashboard.tsx
+++ b/client/src/Dashboard.tsx
@@ -16,6 +16,7 @@ import {
import { featureFlags } from './lib/featureFlags';
import { deriveCanvasLock } from './lib/canvasLock';
import { AGENT_PHASE } from './lib/agentPhases';
+import { CanvasEditGuardContext } from './contexts/canvasEditGuard';
import { prefetchAllNodeSpecs, listCachedNodeSpecs, cachedNodeSpecTypesKey } from './lib/nodeSpec';
import AIAgentNode from './components/AIAgentNode';
import SquareNode from './components/SquareNode';
@@ -1256,6 +1257,7 @@ const DashboardContent: React.FC = () => {
}}
>
<ErrorBoundary>
+ <CanvasEditGuardContext.Provider value={guardCanvasEdit}>
<ReactFlow
nodes={styledNodes}
edges={styledEdges}
@@ -1295,6 +1297,7 @@ const DashboardContent: React.FC = () => {
>
<Controls />
</ReactFlow>
+ </CanvasEditGuardContext.Provider>
</ErrorBoundary>
</div>
diff --git a/client/src/components/ui/EditableNodeLabel.tsx b/client/src/components/ui/EditableNodeLabel.tsx
index 525bad57..e0ce8b50 100644
--- a/client/src/components/ui/EditableNodeLabel.tsx
+++ b/client/src/components/ui/EditableNodeLabel.tsx
@@ -11,13 +11,15 @@
* 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)
+ * the activation gesture; it usually pipes into setRenamingNodeId),
+ * unless the canvas is locked, which the editor's guard reports
*/
import React, { useEffect, useRef, useState, useCallback } from 'react';
import { Input } from '@/components/ui/input';
import { cn } from '@/lib/utils';
import { useAppStore } from '../../store/useAppStore';
+import { useCanvasEditGuard } from '../../contexts/canvasEditGuard';
export interface EditableNodeLabelProps {
/** React Flow node id; the global rename state is keyed on this. */
@@ -45,6 +47,7 @@ const EditableNodeLabel: React.FC<EditableNodeLabelProps> = ({
}) => {
const renamingNodeId = useAppStore((s) => s.renamingNodeId);
const setRenamingNodeId = useAppStore((s) => s.setRenamingNodeId);
+ const guardCanvasEdit = useCanvasEditGuard();
const [isRenaming, setIsRenaming] = useState(false);
const [editLabel, setEditLabel] = useState('');
@@ -83,6 +86,11 @@ const EditableNodeLabel: React.FC<EditableNodeLabelProps> = ({
setRenamingNodeId(null);
}, [setRenamingNodeId]);
+ // A rename is a canvas edit: the same lock as F2 and the context menu.
+ const handleActivate = useCallback(() => {
+ if (onActivate && guardCanvasEdit()) onActivate();
+ }, [onActivate, guardCanvasEdit]);
+
if (isRenaming) {
return (
<Input
@@ -111,7 +119,7 @@ const EditableNodeLabel: React.FC<EditableNodeLabelProps> = ({
return (
<div
- onDoubleClick={onActivate}
+ onDoubleClick={handleActivate}
title="Double-click to rename"
className={cn(
// Both `sq-node-label` and `node-label` co-classes always emit so
diff --git a/client/src/components/ui/__tests__/EditableNodeLabel.test.tsx b/client/src/components/ui/__tests__/EditableNodeLabel.test.tsx
new file mode 100644
index 00000000..9765b686
--- /dev/null
+++ b/client/src/components/ui/__tests__/EditableNodeLabel.test.tsx
@@ -0,0 +1,56 @@
+/**
+ * A double-click rename is a canvas edit, so it obeys the canvas lock the
+ * same way F2 and the context menu do. It used to call `onActivate`
+ * unconditionally, so a running workflow's nodes could still be renamed.
+ */
+
+import { describe, it, expect, vi } from 'vitest';
+import { fireEvent, render, screen } from '@testing-library/react';
+import EditableNodeLabel from '../EditableNodeLabel';
+import { CanvasEditGuardContext } from '../../../contexts/canvasEditGuard';
+
+function renderLabel(onActivate: () => void, guard?: () => boolean) {
+ const label = (
+ <EditableNodeLabel
+ nodeId="wf:aiAgent:1"
+ label="Researcher"
+ defaultLabel="AI Agent"
+ onLabelChange={vi.fn()}
+ onActivate={onActivate}
+ />
+ );
+ return render(
+ guard ? <CanvasEditGuardContext.Provider value={guard}>{label}</CanvasEditGuardContext.Provider> : label,
+ );
+}
+
+describe('EditableNodeLabel double-click', () => {
+ it('starts a rename when the canvas is editable', () => {
+ const onActivate = vi.fn();
+ renderLabel(onActivate, () => true);
+
+ fireEvent.doubleClick(screen.getByText('Researcher'));
+
+ expect(onActivate).toHaveBeenCalledTimes(1);
+ });
+
+ it('does not start a rename while the canvas is locked', () => {
+ const onActivate = vi.fn();
+ const guard = vi.fn(() => false);
+ renderLabel(onActivate, guard);
+
+ fireEvent.doubleClick(screen.getByText('Researcher'));
+
+ expect(guard).toHaveBeenCalledTimes(1);
+ expect(onActivate).not.toHaveBeenCalled();
+ });
+
+ it('allows a rename where no editor provides a guard', () => {
+ const onActivate = vi.fn();
+ renderLabel(onActivate);
+
+ fireEvent.doubleClick(screen.getByText('Researcher'));
+
+ expect(onActivate).toHaveBeenCalledTimes(1);
+ });
+});
diff --git a/client/src/contexts/canvasEditGuard.ts b/client/src/contexts/canvasEditGuard.ts
new file mode 100644
index 00000000..c9502dea
--- /dev/null
+++ b/client/src/contexts/canvasEditGuard.ts
@@ -0,0 +1,19 @@
+/**
+ * Lets canvas node components ask whether the canvas may be edited now.
+ *
+ * Dashboard provides its `guardCanvasEdit`: false (after telling the user
+ * why) while the workflow runs, true otherwise. Node components use it for
+ * edits they start themselves, such as a double-click rename, so those obey
+ * the same lock as F2, the context menu, drop and paste. Outside the editor
+ * nothing provides it and every edit is allowed.
+ */
+
+import { createContext, useContext } from 'react';
+
+export type CanvasEditGuard = () => boolean;
+
+const allowAll: CanvasEditGuard = () => true;
+
+export const CanvasEditGuardContext = createContext<CanvasEditGuard>(allowAll);
+
+export const useCanvasEditGuard = (): CanvasEditGuard => useContext(CanvasEditGuardContext);