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
22e7393b
Commit
22e7393b
authored
Mar 12, 2024
by
StyleZhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
0eb482f3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
52 deletions
+48
-52
hooks.ts
web/app/components/workflow/hooks.ts
+13
-6
index.tsx
...nents/workflow/nodes/_base/components/next-step/index.tsx
+7
-14
use-config.ts
...mponents/workflow/nodes/question-classifier/use-config.ts
+1
-0
zoom-in-out.tsx
web/app/components/workflow/operator/zoom-in-out.tsx
+1
-1
utils.ts
web/app/components/workflow/utils.ts
+26
-31
No files found.
web/app/components/workflow/hooks.ts
View file @
22e7393b
...
...
@@ -70,7 +70,7 @@ export const useWorkflow = () => {
const
nodesInitialData
=
useNodesInitialData
()
const
featuresStore
=
useFeaturesStore
()
const
shouldDebouncedSyncWorkflowDraft
=
()
=>
{
const
shouldDebouncedSyncWorkflowDraft
=
useCallback
(
()
=>
{
const
{
getNodes
,
edges
,
...
...
@@ -111,13 +111,20 @@ export const useWorkflow = () => {
useStore
.
setState
({
draftUpdatedAt
:
res
.
updated_at
})
})
}
}
}
,
[
store
,
reactFlow
,
featuresStore
])
const
{
run
:
handle
SyncWorkflowDraft
}
=
useDebounceFn
(
shouldDebouncedSyncWorkflowDraft
,
{
const
{
run
:
debounced
SyncWorkflowDraft
}
=
useDebounceFn
(
shouldDebouncedSyncWorkflowDraft
,
{
wait
:
2000
,
trailing
:
true
,
})
const
handleSyncWorkflowDraft
=
useCallback
((
shouldDelay
?:
boolean
)
=>
{
if
(
shouldDelay
)
debouncedSyncWorkflowDraft
()
else
shouldDebouncedSyncWorkflowDraft
()
},
[
debouncedSyncWorkflowDraft
,
shouldDebouncedSyncWorkflowDraft
])
const
handleLayout
=
useCallback
(
async
()
=>
{
const
{
getNodes
,
...
...
@@ -332,11 +339,11 @@ export const useWorkflow = () => {
if
(
!
cancelSelection
&&
selectedNode
?.
id
===
nodeId
)
return
const
newNodes
=
produce
(
getNodes
()
,
(
draft
)
=>
{
const
newNodes
=
produce
(
nodes
,
(
draft
)
=>
{
draft
.
forEach
(
node
=>
node
.
data
.
selected
=
false
)
const
selectedNode
=
draft
.
find
(
node
=>
node
.
id
===
nodeId
)
!
if
(
!
cancelSelection
)
if
(
!
cancelSelection
&&
selectedNode
)
selectedNode
.
data
.
selected
=
true
})
setNodes
(
newNodes
)
...
...
@@ -433,7 +440,7 @@ export const useWorkflow = () => {
currentNode
.
data
=
{
...
currentNode
.
data
,
...
data
}
})
setNodes
(
newNodes
)
handleSyncWorkflowDraft
()
handleSyncWorkflowDraft
(
true
)
},
[
store
,
handleSyncWorkflowDraft
])
const
handleNodeAddNext
=
useCallback
((
...
...
web/app/components/workflow/nodes/_base/components/next-step/index.tsx
View file @
22e7393b
import
{
memo
,
useMemo
}
from
'react'
import
{
memo
}
from
'react'
import
{
getConnectedEdges
,
getOutgoers
,
...
...
@@ -10,10 +10,10 @@ import type {
Branch
,
Node
,
}
from
'../../../../types'
import
{
BlockEnum
}
from
'../../../../types'
import
Add
from
'./add'
import
Item
from
'./item'
import
Line
from
'./line'
import
{
BlockEnum
}
from
'@/app/components/workflow/types'
type
NextStepProps
=
{
selectedNode
:
Node
...
...
@@ -22,15 +22,8 @@ const NextStep = ({
selectedNode
,
}:
NextStepProps
)
=>
{
const
store
=
useStoreApi
()
const
branches
=
useMemo
(()
=>
{
const
nodeData
=
selectedNode
.
data
if
(
nodeData
.
type
===
BlockEnum
.
IfElse
)
return
nodeData
.
_targetBranches
if
(
nodeData
.
type
===
BlockEnum
.
QuestionClassifier
)
return
(
nodeData
as
any
).
classes
},
[
selectedNode
])
const
branches
=
selectedNode
.
data
.
_targetBranches
const
nodeWithBranches
=
selectedNode
.
data
.
type
===
BlockEnum
.
IfElse
||
selectedNode
.
data
.
type
===
BlockEnum
.
QuestionClassifier
const
edges
=
useEdges
()
const
outgoers
=
getOutgoers
(
selectedNode
as
Node
,
store
.
getState
().
getNodes
(),
edges
)
const
connectedEdges
=
getConnectedEdges
([
selectedNode
]
as
Node
[],
edges
).
filter
(
edge
=>
edge
.
source
===
selectedNode
!
.
id
)
...
...
@@ -46,7 +39,7 @@ const NextStep = ({
<
Line
linesNumber=
{
branches
?
branches
.
length
:
1
}
/>
<
div
className=
'grow'
>
{
!
b
ranches
&&
!!
outgoers
.
length
&&
(
!
nodeWithB
ranches
&&
!!
outgoers
.
length
&&
(
<
Item
nodeId=
{
outgoers
[
0
].
id
}
data=
{
outgoers
[
0
].
data
}
...
...
@@ -55,7 +48,7 @@ const NextStep = ({
)
}
{
!
b
ranches
&&
!
outgoers
.
length
&&
(
!
nodeWithB
ranches
&&
!
outgoers
.
length
&&
(
<
Add
nodeId=
{
selectedNode
!
.
id
}
sourceHandle=
'source'
...
...
@@ -63,7 +56,7 @@ const NextStep = ({
)
}
{
branches
?.
length
&&
(
!!
branches
?.
length
&&
nodeWithBranches
&&
(
branches
.
map
((
branch
:
Branch
)
=>
{
const
connected
=
connectedEdges
.
find
(
edge
=>
edge
.
sourceHandle
===
branch
.
id
)
const
target
=
outgoers
.
find
(
outgoer
=>
outgoer
.
id
===
connected
?.
target
)
...
...
web/app/components/workflow/nodes/question-classifier/use-config.ts
View file @
22e7393b
...
...
@@ -35,6 +35,7 @@ const useConfig = (id: string, payload: QuestionClassifierNodeType) => {
const
handleClassesChange
=
useCallback
((
newClasses
:
any
)
=>
{
const
newInputs
=
produce
(
inputs
,
(
draft
)
=>
{
draft
.
classes
=
newClasses
draft
.
_targetBranches
=
newClasses
})
setInputs
(
newInputs
)
},
[
inputs
,
setInputs
])
...
...
web/app/components/workflow/operator/zoom-in-out.tsx
View file @
22e7393b
...
...
@@ -95,7 +95,7 @@ const ZoomInOut: FC = () => {
<
ChevronDown
className=
'ml-1 w-4 h-4'
/>
</
div
>
</
PortalToFollowElemTrigger
>
<
PortalToFollowElemContent
>
<
PortalToFollowElemContent
className=
'z-10'
>
<
div
className=
'w-[168px] rounded-lg border-[0.5px] border-gray-200 bg-white shadow-lg'
>
{
ZOOM_IN_OUT_OPTIONS
.
map
((
options
,
i
)
=>
(
...
...
web/app/components/workflow/utils.ts
View file @
22e7393b
import
produce
from
'immer'
import
{
getConnectedEdges
,
getOutgoers
,
...
...
@@ -82,42 +81,38 @@ export const nodesLevelOrderTraverse = (
}
export
const
initialNodes
=
(
nodes
:
Node
[])
=>
{
const
newNodes
=
produce
(
nodes
,
(
draft
)
=>
{
draft
.
forEach
((
node
)
=>
{
node
.
type
=
'custom'
if
(
node
.
data
.
type
===
BlockEnum
.
IfElse
)
{
node
.
data
.
_targetBranches
=
[
{
id
:
'true'
,
name
:
'IS TRUE'
,
},
{
id
:
'false'
,
name
:
'IS FALSE'
,
},
]
}
return
nodes
.
map
((
node
)
=>
{
node
.
type
=
'custom'
if
(
node
.
data
.
type
===
BlockEnum
.
IfElse
)
{
node
.
data
.
_targetBranches
=
[
{
id
:
'true'
,
name
:
'IS TRUE'
,
},
{
id
:
'false'
,
name
:
'IS FALSE'
,
},
]
}
if
(
node
.
data
.
type
===
BlockEnum
.
QuestionClassifier
)
{
node
.
data
.
_targetBranches
=
(
node
.
data
as
QuestionClassifierNodeType
).
classes
.
map
((
topic
)
=>
{
return
topic
})
}
})
})
if
(
node
.
data
.
type
===
BlockEnum
.
QuestionClassifier
)
{
node
.
data
.
_targetBranches
=
(
node
.
data
as
QuestionClassifierNodeType
).
classes
.
map
((
topic
)
=>
{
return
topic
})
}
return
newNodes
return
node
})
}
export
const
initialEdges
=
(
edges
:
Edge
[])
=>
{
const
newEdges
=
produce
(
edges
,
(
draft
)
=>
{
draft
.
forEach
((
edge
)
=>
{
edge
.
type
=
'custom'
})
})
return
edges
.
map
((
edge
)
=>
{
edge
.
type
=
'custom'
return
newEdges
return
edge
})
}
export
type
PositionMap
=
{
...
...
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