/** * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates * SPDX-License-Identifier: MIT */ import React, { useMemo } from 'react'; import { JsonSchemaUtils } from '@flowgram.ai/json-schema'; import { I18n, useScopeAvailable } from '@flowgram.ai/editor'; import { Button, Input, Select } from '@douyinfe/semi-ui'; import { IconChevronDownStroked } from '@douyinfe/semi-icons'; import { InjectVariableSelector } from '@/components/variable-selector'; import { InjectDynamicValueInput } from '@/components/dynamic-value-input'; import { IConditionRule, ConditionOpConfigs, useCondition } from '@/components/condition-context'; import { ConditionRowValueType } from './types'; import './styles.css'; interface PropTypes { value?: ConditionRowValueType; onChange: (value?: ConditionRowValueType) => void; style?: React.CSSProperties; readonly?: boolean; /** * @deprecated use ConditionContext instead to pass ruleConfig to multiple */ ruleConfig?: { ops?: ConditionOpConfigs; rules?: Record; }; } export function ConditionRow({ style, value, onChange, readonly, ruleConfig }: PropTypes) { const { left, operator, right } = value || {}; const available = useScopeAvailable(); const variable = useMemo(() => { if (!left) return undefined; return available.getByKeyPath(left.content); }, [available, left]); const leftSchema = useMemo(() => { if (!variable) return undefined; return JsonSchemaUtils.astToSchema(variable.type, { drilldown: false }); }, [variable?.type?.hash]); const { rule, opConfig, opOptionList, targetSchema } = useCondition({ leftSchema, operator, ruleConfig, onClearOp() { onChange({ ...value, operator: undefined, }); }, onClearRight() { onChange({ ...value, right: undefined, }); }, }); const renderOpSelect = () => ( )} ); } export { type ConditionRowValueType };