mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-06 21:54:01 -05:00
improvement(context-menu): gray out undo redo if the stack is empty (#2657)
This commit is contained in:
@@ -24,6 +24,8 @@ export function PaneContextMenu({
|
|||||||
hasClipboard = false,
|
hasClipboard = false,
|
||||||
disableEdit = false,
|
disableEdit = false,
|
||||||
disableAdmin = false,
|
disableAdmin = false,
|
||||||
|
canUndo = false,
|
||||||
|
canRedo = false,
|
||||||
}: PaneContextMenuProps) {
|
}: PaneContextMenuProps) {
|
||||||
return (
|
return (
|
||||||
<Popover open={isOpen} onOpenChange={onClose} variant='secondary' size='sm'>
|
<Popover open={isOpen} onOpenChange={onClose} variant='secondary' size='sm'>
|
||||||
@@ -40,7 +42,7 @@ export function PaneContextMenu({
|
|||||||
{/* Undo */}
|
{/* Undo */}
|
||||||
<PopoverItem
|
<PopoverItem
|
||||||
className='group'
|
className='group'
|
||||||
disabled={disableEdit}
|
disabled={disableEdit || !canUndo}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
onUndo()
|
onUndo()
|
||||||
onClose()
|
onClose()
|
||||||
@@ -53,7 +55,7 @@ export function PaneContextMenu({
|
|||||||
{/* Redo */}
|
{/* Redo */}
|
||||||
<PopoverItem
|
<PopoverItem
|
||||||
className='group'
|
className='group'
|
||||||
disabled={disableEdit}
|
disabled={disableEdit || !canRedo}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
onRedo()
|
onRedo()
|
||||||
onClose()
|
onClose()
|
||||||
|
|||||||
@@ -86,4 +86,8 @@ export interface PaneContextMenuProps {
|
|||||||
disableEdit?: boolean
|
disableEdit?: boolean
|
||||||
/** Whether admin actions are disabled (no admin permission) */
|
/** Whether admin actions are disabled (no admin permission) */
|
||||||
disableAdmin?: boolean
|
disableAdmin?: boolean
|
||||||
|
/** Whether undo is available */
|
||||||
|
canUndo?: boolean
|
||||||
|
/** Whether redo is available */
|
||||||
|
canRedo?: boolean
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import ReactFlow, {
|
|||||||
import 'reactflow/dist/style.css'
|
import 'reactflow/dist/style.css'
|
||||||
import { createLogger } from '@sim/logger'
|
import { createLogger } from '@sim/logger'
|
||||||
import { useShallow } from 'zustand/react/shallow'
|
import { useShallow } from 'zustand/react/shallow'
|
||||||
|
import { useSession } from '@/lib/auth/auth-client'
|
||||||
import type { OAuthConnectEventDetail } from '@/lib/copilot/tools/client/other/oauth-request-access'
|
import type { OAuthConnectEventDetail } from '@/lib/copilot/tools/client/other/oauth-request-access'
|
||||||
import type { OAuthProvider } from '@/lib/oauth'
|
import type { OAuthProvider } from '@/lib/oauth'
|
||||||
import { DEFAULT_HORIZONTAL_SPACING } from '@/lib/workflows/autolayout/constants'
|
import { DEFAULT_HORIZONTAL_SPACING } from '@/lib/workflows/autolayout/constants'
|
||||||
@@ -65,6 +66,7 @@ import { useCopilotStore } from '@/stores/panel/copilot/store'
|
|||||||
import { usePanelEditorStore } from '@/stores/panel/editor/store'
|
import { usePanelEditorStore } from '@/stores/panel/editor/store'
|
||||||
import { useSearchModalStore } from '@/stores/search-modal/store'
|
import { useSearchModalStore } from '@/stores/search-modal/store'
|
||||||
import { useGeneralStore } from '@/stores/settings/general/store'
|
import { useGeneralStore } from '@/stores/settings/general/store'
|
||||||
|
import { useUndoRedoStore } from '@/stores/undo-redo'
|
||||||
import { useVariablesStore } from '@/stores/variables/store'
|
import { useVariablesStore } from '@/stores/variables/store'
|
||||||
import { useWorkflowDiffStore } from '@/stores/workflow-diff/store'
|
import { useWorkflowDiffStore } from '@/stores/workflow-diff/store'
|
||||||
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
|
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
|
||||||
@@ -232,6 +234,15 @@ const WorkflowContent = React.memo(() => {
|
|||||||
|
|
||||||
const currentWorkflow = useCurrentWorkflow()
|
const currentWorkflow = useCurrentWorkflow()
|
||||||
|
|
||||||
|
// Undo/redo availability for context menu
|
||||||
|
const { data: session } = useSession()
|
||||||
|
const userId = session?.user?.id || 'unknown'
|
||||||
|
const undoRedoStacks = useUndoRedoStore((s) => s.stacks)
|
||||||
|
const undoRedoKey = activeWorkflowId && userId ? `${activeWorkflowId}:${userId}` : ''
|
||||||
|
const undoRedoStack = (undoRedoKey && undoRedoStacks[undoRedoKey]) || { undo: [], redo: [] }
|
||||||
|
const canUndo = undoRedoStack.undo.length > 0
|
||||||
|
const canRedo = undoRedoStack.redo.length > 0
|
||||||
|
|
||||||
const { updateNodeDimensions, setDragStartPosition, getDragStartPosition } = useWorkflowStore(
|
const { updateNodeDimensions, setDragStartPosition, getDragStartPosition } = useWorkflowStore(
|
||||||
useShallow((state) => ({
|
useShallow((state) => ({
|
||||||
updateNodeDimensions: state.updateNodeDimensions,
|
updateNodeDimensions: state.updateNodeDimensions,
|
||||||
@@ -2892,6 +2903,8 @@ const WorkflowContent = React.memo(() => {
|
|||||||
hasClipboard={hasClipboard()}
|
hasClipboard={hasClipboard()}
|
||||||
disableEdit={!effectivePermissions.canEdit}
|
disableEdit={!effectivePermissions.canEdit}
|
||||||
disableAdmin={!effectivePermissions.canAdmin}
|
disableAdmin={!effectivePermissions.canAdmin}
|
||||||
|
canUndo={canUndo}
|
||||||
|
canRedo={canRedo}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user