From 7a1131d8afce0006b2542eb56e199ae2d08b3f10 Mon Sep 17 00:00:00 2001 From: zhaoying Date: Tue, 6 Jan 2026 20:35:01 +0800 Subject: [PATCH] fix(web): workflow bug --- .../Properties/AssignmentList/index.tsx | 25 +- .../components/Properties/CaseList/index.tsx | 14 +- .../Properties/ConditionList/index.tsx | 12 +- .../Properties/HttpRequest/EditableTable.tsx | 252 ++++++++---------- .../Properties/HttpRequest/index.tsx | 33 +-- .../Properties/ParamsList/ParamEditModal.tsx | 1 + .../Workflow/components/Properties/index.tsx | 4 +- web/src/views/Workflow/constant.ts | 6 +- .../views/Workflow/hooks/useWorkflowGraph.ts | 26 +- web/src/views/Workflow/types.ts | 2 +- 10 files changed, 177 insertions(+), 198 deletions(-) diff --git a/web/src/views/Workflow/components/Properties/AssignmentList/index.tsx b/web/src/views/Workflow/components/Properties/AssignmentList/index.tsx index eac3775f..2ac8397b 100644 --- a/web/src/views/Workflow/components/Properties/AssignmentList/index.tsx +++ b/web/src/views/Workflow/components/Properties/AssignmentList/index.tsx @@ -62,6 +62,10 @@ const AssignmentList: FC = ({ placeholder={t('common.pleaseSelect')} options={options} popupMatchSelectWidth={false} + onChange={() => { + form.setFieldValue([parentName, name, 'operation'], undefined); + form.setFieldValue([parentName, name, 'value'], undefined); + }} /> @@ -72,6 +76,7 @@ const AssignmentList: FC = ({ noStyle > ({ ...vo, diff --git a/web/src/views/Workflow/components/Properties/ConditionList/index.tsx b/web/src/views/Workflow/components/Properties/ConditionList/index.tsx index 2f544281..6d955647 100644 --- a/web/src/views/Workflow/components/Properties/ConditionList/index.tsx +++ b/web/src/views/Workflow/components/Properties/ConditionList/index.tsx @@ -9,7 +9,7 @@ import Editor from '../../Editor' interface Case { logical_operator: 'and' | 'or'; - expressions: Array<{ left: string; comparison_operator: string; right: string; input_type: string; }> + expressions: Array<{ left: string; operator: string; right: string; input_type: string; }> } interface CaseListProps { @@ -45,6 +45,8 @@ const operatorsObj: { [key: string]: SelectProps['options'] } = { boolean: [ { value: 'eq', label: 'workflow.config.if-else.boolean.eq' }, { value: 'ne', label: 'workflow.config.if-else.boolean.ne' }, + { value: 'empty', label: 'workflow.config.if-else.empty' }, + { value: 'not_empty', label: 'workflow.config.if-else.not_empty' }, ] } @@ -61,7 +63,7 @@ const ConditionList: FC = ({ expressions: { [index]: { left: newValue, - comparison_operator: undefined, + operator: undefined, right: undefined, input_type: undefined } @@ -87,7 +89,7 @@ const ConditionList: FC = ({ {fields.map((field, index) => { const expressions = form.getFieldValue([parentName, 'expressions']) || []; const currentExpression = expressions[index] || {}; - const currentOperator = currentExpression.comparison_operator; + const currentOperator = currentExpression.operator; const hideRightField = currentOperator === 'empty' || currentOperator === 'not_empty'; const leftFieldValue = currentExpression.left; const leftFieldOption = options.find(option => `{{${option.value}}}` === leftFieldValue); @@ -122,7 +124,7 @@ const ConditionList: FC = ({ - + + ) : ( + + )} + + + ); +}; + export interface TableRow { key: string; - name: string; - value: string; + name?: string; + value?: string; type?: string; } interface EditableTableProps { + parentName: string | string[]; title?: string; - value?: Record | TableRow[]; - onChange?: (value: TableRow[]) => void; options?: Suggestion[]; - typeOptions?: {value: string, label: string}[] + typeOptions?: { value: string, label: string }[] } const EditableTable: React.FC = ({ + parentName, title, - value, - onChange, options = [], typeOptions = [] }) => { - const { t } = useTranslation() - const [rows, setRows] = useState([]); + const { t } = useTranslation(); + const form = Form.useFormInstance(); + const values = Form.useWatch(typeof parentName === 'string' ? [parentName] : parentName, form); - useEffect(() => { - if (Array.isArray(value)) { - setRows([...value]) - } else if (value && Object.keys(value).length > 0) { - setRows(Object.entries(value).map(([key, val], index) => ({ - key: index.toString(), - name: key || '', - value: val || '', - type: typeOptions.length > 0 ? typeOptions[0].value : undefined - }))) - } else { - setRows([]) - } - }, [value, typeOptions]) + const createNewRow = (): TableRow => ({ + key: Date.now().toString(), + name: undefined, + value: undefined, + ...(typeOptions.length > 0 && { type: typeOptions[0].value }) + }); - const handleChange = (key: string, field: 'name' | 'value' | 'type', val: string) => { - const newRows = rows.map(row => - row.key === key ? { ...row, [field]: val } : row - ); - setRows(newRows); - onChange?.(newRows); - }; + const handleAdd = useCallback(() => { + form.setFieldValue(parentName, [...(values ?? []), createNewRow()]); + }, [form, parentName, values, typeOptions]); - const handleAdd = () => { - const newRow: TableRow = { - key: Date.now().toString(), - name: '', - value: '', - ...(typeOptions.length > 0 && { type: typeOptions[0].value }) - }; - const newRows = [...rows, newRow]; - setRows(newRows); - onChange?.(newRows); - }; + const handleDelete = useCallback((index: number) => { + const currentValues = form.getFieldValue(parentName) || []; + form.setFieldValue(parentName, currentValues.filter((_: TableRow, i: number) => i !== index)); + }, [form, parentName]); - const handleDelete = (key: string) => { - const newRows = rows.filter(row => row.key !== key); - setRows(newRows); - onChange?.(newRows); - }; + const createColumn = (dataIndex: string, inputType: 'select' | 'variableSelect', width: string, columnOptions: any[]) => ({ + title: t(`workflow.config.${dataIndex}`), + dataIndex, + width, + onCell: (_: TableRow, index?: number) => ({ + name: typeof parentName === 'string' ? [parentName, index ?? 0, dataIndex] : [...parentName, index ?? 0, dataIndex], + inputType, + options: columnOptions + } as any) + }); - const columns = useMemo(() => { - const baseColumns = [ + const columns: TableProps['columns'] = useMemo(() => { + const hasType = typeOptions.length > 0; + const baseWidth = hasType ? '35%' : '45%'; + + return [ + createColumn('name', 'variableSelect', baseWidth, options), + ...(hasType ? [createColumn('type', 'select', '20%', typeOptions)] : []), + createColumn('value', 'variableSelect', baseWidth, options), { - title: typeOptions.length > 0 ? t('workflow.config.name') : '键', - dataIndex: 'name', - width: typeOptions.length > 0 ? '35%' : '45%', - render: (text: string, record: TableRow) => ( - handleChange(record.key, 'name', value || '')} - /> - ), + title: '', + dataIndex: 'actions', + width: '10%', + render: (_: any, __: TableRow, index: number) => ( +