Commit e11fc8c1 authored by StyleZhang's avatar StyleZhang

init

parent 2edef89a
...@@ -159,6 +159,7 @@ export const X_OFFSET = 64 ...@@ -159,6 +159,7 @@ export const X_OFFSET = 64
export const NODE_WIDTH_X_OFFSET = NODE_WIDTH + X_OFFSET export const NODE_WIDTH_X_OFFSET = NODE_WIDTH + X_OFFSET
export const Y_OFFSET = 39 export const Y_OFFSET = 39
export const TREE_DEEPTH = 20 export const TREE_DEEPTH = 20
export const START_INITIAL_POSITION = { x: 80, y: 282 }
export const RETRIEVAL_OUTPUT_STRUCT = `{ export const RETRIEVAL_OUTPUT_STRUCT = `{
"content": "", "content": "",
......
...@@ -86,9 +86,12 @@ export const useWorkflow = () => { ...@@ -86,9 +86,12 @@ export const useWorkflow = () => {
edges, edges,
} = store.getState() } = store.getState()
const nodes = getNodes() const nodes = getNodes()
const currentNode = nodes.find(node => node.id === nodeId)! const currentNode = nodes.find(node => node.id === nodeId)
const list: Node[] = [] const list: Node[] = []
if (!currentNode)
return list
const traverse = (root: Node, callback: (node: Node) => void) => { const traverse = (root: Node, callback: (node: Node) => void) => {
const incomers = getIncomers(root, nodes, edges) const incomers = getIncomers(root, nodes, edges)
......
...@@ -38,6 +38,7 @@ import { ...@@ -38,6 +38,7 @@ import {
initialEdges, initialEdges,
initialNodes, initialNodes,
} from './utils' } from './utils'
import { START_INITIAL_POSITION } from './constants'
import { import {
fetchWorkflowDraft, fetchWorkflowDraft,
syncWorkflowDraft, syncWorkflowDraft,
...@@ -168,11 +169,11 @@ const WorkflowWrap: FC<WorkflowProps> = ({ ...@@ -168,11 +169,11 @@ const WorkflowWrap: FC<WorkflowProps> = ({
return { return {
id: `${Date.now()}`, id: `${Date.now()}`,
type: 'custom', type: 'custom',
data: nodesInitialData.start, data: {
position: { ...nodesInitialData.start,
x: 100, selected: true,
y: 200,
}, },
position: START_INITIAL_POSITION,
} }
}, [nodesInitialData]) }, [nodesInitialData])
...@@ -214,6 +215,7 @@ const WorkflowWrap: FC<WorkflowProps> = ({ ...@@ -214,6 +215,7 @@ const WorkflowWrap: FC<WorkflowProps> = ({
if (error && error.json && !error.bodyUsed && appDetail) { if (error && error.json && !error.bodyUsed && appDetail) {
error.json().then((err: any) => { error.json().then((err: any) => {
if (err.code === 'draft_workflow_not_exist') { if (err.code === 'draft_workflow_not_exist') {
useStore.setState({ notInitialWorkflow: true })
syncWorkflowDraft({ syncWorkflowDraft({
url: `/apps/${appDetail.id}/workflows/draft`, url: `/apps/${appDetail.id}/workflows/draft`,
params: { params: {
......
import type { MouseEvent } from 'react' import type { MouseEvent } from 'react'
import { import {
useCallback, useCallback,
useEffect,
useState, useState,
} from 'react' } from 'react'
import type { NodeProps } from 'reactflow' import type { NodeProps } from 'reactflow'
...@@ -15,6 +16,7 @@ import type { Node } from '../../../types' ...@@ -15,6 +16,7 @@ import type { Node } from '../../../types'
import BlockSelector from '../../../block-selector' import BlockSelector from '../../../block-selector'
import type { ToolDefaultValue } from '../../../block-selector/types' import type { ToolDefaultValue } from '../../../block-selector/types'
import { useNodesInteractions } from '../../../hooks' import { useNodesInteractions } from '../../../hooks'
import { useStore } from '../../../store'
type NodeHandleProps = { type NodeHandleProps = {
handleId: string handleId: string
...@@ -87,10 +89,12 @@ export const NodeTargetHandle = ({ ...@@ -87,10 +89,12 @@ export const NodeTargetHandle = ({
export const NodeSourceHandle = ({ export const NodeSourceHandle = ({
id, id,
data,
handleId, handleId,
handleClassName, handleClassName,
nodeSelectorClassName, nodeSelectorClassName,
}: NodeHandleProps) => { }: NodeHandleProps) => {
const notInitialWorkflow = useStore(s => s.notInitialWorkflow)
const [open, setOpen] = useState(false) const [open, setOpen] = useState(false)
const { handleNodeAddNext } = useNodesInteractions() const { handleNodeAddNext } = useNodesInteractions()
const edges = useEdges() const edges = useEdges()
...@@ -108,6 +112,11 @@ export const NodeSourceHandle = ({ ...@@ -108,6 +112,11 @@ export const NodeSourceHandle = ({
handleNodeAddNext(id, type, handleId, toolDefaultValue) handleNodeAddNext(id, type, handleId, toolDefaultValue)
}, [handleNodeAddNext, id, handleId]) }, [handleNodeAddNext, id, handleId])
useEffect(() => {
if (notInitialWorkflow && data.type === BlockEnum.Start)
setOpen(true)
}, [notInitialWorkflow, data.type])
return ( return (
<> <>
<Handle <Handle
......
...@@ -37,6 +37,7 @@ type State = { ...@@ -37,6 +37,7 @@ type State = {
edges: Edge[] edges: Edge[]
viewport: Viewport viewport: Viewport
} }
notInitialWorkflow: boolean
} }
type Action = { type Action = {
...@@ -56,6 +57,7 @@ type Action = { ...@@ -56,6 +57,7 @@ type Action = {
setShowInputsPanel: (showInputsPanel: boolean) => void setShowInputsPanel: (showInputsPanel: boolean) => void
setInputs: (inputs: Record<string, string>) => void setInputs: (inputs: Record<string, string>) => void
setBackupDraft: (backupDraft?: State['backupDraft']) => void setBackupDraft: (backupDraft?: State['backupDraft']) => void
setNotInitialWorkflow: (notInitialWorkflow: boolean) => void
} }
export const useStore = create<State & Action>(set => ({ export const useStore = create<State & Action>(set => ({
...@@ -91,4 +93,6 @@ export const useStore = create<State & Action>(set => ({ ...@@ -91,4 +93,6 @@ export const useStore = create<State & Action>(set => ({
setInputs: inputs => set(() => ({ inputs })), setInputs: inputs => set(() => ({ inputs })),
backupDraft: undefined, backupDraft: undefined,
setBackupDraft: backupDraft => set(() => ({ backupDraft })), setBackupDraft: backupDraft => set(() => ({ backupDraft })),
notInitialWorkflow: false,
setNotInitialWorkflow: notInitialWorkflow => set(() => ({ notInitialWorkflow })),
})) }))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment