Skip to content

Commit 4da128d

Browse files
authored
improvement(context-menu): gray out undo redo if the stack is empty (#2657)
1 parent 0c8d05f commit 4da128d

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/context-menu/pane-context-menu.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export function PaneContextMenu({
2424
hasClipboard = false,
2525
disableEdit = false,
2626
disableAdmin = false,
27+
canUndo = false,
28+
canRedo = false,
2729
}: PaneContextMenuProps) {
2830
return (
2931
<Popover open={isOpen} onOpenChange={onClose} variant='secondary' size='sm'>
@@ -40,7 +42,7 @@ export function PaneContextMenu({
4042
{/* Undo */}
4143
<PopoverItem
4244
className='group'
43-
disabled={disableEdit}
45+
disabled={disableEdit || !canUndo}
4446
onClick={() => {
4547
onUndo()
4648
onClose()
@@ -53,7 +55,7 @@ export function PaneContextMenu({
5355
{/* Redo */}
5456
<PopoverItem
5557
className='group'
56-
disabled={disableEdit}
58+
disabled={disableEdit || !canRedo}
5759
onClick={() => {
5860
onRedo()
5961
onClose()

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/context-menu/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,8 @@ export interface PaneContextMenuProps {
8686
disableEdit?: boolean
8787
/** Whether admin actions are disabled (no admin permission) */
8888
disableAdmin?: boolean
89+
/** Whether undo is available */
90+
canUndo?: boolean
91+
/** Whether redo is available */
92+
canRedo?: boolean
8993
}

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import ReactFlow, {
1616
import 'reactflow/dist/style.css'
1717
import { createLogger } from '@sim/logger'
1818
import { useShallow } from 'zustand/react/shallow'
19+
import { useSession } from '@/lib/auth/auth-client'
1920
import type { OAuthConnectEventDetail } from '@/lib/copilot/tools/client/other/oauth-request-access'
2021
import type { OAuthProvider } from '@/lib/oauth'
2122
import { DEFAULT_HORIZONTAL_SPACING } from '@/lib/workflows/autolayout/constants'
@@ -65,6 +66,7 @@ import { useCopilotStore } from '@/stores/panel/copilot/store'
6566
import { usePanelEditorStore } from '@/stores/panel/editor/store'
6667
import { useSearchModalStore } from '@/stores/search-modal/store'
6768
import { useGeneralStore } from '@/stores/settings/general/store'
69+
import { useUndoRedoStore } from '@/stores/undo-redo'
6870
import { useVariablesStore } from '@/stores/variables/store'
6971
import { useWorkflowDiffStore } from '@/stores/workflow-diff/store'
7072
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
@@ -232,6 +234,15 @@ const WorkflowContent = React.memo(() => {
232234

233235
const currentWorkflow = useCurrentWorkflow()
234236

237+
// Undo/redo availability for context menu
238+
const { data: session } = useSession()
239+
const userId = session?.user?.id || 'unknown'
240+
const undoRedoStacks = useUndoRedoStore((s) => s.stacks)
241+
const undoRedoKey = activeWorkflowId && userId ? `${activeWorkflowId}:${userId}` : ''
242+
const undoRedoStack = (undoRedoKey && undoRedoStacks[undoRedoKey]) || { undo: [], redo: [] }
243+
const canUndo = undoRedoStack.undo.length > 0
244+
const canRedo = undoRedoStack.redo.length > 0
245+
235246
const { updateNodeDimensions, setDragStartPosition, getDragStartPosition } = useWorkflowStore(
236247
useShallow((state) => ({
237248
updateNodeDimensions: state.updateNodeDimensions,
@@ -2892,6 +2903,8 @@ const WorkflowContent = React.memo(() => {
28922903
hasClipboard={hasClipboard()}
28932904
disableEdit={!effectivePermissions.canEdit}
28942905
disableAdmin={!effectivePermissions.canAdmin}
2906+
canUndo={canUndo}
2907+
canRedo={canRedo}
28952908
/>
28962909
</>
28972910
)}

0 commit comments

Comments
 (0)