balibabu commited on
Commit
8aa83b1
·
1 Parent(s): eb002c7

feat: Build options for the component id field of the Switch operator #1739 (#2037)

Browse files

### What problem does this PR solve?

feat: Build options for the component id field of the Switch operator
#1739

### Type of change


- [x] New Feature (non-breaking change which adds functionality)

web/src/assets/svg/switch.svg CHANGED
web/src/locales/en.ts CHANGED
@@ -603,7 +603,7 @@ The above is the content you need to summarize.`,
603
  yes: 'Yes',
604
  no: 'No',
605
  key: 'key',
606
- componentId: 'component id',
607
  add: 'Add',
608
  operation: 'operation',
609
  run: 'Run',
@@ -637,6 +637,7 @@ The above is the content you need to summarize.`,
637
  blank: 'Blank',
638
  createFromNothing: 'Create from nothing',
639
  addItem: 'Add Item',
 
640
  nameRequiredMsg: 'Name is required',
641
  nameRepeatedMsg: 'The name cannot be repeated',
642
  keywordExtract: 'Keyword',
@@ -833,6 +834,8 @@ The above is the content you need to summarize.`,
833
  and: 'And',
834
  or: 'Or',
835
  },
 
 
836
  },
837
  footer: {
838
  profile: 'All rights reserved @ React',
 
603
  yes: 'Yes',
604
  no: 'No',
605
  key: 'key',
606
+ componentId: 'Component ID',
607
  add: 'Add',
608
  operation: 'operation',
609
  run: 'Run',
 
637
  blank: 'Blank',
638
  createFromNothing: 'Create from nothing',
639
  addItem: 'Add Item',
640
+ addSubItem: 'Add Sub Item',
641
  nameRequiredMsg: 'Name is required',
642
  nameRepeatedMsg: 'The name cannot be repeated',
643
  keywordExtract: 'Keyword',
 
834
  and: 'And',
835
  or: 'Or',
836
  },
837
+ operator: 'Operator',
838
+ value: 'Value',
839
  },
840
  footer: {
841
  profile: 'All rights reserved @ React',
web/src/locales/zh-traditional.ts CHANGED
@@ -597,6 +597,7 @@ export default {
597
  blank: '空',
598
  createFromNothing: '從無到有',
599
  addItem: '新增',
 
600
  nameRequiredMsg: '名稱不能為空',
601
  nameRepeatedMsg: '名稱不能重複',
602
  keywordExtract: '關鍵字',
@@ -791,6 +792,8 @@ export default {
791
  and: '與',
792
  or: '或',
793
  },
 
 
794
  },
795
  footer: {
796
  profile: '“保留所有權利 @ react”',
 
597
  blank: '空',
598
  createFromNothing: '從無到有',
599
  addItem: '新增',
600
+ addSubItem: '新增子項',
601
  nameRequiredMsg: '名稱不能為空',
602
  nameRepeatedMsg: '名稱不能重複',
603
  keywordExtract: '關鍵字',
 
792
  and: '與',
793
  or: '或',
794
  },
795
+ operator: '操作符',
796
+ value: '值',
797
  },
798
  footer: {
799
  profile: '“保留所有權利 @ react”',
web/src/locales/zh.ts CHANGED
@@ -615,6 +615,7 @@ export default {
615
  blank: '空',
616
  createFromNothing: '从无到有',
617
  addItem: '新增',
 
618
  nameRequiredMsg: '名称不能为空',
619
  nameRepeatedMsg: '名称不能重复',
620
  keywordExtract: '关键词',
@@ -809,6 +810,8 @@ export default {
809
  and: '与',
810
  or: '或',
811
  },
 
 
812
  },
813
  footer: {
814
  profile: 'All rights reserved @ React',
 
615
  blank: '空',
616
  createFromNothing: '从无到有',
617
  addItem: '新增',
618
+ addSubItem: '新增子项',
619
  nameRequiredMsg: '名称不能为空',
620
  nameRepeatedMsg: '名称不能重复',
621
  keywordExtract: '关键词',
 
810
  and: '与',
811
  or: '或',
812
  },
813
+ operator: '操作符',
814
+ value: '值',
815
  },
816
  footer: {
817
  profile: 'All rights reserved @ React',
web/src/pages/flow/canvas/node/relevant-node.tsx CHANGED
@@ -45,8 +45,8 @@ export function RelevantNode({ id, data, selected }: NodeProps<NodeData>) {
45
  className={styles.handle}
46
  id={'c'}
47
  ></Handle>
48
- <CategorizeHandle top={20} right={6} text={'yes'}></CategorizeHandle>
49
- <CategorizeHandle top={80} right={6} text={'no'}></CategorizeHandle>
50
  <Flex vertical align="center" justify="center" gap={0}>
51
  <Flex flex={1}>
52
  <OperatorIcon
 
45
  className={styles.handle}
46
  id={'c'}
47
  ></Handle>
48
+ <CategorizeHandle top={20} right={6} id={'yes'}></CategorizeHandle>
49
+ <CategorizeHandle top={80} right={6} id={'no'}></CategorizeHandle>
50
  <Flex vertical align="center" justify="center" gap={0}>
51
  <Flex flex={1}>
52
  <OperatorIcon
web/src/pages/flow/constant.tsx CHANGED
@@ -97,7 +97,7 @@ export const operatorMap: Record<
97
  fontSize?: number;
98
  iconFontSize?: number;
99
  iconWidth?: number;
100
- moreIconColor?: number;
101
  }
102
  > = {
103
  [Operator.Retrieval]: {
 
97
  fontSize?: number;
98
  iconFontSize?: number;
99
  iconWidth?: number;
100
+ moreIconColor?: string;
101
  }
102
  > = {
103
  [Operator.Retrieval]: {
web/src/pages/flow/generate-form/dynamic-parameters.tsx CHANGED
@@ -4,10 +4,8 @@ import { DeleteOutlined } from '@ant-design/icons';
4
  import { Button, Flex, Select, Table, TableProps } from 'antd';
5
  import { IGenerateParameter } from '../interface';
6
 
7
- import {
8
- useBuildComponentIdSelectOptions,
9
- useHandleOperateParameters,
10
- } from './hooks';
11
  import styles from './index.less';
12
 
13
  interface IProps {
 
4
  import { Button, Flex, Select, Table, TableProps } from 'antd';
5
  import { IGenerateParameter } from '../interface';
6
 
7
+ import { useBuildComponentIdSelectOptions } from '../hooks';
8
+ import { useHandleOperateParameters } from './hooks';
 
 
9
  import styles from './index.less';
10
 
11
  interface IProps {
web/src/pages/flow/generate-form/hooks.ts CHANGED
@@ -1,33 +1,9 @@
1
  import get from 'lodash/get';
2
  import { useCallback, useMemo } from 'react';
3
  import { v4 as uuid } from 'uuid';
4
- import { Operator } from '../constant';
5
  import { IGenerateParameter } from '../interface';
6
  import useGraphStore from '../store';
7
 
8
- // exclude nodes with branches
9
- const ExcludedNodes = [
10
- Operator.Categorize,
11
- Operator.Relevant,
12
- Operator.Begin,
13
- Operator.Answer,
14
- ];
15
-
16
- export const useBuildComponentIdSelectOptions = (nodeId?: string) => {
17
- const nodes = useGraphStore((state) => state.nodes);
18
-
19
- const options = useMemo(() => {
20
- return nodes
21
- .filter(
22
- (x) =>
23
- x.id !== nodeId && !ExcludedNodes.some((y) => y === x.data.label),
24
- )
25
- .map((x) => ({ label: x.data.name, value: x.id }));
26
- }, [nodes, nodeId]);
27
-
28
- return options;
29
- };
30
-
31
  export const useHandleOperateParameters = (nodeId: string) => {
32
  const { getNode, updateNodeForm } = useGraphStore((state) => state);
33
  const node = getNode(nodeId);
 
1
  import get from 'lodash/get';
2
  import { useCallback, useMemo } from 'react';
3
  import { v4 as uuid } from 'uuid';
 
4
  import { IGenerateParameter } from '../interface';
5
  import useGraphStore from '../store';
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  export const useHandleOperateParameters = (nodeId: string) => {
8
  const { getNode, updateNodeForm } = useGraphStore((state) => state);
9
  const node = getNode(nodeId);
web/src/pages/flow/hooks.ts CHANGED
@@ -563,3 +563,26 @@ export const useWatchNodeFormDataChange = () => {
563
  buildSwitchEdgesByFormData,
564
  ]);
565
  };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
563
  buildSwitchEdgesByFormData,
564
  ]);
565
  };
566
+
567
+ // exclude nodes with branches
568
+ const ExcludedNodes = [
569
+ Operator.Categorize,
570
+ Operator.Relevant,
571
+ Operator.Begin,
572
+ Operator.Answer,
573
+ ];
574
+
575
+ export const useBuildComponentIdSelectOptions = (nodeId?: string) => {
576
+ const nodes = useGraphStore((state) => state.nodes);
577
+
578
+ const options = useMemo(() => {
579
+ return nodes
580
+ .filter(
581
+ (x) =>
582
+ x.id !== nodeId && !ExcludedNodes.some((y) => y === x.data.label),
583
+ )
584
+ .map((x) => ({ label: x.data.name, value: x.id }));
585
+ }, [nodes, nodeId]);
586
+
587
+ return options;
588
+ };
web/src/pages/flow/switch-form/index.tsx CHANGED
@@ -9,15 +9,16 @@ import {
9
  SwitchOperatorOptions,
10
  } from '../constant';
11
  import { useBuildFormSelectOptions } from '../form-hooks';
 
12
  import { IOperatorForm, ISwitchForm } from '../interface';
13
  import { getOtherFieldValues } from '../utils';
14
 
15
  const subLabelCol = {
16
- span: 7,
17
  };
18
 
19
  const subWrapperCol = {
20
- span: 17,
21
  };
22
 
23
  const SwitchForm = ({ onValuesChange, node, form }: IOperatorForm) => {
@@ -48,10 +49,12 @@ const SwitchForm = ({ onValuesChange, node, form }: IOperatorForm) => {
48
  }));
49
  }, [t]);
50
 
 
 
51
  return (
52
  <Form
53
- labelCol={{ span: 8 }}
54
- wrapperCol={{ span: 16 }}
55
  form={form}
56
  name="dynamic_form_complex"
57
  autoComplete="off"
@@ -102,7 +105,7 @@ const SwitchForm = ({ onValuesChange, node, form }: IOperatorForm) => {
102
  ])}
103
  />
104
  </Form.Item>
105
- <Form.Item label="Items">
106
  <Form.List name={[field.name, 'items']}>
107
  {(subFields, subOpt) => (
108
  <div
@@ -126,31 +129,34 @@ const SwitchForm = ({ onValuesChange, node, form }: IOperatorForm) => {
126
  }
127
  >
128
  <Form.Item
129
- label={'cpn_id'}
130
  name={[subField.name, 'cpn_id']}
131
  labelCol={subLabelCol}
132
  wrapperCol={subWrapperCol}
133
  >
134
- <Input placeholder="cpn_id" />
 
 
 
135
  </Form.Item>
136
  <Form.Item
137
- label={'operator'}
138
  name={[subField.name, 'operator']}
139
  labelCol={subLabelCol}
140
  wrapperCol={subWrapperCol}
141
  >
142
  <Select
143
- placeholder="operator"
144
  options={switchOperatorOptions}
145
  />
146
  </Form.Item>
147
  <Form.Item
148
- label={'value'}
149
  name={[subField.name, 'value']}
150
  labelCol={subLabelCol}
151
  wrapperCol={subWrapperCol}
152
  >
153
- <Input placeholder="value" />
154
  </Form.Item>
155
  </Card>
156
  ))}
@@ -159,7 +165,7 @@ const SwitchForm = ({ onValuesChange, node, form }: IOperatorForm) => {
159
  onClick={() => subOpt.add()}
160
  block
161
  >
162
- + Add Sub Item
163
  </Button>
164
  </div>
165
  )}
@@ -169,7 +175,7 @@ const SwitchForm = ({ onValuesChange, node, form }: IOperatorForm) => {
169
  ))}
170
 
171
  <Button type="dashed" onClick={() => add()} block>
172
- + Add Item
173
  </Button>
174
  </div>
175
  )}
 
9
  SwitchOperatorOptions,
10
  } from '../constant';
11
  import { useBuildFormSelectOptions } from '../form-hooks';
12
+ import { useBuildComponentIdSelectOptions } from '../hooks';
13
  import { IOperatorForm, ISwitchForm } from '../interface';
14
  import { getOtherFieldValues } from '../utils';
15
 
16
  const subLabelCol = {
17
+ span: 9,
18
  };
19
 
20
  const subWrapperCol = {
21
+ span: 15,
22
  };
23
 
24
  const SwitchForm = ({ onValuesChange, node, form }: IOperatorForm) => {
 
49
  }));
50
  }, [t]);
51
 
52
+ const componentIdOptions = useBuildComponentIdSelectOptions(node?.id);
53
+
54
  return (
55
  <Form
56
+ labelCol={{ span: 4 }}
57
+ wrapperCol={{ span: 20 }}
58
  form={form}
59
  name="dynamic_form_complex"
60
  autoComplete="off"
 
105
  ])}
106
  />
107
  </Form.Item>
108
+ <Form.Item label=" " colon={false}>
109
  <Form.List name={[field.name, 'items']}>
110
  {(subFields, subOpt) => (
111
  <div
 
129
  }
130
  >
131
  <Form.Item
132
+ label={t('flow.componentId')}
133
  name={[subField.name, 'cpn_id']}
134
  labelCol={subLabelCol}
135
  wrapperCol={subWrapperCol}
136
  >
137
+ <Select
138
+ placeholder={t('flow.componentId')}
139
+ options={componentIdOptions}
140
+ />
141
  </Form.Item>
142
  <Form.Item
143
+ label={t('flow.operator')}
144
  name={[subField.name, 'operator']}
145
  labelCol={subLabelCol}
146
  wrapperCol={subWrapperCol}
147
  >
148
  <Select
149
+ placeholder={t('flow.operator')}
150
  options={switchOperatorOptions}
151
  />
152
  </Form.Item>
153
  <Form.Item
154
+ label={t('flow.value')}
155
  name={[subField.name, 'value']}
156
  labelCol={subLabelCol}
157
  wrapperCol={subWrapperCol}
158
  >
159
+ <Input placeholder={t('flow.value')} />
160
  </Form.Item>
161
  </Card>
162
  ))}
 
165
  onClick={() => subOpt.add()}
166
  block
167
  >
168
+ + {t('flow.addSubItem')}
169
  </Button>
170
  </div>
171
  )}
 
175
  ))}
176
 
177
  <Button type="dashed" onClick={() => add()} block>
178
+ + {t('flow.addItem')}
179
  </Button>
180
  </div>
181
  )}