balibabu commited on
Commit
b06739e
·
1 Parent(s): 876b2ca

feat: filter out selected values ​​in other to fields from the curren… (#1307)

Browse files

### 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)

web/src/pages/flow/categorize-form/dynamic-categorize.tsx CHANGED
@@ -1,6 +1,7 @@
1
  import { CloseOutlined } from '@ant-design/icons';
2
  import { Button, Card, Form, Input, Select, Typography } from 'antd';
3
  import { useUpdateNodeInternals } from 'reactflow';
 
4
  import { useBuildCategorizeToOptions, useHandleToSelectChange } from './hooks';
5
 
6
  interface IProps {
@@ -10,7 +11,7 @@ interface IProps {
10
  const DynamicCategorize = ({ nodeId }: IProps) => {
11
  const updateNodeInternals = useUpdateNodeInternals();
12
  const form = Form.useFormInstance();
13
- const options = useBuildCategorizeToOptions();
14
  const { handleSelectChange } = useHandleToSelectChange(nodeId);
15
 
16
  return (
@@ -60,7 +61,15 @@ const DynamicCategorize = ({ nodeId }: IProps) => {
60
  <Form.Item label="to" name={[field.name, 'to']}>
61
  <Select
62
  allowClear
63
- options={options}
 
 
 
 
 
 
 
 
64
  onChange={handleSelectChange(
65
  form.getFieldValue(['items', field.name, 'name']),
66
  )}
 
1
  import { CloseOutlined } from '@ant-design/icons';
2
  import { Button, Card, Form, Input, Select, Typography } from 'antd';
3
  import { useUpdateNodeInternals } from 'reactflow';
4
+ import { ICategorizeItem } from '../interface';
5
  import { useBuildCategorizeToOptions, useHandleToSelectChange } from './hooks';
6
 
7
  interface IProps {
 
11
  const DynamicCategorize = ({ nodeId }: IProps) => {
12
  const updateNodeInternals = useUpdateNodeInternals();
13
  const form = Form.useFormInstance();
14
+ const buildCategorizeToOptions = useBuildCategorizeToOptions();
15
  const { handleSelectChange } = useHandleToSelectChange(nodeId);
16
 
17
  return (
 
61
  <Form.Item label="to" name={[field.name, 'to']}>
62
  <Select
63
  allowClear
64
+ options={buildCategorizeToOptions(
65
+ (form.getFieldValue(['items']) ?? [])
66
+ .map((x: ICategorizeItem) => x.to)
67
+ .filter(
68
+ (x: string) =>
69
+ x !==
70
+ form.getFieldValue(['items', field.name, 'to']),
71
+ ),
72
+ )}
73
  onChange={handleSelectChange(
74
  form.getFieldValue(['items', field.name, 'name']),
75
  )}
web/src/pages/flow/categorize-form/hooks.ts CHANGED
@@ -17,9 +17,20 @@ const excludedNodes = [Operator.Categorize, Operator.Answer, Operator.Begin];
17
  export const useBuildCategorizeToOptions = () => {
18
  const nodes = useGraphStore((state) => state.nodes);
19
 
20
- return nodes
21
- .filter((x) => excludedNodes.every((y) => y !== x.data.label))
22
- .map((x) => ({ label: x.id, value: x.id }));
 
 
 
 
 
 
 
 
 
 
 
23
  };
24
 
25
  /**
 
17
  export const useBuildCategorizeToOptions = () => {
18
  const nodes = useGraphStore((state) => state.nodes);
19
 
20
+ const buildCategorizeToOptions = useCallback(
21
+ (toList: string[]) => {
22
+ return nodes
23
+ .filter(
24
+ (x) =>
25
+ excludedNodes.every((y) => y !== x.data.label) &&
26
+ !toList.some((y) => y === x.id), // filter out selected values ​​in other to fields from the current drop-down box options
27
+ )
28
+ .map((x) => ({ label: x.id, value: x.id }));
29
+ },
30
+ [nodes],
31
+ );
32
+
33
+ return buildCategorizeToOptions;
34
  };
35
 
36
  /**