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
f3c78fe7
Commit
f3c78fe7
authored
Feb 06, 2024
by
StyleZhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
a17c0e5b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
56 deletions
+77
-56
page.tsx
web/app/(commonLayout)/workflow/page.tsx
+52
-1
hooks.ts
web/app/components/workflow/hooks.ts
+2
-2
index.tsx
web/app/components/workflow/index.tsx
+23
-53
No files found.
web/app/(commonLayout)/workflow/page.tsx
View file @
f3c78fe7
...
@@ -4,10 +4,61 @@ import type { FC } from 'react'
...
@@ -4,10 +4,61 @@ import type { FC } from 'react'
import
{
memo
}
from
'react'
import
{
memo
}
from
'react'
import
Workflow
from
'@/app/components/workflow'
import
Workflow
from
'@/app/components/workflow'
const
initialNodes
=
[
{
id
:
'1'
,
type
:
'custom'
,
position
:
{
x
:
330
,
y
:
30
},
data
:
{
type
:
'start'
},
},
{
id
:
'2'
,
type
:
'custom'
,
position
:
{
x
:
330
,
y
:
212
},
data
:
{
type
:
'start'
},
},
{
id
:
'3'
,
type
:
'custom'
,
position
:
{
x
:
150
,
y
:
394
},
data
:
{
type
:
'start'
},
},
{
id
:
'4'
,
type
:
'custom'
,
position
:
{
x
:
510
,
y
:
394
},
data
:
{
type
:
'start'
},
},
]
const
initialEdges
=
[
{
id
:
'1'
,
source
:
'1'
,
target
:
'2'
,
type
:
'custom'
,
},
{
id
:
'2'
,
source
:
'2'
,
target
:
'3'
,
type
:
'custom'
,
},
{
id
:
'3'
,
source
:
'2'
,
target
:
'4'
,
type
:
'custom'
,
},
]
const
Page
:
FC
=
()
=>
{
const
Page
:
FC
=
()
=>
{
return
(
return
(
<
div
className=
'min-w-[720px] w-full h-full overflow-x-auto'
>
<
div
className=
'min-w-[720px] w-full h-full overflow-x-auto'
>
<
Workflow
/>
<
Workflow
nodes=
{
initialNodes
}
edges=
{
initialEdges
}
/>
</
div
>
</
div
>
)
)
}
}
...
...
web/app/components/workflow/hooks.ts
View file @
f3c78fe7
...
@@ -5,8 +5,8 @@ import {
...
@@ -5,8 +5,8 @@ import {
}
from
'react'
}
from
'react'
import
type
{
Node
}
from
'./types'
import
type
{
Node
}
from
'./types'
export
const
useWorkflow
=
(
nodes
:
Node
[])
=>
{
export
const
useWorkflow
=
(
nodes
:
Node
[]
,
initialSelectedNodeId
?:
string
)
=>
{
const
[
selectedNodeId
,
setSelectedNodeId
]
=
useState
(
''
)
const
[
selectedNodeId
,
setSelectedNodeId
]
=
useState
(
initialSelectedNodeId
)
const
handleSelectedNodeIdChange
=
useCallback
((
nodeId
:
string
)
=>
setSelectedNodeId
(
nodeId
),
[])
const
handleSelectedNodeIdChange
=
useCallback
((
nodeId
:
string
)
=>
setSelectedNodeId
(
nodeId
),
[])
...
...
web/app/components/workflow/index.tsx
View file @
f3c78fe7
import
type
{
FC
}
from
'react'
import
type
{
FC
}
from
'react'
import
type
{
Edge
}
from
'reactflow'
import
ReactFlow
,
{
import
ReactFlow
,
{
Background
,
Background
,
ReactFlowProvider
,
ReactFlowProvider
,
...
@@ -16,6 +17,7 @@ import CustomNode, {
...
@@ -16,6 +17,7 @@ import CustomNode, {
Panel
,
Panel
,
}
from
'./nodes'
}
from
'./nodes'
import
CustomEdge
from
'./custom-edge'
import
CustomEdge
from
'./custom-edge'
import
type
{
Node
}
from
'./types'
const
nodeTypes
=
{
const
nodeTypes
=
{
custom
:
CustomNode
,
custom
:
CustomNode
,
...
@@ -24,54 +26,6 @@ const edgeTypes = {
...
@@ -24,54 +26,6 @@ const edgeTypes = {
custom
:
CustomEdge
,
custom
:
CustomEdge
,
}
}
const
initialNodes
=
[
{
id
:
'1'
,
type
:
'custom'
,
position
:
{
x
:
330
,
y
:
30
},
data
:
{
type
:
'start'
},
},
{
id
:
'2'
,
type
:
'custom'
,
position
:
{
x
:
330
,
y
:
212
},
data
:
{
type
:
'start'
},
},
{
id
:
'3'
,
type
:
'custom'
,
position
:
{
x
:
150
,
y
:
394
},
data
:
{
type
:
'start'
},
},
{
id
:
'4'
,
type
:
'custom'
,
position
:
{
x
:
510
,
y
:
394
},
data
:
{
type
:
'start'
},
},
]
const
initialEdges
=
[
{
id
:
'1'
,
source
:
'1'
,
target
:
'2'
,
type
:
'custom'
,
},
{
id
:
'2'
,
source
:
'2'
,
target
:
'3'
,
type
:
'custom'
,
},
{
id
:
'3'
,
source
:
'2'
,
target
:
'4'
,
type
:
'custom'
,
},
]
const
Workflow
=
()
=>
{
const
Workflow
=
()
=>
{
const
{
const
{
nodes
,
nodes
,
...
@@ -96,15 +50,23 @@ const Workflow = () => {
...
@@ -96,15 +50,23 @@ const Workflow = () => {
</
div
>
</
div
>
)
)
}
}
type
WorkflowWrapProps
=
{
const
WorkflowWrap
:
FC
=
()
=>
{
selectedNodeId
?:
string
nodes
:
Node
[]
edges
:
Edge
[]
}
const
WorkflowWrap
:
FC
<
WorkflowWrapProps
>
=
({
nodes
:
initialNodes
,
edges
:
initialEdges
,
selectedNodeId
:
initialSelectedNodeId
,
})
=>
{
const
[
nodes
]
=
useNodesState
(
initialNodes
)
const
[
nodes
]
=
useNodesState
(
initialNodes
)
const
[
edges
]
=
useEdgesState
(
initialEdges
)
const
[
edges
]
=
useEdgesState
(
initialEdges
)
const
{
const
{
selectedNodeId
,
selectedNodeId
,
handleSelectedNodeIdChange
,
handleSelectedNodeIdChange
,
selectedNode
,
selectedNode
,
}
=
useWorkflow
(
nodes
)
}
=
useWorkflow
(
nodes
,
initialSelectedNodeId
)
return
(
return
(
<
WorkflowContext
.
Provider
value=
{
{
<
WorkflowContext
.
Provider
value=
{
{
...
@@ -119,10 +81,18 @@ const WorkflowWrap: FC = () => {
...
@@ -119,10 +81,18 @@ const WorkflowWrap: FC = () => {
)
)
}
}
const
WorkflowWrapWithReactFlowProvider
=
()
=>
{
const
WorkflowWrapWithReactFlowProvider
:
FC
<
WorkflowWrapProps
>
=
({
selectedNodeId
,
nodes
,
edges
,
})
=>
{
return
(
return
(
<
ReactFlowProvider
>
<
ReactFlowProvider
>
<
WorkflowWrap
/>
<
WorkflowWrap
selectedNodeId=
{
selectedNodeId
}
nodes=
{
nodes
}
edges=
{
edges
}
/>
</
ReactFlowProvider
>
</
ReactFlowProvider
>
)
)
}
}
...
...
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