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
54d9cdaa
Commit
54d9cdaa
authored
Mar 05, 2024
by
StyleZhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sync workflow draft
parent
76fe3c1d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
26 deletions
+33
-26
hooks.ts
web/app/components/workflow/hooks.ts
+28
-17
index.tsx
web/app/components/workflow/index.tsx
+3
-7
node-control.tsx
...mponents/workflow/nodes/_base/components/node-control.tsx
+2
-2
No files found.
web/app/components/workflow/hooks.ts
View file @
54d9cdaa
...
...
@@ -24,6 +24,7 @@ import { getLayoutByDagre } from './utils'
import
{
useStore
}
from
'./store'
import
{
syncWorkflowDraft
}
from
'@/service/workflow'
import
{
useFeaturesStore
}
from
'@/app/components/base/features/hooks'
import
{
useStore
as
useAppStore
}
from
'@/app/components/app/store'
export
const
useNodesInitialData
=
()
=>
{
const
{
t
}
=
useTranslation
()
...
...
@@ -46,9 +47,11 @@ export const useWorkflow = () => {
getNodes
,
edges
,
}
=
store
.
getState
()
const
appId
=
useAppStore
.
getState
().
appDetail
?.
id
if
(
appId
)
{
syncWorkflowDraft
({
url
:
`/apps/
${
''
}
/workflows/draft`
,
url
:
`/apps/
${
appId
}
/workflows/draft`
,
params
:
{
graph
:
{
nodes
:
getNodes
(),
...
...
@@ -57,6 +60,7 @@ export const useWorkflow = () => {
features
:
{},
},
})
}
},
[
store
])
const
handleLayout
=
useCallback
(
async
()
=>
{
...
...
@@ -136,7 +140,8 @@ export const useWorkflow = () => {
}
=
useStore
.
getState
()
setIsDragging
(
false
)
setHelpLine
()
},
[])
handleSyncWorkflowDraft
()
},
[
handleSyncWorkflowDraft
])
const
handleNodeEnter
=
useCallback
<
NodeMouseHandler
>
((
_
,
node
)
=>
{
const
{
...
...
@@ -198,7 +203,8 @@ export const useWorkflow = () => {
selectedNode
.
data
.
_selected
=
true
})
setNodes
(
newNodes
)
},
[
store
])
handleSyncWorkflowDraft
()
},
[
store
,
handleSyncWorkflowDraft
])
const
handleNodeClick
=
useCallback
<
NodeMouseHandler
>
((
_
,
node
)
=>
{
if
(
useStore
.
getState
().
isDragging
)
...
...
@@ -233,7 +239,8 @@ export const useWorkflow = () => {
return
filtered
})
setEdges
(
newEdges
)
},
[
store
])
handleSyncWorkflowDraft
()
},
[
store
,
handleSyncWorkflowDraft
])
const
handleNodeDelete
=
useCallback
((
nodeId
:
string
)
=>
{
const
{
...
...
@@ -255,7 +262,8 @@ export const useWorkflow = () => {
return
draft
.
filter
(
edge
=>
!
connectedEdges
.
find
(
connectedEdge
=>
connectedEdge
.
id
===
edge
.
id
))
})
setEdges
(
newEdges
)
},
[
store
])
handleSyncWorkflowDraft
()
},
[
store
,
handleSyncWorkflowDraft
])
const
handleNodeDataUpdate
=
useCallback
(({
id
,
data
}:
{
id
:
string
;
data
:
Record
<
string
,
any
>
})
=>
{
const
{
...
...
@@ -310,7 +318,8 @@ export const useWorkflow = () => {
draft
.
push
(
newEdge
)
})
setEdges
(
newEdges
)
},
[
store
,
nodesInitialData
])
handleSyncWorkflowDraft
()
},
[
store
,
nodesInitialData
,
handleSyncWorkflowDraft
])
const
handleNodeChange
=
useCallback
((
currentNodeId
:
string
,
nodeType
:
BlockEnum
,
sourceHandle
?:
string
)
=>
{
const
{
...
...
@@ -360,8 +369,9 @@ export const useWorkflow = () => {
return
filtered
})
setEdges
(
newEdges
)
handleSyncWorkflowDraft
()
}
},
[
store
,
nodesInitialData
])
},
[
store
,
nodesInitialData
,
handleSyncWorkflowDraft
])
const
handleEdgeEnter
=
useCallback
<
EdgeMouseHandler
>
((
_
,
edge
)
=>
{
const
{
...
...
@@ -401,7 +411,8 @@ export const useWorkflow = () => {
draft
.
splice
(
index
,
1
)
})
setEdges
(
newEdges
)
},
[
store
])
handleSyncWorkflowDraft
()
},
[
store
,
handleSyncWorkflowDraft
])
const
handleEdgesChange
=
useCallback
<
OnEdgesChange
>
((
changes
)
=>
{
const
{
...
...
web/app/components/workflow/index.tsx
View file @
54d9cdaa
...
...
@@ -3,7 +3,6 @@ import {
memo
,
useMemo
,
}
from
'react'
import
{
useParams
}
from
'next/navigation'
import
useSWR
from
'swr'
import
{
useKeyPress
}
from
'ahooks'
import
ReactFlow
,
{
...
...
@@ -120,10 +119,7 @@ const WorkflowWrap: FC<WorkflowProps> = ({
edges
,
})
=>
{
const
appDetail
=
useAppStore
(
state
=>
state
.
appDetail
)
console
.
log
(
appDetail
?.
name
)
console
.
log
(
appDetail
?.
description
)
const
appId
=
useParams
().
appId
const
{
data
,
isLoading
,
error
}
=
useSWR
(
`/apps/
${
appId
}
/workflows/draft`
,
fetchWorkflowDraft
)
const
{
data
,
isLoading
,
error
}
=
useSWR
(
appDetail
?.
id
?
`/apps/
${
appDetail
.
id
}
/workflows/draft`
:
null
,
fetchWorkflowDraft
)
const
nodesInitialData
=
useNodesInitialData
()
const
startNode
=
{
...
...
@@ -155,9 +151,9 @@ const WorkflowWrap: FC<WorkflowProps> = ({
return
[]
},
[
data
,
nodes
])
if
(
error
)
{
if
(
error
&&
appDetail
)
{
syncWorkflowDraft
({
url
:
`/apps/
${
app
I
d
}
/workflows/draft`
,
url
:
`/apps/
${
app
Detail
.
i
d
}
/workflows/draft`
,
params
:
{
graph
:
{
nodes
:
[
startNode
],
...
...
web/app/components/workflow/nodes/_base/components/node-control.tsx
View file @
54d9cdaa
...
...
@@ -31,7 +31,7 @@ const NodeControl: FC<NodeControlProps> = ({
)
}
<
div
className=
'flex items-center justify-center w-5 h-5
cursor-pointer
'
className=
'flex items-center justify-center w-5 h-5
rounded-md cursor-pointer hover:bg-black/5
'
onClick=
{
()
=>
{
handleNodeDataUpdate
({
id
:
nodeId
,
...
...
@@ -45,7 +45,7 @@ const NodeControl: FC<NodeControlProps> = ({
:
<
Play
className=
'w-3 h-3'
/>
}
</
div
>
<
div
className=
'flex items-center justify-center w-5 h-5
cursor-pointer
'
>
<
div
className=
'flex items-center justify-center w-5 h-5
rounded-md cursor-pointer hover:bg-black/5
'
>
<
DotsHorizontal
className=
'w-3 h-3'
/>
</
div
>
</
div
>
...
...
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