Merge pull request #871 from SuanmoSuanyangTechnology/fix/v0.3.0_zy

fix(web): third variable
This commit is contained in:
yingzhao
2026-04-13 15:46:53 +08:00
committed by GitHub
8 changed files with 43 additions and 13 deletions

View File

@@ -2,7 +2,7 @@
* @Author: ZhaoYing
* @Date: 2026-03-05
* @Last Modified by: ZhaoYing
* @Last Modified time: 2026-04-07 16:58:10
* @Last Modified time: 2026-04-13 15:13:36
*/
import { forwardRef, useImperativeHandle, useState } from 'react';
import { Button, Form, Input, Flex, App } from 'antd';
@@ -36,8 +36,6 @@ const OpenStatementSettingModal = forwardRef<OpenStatementSettingModalRef, OpenS
const [visible, setVisible] = useState(false);
const [form] = Form.useForm<FeaturesConfigForm['opening_statement']>();
console.log('chatVariables', chatVariables)
const handleClose = () => {
setVisible(false);
form.resetFields();

View File

@@ -2,7 +2,7 @@
* @Author: ZhaoYing
* @Date: 2025-12-30 13:59:36
* @Last Modified by: ZhaoYing
* @Last Modified time: 2026-04-13 12:16:00
* @Last Modified time: 2026-04-13 15:26:33
*/
import { forwardRef, useImperativeHandle, useState, useRef, useMemo } from 'react';
import { Form, Input, Select, InputNumber, Button, Row, Col, Flex } from 'antd';
@@ -136,7 +136,7 @@ const ChatVariableModal = forwardRef<ChatVariableModalRef, ChatVariableModalProp
form.validateFields().then((values) => {
const defaultValue = Array.isArray(values.defaultValue)
? values.defaultValue.filter((v: any) => v !== undefined && v !== null && v !== '')
: values.type.includes('object')
: values.type.includes('object') && values.defaultValue
? JSON.parse(values.defaultValue)
: values.defaultValue;
refresh({ ...values, defaultValue }, editIndex);

View File

@@ -31,6 +31,8 @@ const ConditionNode: ReactShapeConfig['component'] = ({ node }) => {
};
const labelRender = (value: string) => {
const filterOption = variableList.find(vo => `{{${vo.value}}}` === value)
?? variableList.flatMap(vo => vo.children ?? []).find(child => `{{${child.value}}}` === value)
?? variableList.flatMap(vo => vo.children ?? []).flatMap((child: any) => child.children ?? []).find((grandchild: any) => `{{${grandchild.value}}}` === value)
if (filterOption) {
return (

View File

@@ -30,6 +30,25 @@ const operationsObj = {
],
}
const filterByDataType = (options: Suggestion[], dataType: string): Suggestion[] =>
options.reduce<Suggestion[]>((acc, vo) => {
if (vo.children?.length) {
const children = vo.children.reduce<Suggestion[]>((cacc, child) => {
if (child.children?.length) {
const grandchildren = child.children.filter(gc => gc.dataType === dataType);
if (grandchildren.length) cacc.push({ ...child, children: grandchildren });
} else if (child.dataType === dataType) {
cacc.push(child);
}
return cacc;
}, []);
if (children.length) acc.push({ ...vo, children });
} else if (vo.dataType === dataType) {
acc.push(vo);
}
return acc;
}, []);
const AssignmentList: FC<AssignmentListProps> = ({
parentName,
options = [],
@@ -59,7 +78,9 @@ const AssignmentList: FC<AssignmentListProps> = ({
<Flex gap={10} vertical>
{fields.map(({ key, name, ...restField }) => {
const variableSelector = form.getFieldValue([parentName, name, 'variable_selector']);
const selectedOption = options.find(option => `{{${option.value}}}` === variableSelector);
const selectedOption = options.find(option => `{{${option.value}}}` === variableSelector)
?? options.flatMap(o => o.children ?? []).find(child => `{{${child.value}}}` === variableSelector)
?? options.flatMap(o => o.children ?? []).flatMap((c: any) => c.children ?? []).find((gc: any) => `{{${gc.value}}}` === variableSelector);
const dataType = selectedOption?.dataType;
const operationOptions = dataType === 'number' ? operationsObj.number : operationsObj.default;
@@ -119,7 +140,7 @@ const AssignmentList: FC<AssignmentListProps> = ({
{dataType === 'number' && operation === 'cover'
? <VariableSelect
placeholder={t('common.pleaseSelect')}
options={dataType ? options.filter(vo => vo.dataType === dataType) : options}
options={dataType ? filterByDataType(options, dataType) : options}
size={size}
className="rb:flex-1!"
variant="filled"
@@ -150,7 +171,7 @@ const AssignmentList: FC<AssignmentListProps> = ({
</>
: <VariableSelect
placeholder={t('common.pleaseSelect')}
options={dataType ? options.filter(vo => vo.dataType === dataType) : options}
options={dataType ? filterByDataType(options, dataType) : options}
size={size}
className="rb:flex-1!"
variant="filled"

View File

@@ -329,7 +329,9 @@ const CaseList: FC<CaseListProps> = ({
const currentExpression = currentCase.expressions?.[conditionIndex] || {};
const currentOperator = currentExpression.operator;
const leftFieldValue = currentExpression.left;
const leftFieldOption = options.find(option => `{{${option.value}}}` === leftFieldValue);
const leftFieldOption = options.find(option => `{{${option.value}}}` === leftFieldValue)
?? options.flatMap(o => o.children ?? []).find(child => `{{${child.value}}}` === leftFieldValue)
?? options.flatMap(o => o.children ?? []).flatMap((c: any) => c.children ?? []).find((gc: any) => `{{${gc.value}}}` === leftFieldValue);
const leftFieldType = leftFieldOption?.dataType;
const hideRightField = currentOperator === 'empty' || currentOperator === 'not_empty' || leftFieldType === 'file' || leftFieldType === 'array[object]' || leftFieldType === 'array[file]';
const operatorList = leftFieldType && operatorsObj[leftFieldType]

View File

@@ -155,7 +155,9 @@ const ConditionList: FC<CaseListProps> = ({
const currentExpression = expressions[index] || {};
const currentOperator = currentExpression.operator;
const leftFieldValue = currentExpression.left;
const leftFieldOption = options.find(option => `{{${option.value}}}` === leftFieldValue);
const leftFieldOption = options.find(option => `{{${option.value}}}` === leftFieldValue)
?? options.flatMap(o => o.children ?? []).find(child => `{{${child.value}}}` === leftFieldValue)
?? options.flatMap(o => o.children ?? []).flatMap((c: any) => c.children ?? []).find((gc: any) => `{{${gc.value}}}` === leftFieldValue);
const leftFieldType = leftFieldOption?.dataType;
const hideRightField = currentOperator === 'empty' || currentOperator === 'not_empty' || ['array[object]', 'object'].includes(leftFieldType as string);
const operatorList = leftFieldType && ['array[object]', 'object'].includes(leftFieldType)

View File

@@ -62,14 +62,18 @@ const GroupVariableList: FC<GroupVariableListProps> = ({
*/
useEffect(() => {
if (!isCanAdd && value[0]) {
const firstVariable = options.find(opt => `{{${opt.value}}}` === value[0]);
const firstVariable = options.find(opt => `{{${opt.value}}}` === value[0])
?? options.flatMap(o => o.children ?? []).find(c => `{{${c.value}}}` === value[0])
?? options.flatMap(o => o.children ?? []).flatMap((c: any) => c.children ?? []).find((gc: any) => `{{${gc.value}}}` === value[0]);
if (firstVariable) {
form.setFieldValue(['group_type', 'output'], firstVariable.dataType);
}
} else if (isCanAdd) {
value.forEach((item: any, index: number) => {
if (item?.value?.[0]) {
const firstVariable = options.find(opt => `{{${opt.value}}}` === item.value[0]);
const firstVariable = options.find(opt => `{{${opt.value}}}` === item.value[0])
?? options.flatMap(o => o.children ?? []).find(c => `{{${c.value}}}` === item.value[0])
?? options.flatMap(o => o.children ?? []).flatMap((c: any) => c.children ?? []).find((gc: any) => `{{${gc.value}}}` === item.value[0]);
if (firstVariable) {
form.setFieldValue(['group_type', index], firstVariable.dataType);
}

View File

@@ -2,7 +2,7 @@
* @Author: ZhaoYing
* @Date: 2026-02-03 15:17:48
* @Last Modified by: ZhaoYing
* @Last Modified time: 2026-04-13 12:00:09
* @Last Modified time: 2026-04-13 15:33:58
*/
import { Clipboard, Graph, Keyboard, MiniMap, Node, Snapline, type Edge } from '@antv/x6';
import { register } from '@antv/x6-react-shape';
@@ -111,6 +111,7 @@ export const useWorkflowGraph = ({
graphRef.current.getNodes().forEach(node => {
const data = node.getData()
if (data?.type === 'if-else' || data?.type === 'question-classifier') {
console.log('chatVariables', chatVariables)
node.setData({ ...data, chatVariables }, { silent: true })
}
})