From c93e0355c3bce1db9d1fdcc92670a240799cd4e2 Mon Sep 17 00:00:00 2001 From: balibabu Date: Fri, 29 Nov 2024 16:05:46 +0800 Subject: [PATCH] Feat: Add DatasetTable #3221 (#3743) ### What problem does this PR solve? Feat: Add DatasetTable #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality) --- web/src/components/ui/switch.tsx | 4 +- web/src/layouts/next.tsx | 2 +- .../pages/dataset/dataset/dataset-table.tsx | 208 ++++++++++-------- web/src/pages/dataset/index.tsx | 2 +- web/src/pages/dataset/sidebar/index.tsx | 11 +- web/tailwind.config.js | 1 + web/tailwind.css | 2 + 7 files changed, 132 insertions(+), 98 deletions(-) diff --git a/web/src/components/ui/switch.tsx b/web/src/components/ui/switch.tsx index fa53e7cd429..9c523adabfc 100644 --- a/web/src/components/ui/switch.tsx +++ b/web/src/components/ui/switch.tsx @@ -11,7 +11,7 @@ const Switch = React.forwardRef< >(({ className, ...props }, ref) => ( diff --git a/web/src/layouts/next.tsx b/web/src/layouts/next.tsx index a4fbef17dab..d92a3ff0712 100644 --- a/web/src/layouts/next.tsx +++ b/web/src/layouts/next.tsx @@ -3,7 +3,7 @@ import { Header } from './next-header'; export default function NextLayout() { return ( -
+
diff --git a/web/src/pages/dataset/dataset/dataset-table.tsx b/web/src/pages/dataset/dataset/dataset-table.tsx index bc9dd95010e..3856a287206 100644 --- a/web/src/pages/dataset/dataset/dataset-table.tsx +++ b/web/src/pages/dataset/dataset/dataset-table.tsx @@ -12,7 +12,7 @@ import { getSortedRowModel, useReactTable, } from '@tanstack/react-table'; -import { ArrowUpDown, MoreHorizontal } from 'lucide-react'; +import { ArrowUpDown, MoreHorizontal, Pencil } from 'lucide-react'; import * as React from 'react'; import { Button } from '@/components/ui/button'; @@ -25,6 +25,7 @@ import { DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; +import { Switch } from '@/components/ui/switch'; import { Table, TableBody, @@ -35,6 +36,7 @@ import { } from '@/components/ui/table'; import { RunningStatus } from '@/constants/knowledge'; import { IDocumentInfo } from '@/interfaces/database/document'; +import { useTranslation } from 'react-i18next'; const data: IDocumentInfo[] = [ { @@ -68,97 +70,6 @@ const data: IDocumentInfo[] = [ }, ]; -export const columns: ColumnDef[] = [ - { - id: 'select', - header: ({ table }) => ( - table.toggleAllPageRowsSelected(!!value)} - aria-label="Select all" - /> - ), - cell: ({ row }) => ( - row.toggleSelected(!!value)} - aria-label="Select row" - /> - ), - enableSorting: false, - enableHiding: false, - }, - { - accessorKey: 'status', - header: 'Status', - cell: ({ row }) => ( -
{row.getValue('status')}
- ), - }, - { - accessorKey: 'email', - header: ({ column }) => { - return ( - - ); - }, - cell: ({ row }) =>
{row.getValue('email')}
, - }, - { - accessorKey: 'amount', - header: () =>
Amount
, - cell: ({ row }) => { - const amount = parseFloat(row.getValue('amount')); - - // Format the amount as a dollar amount - const formatted = new Intl.NumberFormat('en-US', { - style: 'currency', - currency: 'USD', - }).format(amount); - - return
{formatted}
; - }, - }, - { - id: 'actions', - enableHiding: false, - cell: ({ row }) => { - const payment = row.original; - - return ( - - - - - - Actions - navigator.clipboard.writeText(payment.id)} - > - Copy payment ID - - - View customer - View payment details - - - ); - }, - }, -]; - export function DatasetTable() { const [sorting, setSorting] = React.useState([]); const [columnFilters, setColumnFilters] = React.useState( @@ -167,6 +78,119 @@ export function DatasetTable() { const [columnVisibility, setColumnVisibility] = React.useState({}); const [rowSelection, setRowSelection] = React.useState({}); + const { t } = useTranslation('translation', { + keyPrefix: 'knowledgeDetails', + }); + + const columns: ColumnDef[] = [ + { + id: 'select', + header: ({ table }) => ( + table.toggleAllPageRowsSelected(!!value)} + aria-label="Select all" + /> + ), + cell: ({ row }) => ( + row.toggleSelected(!!value)} + aria-label="Select row" + /> + ), + enableSorting: false, + enableHiding: false, + }, + { + accessorKey: 'name', + header: ({ column }) => { + return ( + + ); + }, + cell: ({ row }) => ( +
{row.getValue('name')}
+ ), + }, + { + accessorKey: 'create_time', + header: ({ column }) => { + return ( + + ); + }, + cell: ({ row }) => ( +
{row.getValue('create_time')}
+ ), + }, + { + accessorKey: 'parser_id', + header: t('chunkMethod'), + cell: ({ row }) => ( +
{row.getValue('parser_id')}
+ ), + }, + { + accessorKey: 'run', + header: t('parsingStatus'), + cell: ({ row }) => ( + + ), + }, + { + id: 'actions', + header: t('action'), + enableHiding: false, + cell: ({ row }) => { + const payment = row.original; + + return ( +
+ + + + + + + + Actions + navigator.clipboard.writeText(payment.id)} + > + Copy payment ID + + + View customer + View payment details + + +
+ ); + }, + }, + ]; const table = useReactTable({ data, diff --git a/web/src/pages/dataset/index.tsx b/web/src/pages/dataset/index.tsx index 7090b049b2e..d79abb76160 100644 --- a/web/src/pages/dataset/index.tsx +++ b/web/src/pages/dataset/index.tsx @@ -3,7 +3,7 @@ import { SideBar } from './sidebar'; export default function DatasetWrapper() { return ( -
+
diff --git a/web/src/pages/dataset/sidebar/index.tsx b/web/src/pages/dataset/sidebar/index.tsx index 2fb76f97255..e3711bc384b 100644 --- a/web/src/pages/dataset/sidebar/index.tsx +++ b/web/src/pages/dataset/sidebar/index.tsx @@ -2,7 +2,7 @@ import { Button } from '@/components/ui/button'; import { KnowledgeRouteKey } from '@/constants/knowledge'; import { useSecondPathName } from '@/hooks/route-hook'; import { cn } from '@/lib/utils'; -import { Banknote, LayoutGrid, User } from 'lucide-react'; +import { Banknote, LayoutGrid, Trash2, User } from 'lucide-react'; import { useHandleMenuClick } from './hooks'; const items = [ @@ -29,7 +29,7 @@ export function SideBar() { const { handleMenuClick } = useHandleMenuClick(); return ( -