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
6b02eebe
Commit
6b02eebe
authored
Mar 13, 2024
by
Joel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: support start node vars
parent
d0f5318b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
8 deletions
+47
-8
utils.ts
...ponents/workflow/nodes/_base/components/variable/utils.ts
+35
-0
var-reference-picker.tsx
.../nodes/_base/components/variable/var-reference-picker.tsx
+12
-8
No files found.
web/app/components/workflow/nodes/_base/components/variable/utils.ts
0 → 100644
View file @
6b02eebe
import
{
BlockEnum
}
from
'@/app/components/workflow/types'
import
type
{
StartNodeType
}
from
'@/app/components/workflow/nodes/start/types'
import
type
{
NodeOutPutVar
}
from
'@/app/components/workflow/types'
const
formatItem
=
(
item
:
any
):
NodeOutPutVar
=>
{
const
{
id
,
data
}
=
item
const
res
:
NodeOutPutVar
=
{
nodeId
:
id
,
title
:
data
.
title
,
vars
:
[],
}
switch
(
data
.
type
)
{
case
BlockEnum
.
Start
:
{
const
{
variables
,
}
=
data
as
StartNodeType
res
.
vars
=
variables
.
map
((
v
)
=>
{
return
{
variable
:
v
.
variable
,
type
:
v
.
type
,
}
})
break
}
// default:
// // throw new Error('unknown type')
// break
}
return
res
}
export
const
toNodeOutputVars
=
(
nodes
:
any
[]):
NodeOutPutVar
[]
=>
{
return
nodes
.
map
(
formatItem
)
}
web/app/components/workflow/nodes/_base/components/variable/var-reference-picker.tsx
View file @
6b02eebe
...
@@ -2,8 +2,8 @@
...
@@ -2,8 +2,8 @@
import
type
{
FC
}
from
'react'
import
type
{
FC
}
from
'react'
import
React
,
{
useState
}
from
'react'
import
React
,
{
useState
}
from
'react'
import
cn
from
'classnames'
import
cn
from
'classnames'
import
{
mockNodeOutputVars
,
mockNodesData
}
from
'../../../mock'
import
VarReferencePopup
from
'./var-reference-popup'
import
VarReferencePopup
from
'./var-reference-popup'
import
{
toNodeOutputVars
}
from
'./utils'
import
type
{
ValueSelector
}
from
'@/app/components/workflow/types'
import
type
{
ValueSelector
}
from
'@/app/components/workflow/types'
import
{
VarBlockIcon
}
from
'@/app/components/workflow/block-icon'
import
{
VarBlockIcon
}
from
'@/app/components/workflow/block-icon'
import
{
Line3
}
from
'@/app/components/base/icons/src/public/common'
import
{
Line3
}
from
'@/app/components/base/icons/src/public/common'
...
@@ -31,9 +31,8 @@ type Props = {
...
@@ -31,9 +31,8 @@ type Props = {
// return type.charAt(0).toUpperCase() + type.substring(1)
// return type.charAt(0).toUpperCase() + type.substring(1)
// }
// }
// TODO: get data from context
export
const
getNodeInfoById
=
(
nodes
:
any
,
id
:
string
)
=>
{
export
const
getNodeInfoById
=
(
id
:
string
)
=>
{
return
nodes
.
find
((
node
:
any
)
=>
node
.
id
===
id
)
return
mockNodesData
[
id
]
}
}
const
VarReferencePicker
:
FC
<
Props
>
=
({
const
VarReferencePicker
:
FC
<
Props
>
=
({
...
@@ -46,9 +45,14 @@ const VarReferencePicker: FC<Props> = ({
...
@@ -46,9 +45,14 @@ const VarReferencePicker: FC<Props> = ({
})
=>
{
})
=>
{
const
{
getTreeLeafNodes
,
getBeforeNodesInSameBranch
}
=
useWorkflow
()
const
{
getTreeLeafNodes
,
getBeforeNodesInSameBranch
}
=
useWorkflow
()
// console.log(getBeforeNodesInSameBranch(nodeId), getTreeLeafNodes())
// console.log(getBeforeNodesInSameBranch(nodeId), getTreeLeafNodes())
const
availableNodes
=
getBeforeNodesInSameBranch
(
nodeId
)
const
outputVars
=
toNodeOutputVars
(
availableNodes
)
// console.log(outputVars)
const
[
open
,
setOpen
]
=
useState
(
false
)
const
[
open
,
setOpen
]
=
useState
(
false
)
const
hasValue
=
value
.
length
>
0
const
hasValue
=
value
.
length
>
0
const
node
=
hasValue
?
getNodeInfoById
(
value
[
0
])
:
null
const
outputVarNodeId
=
hasValue
?
value
[
0
]
:
''
const
outputVarNode
=
hasValue
?
getNodeInfoById
(
availableNodes
,
outputVarNodeId
)?.
data
:
null
console
.
log
(
hasValue
,
value
,
outputVarNode
)
const
varName
=
hasValue
?
value
[
value
.
length
-
1
]
:
''
const
varName
=
hasValue
?
value
[
value
.
length
-
1
]
:
''
// TODO: get var type through node and value
// TODO: get var type through node and value
const
getVarType
=
()
=>
{
const
getVarType
=
()
=>
{
...
@@ -72,10 +76,10 @@ const VarReferencePicker: FC<Props> = ({
...
@@ -72,10 +76,10 @@ const VarReferencePicker: FC<Props> = ({
<
div
className=
'p-[1px]'
>
<
div
className=
'p-[1px]'
>
<
VarBlockIcon
<
VarBlockIcon
className=
'!text-gray-900'
className=
'!text-gray-900'
type=
{
n
ode
?.
type
}
type=
{
outputVarN
ode
?.
type
}
/>
/>
</
div
>
</
div
>
<
div
className=
'mx-0.5 text-xs font-medium text-gray-700'
>
{
n
ode
?.
title
}
</
div
>
<
div
className=
'mx-0.5 text-xs font-medium text-gray-700'
>
{
outputVarN
ode
?.
title
}
</
div
>
<
Line3
className=
'mr-0.5'
></
Line3
>
<
Line3
className=
'mr-0.5'
></
Line3
>
</
div
>
</
div
>
)
}
)
}
...
@@ -94,7 +98,7 @@ const VarReferencePicker: FC<Props> = ({
...
@@ -94,7 +98,7 @@ const VarReferencePicker: FC<Props> = ({
minWidth
:
227
,
minWidth
:
227
,
}
}
>
}
}
>
<
VarReferencePopup
<
VarReferencePopup
vars=
{
mockNodeO
utputVars
}
vars=
{
o
utputVars
}
onChange=
{
(
value
)
=>
{
onChange=
{
(
value
)
=>
{
onChange
(
value
)
onChange
(
value
)
setOpen
(
false
)
setOpen
(
false
)
...
...
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