From 4df8fa0afb62caa07e63549a5f475729c9197248 Mon Sep 17 00:00:00 2001 From: Joel Date: Wed, 20 Mar 2024 11:42:57 +0800 Subject: [PATCH] feat: if change to defalut operator --- .../nodes/if-else/components/condition-item.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/web/app/components/workflow/nodes/if-else/components/condition-item.tsx b/web/app/components/workflow/nodes/if-else/components/condition-item.tsx index 34130be553..3dc18a3200 100644 --- a/web/app/components/workflow/nodes/if-else/components/condition-item.tsx +++ b/web/app/components/workflow/nodes/if-else/components/condition-item.tsx @@ -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 = ({ ...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) => { onChange({ ...payload,