mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
### What problem does this PR solve? feat: add CategorizeHandle #918 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -1,58 +1,78 @@
|
||||
import { CloseOutlined } from '@ant-design/icons';
|
||||
import { Button, Card, Form, Input, Select, Typography } from 'antd';
|
||||
import { useBuildCategorizeToOptions } from './hooks';
|
||||
import { useBuildCategorizeToOptions, useHandleToSelectChange } from './hooks';
|
||||
|
||||
const DynamicCategorize = () => {
|
||||
interface IProps {
|
||||
nodeId?: string;
|
||||
}
|
||||
|
||||
const DynamicCategorize = ({ nodeId }: IProps) => {
|
||||
const form = Form.useFormInstance();
|
||||
const options = useBuildCategorizeToOptions();
|
||||
const { handleSelectChange } = useHandleToSelectChange(
|
||||
options.map((x) => x.value),
|
||||
nodeId,
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Form.List name="items">
|
||||
{(fields, { add, remove }) => (
|
||||
<div style={{ display: 'flex', rowGap: 16, flexDirection: 'column' }}>
|
||||
{fields.map((field) => (
|
||||
<Card
|
||||
size="small"
|
||||
key={field.key}
|
||||
extra={
|
||||
<CloseOutlined
|
||||
onClick={() => {
|
||||
remove(field.name);
|
||||
}}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<Form.Item
|
||||
label="name"
|
||||
name={[field.name, 'name']}
|
||||
initialValue={`Categorize ${field.name + 1}`}
|
||||
rules={[
|
||||
{ required: true, message: 'Please input your name!' },
|
||||
]}
|
||||
{(fields, { add, remove }) => {
|
||||
const handleAdd = () => {
|
||||
const idx = fields.length;
|
||||
add({ name: `Categorize ${idx + 1}` });
|
||||
};
|
||||
return (
|
||||
<div
|
||||
style={{ display: 'flex', rowGap: 10, flexDirection: 'column' }}
|
||||
>
|
||||
{fields.map((field) => (
|
||||
<Card
|
||||
size="small"
|
||||
key={field.key}
|
||||
extra={
|
||||
<CloseOutlined
|
||||
onClick={() => {
|
||||
remove(field.name);
|
||||
}}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="description"
|
||||
name={[field.name, 'description']}
|
||||
>
|
||||
<Input.TextArea rows={3} />
|
||||
</Form.Item>
|
||||
<Form.Item label="examples" name={[field.name, 'examples']}>
|
||||
<Input.TextArea rows={3} />
|
||||
</Form.Item>
|
||||
<Form.Item label="to" name={[field.name, 'to']}>
|
||||
<Select options={options} />
|
||||
</Form.Item>
|
||||
</Card>
|
||||
))}
|
||||
<Form.Item
|
||||
label="name"
|
||||
name={[field.name, 'name']}
|
||||
// initialValue={`Categorize ${field.name + 1}`}
|
||||
rules={[
|
||||
{ required: true, message: 'Please input your name!' },
|
||||
]}
|
||||
>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="description"
|
||||
name={[field.name, 'description']}
|
||||
>
|
||||
<Input.TextArea rows={3} />
|
||||
</Form.Item>
|
||||
<Form.Item label="examples" name={[field.name, 'examples']}>
|
||||
<Input.TextArea rows={3} />
|
||||
</Form.Item>
|
||||
<Form.Item label="to" name={[field.name, 'to']}>
|
||||
<Select
|
||||
allowClear
|
||||
options={options}
|
||||
onChange={handleSelectChange}
|
||||
/>
|
||||
</Form.Item>
|
||||
</Card>
|
||||
))}
|
||||
|
||||
<Button type="dashed" onClick={() => add()} block>
|
||||
+ Add Item
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
<Button type="dashed" onClick={handleAdd} block>
|
||||
+ Add Item
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
</Form.List>
|
||||
|
||||
<Form.Item noStyle shouldUpdate>
|
||||
|
||||
Reference in New Issue
Block a user