feat: if change to defalut operator

This commit is contained in:
Joel 2024-03-20 11:42:57 +08:00
parent 67b3ee3776
commit 4df8fa0afb
1 changed files with 14 additions and 2 deletions

View File

@ -1,6 +1,6 @@
'use client'
import type { FC } from 'react'
import React, { useCallback } from 'react'
import React, { useCallback, useEffect } from 'react'
import { useTranslation } from 'react-i18next'
import cn from 'classnames'
import VarReferencePicker from '../../_base/components/variable/var-reference-picker'
@ -98,9 +98,21 @@ const Item: FC<ItemProps> = ({
...payload,
variable_selector: value as ValueSelector,
})
// TODO: handle value type change will effect the comparisonOperators
}, [onChange, payload])
// change to default operator if the variable type is changed
useEffect(() => {
if (varType && payload.comparison_operator) {
if (!getOperators(varType).includes(payload.comparison_operator)) {
onChange({
...payload,
comparison_operator: getOperators(varType)[0],
})
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [varType, payload])
const handleValueChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
onChange({
...payload,