diff --git a/site/src/components/routes/home.tsx b/site/src/components/routes/home.tsx
index 089fc5e..fc82859 100644
--- a/site/src/components/routes/home.tsx
+++ b/site/src/components/routes/home.tsx
@@ -30,9 +30,9 @@ export function Home() {
return (
<>
-
Dashboard
+ Dashboard
{systems.length && }
- {JSON.stringify(systems, null, 2)}
+ {/* {JSON.stringify(systems, null, 2)}
*/}
>
)
}
diff --git a/site/src/components/server-table/data-table.tsx b/site/src/components/server-table/data-table.tsx
index 467b5ec..e3ec4ae 100644
--- a/site/src/components/server-table/data-table.tsx
+++ b/site/src/components/server-table/data-table.tsx
@@ -1,9 +1,14 @@
import {
CellContext,
ColumnDef,
+ ColumnFiltersState,
+ getFilteredRowModel,
+ SortingState,
+ getSortedRowModel,
flexRender,
getCoreRowModel,
useReactTable,
+ Column,
} from '@tanstack/react-table'
import {
@@ -15,7 +20,22 @@ import {
TableRow,
} from '@/components/ui/table'
+import { Button } from '@/components/ui/button'
+import { Input } from '@/components/ui/input'
+
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuLabel,
+ DropdownMenuSeparator,
+ DropdownMenuTrigger,
+} from '@/components/ui/dropdown-menu'
+
import { SystemRecord } from '@/types'
+import { MoreHorizontal, ArrowUpDown } from 'lucide-react'
+import { Link } from 'wouter-preact'
+import { useState } from 'preact/hooks'
function CellFormatter(info: CellContext) {
const val = info.getValue() as number
@@ -38,74 +58,141 @@ function CellFormatter(info: CellContext) {
)
}
+function sortableHeader(column: Column, name: string) {
+ return (
+
+ )
+}
+
export function DataTable({ data }: { data: SystemRecord[] }) {
- // console.log('data', data)
const columns: ColumnDef[] = [
{
- header: 'Node',
+ size: 40,
accessorKey: 'name',
+ cell: (info) => {info.getValue() as string},
+ header: ({ column }) => sortableHeader(column, 'Node'),
},
{
- header: 'CPU Load',
accessorKey: 'stats.cpu',
cell: CellFormatter,
+ header: ({ column }) => sortableHeader(column, 'CPU'),
},
{
- header: 'RAM',
accessorKey: 'stats.memPct',
cell: CellFormatter,
+ header: ({ column }) => sortableHeader(column, 'Memory'),
},
{
- header: 'Disk Usage',
accessorKey: 'stats.diskPct',
cell: CellFormatter,
+ header: ({ column }) => sortableHeader(column, 'Disk'),
+ },
+ {
+ id: 'actions',
+ size: 32,
+ maxSize: 32,
+ cell: ({ row }) => {
+ const system = row.original
+
+ return (
+
+
+
+
+
+
+ Actions
+
+
+ View details
+
+
+ navigator.clipboard.writeText(system.id)}>
+ Copy IP address
+
+
+ Delete node
+
+
+
+ )
+ },
},
]
+ const [sorting, setSorting] = useState([])
+
+ const [columnFilters, setColumnFilters] = useState([])
+
const table = useReactTable({
data,
columns,
getCoreRowModel: getCoreRowModel(),
+ onSortingChange: setSorting,
+ getSortedRowModel: getSortedRowModel(),
+ onColumnFiltersChange: setColumnFilters,
+ getFilteredRowModel: getFilteredRowModel(),
+ state: {
+ sorting,
+ columnFilters,
+ },
})
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())}
-
- ))}
+ <>
+
+ table.getColumn('name')?.setFilterValue(event.target.value)}
+ className="max-w-sm"
+ />
+
+
+
+
+ {table.getHeaderGroups().map((headerGroup) => (
+
+ {headerGroup.headers.map((header) => {
+ return (
+
+ {header.isPlaceholder
+ ? null
+ : flexRender(header.column.columnDef.header, header.getContext())}
+
+ )
+ })}
- ))
- ) : (
-
-
- No results.
-
-
- )}
-
-
-
+ ))}
+
+
+ {table.getRowModel().rows?.length ? (
+ table.getRowModel().rows.map((row) => (
+
+ {row.getVisibleCells().map((cell) => (
+
+ {flexRender(cell.column.columnDef.cell, cell.getContext())}
+
+ ))}
+
+ ))
+ ) : (
+
+
+ No results.
+
+
+ )}
+
+
+
+ >
)
}