feat: undo/redo for workflow editor (#3927)

Co-authored-by: StyleZhang <jasonapring2015@outlook.com>
This commit is contained in:
Pascal M
2024-06-26 08:37:12 +02:00
committed by GitHub
parent d0fe56a98e
commit af9448e6f2
38 changed files with 2049 additions and 778 deletions

View File

@@ -24,6 +24,7 @@ import {
import { useResizePanel } from './hooks/use-resize-panel'
import BlockIcon from '@/app/components/workflow/block-icon'
import {
WorkflowHistoryEvent,
useAvailableBlocks,
useNodeDataUpdate,
useNodesInteractions,
@@ -31,6 +32,7 @@ import {
useNodesSyncDraft,
useToolIcon,
useWorkflow,
useWorkflowHistory,
} from '@/app/components/workflow/hooks'
import { canRunBySingle } from '@/app/components/workflow/utils'
import TooltipPlus from '@/app/components/base/tooltip-plus'
@@ -77,6 +79,8 @@ const BasePanel: FC<BasePanelProps> = ({
onResize: handleResize,
})
const { saveStateToHistory } = useWorkflowHistory()
const {
handleNodeDataUpdate,
handleNodeDataUpdateWithSyncDraft,
@@ -84,10 +88,12 @@ const BasePanel: FC<BasePanelProps> = ({
const handleTitleBlur = useCallback((title: string) => {
handleNodeDataUpdateWithSyncDraft({ id, data: { title } })
}, [handleNodeDataUpdateWithSyncDraft, id])
saveStateToHistory(WorkflowHistoryEvent.NodeTitleChange)
}, [handleNodeDataUpdateWithSyncDraft, id, saveStateToHistory])
const handleDescriptionChange = useCallback((desc: string) => {
handleNodeDataUpdateWithSyncDraft({ id, data: { desc } })
}, [handleNodeDataUpdateWithSyncDraft, id])
saveStateToHistory(WorkflowHistoryEvent.NodeDescriptionChange)
}, [handleNodeDataUpdateWithSyncDraft, id, saveStateToHistory])
return (
<div className={cn(