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
466f16eb
Commit
466f16eb
authored
Mar 05, 2024
by
StyleZhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
node name
parent
04d54c03
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
19 deletions
+28
-19
constants.ts
web/app/components/workflow/constants.ts
+1
-1
hooks.ts
web/app/components/workflow/hooks.ts
+15
-3
index.tsx
web/app/components/workflow/index.tsx
+6
-3
node.tsx
web/app/components/workflow/nodes/_base/node.tsx
+6
-12
No files found.
web/app/components/workflow/constants.ts
View file @
466f16eb
...
@@ -12,7 +12,7 @@ import ToolDefault from './nodes/tool/default'
...
@@ -12,7 +12,7 @@ import ToolDefault from './nodes/tool/default'
import
VariableAssignerDefault
from
'./nodes/variable-assigner/default'
import
VariableAssignerDefault
from
'./nodes/variable-assigner/default'
import
EndNodeDefault
from
'./nodes/end/default'
import
EndNodeDefault
from
'./nodes/end/default'
export
const
N
odeInitialData
=
{
export
const
N
ODES_INITIAL_DATA
=
{
[
BlockEnum
.
Start
]:
{
[
BlockEnum
.
Start
]:
{
type
:
BlockEnum
.
Start
,
type
:
BlockEnum
.
Start
,
title
:
''
,
title
:
''
,
...
...
web/app/components/workflow/hooks.ts
View file @
466f16eb
import
{
useCallback
}
from
'react'
import
{
useCallback
}
from
'react'
import
{
useTranslation
}
from
'react-i18next'
import
produce
from
'immer'
import
produce
from
'immer'
import
type
{
import
type
{
EdgeMouseHandler
,
EdgeMouseHandler
,
...
@@ -19,13 +20,24 @@ import type {
...
@@ -19,13 +20,24 @@ import type {
Node
,
Node
,
SelectedNode
,
SelectedNode
,
}
from
'./types'
}
from
'./types'
import
{
N
odeInitialData
}
from
'./constants'
import
{
N
ODES_INITIAL_DATA
}
from
'./constants'
import
{
getLayoutByDagre
}
from
'./utils'
import
{
getLayoutByDagre
}
from
'./utils'
import
{
useStore
}
from
'./store'
import
{
useStore
}
from
'./store'
export
const
useNodesInitialData
=
()
=>
{
const
{
t
}
=
useTranslation
()
return
produce
(
NODES_INITIAL_DATA
,
(
draft
)
=>
{
Object
.
keys
(
draft
).
forEach
((
key
)
=>
{
draft
[
key
as
BlockEnum
].
title
=
t
(
`workflow.blocks.
${
key
}
`
)
})
})
}
export
const
useWorkflow
=
()
=>
{
export
const
useWorkflow
=
()
=>
{
const
store
=
useStoreApi
()
const
store
=
useStoreApi
()
const
reactFlow
=
useReactFlow
()
const
reactFlow
=
useReactFlow
()
const
nodesInitialData
=
useNodesInitialData
()
const
handleLayout
=
useCallback
(
async
()
=>
{
const
handleLayout
=
useCallback
(
async
()
=>
{
const
{
const
{
...
@@ -267,7 +279,7 @@ export const useWorkflow = () => {
...
@@ -267,7 +279,7 @@ export const useWorkflow = () => {
id
:
`
${
Date
.
now
()}
`
,
id
:
`
${
Date
.
now
()}
`
,
type
:
'custom'
,
type
:
'custom'
,
data
:
{
data
:
{
...
Node
InitialData
[
nodeType
],
...
nodes
InitialData
[
nodeType
],
_selected
:
true
,
_selected
:
true
,
},
},
position
:
{
position
:
{
...
@@ -311,7 +323,7 @@ export const useWorkflow = () => {
...
@@ -311,7 +323,7 @@ export const useWorkflow = () => {
id
:
`
${
Date
.
now
()}
`
,
id
:
`
${
Date
.
now
()}
`
,
type
:
'custom'
,
type
:
'custom'
,
data
:
{
data
:
{
...
Node
InitialData
[
nodeType
],
...
nodes
InitialData
[
nodeType
],
_selected
:
currentNode
.
data
.
_selected
,
_selected
:
currentNode
.
data
.
_selected
,
},
},
position
:
{
position
:
{
...
...
web/app/components/workflow/index.tsx
View file @
466f16eb
...
@@ -17,7 +17,10 @@ import type {
...
@@ -17,7 +17,10 @@ import type {
Edge
,
Edge
,
Node
,
Node
,
}
from
'./types'
}
from
'./types'
import
{
useWorkflow
}
from
'./hooks'
import
{
useNodesInitialData
,
useWorkflow
,
}
from
'./hooks'
import
Header
from
'./header'
import
Header
from
'./header'
import
CustomNode
from
'./nodes'
import
CustomNode
from
'./nodes'
import
Operator
from
'./operator'
import
Operator
from
'./operator'
...
@@ -26,7 +29,6 @@ import CustomConnectionLine from './custom-connection-line'
...
@@ -26,7 +29,6 @@ import CustomConnectionLine from './custom-connection-line'
import
Panel
from
'./panel'
import
Panel
from
'./panel'
import
Features
from
'./features'
import
Features
from
'./features'
import
{
useStore
}
from
'./store'
import
{
useStore
}
from
'./store'
import
{
NodeInitialData
}
from
'./constants'
import
{
import
{
fetchWorkflowDraft
,
fetchWorkflowDraft
,
syncWorkflowDraft
,
syncWorkflowDraft
,
...
@@ -115,11 +117,12 @@ const WorkflowWrap: FC<WorkflowProps> = ({
...
@@ -115,11 +117,12 @@ const WorkflowWrap: FC<WorkflowProps> = ({
})
=>
{
})
=>
{
const
appId
=
useParams
().
appId
const
appId
=
useParams
().
appId
const
{
data
,
isLoading
,
error
}
=
useSWR
(
`/apps/
${
appId
}
/workflows/draft`
,
fetchWorkflowDraft
)
const
{
data
,
isLoading
,
error
}
=
useSWR
(
`/apps/
${
appId
}
/workflows/draft`
,
fetchWorkflowDraft
)
const
nodesInitialData
=
useNodesInitialData
()
const
startNode
=
{
const
startNode
=
{
id
:
`
${
Date
.
now
()}
`
,
id
:
`
${
Date
.
now
()}
`
,
type
:
'custom'
,
type
:
'custom'
,
data
:
Node
InitialData
.
start
,
data
:
nodes
InitialData
.
start
,
position
:
{
position
:
{
x
:
100
,
x
:
100
,
y
:
100
,
y
:
100
,
...
...
web/app/components/workflow/nodes/_base/node.tsx
View file @
466f16eb
...
@@ -39,22 +39,16 @@ const BaseNode: FC<BaseNodeProps> = ({
...
@@ -39,22 +39,16 @@ const BaseNode: FC<BaseNodeProps> = ({
{
data
.
title
}
{
data
.
title
}
</
div
>
</
div
>
</
div
>
</
div
>
<
div
className=
'mb-1'
>
{
cloneElement
(
children
,
{
id
,
data
})
}
</
div
>
{
{
children
&&
(
data
.
desc
&&
(
<
div
className=
'
mb-1
'
>
<
div
className=
'
px-3 pt-s1 pb-2 text-xs leading-[18px] text-gray-500 whitespace-pre-line break-words
'
>
{
cloneElement
(
children
,
{
id
,
data
})
}
{
data
.
desc
}
</
div
>
</
div
>
)
)
}
}
<
div
className=
'pb-1'
>
{
data
.
desc
&&
(
<
div
className=
'px-3 pt-1 pb-2 text-xs leading-[18px] text-gray-500 whitespace-pre-line break-words'
>
{
data
.
desc
}
</
div
>
)
}
</
div
>
</
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