balibabu commited on
Commit
ed19e93
·
1 Parent(s): 838db53

feat: add MessageForm #918 (#1312)

Browse files

### What problem does this PR solve?

feat: add MessageForm #918

### Type of change


- [x] New Feature (non-breaking change which adds functionality)

web/src/locales/en.ts CHANGED
@@ -552,6 +552,10 @@ The above is the content you need to summarize.`,
552
  description: 'Description',
553
  examples: 'Examples',
554
  to: 'To',
 
 
 
 
555
  },
556
  footer: {
557
  profile: 'All rights reserved @ React',
 
552
  description: 'Description',
553
  examples: 'Examples',
554
  to: 'To',
555
+ message: 'Messages',
556
+ messagePlaceholder: 'message',
557
+ messageMsg: 'Please input message or delete this field.',
558
+ addField: 'Add field',
559
  },
560
  footer: {
561
  profile: 'All rights reserved @ React',
web/src/locales/zh-traditional.ts CHANGED
@@ -513,6 +513,10 @@ export default {
513
  description: '描述',
514
  examples: '範例',
515
  to: '到',
 
 
 
 
516
  },
517
  footer: {
518
  profile: '“保留所有權利 @ react”',
 
513
  description: '描述',
514
  examples: '範例',
515
  to: '到',
516
+ message: '訊息',
517
+ messagePlaceholder: '訊息',
518
+ messageMsg: '請輸入訊息或刪除此欄位。',
519
+ addField: '新增字段',
520
  },
521
  footer: {
522
  profile: '“保留所有權利 @ react”',
web/src/locales/zh.ts CHANGED
@@ -531,6 +531,10 @@ export default {
531
  description: '描述',
532
  examples: '示例',
533
  to: '到',
 
 
 
 
534
  },
535
  footer: {
536
  profile: 'All rights reserved @ React',
 
531
  description: '描述',
532
  examples: '示例',
533
  to: '到',
534
+ message: '消息',
535
+ messagePlaceholder: '消息',
536
+ messageMsg: '请输入消息或删除此字段。',
537
+ addField: '新增字段',
538
  },
539
  footer: {
540
  profile: 'All rights reserved @ React',
web/src/pages/flow/constant.tsx CHANGED
@@ -1,6 +1,7 @@
1
  import {
2
  DatabaseOutlined,
3
  MergeCellsOutlined,
 
4
  RocketOutlined,
5
  SendOutlined,
6
  SlidersOutlined,
@@ -12,6 +13,7 @@ export enum Operator {
12
  Generate = 'Generate',
13
  Answer = 'Answer',
14
  Categorize = 'Categorize',
 
15
  }
16
 
17
  export const operatorIconMap = {
@@ -20,6 +22,7 @@ export const operatorIconMap = {
20
  [Operator.Answer]: SendOutlined,
21
  [Operator.Begin]: SlidersOutlined,
22
  [Operator.Categorize]: DatabaseOutlined,
 
23
  };
24
 
25
  export const operatorMap = {
@@ -30,6 +33,7 @@ export const operatorMap = {
30
  [Operator.Answer]: { description: 'Answer description' },
31
  [Operator.Begin]: { description: 'Begin description' },
32
  [Operator.Categorize]: { description: 'Categorize description' },
 
33
  };
34
 
35
  export const componentMenuList = [
@@ -49,6 +53,10 @@ export const componentMenuList = [
49
  name: Operator.Categorize,
50
  description: operatorMap[Operator.Categorize].description,
51
  },
 
 
 
 
52
  ];
53
 
54
  export const initialRetrievalValues = {
@@ -106,6 +114,7 @@ export const RestrictedUpstreamMap = {
106
  [Operator.Answer]: [],
107
  [Operator.Retrieval]: [],
108
  [Operator.Generate]: [],
 
109
  };
110
 
111
  export const NodeMap = {
@@ -114,4 +123,5 @@ export const NodeMap = {
114
  [Operator.Retrieval]: 'ragNode',
115
  [Operator.Generate]: 'ragNode',
116
  [Operator.Answer]: 'ragNode',
 
117
  };
 
1
  import {
2
  DatabaseOutlined,
3
  MergeCellsOutlined,
4
+ MessageOutlined,
5
  RocketOutlined,
6
  SendOutlined,
7
  SlidersOutlined,
 
13
  Generate = 'Generate',
14
  Answer = 'Answer',
15
  Categorize = 'Categorize',
16
+ Message = 'Message',
17
  }
18
 
19
  export const operatorIconMap = {
 
22
  [Operator.Answer]: SendOutlined,
23
  [Operator.Begin]: SlidersOutlined,
24
  [Operator.Categorize]: DatabaseOutlined,
25
+ [Operator.Message]: MessageOutlined,
26
  };
27
 
28
  export const operatorMap = {
 
33
  [Operator.Answer]: { description: 'Answer description' },
34
  [Operator.Begin]: { description: 'Begin description' },
35
  [Operator.Categorize]: { description: 'Categorize description' },
36
+ [Operator.Message]: { description: 'Message description' },
37
  };
38
 
39
  export const componentMenuList = [
 
53
  name: Operator.Categorize,
54
  description: operatorMap[Operator.Categorize].description,
55
  },
56
+ {
57
+ name: Operator.Message,
58
+ description: operatorMap[Operator.Message].description,
59
+ },
60
  ];
61
 
62
  export const initialRetrievalValues = {
 
114
  [Operator.Answer]: [],
115
  [Operator.Retrieval]: [],
116
  [Operator.Generate]: [],
117
+ [Operator.Message]: [],
118
  };
119
 
120
  export const NodeMap = {
 
123
  [Operator.Retrieval]: 'ragNode',
124
  [Operator.Generate]: 'ragNode',
125
  [Operator.Answer]: 'ragNode',
126
+ [Operator.Message]: 'ragNode',
127
  };
web/src/pages/flow/flow-drawer/index.tsx CHANGED
@@ -8,6 +8,7 @@ import CategorizeForm from '../categorize-form';
8
  import { Operator } from '../constant';
9
  import GenerateForm from '../generate-form';
10
  import { useHandleFormValuesChange } from '../hooks';
 
11
  import RetrievalForm from '../retrieval-form';
12
 
13
  interface IProps {
@@ -20,6 +21,7 @@ const FormMap = {
20
  [Operator.Generate]: GenerateForm,
21
  [Operator.Answer]: AnswerForm,
22
  [Operator.Categorize]: CategorizeForm,
 
23
  };
24
 
25
  const FlowDrawer = ({
 
8
  import { Operator } from '../constant';
9
  import GenerateForm from '../generate-form';
10
  import { useHandleFormValuesChange } from '../hooks';
11
+ import MessageForm from '../message-form';
12
  import RetrievalForm from '../retrieval-form';
13
 
14
  interface IProps {
 
21
  [Operator.Generate]: GenerateForm,
22
  [Operator.Answer]: AnswerForm,
23
  [Operator.Categorize]: CategorizeForm,
24
+ [Operator.Message]: MessageForm,
25
  };
26
 
27
  const FlowDrawer = ({
web/src/pages/flow/message-form/index.less ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .dynamicDeleteButton {
2
+ position: relative;
3
+ top: 4px;
4
+ margin: 0 8px;
5
+ color: #999;
6
+ font-size: 24px;
7
+ cursor: pointer;
8
+ transition: all 0.3s;
9
+ &:hover {
10
+ color: #777;
11
+ }
12
+ &[disabled] {
13
+ cursor: not-allowed;
14
+ opacity: 0.5;
15
+ }
16
+ }
web/src/pages/flow/message-form/index.tsx CHANGED
@@ -1,44 +1,85 @@
1
  import { useTranslate } from '@/hooks/commonHooks';
2
- import type { FormProps } from 'antd';
3
- import { Form, Input } from 'antd';
4
  import { IOperatorForm } from '../interface';
5
 
6
- type FieldType = {
7
- prologue?: string;
8
- };
9
 
10
- const onFinish: FormProps<FieldType>['onFinish'] = (values) => {
11
- console.log('Success:', values);
 
 
 
 
 
12
  };
13
 
14
- const onFinishFailed: FormProps<FieldType>['onFinishFailed'] = (errorInfo) => {
15
- console.log('Failed:', errorInfo);
 
 
16
  };
17
 
18
  const MessageForm = ({ onValuesChange, form }: IOperatorForm) => {
19
- const { t } = useTranslate('chat');
20
 
21
  return (
22
  <Form
23
  name="basic"
24
- labelCol={{ span: 8 }}
25
- wrapperCol={{ span: 16 }}
26
- style={{ maxWidth: 600 }}
27
  initialValues={{ remember: true }}
28
- onFinish={onFinish}
29
- onFinishFailed={onFinishFailed}
30
  onValuesChange={onValuesChange}
31
  autoComplete="off"
32
  form={form}
33
  >
34
- <Form.Item<FieldType>
35
- name={'prologue'}
36
- label={t('setAnOpener')}
37
- tooltip={t('setAnOpenerTip')}
38
- initialValue={t('setAnOpenerInitial')}
39
- >
40
- <Input.TextArea autoSize={{ minRows: 5 }} />
41
- </Form.Item>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  </Form>
43
  );
44
  };
 
1
  import { useTranslate } from '@/hooks/commonHooks';
2
+ import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
3
+ import { Button, Form, Input } from 'antd';
4
  import { IOperatorForm } from '../interface';
5
 
6
+ import styles from './index.less';
 
 
7
 
8
+ const formItemLayout = {
9
+ labelCol: {
10
+ sm: { span: 6 },
11
+ },
12
+ wrapperCol: {
13
+ sm: { span: 18 },
14
+ },
15
  };
16
 
17
+ const formItemLayoutWithOutLabel = {
18
+ wrapperCol: {
19
+ sm: { span: 18, offset: 6 },
20
+ },
21
  };
22
 
23
  const MessageForm = ({ onValuesChange, form }: IOperatorForm) => {
24
+ const { t } = useTranslate('flow');
25
 
26
  return (
27
  <Form
28
  name="basic"
29
+ {...formItemLayoutWithOutLabel}
 
 
30
  initialValues={{ remember: true }}
 
 
31
  onValuesChange={onValuesChange}
32
  autoComplete="off"
33
  form={form}
34
  >
35
+ <Form.List name="messages">
36
+ {(fields, { add, remove }, {}) => (
37
+ <>
38
+ {fields.map((field, index) => (
39
+ <Form.Item
40
+ {...(index === 0 ? formItemLayout : formItemLayoutWithOutLabel)}
41
+ label={index === 0 ? t('message') : ''}
42
+ required={false}
43
+ key={field.key}
44
+ >
45
+ <Form.Item
46
+ {...field}
47
+ validateTrigger={['onChange', 'onBlur']}
48
+ rules={[
49
+ {
50
+ required: true,
51
+ whitespace: true,
52
+ message: t('messageMsg'),
53
+ },
54
+ ]}
55
+ noStyle
56
+ >
57
+ <Input
58
+ placeholder={t('messagePlaceholder')}
59
+ style={{ width: '80%' }}
60
+ />
61
+ </Form.Item>
62
+ {fields.length > 1 ? (
63
+ <MinusCircleOutlined
64
+ className={styles.dynamicDeleteButton}
65
+ onClick={() => remove(field.name)}
66
+ />
67
+ ) : null}
68
+ </Form.Item>
69
+ ))}
70
+ <Form.Item>
71
+ <Button
72
+ type="dashed"
73
+ onClick={() => add()}
74
+ style={{ width: '80%' }}
75
+ icon={<PlusOutlined />}
76
+ >
77
+ {t('addField')}
78
+ </Button>
79
+ </Form.Item>
80
+ </>
81
+ )}
82
+ </Form.List>
83
  </Form>
84
  );
85
  };