balibabu commited on
Commit
b95a338
·
1 Parent(s): f011ffe

Fix: The cursor is lost after entering a character in the operator form #4072 (#4073)

Browse files

### What problem does this PR solve?

Fix: The cursor is lost after entering a character in the operator form
#4072

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

web/src/pages/flow/flow-drawer/index.tsx CHANGED
@@ -4,7 +4,7 @@ import { CloseOutlined } from '@ant-design/icons';
4
  import { Drawer, Flex, Form, Input } from 'antd';
5
  import { lowerFirst } from 'lodash';
6
  import { Play } from 'lucide-react';
7
- import { useEffect } from 'react';
8
  import { Node } from 'reactflow';
9
  import { Operator, operatorMap } from '../constant';
10
  import AkShareForm from '../form/akshare-form';
@@ -108,6 +108,7 @@ const FormDrawer = ({
108
  id: node?.id,
109
  data: node?.data,
110
  });
 
111
 
112
  const { t } = useTranslate('flow');
113
 
@@ -115,10 +116,13 @@ const FormDrawer = ({
115
 
116
  useEffect(() => {
117
  if (visible) {
118
- form.resetFields();
 
 
119
  form.setFieldsValue(node?.data?.form);
 
120
  }
121
- }, [visible, form, node?.data?.form]);
122
 
123
  return (
124
  <Drawer
 
4
  import { Drawer, Flex, Form, Input } from 'antd';
5
  import { lowerFirst } from 'lodash';
6
  import { Play } from 'lucide-react';
7
+ import { useEffect, useRef } from 'react';
8
  import { Node } from 'reactflow';
9
  import { Operator, operatorMap } from '../constant';
10
  import AkShareForm from '../form/akshare-form';
 
108
  id: node?.id,
109
  data: node?.data,
110
  });
111
+ const previousId = useRef<string | undefined>(node?.id);
112
 
113
  const { t } = useTranslate('flow');
114
 
 
116
 
117
  useEffect(() => {
118
  if (visible) {
119
+ if (node?.id !== previousId.current) {
120
+ form.resetFields();
121
+ }
122
  form.setFieldsValue(node?.data?.form);
123
+ previousId.current = node?.id;
124
  }
125
+ }, [visible, form, node?.data?.form, node?.id]);
126
 
127
  return (
128
  <Drawer