Skip to content

Commit

Permalink
Feat: Add DatasetTable #3221 (#3743)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?

Feat: Add DatasetTable #3221

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
  • Loading branch information
cike8899 authored Nov 29, 2024
1 parent 1e0fc76 commit c93e035
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 98 deletions.
4 changes: 2 additions & 2 deletions web/src/components/ui/switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ const Switch = React.forwardRef<
>(({ className, ...props }, ref) => (
<SwitchPrimitives.Root
className={cn(
'peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input',
'peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-colors-background-core-standard data-[state=unchecked]:bg-colors-background-inverse-standard',
className,
)}
{...props}
ref={ref}
>
<SwitchPrimitives.Thumb
className={cn(
'pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0',
'pointer-events-none block h-5 w-5 rounded-full bg-colors-text-neutral-strong shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0',
)}
/>
</SwitchPrimitives.Root>
Expand Down
2 changes: 1 addition & 1 deletion web/src/layouts/next.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Header } from './next-header';

export default function NextLayout() {
return (
<section>
<section className="h-full flex flex-col">
<Header></Header>
<Outlet />
</section>
Expand Down
208 changes: 116 additions & 92 deletions web/src/pages/dataset/dataset/dataset-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -25,6 +25,7 @@ import {
DropdownMenuSeparator,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
import { Switch } from '@/components/ui/switch';
import {
Table,
TableBody,
Expand All @@ -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[] = [
{
Expand Down Expand Up @@ -68,97 +70,6 @@ const data: IDocumentInfo[] = [
},
];

export const columns: ColumnDef<IDocumentInfo>[] = [
{
id: 'select',
header: ({ table }) => (
<Checkbox
checked={
table.getIsAllPageRowsSelected() ||
(table.getIsSomePageRowsSelected() && 'indeterminate')
}
onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
aria-label="Select all"
/>
),
cell: ({ row }) => (
<Checkbox
checked={row.getIsSelected()}
onCheckedChange={(value) => row.toggleSelected(!!value)}
aria-label="Select row"
/>
),
enableSorting: false,
enableHiding: false,
},
{
accessorKey: 'status',
header: 'Status',
cell: ({ row }) => (
<div className="capitalize">{row.getValue('status')}</div>
),
},
{
accessorKey: 'email',
header: ({ column }) => {
return (
<Button
variant="ghost"
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
>
Email
<ArrowUpDown />
</Button>
);
},
cell: ({ row }) => <div className="lowercase">{row.getValue('email')}</div>,
},
{
accessorKey: 'amount',
header: () => <div className="text-right">Amount</div>,
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 <div className="text-right font-medium">{formatted}</div>;
},
},
{
id: 'actions',
enableHiding: false,
cell: ({ row }) => {
const payment = row.original;

return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" className="h-8 w-8 p-0">
<span className="sr-only">Open menu</span>
<MoreHorizontal />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuLabel>Actions</DropdownMenuLabel>
<DropdownMenuItem
onClick={() => navigator.clipboard.writeText(payment.id)}
>
Copy payment ID
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem>View customer</DropdownMenuItem>
<DropdownMenuItem>View payment details</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
);
},
},
];

export function DatasetTable() {
const [sorting, setSorting] = React.useState<SortingState>([]);
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>(
Expand All @@ -167,6 +78,119 @@ export function DatasetTable() {
const [columnVisibility, setColumnVisibility] =
React.useState<VisibilityState>({});
const [rowSelection, setRowSelection] = React.useState({});
const { t } = useTranslation('translation', {
keyPrefix: 'knowledgeDetails',
});

const columns: ColumnDef<IDocumentInfo>[] = [
{
id: 'select',
header: ({ table }) => (
<Checkbox
checked={
table.getIsAllPageRowsSelected() ||
(table.getIsSomePageRowsSelected() && 'indeterminate')
}
onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
aria-label="Select all"
/>
),
cell: ({ row }) => (
<Checkbox
checked={row.getIsSelected()}
onCheckedChange={(value) => row.toggleSelected(!!value)}
aria-label="Select row"
/>
),
enableSorting: false,
enableHiding: false,
},
{
accessorKey: 'name',
header: ({ column }) => {
return (
<Button
variant="ghost"
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
>
{t('name')}
<ArrowUpDown />
</Button>
);
},
cell: ({ row }) => (
<div className="capitalize">{row.getValue('name')}</div>
),
},
{
accessorKey: 'create_time',
header: ({ column }) => {
return (
<Button
variant="ghost"
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
>
{t('uploadDate')}
<ArrowUpDown />
</Button>
);
},
cell: ({ row }) => (
<div className="lowercase">{row.getValue('create_time')}</div>
),
},
{
accessorKey: 'parser_id',
header: t('chunkMethod'),
cell: ({ row }) => (
<div className="capitalize">{row.getValue('parser_id')}</div>
),
},
{
accessorKey: 'run',
header: t('parsingStatus'),
cell: ({ row }) => (
<Button variant="destructive" size={'sm'}>
{row.getValue('run')}
</Button>
),
},
{
id: 'actions',
header: t('action'),
enableHiding: false,
cell: ({ row }) => {
const payment = row.original;

return (
<section className="flex gap-4 items-center">
<Switch id="airplane-mode" />
<Button variant="secondary" size={'icon'}>
<Pencil />
</Button>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="secondary" size={'icon'}>
<MoreHorizontal />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuLabel>Actions</DropdownMenuLabel>
<DropdownMenuItem
onClick={() => navigator.clipboard.writeText(payment.id)}
>
Copy payment ID
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem>View customer</DropdownMenuItem>
<DropdownMenuItem>View payment details</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</section>
);
},
},
];

const table = useReactTable({
data,
Expand Down
2 changes: 1 addition & 1 deletion web/src/pages/dataset/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SideBar } from './sidebar';

export default function DatasetWrapper() {
return (
<div className="text-foreground flex">
<div className="text-foreground flex flex-1">
<SideBar></SideBar>
<div className="flex-1">
<Outlet />
Expand Down
11 changes: 9 additions & 2 deletions web/src/pages/dataset/sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -29,7 +29,7 @@ export function SideBar() {
const { handleMenuClick } = useHandleMenuClick();

return (
<aside className="w-[303px]">
<aside className="w-[303px] relative">
<div className="p-6 space-y-2 border-b">
<div
className="w-[70px] h-[70px] rounded-xl bg-cover"
Expand Down Expand Up @@ -61,6 +61,13 @@ export function SideBar() {
);
})}
</div>
<Button
variant="outline"
className="absolute bottom-6 left-6 right-6 text-colors-text-functional-danger border-colors-text-functional-danger"
>
<Trash2 />
Delete dataset
</Button>
</aside>
);
}
1 change: 1 addition & 0 deletions web/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = {
'colors-text-core-standard': 'var(--colors-text-core-standard)',
'colors-text-neutral-strong': 'var(--colors-text-neutral-strong)',
'colors-text-neutral-standard': 'var(--colors-text-neutral-standard)',
'colors-text-functional-danger': 'var(--colors-text-functional-danger)',

primary: {
DEFAULT: 'hsl(var(--primary))',
Expand Down
2 changes: 2 additions & 0 deletions web/tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
--colors-text-core-standard: rgba(127, 105, 255, 1);
--colors-text-neutral-strong: rgb(130, 121, 121);
--colors-text-neutral-standard: rgba(230, 227, 246, 1);
--colors-text-functional-danger: rgba(255, 81, 81, 1);
}

.dark {
Expand Down Expand Up @@ -122,6 +123,7 @@
--colors-text-core-standard: rgba(137, 126, 255, 1);
--colors-text-neutral-strong: rgba(255, 255, 255, 1);
--colors-text-neutral-standard: rgba(230, 227, 246, 1);
--colors-text-functional-danger: rgba(255, 81, 81, 1);
}
}

Expand Down

0 comments on commit c93e035

Please sign in to comment.