diff --git a/web/src/pages/agent/form/begin-form/index.tsx b/web/src/pages/agent/form/begin-form/index.tsx index 49c12601c..507752ea0 100644 --- a/web/src/pages/agent/form/begin-form/index.tsx +++ b/web/src/pages/agent/form/begin-form/index.tsx @@ -17,7 +17,7 @@ import { useTranslation } from 'react-i18next'; import { AgentDialogueMode } from '../../constant'; import { INextOperatorForm } from '../../interface'; import { ParameterDialog } from './parameter-dialog'; -import QueryTable from './query-table'; +import { QueryTable } from './query-table'; import { useEditQueryRecord } from './use-edit-query'; const ModeOptions = buildSelectOptions([ diff --git a/web/src/pages/agent/form/begin-form/query-table.tsx b/web/src/pages/agent/form/begin-form/query-table.tsx index 445cf201d..90bc23acc 100644 --- a/web/src/pages/agent/form/begin-form/query-table.tsx +++ b/web/src/pages/agent/form/begin-form/query-table.tsx @@ -1,9 +1,38 @@ -import { DeleteOutlined, EditOutlined } from '@ant-design/icons'; -import type { TableProps } from 'antd'; -import { Collapse, Space, Table, Tooltip } from 'antd'; -import { BeginQuery } from '../../interface'; +'use client'; +import { + ColumnDef, + ColumnFiltersState, + SortingState, + VisibilityState, + flexRender, + getCoreRowModel, + getFilteredRowModel, + getPaginationRowModel, + getSortedRowModel, + useReactTable, +} from '@tanstack/react-table'; +import { Pencil, Trash2 } from 'lucide-react'; +import * as React from 'react'; + +import { TableEmpty } from '@/components/table-skeleton'; +import { Button } from '@/components/ui/button'; +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, +} from '@/components/ui/table'; +import { + Tooltip, + TooltipContent, + TooltipTrigger, +} from '@/components/ui/tooltip'; +import { cn } from '@/lib/utils'; import { useTranslation } from 'react-i18next'; +import { BeginQuery } from '../../interface'; interface IProps { data: BeginQuery[]; @@ -11,80 +40,150 @@ interface IProps { showModal(index: number, record: BeginQuery): void; } -const QueryTable = ({ data, deleteRecord, showModal }: IProps) => { +export function QueryTable({ data, deleteRecord, showModal }: IProps) { const { t } = useTranslation(); - const columns: TableProps['columns'] = [ + const [sorting, setSorting] = React.useState([]); + const [columnFilters, setColumnFilters] = React.useState( + [], + ); + const [columnVisibility, setColumnVisibility] = + React.useState({}); + + const columns: ColumnDef[] = [ { - title: 'Key', - dataIndex: 'key', - key: 'key', - ellipsis: { - showTitle: false, + accessorKey: 'key', + header: 'key', + meta: { cellClassName: 'max-w-16' }, + cell: ({ row }) => { + const key: string = row.getValue('key'); + return ( + + +
{key}
+
+ +

{key}

+
+
+ ); }, - render: (key) => ( - - {key} - - ), }, { - title: t('flow.name'), - dataIndex: 'name', - key: 'name', - ellipsis: { - showTitle: false, + accessorKey: 'name', + header: t('flow.name'), + meta: { cellClassName: 'max-w-20' }, + cell: ({ row }) => { + const name: string = row.getValue('name'); + return ( + + +
{name}
+
+ +

{name}

+
+
+ ); }, - render: (name) => ( - - {name} - - ), }, { - title: t('flow.type'), - dataIndex: 'type', - key: 'type', + accessorKey: 'type', + header: t('flow.type'), + cell: ({ row }) =>
{row.getValue('type')}
, }, { - title: t('flow.optional'), - dataIndex: 'optional', - key: 'optional', - render: (optional) => (optional ? 'Yes' : 'No'), + accessorKey: 'optional', + header: t('flow.optional'), + cell: ({ row }) =>
{row.getValue('optional') ? 'Yes' : 'No'}
, }, { - title: t('common.action'), - key: 'action', - render: (_, record, idx) => ( - - showModal(idx, record)} /> - deleteRecord(idx)} - /> - - ), + id: 'actions', + enableHiding: false, + header: t('common.action'), + cell: ({ row }) => { + const record = row.original; + const idx = row.index; + + return ( +
+ + +
+ ); + }, }, ]; - return ( - {t('flow.input')}, - children: ( - - columns={columns} - dataSource={data} - pagination={false} - /> - ), - }, - ]} - /> - ); -}; + const table = useReactTable({ + data, + columns, + onSortingChange: setSorting, + onColumnFiltersChange: setColumnFilters, + getCoreRowModel: getCoreRowModel(), + getPaginationRowModel: getPaginationRowModel(), + getSortedRowModel: getSortedRowModel(), + getFilteredRowModel: getFilteredRowModel(), + onColumnVisibilityChange: setColumnVisibility, + state: { + sorting, + columnFilters, + columnVisibility, + }, + }); -export default QueryTable; + return ( +
+
+ + + {table.getHeaderGroups().map((headerGroup) => ( + + {headerGroup.headers.map((header) => { + return ( + + {header.isPlaceholder + ? null + : flexRender( + header.column.columnDef.header, + header.getContext(), + )} + + ); + })} + + ))} + + + {table.getRowModel().rows?.length ? ( + table.getRowModel().rows.map((row) => ( + + {row.getVisibleCells().map((cell) => ( + + {flexRender( + cell.column.columnDef.cell, + cell.getContext(), + )} + + ))} + + )) + ) : ( + + )} + +
+
+
+ ); +}