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-variables.tsx 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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, Collapse, Flex, Input, Select, Table, TableProps } from 'antd';
  5. import { trim } from 'lodash';
  6. import { useBuildVariableOptions } from '../../hooks/use-get-begin-query';
  7. import { IInvokeVariable } from '../../interface';
  8. import { useHandleOperateParameters } from './hooks';
  9. import { RAGFlowNodeType } from '@/interfaces/database/flow';
  10. import styles from './index.less';
  11. interface IProps {
  12. node?: RAGFlowNodeType;
  13. }
  14. const components = {
  15. body: {
  16. row: EditableRow,
  17. cell: EditableCell,
  18. },
  19. };
  20. const DynamicVariablesForm = ({ node }: IProps) => {
  21. const nodeId = node?.id;
  22. const { t } = useTranslate('flow');
  23. const options = useBuildVariableOptions(nodeId, node?.parentId);
  24. const {
  25. dataSource,
  26. handleAdd,
  27. handleRemove,
  28. handleSave,
  29. handleComponentIdChange,
  30. handleValueChange,
  31. } = useHandleOperateParameters(nodeId!);
  32. const columns: TableProps<IInvokeVariable>['columns'] = [
  33. {
  34. title: t('key'),
  35. dataIndex: 'key',
  36. key: 'key',
  37. onCell: (record: IInvokeVariable) => ({
  38. record,
  39. editable: true,
  40. dataIndex: 'key',
  41. title: 'key',
  42. handleSave,
  43. }),
  44. },
  45. {
  46. title: t('componentId'),
  47. dataIndex: 'component_id',
  48. key: 'component_id',
  49. align: 'center',
  50. width: 140,
  51. render(text, record) {
  52. return (
  53. <Select
  54. style={{ width: '100%' }}
  55. allowClear
  56. options={options}
  57. value={text}
  58. disabled={trim(record.value) !== ''}
  59. onChange={handleComponentIdChange(record)}
  60. />
  61. );
  62. },
  63. },
  64. {
  65. title: t('value'),
  66. dataIndex: 'value',
  67. key: 'value',
  68. align: 'center',
  69. width: 140,
  70. render(text, record) {
  71. return (
  72. <Input
  73. value={text}
  74. disabled={!!record.component_id}
  75. onChange={handleValueChange(record)}
  76. />
  77. );
  78. },
  79. },
  80. {
  81. title: t('operation'),
  82. dataIndex: 'operation',
  83. width: 20,
  84. key: 'operation',
  85. align: 'center',
  86. fixed: 'right',
  87. render(_, record) {
  88. return <DeleteOutlined onClick={handleRemove(record.id)} />;
  89. },
  90. },
  91. ];
  92. return (
  93. <Collapse
  94. className={styles.dynamicParameterVariable}
  95. defaultActiveKey={['1']}
  96. items={[
  97. {
  98. key: '1',
  99. label: (
  100. <Flex justify={'space-between'}>
  101. <span className={styles.title}>{t('parameter')}</span>
  102. <Button size="small" onClick={handleAdd}>
  103. {t('add')}
  104. </Button>
  105. </Flex>
  106. ),
  107. children: (
  108. <Table
  109. dataSource={dataSource}
  110. columns={columns}
  111. rowKey={'id'}
  112. components={components}
  113. rowClassName={() => styles.editableRow}
  114. scroll={{ x: true }}
  115. bordered
  116. />
  117. ),
  118. },
  119. ]}
  120. />
  121. );
  122. };
  123. export default DynamicVariablesForm;