mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 19:59:50 +08:00
chore: type value change to array
This commit is contained in:
parent
f8d26e46ac
commit
87e560de8a
|
@ -128,14 +128,14 @@ const ConditionItem = ({
|
|||
return undefined
|
||||
}, [condition.key, file, isSubVariableKey])
|
||||
|
||||
const isTransferMethod = fileAttr?.key === 'transfer_method'
|
||||
const isArrayValue = fileAttr?.key === 'transfer_method' || fileAttr?.key === 'type'
|
||||
|
||||
const handleUpdateConditionValue = useCallback((value: string) => {
|
||||
if (value === condition.value || (isTransferMethod && value === condition.value?.[0]))
|
||||
if (value === condition.value || (isArrayValue && value === condition.value?.[0]))
|
||||
return
|
||||
const newCondition = {
|
||||
...condition,
|
||||
value: isTransferMethod ? [value] : value,
|
||||
value: isArrayValue ? [value] : value,
|
||||
}
|
||||
doUpdateCondition(newCondition)
|
||||
}, [condition, doUpdateCondition, fileAttr])
|
||||
|
@ -273,7 +273,7 @@ const ConditionItem = ({
|
|||
<Select
|
||||
wrapperClassName='h-8'
|
||||
className='px-2 text-xs rounded-t-none'
|
||||
defaultValue={isTransferMethod ? (condition.value as string[])?.[0] : (condition.value as string)}
|
||||
defaultValue={isArrayValue ? (condition.value as string[])?.[0] : (condition.value as string)}
|
||||
items={selectOptions}
|
||||
onSelect={item => handleUpdateConditionValue(item.value as string)}
|
||||
hideChecked
|
||||
|
|
|
@ -75,5 +75,5 @@ export const TRANSFER_METHOD = [
|
|||
{ value: TransferMethod.remote_url, i18nKey: 'url' },
|
||||
]
|
||||
|
||||
export const SUB_VARIABLES = ['type', 'size', 'name', 'url', 'extension', 'mime_type', 'transfer_method', 'url']
|
||||
export const SUB_VARIABLES = ['type', 'size', 'name', 'url', 'extension', 'mime_type', 'transfer_method']
|
||||
export const OUTPUT_FILE_SUB_VARIABLES = SUB_VARIABLES.filter(key => key !== 'transfer_method')
|
||||
|
|
|
@ -30,7 +30,7 @@ const FilterCondition: FC<Props> = ({
|
|||
}) => {
|
||||
const { t } = useTranslation()
|
||||
const isSelect = [ComparisonOperator.in, ComparisonOperator.notIn, ComparisonOperator.allOf].includes(condition.comparison_operator)
|
||||
const isTransferMethod = condition.key === 'transfer_method'
|
||||
const isArrayValue = condition.key === 'transfer_method' || condition.key === 'type'
|
||||
const selectOptions = useMemo(() => {
|
||||
if (isSelect) {
|
||||
if (condition.key === 'type' || condition.comparison_operator === ComparisonOperator.allOf) {
|
||||
|
@ -39,7 +39,7 @@ const FilterCondition: FC<Props> = ({
|
|||
value: item.value,
|
||||
}))
|
||||
}
|
||||
if (isTransferMethod) {
|
||||
if (condition.key === 'transfer_method') {
|
||||
return TRANSFER_METHOD.map(item => ({
|
||||
name: t(`${optionNameI18NPrefix}.${item.i18nKey}`),
|
||||
value: item.value,
|
||||
|
@ -48,15 +48,15 @@ const FilterCondition: FC<Props> = ({
|
|||
return []
|
||||
}
|
||||
return []
|
||||
}, [condition.comparison_operator, condition.key, isSelect, t, isTransferMethod])
|
||||
}, [condition.comparison_operator, condition.key, isSelect, t, isArrayValue])
|
||||
const handleChange = useCallback((key: string) => {
|
||||
return (value: any) => {
|
||||
onChange({
|
||||
...condition,
|
||||
[key]: isTransferMethod ? [value] : value,
|
||||
[key]: isArrayValue ? [value] : value,
|
||||
})
|
||||
}
|
||||
}, [condition, onChange, isTransferMethod])
|
||||
}, [condition, onChange, isArrayValue])
|
||||
|
||||
const handleSubVariableChange = useCallback((value: string) => {
|
||||
onChange({
|
||||
|
@ -89,7 +89,7 @@ const FilterCondition: FC<Props> = ({
|
|||
{isSelect && (
|
||||
<Select
|
||||
items={selectOptions}
|
||||
defaultValue={isTransferMethod ? (condition.value as string[])[0] : condition.value as string}
|
||||
defaultValue={isArrayValue ? (condition.value as string[])[0] : condition.value as string}
|
||||
onSelect={item => handleChange('value')(item.value)}
|
||||
className='!text-[13px]'
|
||||
wrapperClassName='grow h-8'
|
||||
|
|
Loading…
Reference in New Issue
Block a user