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
35c56237
Commit
35c56237
authored
Feb 27, 2024
by
Joel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: url selector
parent
236cc6f5
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
132 additions
and
6 deletions
+132
-6
api-input.tsx
...p/components/workflow/nodes/http/components/api-input.tsx
+60
-0
use-key-value-list.ts
...omponents/workflow/nodes/http/hooks/use-key-value-list.ts
+23
-0
panel.tsx
web/app/components/workflow/nodes/http/panel.tsx
+10
-2
types.ts
web/app/components/workflow/nodes/http/types.ts
+15
-1
use-config.ts
web/app/components/workflow/nodes/http/use-config.ts
+24
-3
No files found.
web/app/components/workflow/nodes/http/components/api-input.tsx
0 → 100644
View file @
35c56237
'use client'
import
type
{
FC
}
from
'react'
import
React
,
{
useCallback
}
from
'react'
import
{
MethodEnum
}
from
'../types'
import
Selector
from
'../../_base/components/selector'
import
{
ChevronDown
}
from
'@/app/components/base/icons/src/vender/line/arrows'
const
MethodOptions
=
[
{
label
:
'GET'
,
value
:
MethodEnum
.
get
},
{
label
:
'POST'
,
value
:
MethodEnum
.
post
},
{
label
:
'HEAD'
,
value
:
MethodEnum
.
head
},
{
label
:
'PATCH'
,
value
:
MethodEnum
.
patch
},
{
label
:
'PUT'
,
value
:
MethodEnum
.
put
},
{
label
:
'DELETE'
,
value
:
MethodEnum
.
delete
},
]
type
Props
=
{
readonly
:
boolean
method
:
MethodEnum
onMethodChange
:
(
method
:
MethodEnum
)
=>
void
url
:
string
onUrlChange
:
(
url
:
string
)
=>
void
}
const
ApiInput
:
FC
<
Props
>
=
({
readonly
,
method
,
onMethodChange
,
url
,
onUrlChange
,
})
=>
{
const
handleUrlChange
=
useCallback
((
e
:
React
.
ChangeEvent
<
HTMLInputElement
>
)
=>
{
onUrlChange
(
e
.
target
.
value
)
},
[
onUrlChange
])
return
(
<
div
className=
'flex items-center h-8 rounded-lg bg-white border border-gray-200 shadow-xs'
>
<
Selector
value=
{
method
}
onChange=
{
onMethodChange
}
options=
{
MethodOptions
}
trigger=
{
<
div
className=
'h-8 shrink-0 flex items-center px-2.5 cursor-pointer border-r border-black/5'
>
<
div
className=
'w-12 pl-0.5 leading-[18px] text-xs font-medium text-gray-900 uppercase'
>
{
method
}
</
div
>
<
ChevronDown
className=
'ml-1 w-3.5 h-3.5 text-gray-700'
/>
</
div
>
}
popupClassName=
'top-[34px] w-[108px]'
showChecked
readonly=
{
readonly
}
/>
<
input
type=
'text'
readOnly=
{
readonly
}
value=
{
url
}
onChange=
{
handleUrlChange
}
className=
'w-0 grow h-6 leading-6 px-2.5 border-0 text-gray-900 text-[13px] placeholder:text-gray-400 focus:outline-none'
/>
</
div
>
)
}
export
default
React
.
memo
(
ApiInput
)
web/app/components/workflow/nodes/http/hooks/use-key-value-list.ts
0 → 100644
View file @
35c56237
import
{
useCallback
,
useState
}
from
'react'
import
type
{
KeyValue
}
from
'../types'
const
strToKeyValueList
=
(
value
:
string
)
=>
{
return
value
.
split
(
'
\
n'
).
map
((
item
)
=>
{
const
[
key
,
value
]
=
item
.
split
(
':'
)
return
{
key
:
key
.
trim
(),
value
:
value
.
trim
()
}
})
}
const
useKeyValueList
=
(
value
:
string
)
=>
{
const
[
list
,
setList
]
=
useState
<
KeyValue
[]
>
(
value
?
strToKeyValueList
(
value
)
:
[])
const
addItem
=
useCallback
(()
=>
{
setList
(
prev
=>
[...
prev
,
{
key
:
''
,
value
:
''
}])
},
[])
return
{
list
,
setList
,
addItem
,
}
}
export
default
useKeyValueList
web/app/components/workflow/nodes/http/panel.tsx
View file @
35c56237
...
@@ -2,12 +2,12 @@ import type { FC } from 'react'
...
@@ -2,12 +2,12 @@ import type { FC } from 'react'
import
{
useTranslation
}
from
'react-i18next'
import
{
useTranslation
}
from
'react-i18next'
import
useConfig
from
'./use-config'
import
useConfig
from
'./use-config'
import
{
mockData
}
from
'./mock'
import
{
mockData
}
from
'./mock'
import
ApiInput
from
'./components/api-input'
import
VarList
from
'@/app/components/workflow/nodes/_base/components/variable/var-list'
import
VarList
from
'@/app/components/workflow/nodes/_base/components/variable/var-list'
import
Field
from
'@/app/components/workflow/nodes/_base/components/field'
import
Field
from
'@/app/components/workflow/nodes/_base/components/field'
import
AddButton
from
'@/app/components/base/button/add-button'
import
AddButton
from
'@/app/components/base/button/add-button'
import
Split
from
'@/app/components/workflow/nodes/_base/components/split'
import
Split
from
'@/app/components/workflow/nodes/_base/components/split'
import
OutputVars
,
{
VarItem
}
from
'@/app/components/workflow/nodes/_base/components/output-vars'
import
OutputVars
,
{
VarItem
}
from
'@/app/components/workflow/nodes/_base/components/output-vars'
const
i18nPrefix
=
'workflow.nodes.http'
const
i18nPrefix
=
'workflow.nodes.http'
const
Panel
:
FC
=
()
=>
{
const
Panel
:
FC
=
()
=>
{
...
@@ -18,6 +18,8 @@ const Panel: FC = () => {
...
@@ -18,6 +18,8 @@ const Panel: FC = () => {
inputs
,
inputs
,
handleVarListChange
,
handleVarListChange
,
handleAddVariable
,
handleAddVariable
,
handleMethodChange
,
handleUrlChange
,
}
=
useConfig
(
mockData
)
}
=
useConfig
(
mockData
)
return
(
return
(
...
@@ -38,7 +40,13 @@ const Panel: FC = () => {
...
@@ -38,7 +40,13 @@ const Panel: FC = () => {
<
Field
<
Field
title=
{
t
(
`${i18nPrefix}.api`
)
}
title=
{
t
(
`${i18nPrefix}.api`
)
}
>
>
API
<
ApiInput
readonly=
{
readOnly
}
method=
{
inputs
.
method
}
onMethodChange=
{
handleMethodChange
}
url=
{
inputs
.
url
}
onUrlChange=
{
handleUrlChange
}
/>
</
Field
>
</
Field
>
<
Field
<
Field
title=
{
t
(
`${i18nPrefix}.headers`
)
}
title=
{
t
(
`${i18nPrefix}.headers`
)
}
...
...
web/app/components/workflow/nodes/http/types.ts
View file @
35c56237
import
type
{
CommonNodeType
,
Variable
}
from
'@/app/components/workflow/types'
import
type
{
CommonNodeType
,
Variable
}
from
'@/app/components/workflow/types'
export
enum
MethodEnum
{
get
=
'get'
,
post
=
'post'
,
head
=
'head'
,
patch
=
'patch'
,
put
=
'put'
,
delete
=
'delete'
,
}
export
type
KeyValue
=
{
key
:
string
value
:
string
}
export
type
HttpNodeType
=
CommonNodeType
&
{
export
type
HttpNodeType
=
CommonNodeType
&
{
variables
:
Variable
[]
variables
:
Variable
[]
method
:
string
method
:
MethodEnum
url
:
string
url
:
string
headers
:
string
headers
:
string
params
:
string
params
:
string
...
...
web/app/components/workflow/nodes/http/use-config.ts
View file @
35c56237
import
{
useState
}
from
'react'
import
{
use
Callback
,
use
State
}
from
'react'
import
useVarList
from
'../_base/hooks/use-var-list'
import
useVarList
from
'../_base/hooks/use-var-list'
import
type
{
HttpNodeType
}
from
'./types'
import
type
{
HttpNodeType
,
MethodEnum
}
from
'./types'
import
useKeyValueList
from
'./hooks/use-key-value-list'
const
useConfig
=
(
initInputs
:
HttpNodeType
)
=>
{
const
useConfig
=
(
initInputs
:
HttpNodeType
)
=>
{
const
[
inputs
,
setInputs
]
=
useState
<
HttpNodeType
>
(
initInputs
)
const
[
inputs
,
setInputs
]
=
useState
<
HttpNodeType
>
(
initInputs
)
...
@@ -10,10 +10,31 @@ const useConfig = (initInputs: HttpNodeType) => {
...
@@ -10,10 +10,31 @@ const useConfig = (initInputs: HttpNodeType) => {
setInputs
,
setInputs
,
})
})
const
handleMethodChange
=
useCallback
((
method
:
MethodEnum
)
=>
{
setInputs
(
prev
=>
({
...
prev
,
method
,
}))
},
[])
const
handleUrlChange
=
useCallback
((
url
:
string
)
=>
{
setInputs
(
prev
=>
({
...
prev
,
url
,
}))
},
[])
const
{
list
:
headers
,
setList
:
setHeaders
,
addItem
:
addHeader
}
=
useKeyValueList
(
inputs
.
headers
)
return
{
return
{
inputs
,
inputs
,
handleVarListChange
,
handleVarListChange
,
handleAddVariable
,
handleAddVariable
,
handleMethodChange
,
handleUrlChange
,
headers
,
setHeaders
,
addHeader
,
}
}
}
}
...
...
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