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
31930159
Commit
31930159
authored
Feb 26, 2024
by
Joel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: var assigner data logic
parent
6e2611c8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
0 deletions
+61
-0
use-config.ts
...components/workflow/nodes/variable-assigner/use-config.ts
+28
-0
use-var-list.ts
...mponents/workflow/nodes/variable-assigner/use-var-list.ts
+33
-0
No files found.
web/app/components/workflow/nodes/variable-assigner/use-config.ts
0 → 100644
View file @
31930159
import
{
useCallback
,
useState
}
from
'react'
import
produce
from
'immer'
import
useVarList
from
'./use-var-list'
import
type
{
VariableAssignerNodeType
}
from
'./types'
const
useConfig
=
(
initInputs
:
VariableAssignerNodeType
)
=>
{
const
[
inputs
,
setInputs
]
=
useState
<
VariableAssignerNodeType
>
(
initInputs
)
const
handleOutputTypeChange
=
useCallback
((
outputType
:
string
)
=>
{
const
newInputs
=
produce
(
inputs
,
(
draft
)
=>
{
draft
.
output_type
=
outputType
})
setInputs
(
newInputs
)
},
[
inputs
,
setInputs
])
const
{
handleVarListChange
,
handleAddVariable
}
=
useVarList
({
inputs
,
setInputs
,
})
return
{
inputs
,
handleOutputTypeChange
,
handleVarListChange
,
handleAddVariable
,
}
}
export
default
useConfig
web/app/components/workflow/nodes/variable-assigner/use-var-list.ts
0 → 100644
View file @
31930159
import
{
useCallback
}
from
'react'
import
produce
from
'immer'
import
type
{
VariableAssignerNodeType
}
from
'./types'
import
type
{
Variable
}
from
'@/app/components/workflow/types'
type
Params
=
{
inputs
:
VariableAssignerNodeType
setInputs
:
(
newInputs
:
VariableAssignerNodeType
)
=>
void
}
function
useVarList
({
inputs
,
setInputs
,
}:
Params
)
{
const
handleVarListChange
=
useCallback
((
newList
:
Variable
[])
=>
{
const
newInputs
=
produce
(
inputs
,
(
draft
:
any
)
=>
{
draft
.
variables
=
newList
})
setInputs
(
newInputs
)
},
[
inputs
,
setInputs
])
const
handleAddVariable
=
useCallback
(()
=>
{
const
newInputs
=
produce
(
inputs
,
(
draft
:
any
)
=>
{
draft
.
variables
.
push
([])
})
setInputs
(
newInputs
)
},
[
inputs
,
setInputs
])
return
{
handleVarListChange
,
handleAddVariable
,
}
}
export
default
useVarList
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