Skip to content

Commit

Permalink
feat: filter out selected values ​​in other to fields from the curren… (
Browse files Browse the repository at this point in the history
#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)
  • Loading branch information
cike8899 authored Jun 28, 2024
1 parent 89004f1 commit 0acf419
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
13 changes: 11 additions & 2 deletions web/src/pages/flow/categorize-form/dynamic-categorize.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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 (
Expand Down Expand Up @@ -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']),
)}
Expand Down
17 changes: 14 additions & 3 deletions web/src/pages/flow/categorize-form/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

/**
Expand Down

0 comments on commit 0acf419

Please sign in to comment.