/** * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates * SPDX-License-Identifier: MIT */ import React, { useMemo } from 'react'; import { I18n } from '@flowgram.ai/editor'; import { Button, Icon, Input, Select } from '@douyinfe/semi-ui'; import { IconChevronDownStroked } from '@douyinfe/semi-icons'; import { useTypeManager } from '@/plugins'; import { InjectDynamicValueInput } from '@/components/dynamic-value-input'; import { useCondition, type ConditionOpConfigs, type IConditionRule, } from '@/components/condition-context'; import { DBConditionOptionType, DBConditionRowValueType } from './types'; import './styles.css'; interface PropTypes { value?: DBConditionRowValueType; onChange: (value?: DBConditionRowValueType) => void; style?: React.CSSProperties; options?: DBConditionOptionType[]; readonly?: boolean; /** * @deprecated use ConditionContext instead to pass ruleConfig to multiple */ ruleConfig?: { ops?: ConditionOpConfigs; rules?: Record; }; } export function DBConditionRow({ style, value, onChange, readonly, options, ruleConfig, }: PropTypes) { const { left, operator, right } = value || {}; const typeManager = useTypeManager(); const leftSchema = useMemo( () => options?.find((item) => item.value === left)?.schema, [left, options] ); const { opConfig, rule, opOptionList, targetSchema } = useCondition({ leftSchema, operator, ruleConfig, onClearOp() { onChange({ ...value, operator: undefined, }); }, onClearRight() { onChange({ ...value, right: undefined, }); }, }); const renderDBOptionSelect = () => ( { onChange({ ...value, operator: v as string, }); }} triggerRender={({ value }) => ( )} /> ); return (
{renderOpSelect()}
{renderDBOptionSelect()}
{targetSchema ? ( onChange({ ...value, right: v })} /> ) : ( )}
); } export { type DBConditionRowValueType, type DBConditionOptionType };