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
c5d148bf
Unverified
Commit
c5d148bf
authored
Aug 14, 2023
by
Krasus.Chen
Committed by
GitHub
Aug 14, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix #794 input bug (#801)
parent
e5e86fc0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
13 deletions
+25
-13
index.tsx
web/app/components/app/configuration/config-var/index.tsx
+23
-13
app-debug.en.ts
web/i18n/lang/app-debug.en.ts
+1
-0
app-debug.zh.ts
web/i18n/lang/app-debug.zh.ts
+1
-0
No files found.
web/app/components/app/configuration/config-var/index.tsx
View file @
c5d148bf
...
@@ -16,6 +16,7 @@ import { DEFAULT_VALUE_MAX_LEN, getMaxVarNameLength } from '@/config'
...
@@ -16,6 +16,7 @@ import { DEFAULT_VALUE_MAX_LEN, getMaxVarNameLength } from '@/config'
import
{
checkKeys
,
getNewVar
}
from
'@/utils/var'
import
{
checkKeys
,
getNewVar
}
from
'@/utils/var'
import
Switch
from
'@/app/components/base/switch'
import
Switch
from
'@/app/components/base/switch'
import
Toast
from
'@/app/components/base/toast'
import
Toast
from
'@/app/components/base/toast'
import
{
Timeout
}
from
'ahooks/lib/useRequest/src/types'
export
type
IConfigVarProps
=
{
export
type
IConfigVarProps
=
{
promptVariables
:
PromptVariable
[]
promptVariables
:
PromptVariable
[]
...
@@ -23,6 +24,8 @@ export type IConfigVarProps = {
...
@@ -23,6 +24,8 @@ export type IConfigVarProps = {
onPromptVariablesChange
?:
(
promptVariables
:
PromptVariable
[])
=>
void
onPromptVariablesChange
?:
(
promptVariables
:
PromptVariable
[])
=>
void
}
}
let
conflictTimer
:
Timeout
const
ConfigVar
:
FC
<
IConfigVarProps
>
=
({
promptVariables
,
readonly
,
onPromptVariablesChange
})
=>
{
const
ConfigVar
:
FC
<
IConfigVarProps
>
=
({
promptVariables
,
readonly
,
onPromptVariablesChange
})
=>
{
const
{
t
}
=
useTranslation
()
const
{
t
}
=
useTranslation
()
const
hasVar
=
promptVariables
.
length
>
0
const
hasVar
=
promptVariables
.
length
>
0
...
@@ -34,11 +37,9 @@ const ConfigVar: FC<IConfigVarProps> = ({ promptVariables, readonly, onPromptVar
...
@@ -34,11 +37,9 @@ const ConfigVar: FC<IConfigVarProps> = ({ promptVariables, readonly, onPromptVar
return
obj
return
obj
})()
})()
const
updatePromptVariable
=
(
key
:
string
,
updateKey
:
string
,
newValue
:
any
)
=>
{
const
updatePromptVariable
=
(
index
:
number
,
updateKey
:
string
,
newValue
:
any
)
=>
{
if
(
!
(
key
in
promptVariableObj
))
const
newPromptVariables
=
promptVariables
.
map
((
item
,
i
)
=>
{
return
if
(
i
===
index
)
{
const
newPromptVariables
=
promptVariables
.
map
((
item
)
=>
{
if
(
item
.
key
===
key
)
{
return
{
return
{
...
item
,
...
item
,
[
updateKey
]:
newValue
,
[
updateKey
]:
newValue
,
...
@@ -51,11 +52,9 @@ const ConfigVar: FC<IConfigVarProps> = ({ promptVariables, readonly, onPromptVar
...
@@ -51,11 +52,9 @@ const ConfigVar: FC<IConfigVarProps> = ({ promptVariables, readonly, onPromptVar
onPromptVariablesChange
?.(
newPromptVariables
)
onPromptVariablesChange
?.(
newPromptVariables
)
}
}
const
batchUpdatePromptVariable
=
(
key
:
string
,
updateKeys
:
string
[],
newValues
:
any
[])
=>
{
const
batchUpdatePromptVariable
=
(
index
:
number
,
updateKeys
:
string
[],
newValues
:
any
[])
=>
{
if
(
!
(
key
in
promptVariableObj
))
const
newPromptVariables
=
promptVariables
.
map
((
item
,
i
)
=>
{
return
if
(
i
===
index
)
{
const
newPromptVariables
=
promptVariables
.
map
((
item
)
=>
{
if
(
item
.
key
===
key
)
{
const
newItem
:
any
=
{
...
item
}
const
newItem
:
any
=
{
...
item
}
updateKeys
.
forEach
((
updateKey
,
i
)
=>
{
updateKeys
.
forEach
((
updateKey
,
i
)
=>
{
newItem
[
updateKey
]
=
newValues
[
i
]
newItem
[
updateKey
]
=
newValues
[
i
]
...
@@ -68,8 +67,8 @@ const ConfigVar: FC<IConfigVarProps> = ({ promptVariables, readonly, onPromptVar
...
@@ -68,8 +67,8 @@ const ConfigVar: FC<IConfigVarProps> = ({ promptVariables, readonly, onPromptVar
onPromptVariablesChange
?.(
newPromptVariables
)
onPromptVariablesChange
?.(
newPromptVariables
)
}
}
const
updatePromptKey
=
(
index
:
number
,
newKey
:
string
)
=>
{
const
updatePromptKey
=
(
index
:
number
,
newKey
:
string
)
=>
{
clearTimeout
(
conflictTimer
)
const
{
isValid
,
errorKey
,
errorMessageKey
}
=
checkKeys
([
newKey
],
true
)
const
{
isValid
,
errorKey
,
errorMessageKey
}
=
checkKeys
([
newKey
],
true
)
if
(
!
isValid
)
{
if
(
!
isValid
)
{
Toast
.
notify
({
Toast
.
notify
({
...
@@ -78,6 +77,7 @@ const ConfigVar: FC<IConfigVarProps> = ({ promptVariables, readonly, onPromptVar
...
@@ -78,6 +77,7 @@ const ConfigVar: FC<IConfigVarProps> = ({ promptVariables, readonly, onPromptVar
})
})
return
return
}
}
const
newPromptVariables
=
promptVariables
.
map
((
item
,
i
)
=>
{
const
newPromptVariables
=
promptVariables
.
map
((
item
,
i
)
=>
{
if
(
i
===
index
)
{
if
(
i
===
index
)
{
return
{
return
{
...
@@ -85,10 +85,20 @@ const ConfigVar: FC<IConfigVarProps> = ({ promptVariables, readonly, onPromptVar
...
@@ -85,10 +85,20 @@ const ConfigVar: FC<IConfigVarProps> = ({ promptVariables, readonly, onPromptVar
key
:
newKey
,
key
:
newKey
,
}
}
}
}
return
item
return
item
})
})
conflictTimer
=
setTimeout
(()
=>
{
const
isKeyExists
=
promptVariables
.
some
(
item
=>
item
.
key
.
trim
()
===
newKey
.
trim
())
if
(
isKeyExists
)
{
Toast
.
notify
({
type
:
'error'
,
message
:
t
(
`appDebug.varKeyError.keyAlreadyExists`
,
{
key
:
newKey
}),
})
return
}
},
1000
)
onPromptVariablesChange
?.(
newPromptVariables
)
onPromptVariablesChange
?.(
newPromptVariables
)
}
}
...
@@ -196,7 +206,7 @@ const ConfigVar: FC<IConfigVarProps> = ({ promptVariables, readonly, onPromptVar
...
@@ -196,7 +206,7 @@ const ConfigVar: FC<IConfigVarProps> = ({ promptVariables, readonly, onPromptVar
type=
"text"
type=
"text"
placeholder=
{
key
}
placeholder=
{
key
}
value=
{
name
}
value=
{
name
}
onChange=
{
e
=>
updatePromptVariable
(
key
,
'name'
,
e
.
target
.
value
)
}
onChange=
{
e
=>
updatePromptVariable
(
index
,
'name'
,
e
.
target
.
value
)
}
maxLength=
{
getMaxVarNameLength
(
name
)
}
maxLength=
{
getMaxVarNameLength
(
name
)
}
className=
"h-6 leading-6 block w-full rounded-md border-0 py-1.5 text-gray-900 placeholder:text-gray-400 focus:outline-none focus:ring-1 focus:ring-inset focus:ring-gray-200"
className=
"h-6 leading-6 block w-full rounded-md border-0 py-1.5 text-gray-900 placeholder:text-gray-400 focus:outline-none focus:ring-1 focus:ring-inset focus:ring-gray-200"
/>)
/>)
...
...
web/i18n/lang/app-debug.en.ts
View file @
c5d148bf
...
@@ -121,6 +121,7 @@ const translation = {
...
@@ -121,6 +121,7 @@ const translation = {
tooLong
:
'Variable key: {{key}} too length. Can not be longer then 16 characters'
,
tooLong
:
'Variable key: {{key}} too length. Can not be longer then 16 characters'
,
notValid
:
'Variable key: {{key}} is invalid. Can only contain letters, numbers, and underscores'
,
notValid
:
'Variable key: {{key}} is invalid. Can only contain letters, numbers, and underscores'
,
notStartWithNumber
:
'Variable key: {{key}} can not start with a number'
,
notStartWithNumber
:
'Variable key: {{key}} can not start with a number'
,
keyAlreadyExists
:
'Variable key: :{{key}} already exists'
,
},
},
variableConig
:
{
variableConig
:
{
modalTitle
:
'Field settings'
,
modalTitle
:
'Field settings'
,
...
...
web/i18n/lang/app-debug.zh.ts
View file @
c5d148bf
...
@@ -117,6 +117,7 @@ const translation = {
...
@@ -117,6 +117,7 @@ const translation = {
tooLong
:
'变量: {{key}} 长度太长。不能超过 16 个字符'
,
tooLong
:
'变量: {{key}} 长度太长。不能超过 16 个字符'
,
notValid
:
'变量: {{key}} 非法。只能包含英文字符,数字和下划线'
,
notValid
:
'变量: {{key}} 非法。只能包含英文字符,数字和下划线'
,
notStartWithNumber
:
'变量: {{key}} 不能以数字开头'
,
notStartWithNumber
:
'变量: {{key}} 不能以数字开头'
,
keyAlreadyExists
:
'变量:{{key}} 已存在'
,
},
},
variableConig
:
{
variableConig
:
{
modalTitle
:
'变量设置'
,
modalTitle
:
'变量设置'
,
...
...
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