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
cbe7de58
Commit
cbe7de58
authored
Mar 13, 2024
by
StyleZhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
backup draft
parent
801160c4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
30 deletions
+51
-30
index.tsx
web/app/components/workflow/block-selector/index.tsx
+2
-2
custom-edge.tsx
web/app/components/workflow/custom-edge.tsx
+28
-18
use-workflow-run.ts
web/app/components/workflow/hooks/use-workflow-run.ts
+21
-10
No files found.
web/app/components/workflow/block-selector/index.tsx
View file @
cbe7de58
...
@@ -61,8 +61,8 @@ const NodeSelector: FC<NodeSelectorProps> = ({
...
@@ -61,8 +61,8 @@ const NodeSelector: FC<NodeSelectorProps> = ({
},
[
onOpenChange
])
},
[
onOpenChange
])
const
handleTrigger
=
useCallback
<
MouseEventHandler
<
HTMLDivElement
>>
((
e
)
=>
{
const
handleTrigger
=
useCallback
<
MouseEventHandler
<
HTMLDivElement
>>
((
e
)
=>
{
e
.
stopPropagation
()
e
.
stopPropagation
()
setLocalOpen
(
v
=>
!
v
)
handleOpenChange
(
!
open
)
},
[])
},
[
handleOpenChange
,
open
])
const
handleSelect
=
useCallback
<
OnSelectBlock
>
((
type
,
toolDefaultValue
)
=>
{
const
handleSelect
=
useCallback
<
OnSelectBlock
>
((
type
,
toolDefaultValue
)
=>
{
handleOpenChange
(
false
)
handleOpenChange
(
false
)
onSelect
(
type
,
toolDefaultValue
)
onSelect
(
type
,
toolDefaultValue
)
...
...
web/app/components/workflow/custom-edge.tsx
View file @
cbe7de58
import
{
memo
}
from
'react'
import
{
memo
,
useCallback
,
useState
,
}
from
'react'
import
type
{
EdgeProps
}
from
'reactflow'
import
type
{
EdgeProps
}
from
'reactflow'
import
{
import
{
BaseEdge
,
BaseEdge
,
...
@@ -29,6 +33,10 @@ const CustomEdge = ({
...
@@ -29,6 +33,10 @@ const CustomEdge = ({
targetY
,
targetY
,
targetPosition
:
Position
.
Left
,
targetPosition
:
Position
.
Left
,
})
})
const
[
open
,
setOpen
]
=
useState
(
false
)
const
handleOpenChange
=
useCallback
((
v
:
boolean
)
=>
{
setOpen
(
v
)
},
[])
return
(
return
(
<>
<>
...
@@ -41,23 +49,25 @@ const CustomEdge = ({
...
@@ -41,23 +49,25 @@ const CustomEdge = ({
}
}
}
}
/>
/>
<
EdgeLabelRenderer
>
<
EdgeLabelRenderer
>
{
<
div
data
?.
_hovering
&&
(
className=
{
`
<
div
nopan nodrag
className=
'nopan nodrag'
${data?._hovering ? 'block' : 'hidden'}
style=
{
{
${open && '!block'}
position
:
'absolute'
,
`
}
transform
:
`translate(-50%, -50%) translate(${labelX}px, ${labelY}px)`
,
style=
{
{
pointerEvents
:
'all'
,
position
:
'absolute'
,
}
}
transform
:
`translate(-50%, -50%) translate(${labelX}px, ${labelY}px)`
,
>
pointerEvents
:
'all'
,
<
BlockSelector
}
}
asChild
>
onSelect=
{
()
=>
{}
}
<
BlockSelector
/>
open=
{
open
}
</
div
>
onOpenChange=
{
handleOpenChange
}
)
asChild
}
onSelect=
{
()
=>
{}
}
/>
</
div
>
</
EdgeLabelRenderer
>
</
EdgeLabelRenderer
>
</>
</>
)
)
...
...
web/app/components/workflow/hooks/use-workflow-run.ts
View file @
cbe7de58
...
@@ -22,6 +22,23 @@ export const useWorkflowRun = () => {
...
@@ -22,6 +22,23 @@ export const useWorkflowRun = () => {
const
reactflow
=
useReactFlow
()
const
reactflow
=
useReactFlow
()
const
workflowContainerRef
=
useRef
<
HTMLDivElement
>
(
null
)
const
workflowContainerRef
=
useRef
<
HTMLDivElement
>
(
null
)
const
handleBackupDraft
=
useCallback
(()
=>
{
const
{
getNodes
,
getEdges
,
getViewport
,
}
=
reactflow
const
{
setBackupDraft
,
}
=
useStore
.
getState
()
setBackupDraft
({
nodes
:
getNodes
(),
edges
:
getEdges
(),
viewport
:
getViewport
(),
})
},
[
reactflow
])
const
handleLoadBackupDraft
=
useCallback
(()
=>
{
const
handleLoadBackupDraft
=
useCallback
(()
=>
{
const
{
const
{
setNodes
,
setNodes
,
...
@@ -55,9 +72,10 @@ export const useWorkflowRun = () => {
...
@@ -55,9 +72,10 @@ export const useWorkflowRun = () => {
handleLoadBackupDraft
()
handleLoadBackupDraft
()
}
}
else
{
else
{
handleBackupDraft
()
const
newNodes
=
produce
(
getNodes
(),
(
draft
)
=>
{
const
newNodes
=
produce
(
getNodes
(),
(
draft
)
=>
{
draft
.
forEach
((
node
)
=>
{
draft
.
forEach
((
node
)
=>
{
node
.
data
.
_runningStatus
=
shouldClear
?
undefined
:
NodeRunningStatus
.
Waiting
node
.
data
.
_runningStatus
=
NodeRunningStatus
.
Waiting
})
})
})
})
setNodes
(
newNodes
)
setNodes
(
newNodes
)
...
@@ -68,7 +86,7 @@ export const useWorkflowRun = () => {
...
@@ -68,7 +86,7 @@ export const useWorkflowRun = () => {
})
})
setEdges
(
newEdges
)
setEdges
(
newEdges
)
}
}
},
[
store
,
handleLoadBackupDraft
])
},
[
store
,
handleLoadBackupDraft
,
handleBackupDraft
])
const
handleRun
=
useCallback
((
params
:
any
,
callback
?:
IOtherOptions
)
=>
{
const
handleRun
=
useCallback
((
params
:
any
,
callback
?:
IOtherOptions
)
=>
{
const
{
const
{
...
@@ -77,8 +95,6 @@ export const useWorkflowRun = () => {
...
@@ -77,8 +95,6 @@ export const useWorkflowRun = () => {
edges
,
edges
,
setEdges
,
setEdges
,
}
=
store
.
getState
()
}
=
store
.
getState
()
const
{
getViewport
}
=
reactflow
const
{
setBackupDraft
}
=
useStore
.
getState
()
const
appDetail
=
useAppStore
.
getState
().
appDetail
const
appDetail
=
useAppStore
.
getState
().
appDetail
const
workflowContainer
=
document
.
getElementById
(
'workflow-container'
)
const
workflowContainer
=
document
.
getElementById
(
'workflow-container'
)
...
@@ -87,12 +103,6 @@ export const useWorkflowRun = () => {
...
@@ -87,12 +103,6 @@ export const useWorkflowRun = () => {
clientHeight
,
clientHeight
,
}
=
workflowContainer
!
}
=
workflowContainer
!
setBackupDraft
({
nodes
:
getNodes
(),
edges
,
viewport
:
getViewport
(),
})
let
url
=
''
let
url
=
''
if
(
appDetail
?.
mode
===
'advanced-chat'
)
if
(
appDetail
?.
mode
===
'advanced-chat'
)
url
=
`/apps/
${
appDetail
.
id
}
/advanced-chat/workflows/draft/run`
url
=
`/apps/
${
appDetail
.
id
}
/advanced-chat/workflows/draft/run`
...
@@ -164,6 +174,7 @@ export const useWorkflowRun = () => {
...
@@ -164,6 +174,7 @@ export const useWorkflowRun = () => {
},
[
store
,
reactflow
])
},
[
store
,
reactflow
])
return
{
return
{
handleBackupDraft
,
handleRunSetting
,
handleRunSetting
,
handleRun
,
handleRun
,
workflowContainerRef
,
workflowContainerRef
,
...
...
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