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(

View File

@@ -13,8 +13,10 @@ import {
generateNewNode,
} from '../../utils'
import {
WorkflowHistoryEvent,
useAvailableBlocks,
useNodesReadOnly,
useWorkflowHistory,
} from '../../hooks'
import { NODES_INITIAL_DATA } from '../../constants'
import InsertBlock from './insert-block'
@@ -42,6 +44,7 @@ const AddBlock = ({
const { nodesReadOnly } = useNodesReadOnly()
const { availableNextBlocks } = useAvailableBlocks(BlockEnum.Start, true)
const { availablePrevBlocks } = useAvailableBlocks(iterationNodeData.startNodeType, true)
const { saveStateToHistory } = useWorkflowHistory()
const handleSelect = useCallback<OnSelectBlock>((type, toolDefaultValue) => {
const {
@@ -78,7 +81,8 @@ const AddBlock = ({
draft.push(newNode)
})
setNodes(newNodes)
}, [store, t, iterationNodeId])
saveStateToHistory(WorkflowHistoryEvent.NodeAdd)
}, [store, t, iterationNodeId, saveStateToHistory])
const renderTriggerElement = useCallback((open: boolean) => {
return (