balibabu commited on
Commit
1800b7d
·
1 Parent(s): 0dfad6e

Feat: merge the begin operator's url and file into one field #3355 (#3521)

Browse files

### What problem does this PR solve?

Feat: merge the begin operator's url and file into one field #3355
### Type of change


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

web/src/pages/flow/constant.tsx CHANGED
@@ -45,7 +45,6 @@ import {
45
  import upperFirst from 'lodash/upperFirst';
46
  import {
47
  CloudUpload,
48
- Link2,
49
  ListOrdered,
50
  OptionIcon,
51
  TextCursorInput,
@@ -2876,7 +2875,6 @@ export enum BeginQueryType {
2876
  File = 'file',
2877
  Integer = 'integer',
2878
  Boolean = 'boolean',
2879
- Url = 'url',
2880
  }
2881
 
2882
  export const BeginQueryTypeIconMap = {
@@ -2886,5 +2884,4 @@ export const BeginQueryTypeIconMap = {
2886
  [BeginQueryType.File]: CloudUpload,
2887
  [BeginQueryType.Integer]: ListOrdered,
2888
  [BeginQueryType.Boolean]: ToggleLeft,
2889
- [BeginQueryType.Url]: Link2,
2890
  };
 
45
  import upperFirst from 'lodash/upperFirst';
46
  import {
47
  CloudUpload,
 
48
  ListOrdered,
49
  OptionIcon,
50
  TextCursorInput,
 
2875
  File = 'file',
2876
  Integer = 'integer',
2877
  Boolean = 'boolean',
 
2878
  }
2879
 
2880
  export const BeginQueryTypeIconMap = {
 
2884
  [BeginQueryType.File]: CloudUpload,
2885
  [BeginQueryType.Integer]: ListOrdered,
2886
  [BeginQueryType.Boolean]: ToggleLeft,
 
2887
  };
web/src/pages/flow/form/generate-form/dynamic-parameters.tsx CHANGED
@@ -36,7 +36,6 @@ const DynamicParameters = ({ nodeId }: IProps) => {
36
  title: t('key'),
37
  dataIndex: 'key',
38
  key: 'key',
39
- width: 50,
40
  onCell: (record: IGenerateParameter) => ({
41
  record,
42
  editable: true,
 
36
  title: t('key'),
37
  dataIndex: 'key',
38
  key: 'key',
 
39
  onCell: (record: IGenerateParameter) => ({
40
  record,
41
  editable: true,
web/src/pages/flow/run-drawer/index.tsx CHANGED
@@ -5,11 +5,10 @@ import { useHandleSubmittable } from '@/hooks/login-hooks';
5
  import { IModalProps } from '@/interfaces/common';
6
  import api from '@/utils/api';
7
  import { getAuthorization } from '@/utils/authorization-util';
8
- import { InboxOutlined } from '@ant-design/icons';
9
  import {
10
  Button,
11
  Drawer,
12
- Flex,
13
  Form,
14
  FormItemProps,
15
  Input,
@@ -19,7 +18,6 @@ import {
19
  Upload,
20
  } from 'antd';
21
  import { pick } from 'lodash';
22
- import { Link2, Trash2 } from 'lucide-react';
23
  import React, { useCallback, useState } from 'react';
24
  import { useTranslation } from 'react-i18next';
25
  import { BeginQueryType } from '../constant';
@@ -33,6 +31,7 @@ import { getDrawerWidth } from '../utils';
33
  import { PopoverForm } from './popover-form';
34
 
35
  import { UploadChangeParam, UploadFile } from 'antd/es/upload';
 
36
  import styles from './index.less';
37
 
38
  const RunDrawer = ({
@@ -60,18 +59,6 @@ const RunDrawer = ({
60
  [setRecord, showPopover],
61
  );
62
 
63
- const handleRemoveUrl = useCallback(
64
- (key: number, index: number) => () => {
65
- const list: any[] = form.getFieldValue(key);
66
-
67
- form.setFieldValue(
68
- key,
69
- list.filter((_, idx) => idx !== index),
70
- );
71
- },
72
- [form],
73
- );
74
-
75
  const getBeginNodeDataQuery = useGetBeginNodeDataQuery();
76
  const query: BeginQuery[] = getBeginNodeDataQuery();
77
 
@@ -126,27 +113,47 @@ const RunDrawer = ({
126
  </Form.Item>
127
  ),
128
  [BeginQueryType.File]: (
129
- <Form.Item
130
- {...props}
131
- valuePropName="fileList"
132
- getValueFromEvent={normFile}
133
- >
134
- <Upload.Dragger
135
- name="file"
136
- action={api.parse}
137
- multiple
138
- headers={{ [Authorization]: getAuthorization() }}
139
- onChange={onChange(q.optional)}
140
- >
141
- <p className="ant-upload-drag-icon">
142
- <InboxOutlined />
143
- </p>
144
- <p className="ant-upload-text">{t('fileManager.uploadTitle')}</p>
145
- <p className="ant-upload-hint">
146
- {t('fileManager.uploadDescription')}
147
- </p>
148
- </Upload.Dragger>
149
- </Form.Item>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  ),
151
  [BeginQueryType.Integer]: (
152
  <Form.Item {...props}>
@@ -158,66 +165,11 @@ const RunDrawer = ({
158
  <Switch></Switch>
159
  </Form.Item>
160
  ),
161
- [BeginQueryType.Url]: (
162
- <React.Fragment key={idx}>
163
- <Form.Item
164
- {...pick(props, ['key', 'label', 'rules'])}
165
- required={!q.optional}
166
- className={urlList.length > 0 ? 'mb-1' : ''}
167
- >
168
- <PopoverForm visible={visible} switchVisible={switchVisible}>
169
- <Button
170
- onClick={handleShowPopover(idx)}
171
- className="text-buttonBlueText"
172
- >
173
- {t('flow.pasteFileLink')}
174
- </Button>
175
- </PopoverForm>
176
- </Form.Item>
177
- <Form.Item name={idx} noStyle {...pick(props, ['rules'])} />
178
- <Form.Item
179
- noStyle
180
- shouldUpdate={(prevValues, curValues) =>
181
- prevValues[idx] !== curValues[idx]
182
- }
183
- >
184
- {({ getFieldValue }) => {
185
- const urlInfo: { url: string; result: string }[] =
186
- getFieldValue(idx) || [];
187
- return urlInfo.length ? (
188
- <Flex vertical gap={8} className="mb-3">
189
- {urlInfo.map((u, index) => (
190
- <div
191
- key={index}
192
- className="flex items-center justify-between gap-2 hover:bg-slate-100 group"
193
- >
194
- <Link2 className="size-5"></Link2>
195
- <span className="flex-1 truncate"> {u.url}</span>
196
- <Trash2
197
- className="size-4 invisible group-hover:visible cursor-pointer"
198
- onClick={handleRemoveUrl(idx, index)}
199
- />
200
- </div>
201
- ))}
202
- </Flex>
203
- ) : null;
204
- }}
205
- </Form.Item>
206
- </React.Fragment>
207
- ),
208
  };
209
 
210
  return BeginQueryTypeMap[q.type as BeginQueryType];
211
  },
212
- [
213
- form,
214
- handleRemoveUrl,
215
- handleShowPopover,
216
- onChange,
217
- switchVisible,
218
- t,
219
- visible,
220
- ],
221
  );
222
 
223
  const { handleRun } = useSaveGraphBeforeOpeningDebugDrawer(showChatModal!);
@@ -239,20 +191,11 @@ const RunDrawer = ({
239
  if (Array.isArray(value)) {
240
  nextValue = ``;
241
 
242
- value.forEach((x, idx) => {
243
- if (x?.originFileObj instanceof File) {
244
- if (idx === 0) {
245
- nextValue += `${x.name}\n\n${x.response?.data}\n\n`;
246
- } else {
247
- nextValue += `${x.response?.data}\n\n`;
248
- }
249
- } else {
250
- if (idx === 0) {
251
- nextValue += `${x.url}\n\n${x.result}\n\n`;
252
- } else {
253
- nextValue += `${x.result}\n\n`;
254
- }
255
- }
256
  });
257
  }
258
  return { ...item, value: nextValue };
@@ -277,7 +220,7 @@ const RunDrawer = ({
277
  const { basicForm } = forms;
278
  const urlInfo = basicForm.getFieldValue(currentRecord) || [];
279
  basicForm.setFieldsValue({
280
- [currentRecord]: [...urlInfo, values],
281
  });
282
  hidePopover();
283
  }
 
5
  import { IModalProps } from '@/interfaces/common';
6
  import api from '@/utils/api';
7
  import { getAuthorization } from '@/utils/authorization-util';
8
+ import { UploadOutlined } from '@ant-design/icons';
9
  import {
10
  Button,
11
  Drawer,
 
12
  Form,
13
  FormItemProps,
14
  Input,
 
18
  Upload,
19
  } from 'antd';
20
  import { pick } from 'lodash';
 
21
  import React, { useCallback, useState } from 'react';
22
  import { useTranslation } from 'react-i18next';
23
  import { BeginQueryType } from '../constant';
 
31
  import { PopoverForm } from './popover-form';
32
 
33
  import { UploadChangeParam, UploadFile } from 'antd/es/upload';
34
+ import { Link } from 'lucide-react';
35
  import styles from './index.less';
36
 
37
  const RunDrawer = ({
 
59
  [setRecord, showPopover],
60
  );
61
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  const getBeginNodeDataQuery = useGetBeginNodeDataQuery();
63
  const query: BeginQuery[] = getBeginNodeDataQuery();
64
 
 
113
  </Form.Item>
114
  ),
115
  [BeginQueryType.File]: (
116
+ <React.Fragment key={idx}>
117
+ <Form.Item label={q.name} required={!q.optional}>
118
+ <div className="relative">
119
+ <Form.Item
120
+ {...props}
121
+ valuePropName="fileList"
122
+ getValueFromEvent={normFile}
123
+ noStyle
124
+ >
125
+ <Upload
126
+ name="file"
127
+ action={api.parse}
128
+ multiple
129
+ headers={{ [Authorization]: getAuthorization() }}
130
+ onChange={onChange(q.optional)}
131
+ >
132
+ <Button icon={<UploadOutlined />}>
133
+ {t('common.upload')}
134
+ </Button>
135
+ </Upload>
136
+ </Form.Item>
137
+ <Form.Item
138
+ {...pick(props, ['key', 'label', 'rules'])}
139
+ required={!q.optional}
140
+ className={urlList.length > 0 ? 'mb-1' : ''}
141
+ noStyle
142
+ >
143
+ <PopoverForm visible={visible} switchVisible={switchVisible}>
144
+ <Button
145
+ onClick={handleShowPopover(idx)}
146
+ className="absolute left-1/2 top-0"
147
+ icon={<Link className="size-3" />}
148
+ >
149
+ {t('flow.pasteFileLink')}
150
+ </Button>
151
+ </PopoverForm>
152
+ </Form.Item>
153
+ </div>
154
+ </Form.Item>
155
+ <Form.Item name={idx} noStyle {...pick(props, ['rules'])} />
156
+ </React.Fragment>
157
  ),
158
  [BeginQueryType.Integer]: (
159
  <Form.Item {...props}>
 
165
  <Switch></Switch>
166
  </Form.Item>
167
  ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  };
169
 
170
  return BeginQueryTypeMap[q.type as BeginQueryType];
171
  },
172
+ [form, handleShowPopover, onChange, switchVisible, t, visible],
 
 
 
 
 
 
 
 
173
  );
174
 
175
  const { handleRun } = useSaveGraphBeforeOpeningDebugDrawer(showChatModal!);
 
191
  if (Array.isArray(value)) {
192
  nextValue = ``;
193
 
194
+ value.forEach((x) => {
195
+ nextValue +=
196
+ x?.originFileObj instanceof File
197
+ ? `${x.name}\n${x.response?.data}\n----\n`
198
+ : `${x.url}\n${x.result}\n----\n`;
 
 
 
 
 
 
 
 
 
199
  });
200
  }
201
  return { ...item, value: nextValue };
 
220
  const { basicForm } = forms;
221
  const urlInfo = basicForm.getFieldValue(currentRecord) || [];
222
  basicForm.setFieldsValue({
223
+ [currentRecord]: [...urlInfo, { ...values, name: values.url }],
224
  });
225
  hidePopover();
226
  }