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
5153068a
Commit
5153068a
authored
Feb 22, 2024
by
Joel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: start var list
parent
701e4413
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
146 additions
and
3 deletions
+146
-3
var-item.tsx
...p/components/workflow/nodes/start/components/var-item.tsx
+59
-0
var-list.tsx
...p/components/workflow/nodes/start/components/var-list.tsx
+50
-0
panel.tsx
web/app/components/workflow/nodes/start/panel.tsx
+18
-2
use-config.ts
web/app/components/workflow/nodes/start/use-config.ts
+18
-1
workflow.en.ts
web/i18n/lang/workflow.en.ts
+1
-0
No files found.
web/app/components/workflow/nodes/start/components/var-item.tsx
0 → 100644
View file @
5153068a
'use client'
import
type
{
FC
}
from
'react'
import
React
,
{
useRef
}
from
'react'
import
{
useHover
}
from
'ahooks'
import
{
useTranslation
}
from
'react-i18next'
import
InputVarTypeIcon
from
'../../_base/components/input-var-type-icon'
import
type
{
InputVar
}
from
'@/app/components/workflow/types'
import
{
Variable02
}
from
'@/app/components/base/icons/src/vender/solid/development'
import
{
Edit03
}
from
'@/app/components/base/icons/src/vender/solid/general'
import
{
Trash03
}
from
'@/app/components/base/icons/src/vender/line/general'
type
Props
=
{
readonly
:
boolean
payload
:
InputVar
onChange
:
(
item
:
InputVar
)
=>
void
onRemove
:
()
=>
void
}
const
VarItem
:
FC
<
Props
>
=
({
readonly
,
payload
,
})
=>
{
const
{
t
}
=
useTranslation
()
const
ref
=
useRef
(
null
)
const
isHovering
=
useHover
(
ref
)
return
(
<
div
ref=
{
ref
}
className=
'flex items-center h-8 justify-between px-2.5 bg-white rounded-lg border border-gray-200 shadow-xs cursor-pointer hover:shadow-md'
>
<
div
className=
'flex items-center space-x-1 grow w-0'
>
<
Variable02
className=
'w-3.5 h-3.5 text-primary-500'
/>
<
div
className=
'shrink-0 truncate text-[13px] font-medium text-gray-700'
>
{
payload
.
variable
}
</
div
>
<
div
className=
'shrink-0 text-xs font-medium text-gray-400'
>
·
</
div
>
<
div
className=
'grow w-0 truncate text-[13px] font-medium text-gray-500'
>
{
payload
.
label
}
</
div
>
</
div
>
<
div
className=
'shrink-0 ml-2 flex items-center'
>
{
!
isHovering
?
(
<>
{
payload
.
required
&&
(
<
div
className=
'mr-2 text-xs font-normal text-gray-500'
>
{
t
(
'workflow.nodes.start.required'
)
}
</
div
>
)
}
<
InputVarTypeIcon
type=
{
payload
.
type
}
className=
'w-3.5 h-3.5 text-gray-500'
/>
</>
)
:
(
!
readonly
&&
(
<>
<
div
className=
'mr-1 p-1 rounded-md cursor-pointer hover:bg-black/5'
>
<
Edit03
className=
'w-4 h-4 text-gray-500'
/>
</
div
>
<
div
className=
'p-1 rounded-md cursor-pointer hover:bg-black/5'
>
<
Trash03
className=
'w-4 h-4 text-gray-500'
/>
</
div
>
</>
))
}
</
div
>
</
div
>
)
}
export
default
React
.
memo
(
VarItem
)
web/app/components/workflow/nodes/start/components/var-list.tsx
0 → 100644
View file @
5153068a
'use client'
import
type
{
FC
}
from
'react'
import
React
,
{
useCallback
}
from
'react'
import
produce
from
'immer'
import
VarItem
from
'./var-item'
import
type
{
InputVar
}
from
'@/app/components/workflow/types'
type
Props
=
{
readonly
:
boolean
list
:
InputVar
[]
onChange
:
(
list
:
InputVar
[])
=>
void
}
const
VarList
:
FC
<
Props
>
=
({
readonly
,
list
,
onChange
,
})
=>
{
const
handleVarNameChange
=
useCallback
((
index
:
number
)
=>
{
return
(
payload
:
InputVar
)
=>
{
const
newList
=
produce
(
list
,
(
draft
)
=>
{
draft
[
index
]
=
payload
})
onChange
(
newList
)
}
},
[
list
,
onChange
])
const
handleVarRemove
=
useCallback
((
index
:
number
)
=>
{
return
()
=>
{
const
newList
=
produce
(
list
,
(
draft
)
=>
{
draft
.
splice
(
index
,
1
)
})
onChange
(
newList
)
}
},
[
list
,
onChange
])
return
(
<
div
className=
'space-y-1'
>
{
list
.
map
((
item
,
index
)
=>
(
<
VarItem
key=
{
index
}
readonly=
{
readonly
}
payload=
{
item
}
onChange=
{
handleVarNameChange
(
index
)
}
onRemove=
{
handleVarRemove
(
index
)
}
/>
))
}
</
div
>
)
}
export
default
React
.
memo
(
VarList
)
web/app/components/workflow/nodes/start/panel.tsx
View file @
5153068a
import
type
{
FC
}
from
'react'
import
{
useTranslation
}
from
'react-i18next'
import
VarList
from
'./components/var-list'
import
useConfig
from
'./use-config'
import
{
mockData
}
from
'./mock'
import
Split
from
'@/app/components/workflow/nodes/_base/components/split'
import
Field
from
'@/app/components/workflow/nodes/_base/components/field'
import
OutputVars
,
{
VarItem
}
from
'@/app/components/workflow/nodes/_base/components/output-vars'
import
AddButton
from
'@/app/components/base/button/add-button'
const
i18nPrefix
=
'workflow.nodes.start'
const
Panel
:
FC
=
()
=>
{
const
{
t
}
=
useTranslation
()
const
readOnly
=
false
const
{
inputs
,
handleVarListChange
,
}
=
useConfig
(
mockData
)
return
(
<
div
className=
'mt-2'
>
<
div
className=
'px-4 pb-4 space-y-4'
>
<
Field
title=
{
t
(
`${i18nPrefix}.model`
)
}
title=
{
t
(
`${i18nPrefix}.inputField`
)
}
operations=
{
<
AddButton
onClick=
{
()
=>
{
}
}
/>
}
>
ss
<
VarList
readonly=
{
readOnly
}
list=
{
inputs
.
variables
}
onChange=
{
handleVarListChange
}
/>
</
Field
>
</
div
>
<
Split
/>
...
...
web/app/components/workflow/nodes/start/use-config.ts
View file @
5153068a
import
{
useState
}
from
'react'
import
{
useCallback
,
useState
}
from
'react'
import
produce
from
'immer'
import
type
{
StartNodeType
}
from
'./types'
import
type
{
InputVar
}
from
'@/app/components/workflow/types'
const
useConfig
=
(
initInputs
:
StartNodeType
)
=>
{
const
[
inputs
,
setInputs
]
=
useState
<
StartNodeType
>
(
initInputs
)
const
handleVarListChange
=
useCallback
((
newList
:
InputVar
[])
=>
{
const
newInputs
=
produce
(
inputs
,
(
draft
:
any
)
=>
{
draft
.
variables
=
newList
})
setInputs
(
newInputs
)
},
[
inputs
,
setInputs
])
const
handleAddVariable
=
useCallback
((
payload
:
InputVar
)
=>
{
const
newInputs
=
produce
(
inputs
,
(
draft
:
any
)
=>
{
draft
.
variables
.
push
(
payload
)
})
setInputs
(
newInputs
)
},
[
inputs
,
setInputs
])
return
{
inputs
,
handleVarListChange
,
handleAddVariable
,
}
}
...
...
web/i18n/lang/workflow.en.ts
View file @
5153068a
...
...
@@ -6,6 +6,7 @@ const translation = {
},
start
:
{
required
:
'required'
,
inputField
:
'Input Field'
,
builtInVar
:
'Built-in Variables'
,
outputVars
:
{
query
:
'User input'
,
...
...
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