|
@@ -5,17 +5,17 @@
|
|
|
|
|
|
|
|
import React, { useMemo } from 'react';
|
|
import React, { useMemo } from 'react';
|
|
|
|
|
|
|
|
-import { I18n } from '@flowgram.ai/editor';
|
|
|
|
|
-import { Input } from '@douyinfe/semi-ui';
|
|
|
|
|
|
|
+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 { InjectVariableSelector } from '@/components/variable-selector';
|
|
|
import { InjectDynamicValueInput } from '@/components/dynamic-value-input';
|
|
import { InjectDynamicValueInput } from '@/components/dynamic-value-input';
|
|
|
|
|
+import { IConditionRule, ConditionOpConfigs, useCondition } from '@/components/condition-context';
|
|
|
|
|
|
|
|
-import { ConditionRowValueType, IRules, OpConfigs } from './types';
|
|
|
|
|
|
|
+import { ConditionRowValueType } from './types';
|
|
|
import { UIContainer, UILeft, UIOperator, UIRight, UIValues } from './styles';
|
|
import { UIContainer, UILeft, UIOperator, UIRight, UIValues } from './styles';
|
|
|
-import { useRule } from './hooks/useRule';
|
|
|
|
|
-import { useOp } from './hooks/useOp';
|
|
|
|
|
-import { defaultOpConfigs, defaultRules } from './constants';
|
|
|
|
|
|
|
|
|
|
interface PropTypes {
|
|
interface PropTypes {
|
|
|
value?: ConditionRowValueType;
|
|
value?: ConditionRowValueType;
|
|
@@ -23,8 +23,8 @@ interface PropTypes {
|
|
|
style?: React.CSSProperties;
|
|
style?: React.CSSProperties;
|
|
|
readonly?: boolean;
|
|
readonly?: boolean;
|
|
|
ruleConfig?: {
|
|
ruleConfig?: {
|
|
|
- ops?: OpConfigs;
|
|
|
|
|
- rules?: IRules;
|
|
|
|
|
|
|
+ ops?: ConditionOpConfigs;
|
|
|
|
|
+ rules?: Record<string, IConditionRule>;
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -41,19 +41,44 @@ export function ConditionRow({
|
|
|
ruleConfig = defaultRuleConfig,
|
|
ruleConfig = defaultRuleConfig,
|
|
|
}: PropTypes) {
|
|
}: PropTypes) {
|
|
|
const { left, operator, right } = value || {};
|
|
const { left, operator, right } = value || {};
|
|
|
- const { rule } = useRule(left, ruleConfig.rules);
|
|
|
|
|
- const { renderOpSelect, opConfig } = useOp({
|
|
|
|
|
- rule,
|
|
|
|
|
- op: operator,
|
|
|
|
|
- onChange: (v) => onChange({ ...value, operator: v }),
|
|
|
|
|
- readonly,
|
|
|
|
|
- userOps: ruleConfig.ops,
|
|
|
|
|
|
|
+
|
|
|
|
|
+ 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,
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- const targetSchema = useMemo(() => {
|
|
|
|
|
- const targetType: string | null = rule?.[operator || ''] || null;
|
|
|
|
|
- return targetType ? { type: targetType, extra: { weak: true } } : null;
|
|
|
|
|
- }, [rule, opConfig]);
|
|
|
|
|
|
|
+ const renderOpSelect = () => (
|
|
|
|
|
+ <Select
|
|
|
|
|
+ style={{ height: 22 }}
|
|
|
|
|
+ disabled={readonly}
|
|
|
|
|
+ size="small"
|
|
|
|
|
+ value={operator}
|
|
|
|
|
+ optionList={opOptionList}
|
|
|
|
|
+ onChange={(v) => {
|
|
|
|
|
+ onChange({
|
|
|
|
|
+ ...value,
|
|
|
|
|
+ operator: v as string,
|
|
|
|
|
+ });
|
|
|
|
|
+ }}
|
|
|
|
|
+ triggerRender={({ value }) => (
|
|
|
|
|
+ <Button size="small" disabled={!rule}>
|
|
|
|
|
+ {opConfig?.abbreviation || <IconChevronDownStroked size="small" />}
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ )}
|
|
|
|
|
+ />
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<UIContainer style={style}>
|
|
<UIContainer style={style}>
|
|
@@ -97,7 +122,4 @@ export function ConditionRow({
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-ConditionRow.defaultRules = defaultRules;
|
|
|
|
|
-ConditionRow.defaultOpConfigs = defaultOpConfigs;
|
|
|
|
|
-
|
|
|
|
|
export { type ConditionRowValueType };
|
|
export { type ConditionRowValueType };
|