import { DeleteOutlined } from '@ant-design/icons'; import { Button, Col, Divider, Form, Input, Row, Select, Switch, Table, TableProps, } from 'antd'; import classNames from 'classnames'; import { useState } from 'react'; import { v4 as uuid } from 'uuid'; import { EditableCell, EditableRow } from './editable-cell'; import { ISegmentedContentProps } from './interface'; import styles from './index.less'; interface DataType { key: string; optional: boolean; } const { Option } = Select; const PromptEngine = ({ show }: ISegmentedContentProps) => { const [dataSource, setDataSource] = useState([]); const components = { body: { row: EditableRow, cell: EditableCell, }, }; const handleRemove = (key: string) => () => { const newData = dataSource.filter((item) => item.key !== key); setDataSource(newData); }; const handleSave = (row: DataType) => { const newData = [...dataSource]; const index = newData.findIndex((item) => row.key === item.key); const item = newData[index]; newData.splice(index, 1, { ...item, ...row, }); setDataSource(newData); }; const columns: TableProps['columns'] = [ { title: 'key', dataIndex: 'variable', key: 'variable', onCell: (record: DataType) => ({ record, editable: true, dataIndex: 'variable', title: 'key', handleSave, }), }, { title: 'optional', dataIndex: 'optional', key: 'optional', width: 40, align: 'center', render() { return ; }, }, { title: 'operation', dataIndex: 'operation', width: 30, key: 'operation', align: 'center', render(_, record) { return ; }, }, ]; const handleAdd = () => { setDataSource((state) => [ ...state, { key: uuid(), variable: '', optional: true, }, ]); }; return (
{dataSource.length > 0 && ( styles.editableRow} /> )} ); }; export default PromptEngine;