mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-08-13 18:36:01 +08:00
feat: filter out selected values in other to fields from the curren… (#1307)
### What problem does this PR solve? feat: filter out selected values in other to fields from the current drop-down box options #918 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
parent
89004f1faf
commit
0acf4194ca
@ -1,6 +1,7 @@
|
||||
import { CloseOutlined } from '@ant-design/icons';
|
||||
import { Button, Card, Form, Input, Select, Typography } from 'antd';
|
||||
import { useUpdateNodeInternals } from 'reactflow';
|
||||
import { ICategorizeItem } from '../interface';
|
||||
import { useBuildCategorizeToOptions, useHandleToSelectChange } from './hooks';
|
||||
|
||||
interface IProps {
|
||||
@ -10,7 +11,7 @@ interface IProps {
|
||||
const DynamicCategorize = ({ nodeId }: IProps) => {
|
||||
const updateNodeInternals = useUpdateNodeInternals();
|
||||
const form = Form.useFormInstance();
|
||||
const options = useBuildCategorizeToOptions();
|
||||
const buildCategorizeToOptions = useBuildCategorizeToOptions();
|
||||
const { handleSelectChange } = useHandleToSelectChange(nodeId);
|
||||
|
||||
return (
|
||||
@ -60,7 +61,15 @@ const DynamicCategorize = ({ nodeId }: IProps) => {
|
||||
<Form.Item label="to" name={[field.name, 'to']}>
|
||||
<Select
|
||||
allowClear
|
||||
options={options}
|
||||
options={buildCategorizeToOptions(
|
||||
(form.getFieldValue(['items']) ?? [])
|
||||
.map((x: ICategorizeItem) => x.to)
|
||||
.filter(
|
||||
(x: string) =>
|
||||
x !==
|
||||
form.getFieldValue(['items', field.name, 'to']),
|
||||
),
|
||||
)}
|
||||
onChange={handleSelectChange(
|
||||
form.getFieldValue(['items', field.name, 'name']),
|
||||
)}
|
||||
|
@ -17,9 +17,20 @@ const excludedNodes = [Operator.Categorize, Operator.Answer, Operator.Begin];
|
||||
export const useBuildCategorizeToOptions = () => {
|
||||
const nodes = useGraphStore((state) => state.nodes);
|
||||
|
||||
return nodes
|
||||
.filter((x) => excludedNodes.every((y) => y !== x.data.label))
|
||||
.map((x) => ({ label: x.id, value: x.id }));
|
||||
const buildCategorizeToOptions = useCallback(
|
||||
(toList: string[]) => {
|
||||
return nodes
|
||||
.filter(
|
||||
(x) =>
|
||||
excludedNodes.every((y) => y !== x.data.label) &&
|
||||
!toList.some((y) => y === x.id), // filter out selected values in other to fields from the current drop-down box options
|
||||
)
|
||||
.map((x) => ({ label: x.id, value: x.id }));
|
||||
},
|
||||
[nodes],
|
||||
);
|
||||
|
||||
return buildCategorizeToOptions;
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user