Skip to main content
Glama
data-table.tsx4.41 kB
"use client" import { Skeleton } from "@repo/ui/components/ui/skeleton" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@repo/ui/components/ui/table" import { type ColumnDef, type ColumnFiltersState, flexRender, getCoreRowModel, getFacetedRowModel, getFacetedUniqueValues, getFilteredRowModel, getPaginationRowModel, getSortedRowModel, type SortingState, useReactTable, type VisibilityState, } from "@tanstack/react-table" import * as React from "react" import { DataTablePagination } from "./data-table-pagination" // import { DataTableToolbar } from "./data-table-toolbar" interface DataTableProps<TData, TValue> { columns: ColumnDef<TData, TValue>[] data: TData[] loading?: boolean pagination?: { page: number limit: number total: number onPageChange: (page: number) => void } } export function DataTable<TData, TValue>({ columns, data, loading = false, pagination, }: DataTableProps<TData, TValue>) { const [rowSelection, setRowSelection] = React.useState({}) const [columnVisibility, setColumnVisibility] = React.useState<VisibilityState>({}) const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>( [] ) const [sorting, setSorting] = React.useState<SortingState>([]) const table = useReactTable({ data, columns, state: { sorting, columnVisibility, rowSelection, columnFilters, }, enableRowSelection: true, onRowSelectionChange: setRowSelection, onSortingChange: setSorting, onColumnFiltersChange: setColumnFilters, onColumnVisibilityChange: setColumnVisibility, getCoreRowModel: getCoreRowModel(), getFilteredRowModel: getFilteredRowModel(), getPaginationRowModel: getPaginationRowModel(), getSortedRowModel: getSortedRowModel(), getFacetedRowModel: getFacetedRowModel(), getFacetedUniqueValues: getFacetedUniqueValues(), }) return ( <div className="space-y-4"> {/* <DataTableToolbar table={table} /> */} <div className="rounded-md border"> <Table> <TableHeader> {table.getHeaderGroups().map((headerGroup) => ( <TableRow key={headerGroup.id}> {headerGroup.headers.map((header) => { return ( <TableHead key={header.id} colSpan={header.colSpan}> {header.isPlaceholder ? null : flexRender( header.column.columnDef.header, header.getContext() )} </TableHead> ) })} </TableRow> ))} </TableHeader> <TableBody> {loading ? ( // 骨架屏 Array.from({ length: 5 }).map((_, index) => ( <TableRow key={index}> {columns.map((_, colIndex) => ( <TableCell key={colIndex}> <Skeleton className="h-6 w-full" /> </TableCell> ))} </TableRow> )) ) : table.getRowModel().rows?.length ? ( table.getRowModel().rows.map((row) => ( <TableRow key={row.id} data-state={row.getIsSelected() && "selected"} > {row.getVisibleCells().map((cell) => ( <TableCell key={cell.id}> {flexRender( cell.column.columnDef.cell, cell.getContext() )} </TableCell> ))} </TableRow> )) ) : ( <TableRow> <TableCell colSpan={columns.length} className="h-24 text-center" > 暂无数据 </TableCell> </TableRow> )} </TableBody> </Table> </div> {pagination && ( <DataTablePagination table={table} total={pagination.total} page={pagination.page} limit={pagination.limit} onPageChange={pagination.onPageChange} /> )} </div> ) }

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/metacode0602/open-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server