Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
e11fc8c1
Commit
e11fc8c1
authored
Mar 13, 2024
by
StyleZhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
2edef89a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
24 additions
and
5 deletions
+24
-5
constants.ts
web/app/components/workflow/constants.ts
+1
-0
use-workflow.ts
web/app/components/workflow/hooks/use-workflow.ts
+4
-1
index.tsx
web/app/components/workflow/index.tsx
+6
-4
node-handle.tsx
...omponents/workflow/nodes/_base/components/node-handle.tsx
+9
-0
store.ts
web/app/components/workflow/store.ts
+4
-0
No files found.
web/app/components/workflow/constants.ts
View file @
e11fc8c1
...
...
@@ -159,6 +159,7 @@ export const X_OFFSET = 64
export
const
NODE_WIDTH_X_OFFSET
=
NODE_WIDTH
+
X_OFFSET
export
const
Y_OFFSET
=
39
export
const
TREE_DEEPTH
=
20
export
const
START_INITIAL_POSITION
=
{
x
:
80
,
y
:
282
}
export
const
RETRIEVAL_OUTPUT_STRUCT
=
`{
"content": "",
...
...
web/app/components/workflow/hooks/use-workflow.ts
View file @
e11fc8c1
...
...
@@ -86,9 +86,12 @@ export const useWorkflow = () => {
edges
,
}
=
store
.
getState
()
const
nodes
=
getNodes
()
const
currentNode
=
nodes
.
find
(
node
=>
node
.
id
===
nodeId
)
!
const
currentNode
=
nodes
.
find
(
node
=>
node
.
id
===
nodeId
)
const
list
:
Node
[]
=
[]
if
(
!
currentNode
)
return
list
const
traverse
=
(
root
:
Node
,
callback
:
(
node
:
Node
)
=>
void
)
=>
{
const
incomers
=
getIncomers
(
root
,
nodes
,
edges
)
...
...
web/app/components/workflow/index.tsx
View file @
e11fc8c1
...
...
@@ -38,6 +38,7 @@ import {
initialEdges
,
initialNodes
,
}
from
'./utils'
import
{
START_INITIAL_POSITION
}
from
'./constants'
import
{
fetchWorkflowDraft
,
syncWorkflowDraft
,
...
...
@@ -168,11 +169,11 @@ const WorkflowWrap: FC<WorkflowProps> = ({
return
{
id
:
`
${
Date
.
now
()}
`
,
type
:
'custom'
,
data
:
nodesInitialData
.
start
,
position
:
{
x
:
100
,
y
:
200
,
data
:
{
...
nodesInitialData
.
start
,
selected
:
true
,
},
position
:
START_INITIAL_POSITION
,
}
},
[
nodesInitialData
])
...
...
@@ -214,6 +215,7 @@ const WorkflowWrap: FC<WorkflowProps> = ({
if
(
error
&&
error
.
json
&&
!
error
.
bodyUsed
&&
appDetail
)
{
error
.
json
().
then
((
err
:
any
)
=>
{
if
(
err
.
code
===
'draft_workflow_not_exist'
)
{
useStore
.
setState
({
notInitialWorkflow
:
true
})
syncWorkflowDraft
({
url
:
`/apps/
${
appDetail
.
id
}
/workflows/draft`
,
params
:
{
...
...
web/app/components/workflow/nodes/_base/components/node-handle.tsx
View file @
e11fc8c1
import
type
{
MouseEvent
}
from
'react'
import
{
useCallback
,
useEffect
,
useState
,
}
from
'react'
import
type
{
NodeProps
}
from
'reactflow'
...
...
@@ -15,6 +16,7 @@ import type { Node } from '../../../types'
import
BlockSelector
from
'../../../block-selector'
import
type
{
ToolDefaultValue
}
from
'../../../block-selector/types'
import
{
useNodesInteractions
}
from
'../../../hooks'
import
{
useStore
}
from
'../../../store'
type
NodeHandleProps
=
{
handleId
:
string
...
...
@@ -87,10 +89,12 @@ export const NodeTargetHandle = ({
export
const
NodeSourceHandle
=
({
id
,
data
,
handleId
,
handleClassName
,
nodeSelectorClassName
,
}:
NodeHandleProps
)
=>
{
const
notInitialWorkflow
=
useStore
(
s
=>
s
.
notInitialWorkflow
)
const
[
open
,
setOpen
]
=
useState
(
false
)
const
{
handleNodeAddNext
}
=
useNodesInteractions
()
const
edges
=
useEdges
()
...
...
@@ -108,6 +112,11 @@ export const NodeSourceHandle = ({
handleNodeAddNext
(
id
,
type
,
handleId
,
toolDefaultValue
)
},
[
handleNodeAddNext
,
id
,
handleId
])
useEffect
(()
=>
{
if
(
notInitialWorkflow
&&
data
.
type
===
BlockEnum
.
Start
)
setOpen
(
true
)
},
[
notInitialWorkflow
,
data
.
type
])
return
(
<>
<
Handle
...
...
web/app/components/workflow/store.ts
View file @
e11fc8c1
...
...
@@ -37,6 +37,7 @@ type State = {
edges
:
Edge
[]
viewport
:
Viewport
}
notInitialWorkflow
:
boolean
}
type
Action
=
{
...
...
@@ -56,6 +57,7 @@ type Action = {
setShowInputsPanel
:
(
showInputsPanel
:
boolean
)
=>
void
setInputs
:
(
inputs
:
Record
<
string
,
string
>
)
=>
void
setBackupDraft
:
(
backupDraft
?:
State
[
'backupDraft'
])
=>
void
setNotInitialWorkflow
:
(
notInitialWorkflow
:
boolean
)
=>
void
}
export
const
useStore
=
create
<
State
&
Action
>
(
set
=>
({
...
...
@@ -91,4 +93,6 @@ export const useStore = create<State & Action>(set => ({
setInputs
:
inputs
=>
set
(()
=>
({
inputs
})),
backupDraft
:
undefined
,
setBackupDraft
:
backupDraft
=>
set
(()
=>
({
backupDraft
})),
notInitialWorkflow
:
false
,
setNotInitialWorkflow
:
notInitialWorkflow
=>
set
(()
=>
({
notInitialWorkflow
})),
}))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment