Skip to content

Commit aec9c12

Browse files
xlorneclaude
andcommitted
fix: properly integrate with @flowgram.ai editor state for NodeTitleStrategy
- Remove local Form component that was causing conflicts - Use onChangeRef to save Field's onChange callback - Call onChange when modal confirms to update editor state - Use displayScript state to sync with editor value - Remove unnecessary Form wrapper This fixes: 1. Display not updating after modal save 2. Data lost when switching between nodes Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9c1559f commit aec9c12

1 file changed

Lines changed: 30 additions & 15 deletions

File tree

  • frontend/packages/flow-pc/flow-pc-design/src/components/design-editor/node-components/strategy

frontend/packages/flow-pc/flow-pc-design/src/components/design-editor/node-components/strategy/node-title.tsx

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import React, { useState, useMemo } from 'react';
2-
import { Form, Button, Space } from 'antd';
1+
import React, { useState, useMemo, useRef } from 'react';
2+
import { Button, Space } from 'antd';
33
import { EditOutlined } from '@ant-design/icons';
44
import { Field, FieldRenderProps } from '@flowgram.ai/fixed-layout-editor';
55
import { GroovyVariableService } from '@/services/groovy-variable-service';
@@ -10,9 +10,11 @@ import { TitleConfigModal } from './TitleConfigModal';
1010
* 节点标题策略配置
1111
*/
1212
export const NodeTitleStrategy: React.FC = () => {
13-
const [form] = Form.useForm();
1413
const [showConfigModal, setShowConfigModal] = useState(false);
1514
const [currentScript, setCurrentScript] = useState('');
15+
const [displayScript, setDisplayScript] = useState('');
16+
// 使用 ref 保存 onChange 回调,以便在弹框确认后更新编辑器状态
17+
const onChangeRef = useRef<((value: string) => void) | null>(null);
1618

1719
// 获取表单字段(从context获取)
1820
const formFields = useMemo(() => {
@@ -45,23 +47,36 @@ export const NodeTitleStrategy: React.FC = () => {
4547
};
4648

4749
const handleOpenConfig = () => {
48-
const script = form.getFieldValue(['NodeTitleStrategy', 'script']) || '';
49-
setCurrentScript(script);
50+
// 使用当前显示的脚本值
51+
setCurrentScript(displayScript);
5052
setShowConfigModal(true);
5153
};
5254

5355
const handleConfirm = (script: string) => {
54-
form.setFieldValue(['NodeTitleStrategy', 'script'], script);
56+
// 更新显示的脚本值
57+
setDisplayScript(script);
58+
// 关键修复:调用 onChange 回调更新编辑器状态
59+
if (onChangeRef.current) {
60+
onChangeRef.current(script);
61+
}
5562
setShowConfigModal(false);
5663
};
5764

5865
return (
5966
<>
60-
<Form form={form} style={{ width: '100%' }} layout="vertical">
61-
<Form.Item label="节点标题" name="NodeTitleStrategy.script" initialValue="def run(request){return '你有一条待办'}">
62-
<Field
63-
name="NodeTitleStrategy.script"
64-
render={({ field: { value } }: FieldRenderProps<any>) => (
67+
<div style={{ width: '100%' }}>
68+
<Field
69+
name="NodeTitleStrategy.script"
70+
render={({ field: { value, onChange } }: FieldRenderProps<any>) => {
71+
// 保存 onChange 回调到 ref
72+
onChangeRef.current = onChange;
73+
74+
// 更新显示的脚本值(当编辑器状态改变时)
75+
if (value !== displayScript) {
76+
setDisplayScript(value || '');
77+
}
78+
79+
return (
6580
<Space.Compact style={{ width: '100%' }}>
6681
<div
6782
style={{
@@ -86,10 +101,10 @@ export const NodeTitleStrategy: React.FC = () => {
86101
编辑
87102
</Button>
88103
</Space.Compact>
89-
)}
90-
/>
91-
</Form.Item>
92-
</Form>
104+
);
105+
}}
106+
/>
107+
</div>
93108

94109
{showConfigModal && (
95110
<TitleConfigModal

0 commit comments

Comments
 (0)