You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dynamic-parameters.tsx 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { EditableCell, EditableRow } from '@/components/editable-cell';
  2. import { useTranslate } from '@/hooks/common-hooks';
  3. import { DeleteOutlined } from '@ant-design/icons';
  4. import { Button, Flex, Select, Table, TableProps } from 'antd';
  5. import { Node } from 'reactflow';
  6. import { useBuildComponentIdSelectOptions } from '../../hooks/use-get-begin-query';
  7. import { IGenerateParameter, NodeData } from '../../interface';
  8. import { useHandleOperateParameters } from './hooks';
  9. import styles from './index.less';
  10. interface IProps {
  11. node?: Node<NodeData>;
  12. }
  13. const components = {
  14. body: {
  15. row: EditableRow,
  16. cell: EditableCell,
  17. },
  18. };
  19. const DynamicParameters = ({ node }: IProps) => {
  20. const nodeId = node?.id;
  21. const { t } = useTranslate('flow');
  22. const options = useBuildComponentIdSelectOptions(nodeId, node?.parentId);
  23. const {
  24. dataSource,
  25. handleAdd,
  26. handleRemove,
  27. handleSave,
  28. handleComponentIdChange,
  29. } = useHandleOperateParameters(nodeId!);
  30. const columns: TableProps<IGenerateParameter>['columns'] = [
  31. {
  32. title: t('key'),
  33. dataIndex: 'key',
  34. key: 'key',
  35. width: '40%',
  36. onCell: (record: IGenerateParameter) => ({
  37. record,
  38. editable: true,
  39. dataIndex: 'key',
  40. title: 'key',
  41. handleSave,
  42. }),
  43. },
  44. {
  45. title: t('componentId'),
  46. dataIndex: 'component_id',
  47. key: 'component_id',
  48. align: 'center',
  49. width: '40%',
  50. render(text, record) {
  51. return (
  52. <Select
  53. style={{ width: '100%' }}
  54. allowClear
  55. options={options}
  56. value={text}
  57. onChange={handleComponentIdChange(record)}
  58. />
  59. );
  60. },
  61. },
  62. {
  63. title: t('operation'),
  64. dataIndex: 'operation',
  65. width: 20,
  66. key: 'operation',
  67. align: 'center',
  68. fixed: 'right',
  69. render(_, record) {
  70. return <DeleteOutlined onClick={handleRemove(record.id)} />;
  71. },
  72. },
  73. ];
  74. return (
  75. <section>
  76. <Flex justify="end">
  77. <Button size="small" onClick={handleAdd}>
  78. {t('add')}
  79. </Button>
  80. </Flex>
  81. <Table
  82. dataSource={dataSource}
  83. columns={columns}
  84. rowKey={'id'}
  85. className={styles.variableTable}
  86. components={components}
  87. rowClassName={() => styles.editableRow}
  88. scroll={{ x: true }}
  89. bordered
  90. />
  91. </section>
  92. );
  93. };
  94. export default DynamicParameters;