mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-06-04 03:13:58 +08:00

### What problem does this PR solve? feat: monitor changes in the table of relevant operators and synchronize them to the edge #918 feat: fixed the issue of repeated requests when opening the graph page #918 feat: cache node anchor coordinate information #918 feat: monitor changes in the data.form field of the categorize and relevant operators and then synchronize them to the edge #918 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
103 lines
3.2 KiB
TypeScript
103 lines
3.2 KiB
TypeScript
import { useTranslate } from '@/hooks/commonHooks';
|
|
import { CloseOutlined } from '@ant-design/icons';
|
|
import { Button, Card, Form, Input, Select } from 'antd';
|
|
import { humanId } from 'human-id';
|
|
import { useUpdateNodeInternals } from 'reactflow';
|
|
import { Operator } from '../constant';
|
|
import { useBuildFormSelectOptions } from '../form-hooks';
|
|
import { ICategorizeItem } from '../interface';
|
|
|
|
interface IProps {
|
|
nodeId?: string;
|
|
}
|
|
|
|
const DynamicCategorize = ({ nodeId }: IProps) => {
|
|
const updateNodeInternals = useUpdateNodeInternals();
|
|
const form = Form.useFormInstance();
|
|
const buildCategorizeToOptions = useBuildFormSelectOptions(
|
|
Operator.Categorize,
|
|
nodeId,
|
|
);
|
|
const { t } = useTranslate('flow');
|
|
|
|
return (
|
|
<>
|
|
<Form.List name="items">
|
|
{(fields, { add, remove }) => {
|
|
const handleAdd = () => {
|
|
add({ name: humanId() });
|
|
if (nodeId) updateNodeInternals(nodeId);
|
|
};
|
|
return (
|
|
<div
|
|
style={{ display: 'flex', rowGap: 10, flexDirection: 'column' }}
|
|
>
|
|
{fields.map((field) => (
|
|
<Card
|
|
size="small"
|
|
key={field.key}
|
|
extra={
|
|
<CloseOutlined
|
|
onClick={() => {
|
|
remove(field.name);
|
|
}}
|
|
/>
|
|
}
|
|
>
|
|
<Form.Item
|
|
label={t('name')} // TODO: repeatability check
|
|
name={[field.name, 'name']}
|
|
rules={[{ required: true, message: t('nameMessage') }]}
|
|
>
|
|
<Input />
|
|
</Form.Item>
|
|
<Form.Item
|
|
label={t('description')}
|
|
name={[field.name, 'description']}
|
|
>
|
|
<Input.TextArea rows={3} />
|
|
</Form.Item>
|
|
<Form.Item
|
|
label={t('examples')}
|
|
name={[field.name, 'examples']}
|
|
>
|
|
<Input.TextArea rows={3} />
|
|
</Form.Item>
|
|
<Form.Item label={t('to')} name={[field.name, 'to']}>
|
|
<Select
|
|
allowClear
|
|
options={buildCategorizeToOptions(
|
|
(form.getFieldValue(['items']) ?? [])
|
|
.map((x: ICategorizeItem) => x.to)
|
|
.filter(
|
|
(x: string) =>
|
|
x !==
|
|
form.getFieldValue(['items', field.name, 'to']),
|
|
),
|
|
)}
|
|
/>
|
|
</Form.Item>
|
|
</Card>
|
|
))}
|
|
|
|
<Button type="dashed" onClick={handleAdd} block>
|
|
+ {t('addItem')}
|
|
</Button>
|
|
</div>
|
|
);
|
|
}}
|
|
</Form.List>
|
|
|
|
{/* <Form.Item noStyle shouldUpdate>
|
|
{() => (
|
|
<Typography>
|
|
<pre>{JSON.stringify(form.getFieldsValue(), null, 2)}</pre>
|
|
</Typography>
|
|
)}
|
|
</Form.Item> */}
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default DynamicCategorize;
|