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
16abcf08
Commit
16abcf08
authored
Mar 07, 2024
by
StyleZhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
node control
parent
173336f2
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
71 additions
and
70 deletions
+71
-70
hooks.ts
web/app/components/workflow/hooks.ts
+1
-0
index.tsx
web/app/components/workflow/index.tsx
+2
-6
node-control.tsx
...mponents/workflow/nodes/_base/components/node-control.tsx
+1
-1
node.tsx
web/app/components/workflow/nodes/_base/node.tsx
+64
-44
index.tsx
web/app/components/workflow/nodes/index.tsx
+3
-18
types.ts
web/app/components/workflow/types.ts
+0
-1
No files found.
web/app/components/workflow/hooks.ts
View file @
16abcf08
...
...
@@ -368,6 +368,7 @@ export const useWorkflow = () => {
x
:
currentNode
.
position
.
x
,
y
:
currentNode
.
position
.
y
,
},
targetPosition
:
Position
.
Left
,
}
const
newNodes
=
produce
(
nodes
,
(
draft
)
=>
{
const
index
=
draft
.
findIndex
(
node
=>
node
.
id
===
currentNodeId
)
...
...
web/app/components/workflow/index.tsx
View file @
16abcf08
...
...
@@ -9,8 +9,6 @@ import { useKeyPress } from 'ahooks'
import
ReactFlow
,
{
Background
,
ReactFlowProvider
,
useEdgesState
,
useNodesState
,
useOnViewportChange
,
}
from
'reactflow'
import
type
{
Viewport
}
from
'reactflow'
...
...
@@ -56,13 +54,11 @@ type WorkflowProps = {
viewport
?:
Viewport
}
const
Workflow
:
FC
<
WorkflowProps
>
=
memo
(({
nodes
:
initialNodes
,
edges
:
initialEdges
,
nodes
,
edges
,
viewport
,
})
=>
{
const
showFeaturesPanel
=
useStore
(
state
=>
state
.
showFeaturesPanel
)
const
[
nodes
]
=
useNodesState
(
initialNodes
)
const
[
edges
]
=
useEdgesState
(
initialEdges
)
const
{
handleSyncWorkflowDraft
,
...
...
web/app/components/workflow/nodes/_base/components/node-control.tsx
View file @
16abcf08
...
...
@@ -21,7 +21,7 @@ const NodeControl: FC<NodeControlProps> = ({
const
{
handleNodeDataUpdate
}
=
useWorkflow
()
return
(
<
div
className=
'
absolute right-0 -top-7
flex items-center px-0.5 h-6 bg-white rounded-lg border-[0.5px] border-gray-100 shadow-xs text-gray-500'
>
<
div
className=
'flex items-center px-0.5 h-6 bg-white rounded-lg border-[0.5px] border-gray-100 shadow-xs text-gray-500'
>
{
isRunning
&&
(
<
div
className=
'flex items-center px-1 h-5 rounded-md bg-primary-50 text-xs font-medium text-primary-600'
>
...
...
web/app/components/workflow/nodes/_base/node.tsx
View file @
16abcf08
...
...
@@ -8,10 +8,12 @@ import {
}
from
'react'
import
type
{
NodeProps
}
from
'../../types'
import
{
BlockEnum
}
from
'../../types'
import
{
canRunBySingle
}
from
'../../utils'
import
{
NodeSourceHandle
,
NodeTargetHandle
,
}
from
'./components/node-handle'
import
NodeControl
from
'./components/node-control'
import
BlockIcon
from
'@/app/components/workflow/block-icon'
type
BaseNodeProps
=
{
...
...
@@ -26,55 +28,73 @@ const BaseNode: FC<BaseNodeProps> = ({
return
(
<
div
className=
{
`
group relative w-[240px] bg-[#fcfdff] rounded-2xl shadow-xs
hover:shadow-lg
${data._selected ? 'border-[2px] border-primary-600' : 'border border-white'}
flex border-[2px] rounded-2xl
${data._selected ? 'border-primary-600' : 'border-transparent'}
`
}
>
{
data
.
type
!==
BlockEnum
.
VariableAssigner
&&
(
<
NodeTargetHandle
id=
{
id
}
data=
{
data
}
handleClassName=
'!top-[17px] !-left-2'
handleId=
'target'
<
div
className=
{
`
group relative w-[240px] bg-[#fcfdff] shadow-xs
border border-transparent rounded-[15px]
hover:shadow-lg
`
}
>
{
data
.
type
!==
BlockEnum
.
VariableAssigner
&&
(
<
NodeTargetHandle
id=
{
id
}
data=
{
data
}
handleClassName=
'!top-4 !-left-[9px]'
handleId=
'target'
/>
)
}
{
data
.
type
!==
BlockEnum
.
IfElse
&&
data
.
type
!==
BlockEnum
.
QuestionClassifier
&&
(
<
NodeSourceHandle
id=
{
id
}
data=
{
data
}
handleClassName=
'!top-4 !-right-[9px]'
handleId=
'source'
/>
)
}
{
canRunBySingle
(
data
.
type
)
&&
(
<
div
className=
'hidden group-hover:flex pb-1 absolute right-0 -top-7 h-7'
>
<
NodeControl
nodeId=
{
id
}
isRunning=
{
data
.
_isSingleRun
}
/>
</
div
>
)
}
<
div
className=
'flex items-center px-3 pt-3 pb-2'
>
<
BlockIcon
className=
'shrink-0 mr-2'
type=
{
data
.
type
}
size=
'md'
icon=
{
data
.
_icon
}
/>
)
}
{
data
.
type
!==
BlockEnum
.
IfElse
&&
data
.
type
!==
BlockEnum
.
QuestionClassifier
&&
(
<
NodeSourceHandle
id=
{
id
}
data=
{
data
}
handleClassName=
'!top-[17px] !-right-2'
handleId=
'source'
/>
)
}
<
div
className=
'flex items-center px-3 pt-3 pb-2'
>
<
BlockIcon
className=
'shrink-0 mr-2'
type=
{
data
.
type
}
size=
'md'
icon=
{
data
.
_icon
}
/>
<
div
title=
{
data
.
title
}
className=
'grow text-[13px] font-semibold text-gray-700 truncate'
>
{
data
.
title
}
<
div
title=
{
data
.
title
}
className=
'grow text-[13px] font-semibold text-gray-700 truncate'
>
{
data
.
title
}
</
div
>
</
div
>
<
div
className=
'mb-1'
>
{
cloneElement
(
children
,
{
id
,
data
})
}
</
div
>
{
data
.
desc
&&
(
<
div
className=
'px-3 pt-s1 pb-2 text-xs leading-[18px] text-gray-500 whitespace-pre-line break-words'
>
{
data
.
desc
}
</
div
>
)
}
</
div
>
<
div
className=
'mb-1'
>
{
cloneElement
(
children
,
{
id
,
data
})
}
</
div
>
{
data
.
desc
&&
(
<
div
className=
'px-3 pt-s1 pb-2 text-xs leading-[18px] text-gray-500 whitespace-pre-line break-words'
>
{
data
.
desc
}
</
div
>
)
}
</
div
>
)
}
...
...
web/app/components/workflow/nodes/index.tsx
View file @
16abcf08
import
{
memo
}
from
'react'
import
type
{
NodeProps
}
from
'reactflow'
import
type
{
Node
}
from
'../types'
import
{
canRunBySingle
}
from
'../utils'
import
{
NodeComponentMap
,
PanelComponentMap
,
}
from
'./constants'
import
BaseNode
from
'./_base/node'
import
BasePanel
from
'./_base/panel'
import
NodeControl
from
'./_base/components/node-control'
const
CustomNode
=
memo
((
props
:
NodeProps
)
=>
{
const
nodeId
=
props
.
id
const
nodeData
=
props
.
data
const
NodeComponent
=
NodeComponentMap
[
nodeData
.
type
]
return
(
<>
<
BaseNode
{
...
props
}
>
<
NodeComponent
/>
</
BaseNode
>
{
nodeData
.
_selected
&&
canRunBySingle
(
nodeData
.
type
)
&&
(
<
NodeControl
nodeId=
{
nodeId
}
isRunning=
{
nodeData
.
_isSingleRun
}
/>
)
}
</>
<
BaseNode
{
...
props
}
>
<
NodeComponent
/>
</
BaseNode
>
)
})
CustomNode
.
displayName
=
'CustomNode'
...
...
web/app/components/workflow/types.ts
View file @
16abcf08
...
...
@@ -27,7 +27,6 @@ export type Branch = {
export
type
CommonNodeType
<
T
=
{}
>
=
{
_selected
?:
boolean
_hovering
?:
boolean
_targetBranches
?:
Branch
[]
_isSingleRun
?:
boolean
_icon
?:
Collection
[
'icon'
]
...
...
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