chore: type value change to array

This commit is contained in:
Joel 2024-09-25 15:19:28 +08:00
parent f8d26e46ac
commit 87e560de8a
3 changed files with 11 additions and 11 deletions

View File

@ -128,14 +128,14 @@ const ConditionItem = ({
return undefined return undefined
}, [condition.key, file, isSubVariableKey]) }, [condition.key, file, isSubVariableKey])
const isTransferMethod = fileAttr?.key === 'transfer_method' const isArrayValue = fileAttr?.key === 'transfer_method' || fileAttr?.key === 'type'
const handleUpdateConditionValue = useCallback((value: string) => { const handleUpdateConditionValue = useCallback((value: string) => {
if (value === condition.value || (isTransferMethod && value === condition.value?.[0])) if (value === condition.value || (isArrayValue && value === condition.value?.[0]))
return return
const newCondition = { const newCondition = {
...condition, ...condition,
value: isTransferMethod ? [value] : value, value: isArrayValue ? [value] : value,
} }
doUpdateCondition(newCondition) doUpdateCondition(newCondition)
}, [condition, doUpdateCondition, fileAttr]) }, [condition, doUpdateCondition, fileAttr])
@ -273,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={isTransferMethod ? (condition.value as string[])?.[0] : (condition.value as string)} defaultValue={isArrayValue ? (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

View File

@ -75,5 +75,5 @@ export const TRANSFER_METHOD = [
{ value: TransferMethod.remote_url, i18nKey: 'url' }, { 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') export const OUTPUT_FILE_SUB_VARIABLES = SUB_VARIABLES.filter(key => key !== 'transfer_method')

View File

@ -30,7 +30,7 @@ const FilterCondition: FC<Props> = ({
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
const isSelect = [ComparisonOperator.in, ComparisonOperator.notIn, ComparisonOperator.allOf].includes(condition.comparison_operator) 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(() => { const selectOptions = useMemo(() => {
if (isSelect) { if (isSelect) {
if (condition.key === 'type' || condition.comparison_operator === ComparisonOperator.allOf) { if (condition.key === 'type' || condition.comparison_operator === ComparisonOperator.allOf) {
@ -39,7 +39,7 @@ const FilterCondition: FC<Props> = ({
value: item.value, value: item.value,
})) }))
} }
if (isTransferMethod) { if (condition.key === 'transfer_method') {
return TRANSFER_METHOD.map(item => ({ return TRANSFER_METHOD.map(item => ({
name: t(`${optionNameI18NPrefix}.${item.i18nKey}`), name: t(`${optionNameI18NPrefix}.${item.i18nKey}`),
value: item.value, value: item.value,
@ -48,15 +48,15 @@ const FilterCondition: FC<Props> = ({
return [] return []
} }
return [] return []
}, [condition.comparison_operator, condition.key, isSelect, t, isTransferMethod]) }, [condition.comparison_operator, condition.key, isSelect, t, isArrayValue])
const handleChange = useCallback((key: string) => { const handleChange = useCallback((key: string) => {
return (value: any) => { return (value: any) => {
onChange({ onChange({
...condition, ...condition,
[key]: isTransferMethod ? [value] : value, [key]: isArrayValue ? [value] : value,
}) })
} }
}, [condition, onChange, isTransferMethod]) }, [condition, onChange, isArrayValue])
const handleSubVariableChange = useCallback((value: string) => { const handleSubVariableChange = useCallback((value: string) => {
onChange({ onChange({
@ -89,7 +89,7 @@ const FilterCondition: FC<Props> = ({
{isSelect && ( {isSelect && (
<Select <Select
items={selectOptions} 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)} onSelect={item => handleChange('value')(item.value)}
className='!text-[13px]' className='!text-[13px]'
wrapperClassName='grow h-8' wrapperClassName='grow h-8'