Fix: Fixed the issue that the script text of the code operator is not displayed after refreshing the page after saving the script text of the code operator #4977 (#7825)

### What problem does this PR solve?

Fix: Fixed the issue that the script text of the code operator is not
displayed after refreshing the page after saving the script text of the
code operator #4977

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
balibabu 2025-05-23 18:57:45 +08:00 committed by GitHub
parent e604634d2a
commit f9e6ad86b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,7 +5,8 @@ import { DynamicInputVariable } from './dynamic-input-variable';
import { CodeTemplateStrMap, ProgrammingLanguage } from '@/constants/agent'; import { CodeTemplateStrMap, ProgrammingLanguage } from '@/constants/agent';
import { ICodeForm } from '@/interfaces/database/flow'; import { ICodeForm } from '@/interfaces/database/flow';
import { useEffect } from 'react'; import { useCallback } from 'react';
import useGraphStore from '../../store';
import styles from './index.less'; import styles from './index.less';
loader.config({ paths: { vs: '/vs' } }); loader.config({ paths: { vs: '/vs' } });
@ -17,16 +18,20 @@ const options = [
const CodeForm = ({ onValuesChange, form, node }: IOperatorForm) => { const CodeForm = ({ onValuesChange, form, node }: IOperatorForm) => {
const formData = node?.data.form as ICodeForm; const formData = node?.data.form as ICodeForm;
const updateNodeForm = useGraphStore((state) => state.updateNodeForm);
useEffect(() => { const handleChange = useCallback(
setTimeout(() => { (value: ProgrammingLanguage) => {
// TODO: Direct operation zustand is more elegant if (node?.id) {
form?.setFieldValue( updateNodeForm(
'script', node?.id,
CodeTemplateStrMap[formData.lang as ProgrammingLanguage], CodeTemplateStrMap[value as ProgrammingLanguage],
); ['script'],
}, 0); );
}, [form, formData.lang]); }
},
[node?.id, updateNodeForm],
);
return ( return (
<Form <Form
@ -42,9 +47,10 @@ const CodeForm = ({ onValuesChange, form, node }: IOperatorForm) => {
label={ label={
<Form.Item name={'lang'} className={styles.languageItem}> <Form.Item name={'lang'} className={styles.languageItem}>
<Select <Select
defaultValue={'python'} defaultValue={ProgrammingLanguage.Python}
popupMatchSelectWidth={false} popupMatchSelectWidth={false}
options={options} options={options}
onChange={handleChange}
/> />
</Form.Item> </Form.Item>
} }