mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-18 10:35:55 +08:00
chore: transfer value to string array
This commit is contained in:
parent
9fe2f321ae
commit
0281eb796d
@ -59,7 +59,7 @@ const ConditionValue = ({
|
|||||||
const selectName = useCallback((c: Condition) => {
|
const selectName = useCallback((c: Condition) => {
|
||||||
const isSelect = c.comparison_operator === ComparisonOperator.in || c.comparison_operator === ComparisonOperator.notIn
|
const isSelect = c.comparison_operator === ComparisonOperator.in || c.comparison_operator === ComparisonOperator.notIn
|
||||||
if (isSelect) {
|
if (isSelect) {
|
||||||
const name = [...FILE_TYPE_OPTIONS, ...TRANSFER_METHOD].filter(item => item.value === c.value)[0]
|
const name = [...FILE_TYPE_OPTIONS, ...TRANSFER_METHOD].filter(item => item.value === (Array.isArray(c.value) ? c.value[0] : c.value))[0]
|
||||||
return name
|
return name
|
||||||
? t(`workflow.nodes.ifElse.optionName.${name.i18nKey}`).replace(/{{#([^#]*)#}}/g, (a, b) => {
|
? t(`workflow.nodes.ifElse.optionName.${name.i18nKey}`).replace(/{{#([^#]*)#}}/g, (a, b) => {
|
||||||
const arr: string[] = b.split('.')
|
const arr: string[] = b.split('.')
|
||||||
|
@ -107,16 +107,6 @@ const ConditionItem = ({
|
|||||||
doUpdateCondition(newCondition)
|
doUpdateCondition(newCondition)
|
||||||
}, [condition, doUpdateCondition])
|
}, [condition, doUpdateCondition])
|
||||||
|
|
||||||
const handleUpdateConditionValue = useCallback((value: string) => {
|
|
||||||
if (value === condition.value)
|
|
||||||
return
|
|
||||||
const newCondition = {
|
|
||||||
...condition,
|
|
||||||
value,
|
|
||||||
}
|
|
||||||
doUpdateCondition(newCondition)
|
|
||||||
}, [condition, doUpdateCondition])
|
|
||||||
|
|
||||||
const handleUpdateConditionNumberVarType = useCallback((numberVarType: NumberVarType) => {
|
const handleUpdateConditionNumberVarType = useCallback((numberVarType: NumberVarType) => {
|
||||||
const newCondition = {
|
const newCondition = {
|
||||||
...condition,
|
...condition,
|
||||||
@ -138,6 +128,18 @@ const ConditionItem = ({
|
|||||||
return undefined
|
return undefined
|
||||||
}, [condition.key, file, isSubVariableKey])
|
}, [condition.key, file, isSubVariableKey])
|
||||||
|
|
||||||
|
const isTransferMethod = fileAttr?.key === 'transfer_method'
|
||||||
|
|
||||||
|
const handleUpdateConditionValue = useCallback((value: string) => {
|
||||||
|
if (value === condition.value || (isTransferMethod && value === condition.value?.[0]))
|
||||||
|
return
|
||||||
|
const newCondition = {
|
||||||
|
...condition,
|
||||||
|
value: isTransferMethod ? [value] : value,
|
||||||
|
}
|
||||||
|
doUpdateCondition(newCondition)
|
||||||
|
}, [condition, doUpdateCondition, fileAttr])
|
||||||
|
|
||||||
const isSelect = condition.comparison_operator && [ComparisonOperator.in, ComparisonOperator.notIn].includes(condition.comparison_operator)
|
const isSelect = condition.comparison_operator && [ComparisonOperator.in, ComparisonOperator.notIn].includes(condition.comparison_operator)
|
||||||
const selectOptions = useMemo(() => {
|
const selectOptions = useMemo(() => {
|
||||||
if (isSelect) {
|
if (isSelect) {
|
||||||
@ -242,7 +244,7 @@ const ConditionItem = ({
|
|||||||
<div className='px-2 py-1 max-h-[100px] border-t border-t-divider-subtle overflow-y-auto'>
|
<div className='px-2 py-1 max-h-[100px] border-t border-t-divider-subtle overflow-y-auto'>
|
||||||
<ConditionInput
|
<ConditionInput
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
value={condition.value}
|
value={condition.value as string}
|
||||||
onChange={handleUpdateConditionValue}
|
onChange={handleUpdateConditionValue}
|
||||||
nodesOutputVars={nodesOutputVars}
|
nodesOutputVars={nodesOutputVars}
|
||||||
availableNodes={availableNodes}
|
availableNodes={availableNodes}
|
||||||
@ -256,7 +258,7 @@ const ConditionItem = ({
|
|||||||
<ConditionNumberInput
|
<ConditionNumberInput
|
||||||
numberVarType={condition.numberVarType}
|
numberVarType={condition.numberVarType}
|
||||||
onNumberVarTypeChange={handleUpdateConditionNumberVarType}
|
onNumberVarTypeChange={handleUpdateConditionNumberVarType}
|
||||||
value={condition.value}
|
value={condition.value as string}
|
||||||
onValueChange={handleUpdateConditionValue}
|
onValueChange={handleUpdateConditionValue}
|
||||||
variables={numberVariables}
|
variables={numberVariables}
|
||||||
isShort={isValueFieldShort}
|
isShort={isValueFieldShort}
|
||||||
@ -271,7 +273,7 @@ const ConditionItem = ({
|
|||||||
<Select
|
<Select
|
||||||
wrapperClassName='h-8'
|
wrapperClassName='h-8'
|
||||||
className='px-2 text-xs rounded-t-none'
|
className='px-2 text-xs rounded-t-none'
|
||||||
defaultValue={condition.value}
|
defaultValue={isTransferMethod ? (condition.value as string[])?.[0] : (condition.value as string)}
|
||||||
items={selectOptions}
|
items={selectOptions}
|
||||||
onSelect={item => handleUpdateConditionValue(item.value as string)}
|
onSelect={item => handleUpdateConditionValue(item.value as string)}
|
||||||
hideChecked
|
hideChecked
|
||||||
|
@ -18,7 +18,7 @@ type ConditionValueProps = {
|
|||||||
variableSelector: string[]
|
variableSelector: string[]
|
||||||
labelName?: string
|
labelName?: string
|
||||||
operator: ComparisonOperator
|
operator: ComparisonOperator
|
||||||
value: string
|
value: string | string[]
|
||||||
}
|
}
|
||||||
const ConditionValue = ({
|
const ConditionValue = ({
|
||||||
variableSelector,
|
variableSelector,
|
||||||
@ -36,6 +36,9 @@ const ConditionValue = ({
|
|||||||
if (notHasValue)
|
if (notHasValue)
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
if (Array.isArray(value)) // transfer method
|
||||||
|
return value[0]
|
||||||
|
|
||||||
return value.replace(/{{#([^#]*)#}}/g, (a, b) => {
|
return value.replace(/{{#([^#]*)#}}/g, (a, b) => {
|
||||||
const arr: string[] = b.split('.')
|
const arr: string[] = b.split('.')
|
||||||
if (isSystemVar(arr))
|
if (isSystemVar(arr))
|
||||||
@ -48,7 +51,7 @@ const ConditionValue = ({
|
|||||||
const isSelect = operator === ComparisonOperator.in || operator === ComparisonOperator.notIn
|
const isSelect = operator === ComparisonOperator.in || operator === ComparisonOperator.notIn
|
||||||
const selectName = useMemo(() => {
|
const selectName = useMemo(() => {
|
||||||
if (isSelect) {
|
if (isSelect) {
|
||||||
const name = [...FILE_TYPE_OPTIONS, ...TRANSFER_METHOD].filter(item => item.value === value)[0]
|
const name = [...FILE_TYPE_OPTIONS, ...TRANSFER_METHOD].filter(item => item.value === (Array.isArray(value) ? value[0] : value))[0]
|
||||||
return name
|
return name
|
||||||
? t(`workflow.nodes.ifElse.optionName.${name.i18nKey}`).replace(/{{#([^#]*)#}}/g, (a, b) => {
|
? t(`workflow.nodes.ifElse.optionName.${name.i18nKey}`).replace(/{{#([^#]*)#}}/g, (a, b) => {
|
||||||
const arr: string[] = b.split('.')
|
const arr: string[] = b.split('.')
|
||||||
|
@ -41,7 +41,7 @@ export type Condition = {
|
|||||||
variable_selector?: ValueSelector
|
variable_selector?: ValueSelector
|
||||||
key?: string // sub variable key
|
key?: string // sub variable key
|
||||||
comparison_operator?: ComparisonOperator
|
comparison_operator?: ComparisonOperator
|
||||||
value: string
|
value: string | string[]
|
||||||
numberVarType?: NumberVarType
|
numberVarType?: NumberVarType
|
||||||
sub_variable_condition?: CaseItem
|
sub_variable_condition?: CaseItem
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user