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:
balibabu 2024-06-28 11:40:21 +08:00 committed by GitHub
parent 89004f1faf
commit 0acf4194ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 5 deletions

View File

@ -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']),
)}

View File

@ -17,9 +17,20 @@ const excludedNodes = [Operator.Categorize, Operator.Answer, Operator.Begin];
export const useBuildCategorizeToOptions = () => {
const nodes = useGraphStore((state) => state.nodes);
const buildCategorizeToOptions = useCallback(
(toList: string[]) => {
return nodes
.filter((x) => excludedNodes.every((y) => y !== x.data.label))
.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;
};
/**